Преглед на файлове

Allow external reporting of detected hardware

Neal Wilson преди 11 години
родител
ревизия
b92e42049d
променени са 1 файла, в които са добавени 50 реда и са изтрити 24 реда
  1. 50
    24
      src/dataqsdk.w

+ 50
- 24
src/dataqsdk.w Целия файл

@@ -30,6 +30,7 @@ class DataqSdkDevice : public QObject
30 30
 		Channel* newChannel(Units::Unit scale);
31 31
 		Q_INVOKABLE void setClockRate(double Hz);
32 32
 		Q_INVOKABLE void start();
33
+		QStringList detectPorts();
33 34
 };
34 35
 
35 36
 @ The |DataqSdkDevice| class has as a private member an instance of a class
@@ -419,15 +420,12 @@ void DataqSdkDevice::start()
419 420
 	imp->start();
420 421
 }
421 422
 
422
-@ Setting up the device begins by constructing a new |DataqSdkDevice| object.
423
-The constructor takes as its argument a string which identifies the device. For
424
-legacy reasons this currently accepts device names such as |"Dev1"| and looks
425
-up currently connected devices to determine which serial port should be used.
426
-Now that it is preferred to configure devices graphically this is not a good
427
-way to do this. This should be changed before release.
423
+@ When configuring Typica to use a device supported through the DATAQ SDK it is
424
+useful to have a way to report the ports where supported hardware has been
425
+detected. This is also used for automatic detection.
428 426
 
429 427
 @<DataqSdkDevice implementation@>=
430
-DataqSdkDevice::DataqSdkDevice(QString device) : imp(new DataqSdkDeviceImplementation)
428
+QStringList DataqSdkDevice::detectPorts()
431 429
 {
432 430
 	QSettings deviceLookup("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\usbser\\Enum",
433 431
 	             QSettings::NativeFormat);
@@ -441,34 +439,62 @@ DataqSdkDevice::DataqSdkDevice(QString device) : imp(new DataqSdkDeviceImplement
441 439
 			devices.append(value.split("\\").at(2));
442 440
 		}
443 441
 	}
444
-	device = device.remove(0, 3);
445
-	int index = device.toInt() - 1;
446
-	if(index >= 0 && index < devices.size())
442
+	QStringList portList;
443
+	foreach(QString device, devices)
447 444
 	{
448
-		QString deviceKey = QString(
449
-		"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_0683&PID_1450\\%1").
450
-			arg(devices.at(index));
445
+		QString deviceKey = QString("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_0683&PID_1450\\%1").arg(device);
451 446
 		QSettings deviceEntry(deviceKey, QSettings::NativeFormat);
452
-		QString portString = deviceEntry.value("FriendlyName").toString();
453
-		int rstart = portString.indexOf("COM");
454
-		portString.remove(0, rstart + 3);
455
-		portString.chop(1);
456
-		if(portString.toInt() < 10)
447
+		QString friendlyName = deviceEntry.value("FriendlyName").toString();
448
+		friendlyName.remove(0, friendlyName.indexOf("COM"));
449
+		friendlyName.chop(1);
450
+		portList.append(friendlyName);
451
+	}
452
+	return portList;
453
+}
454
+
455
+@ Setting up the device begins by constructing a new |DataqSdkDevice| object.
456
+The constructor takes as its argument a string which identifies the device. For
457
+legacy reasons this currently accepts device names such as |"Dev1"| and looks
458
+up currently connected devices to determine which serial port should be used.
459
+Now that it is preferred to configure devices graphically this is not a good
460
+way to do this. This should be changed before release.
461
+
462
+@<DataqSdkDevice implementation@>=
463
+DataqSdkDevice::DataqSdkDevice(QString device) : imp(new DataqSdkDeviceImplementation)
464
+{
465
+	bool usesAuto = false;
466
+	int autoIndex = device.toInt(&usesAuto);
467
+	QString finalizedPort;
468
+	if(usesAuto)
469
+	{
470
+		QStringList portList = detectPorts();
471
+		if(autoIndex > 0 && autoIndex <= portList.size())
457 472
 		{
458
-			imp->device = QString("DI10%1NT.DLL").arg(portString);
473
+			finalizedPort = portList.at(autoIndex - 1);
459 474
 		}
460 475
 		else
461 476
 		{
462
-			imp->device = QString("DI1%1NT.DLL").arg(portString);
477
+			imp->error = 8; // Failed to find device.
478
+			qDebug() << "Failed to detect port.";
463 479
 		}
464
-		imp->deviceNumber = 0x12C02D00;
465
-		imp->deviceNumber += portString.toInt();
466
-		imp->ready = true;
467 480
 	}
468 481
 	else
469 482
 	{
470
-		imp->error = 8; // Failed to find device.
483
+		finalizedPort = device;
484
+	}
485
+	int rstart = finalizedPort.indexOf("COM");
486
+	finalizedPort.remove(0, rstart + 3);
487
+	if(finalizedPort.toInt() < 10)
488
+	{
489
+		imp->device = QString("DI10%1NT.DLL").arg(finalizedPort);
490
+	}
491
+	else
492
+	{
493
+		imp->device = QString("DI1%1NT.DLL").arg(finalizedPort);
471 494
 	}
495
+	imp->deviceNumber = 0x12C02D00;
496
+	imp->deviceNumber += finalizedPort.toInt();
497
+	imp->ready = true;
472 498
 }
473 499
 
474 500
 @ Once the |DataqSdkDevice| is created, one or more channels can be added.

Loading…
Отказ
Запис