|
@@ -631,7 +631,8 @@ void setDataqSdkDeviceProperties(QScriptValue value, QScriptEngine *engine)
|
631
|
631
|
value.setProperty("newChannel", engine->newFunction(DataqSdkDevice_newChannel));
|
632
|
632
|
}
|
633
|
633
|
|
634
|
|
-@ The |newChannel()| wrapper requires two arguments.
|
|
634
|
+@ The |newChannel()| wrapper requires one argument to specify the measurement
|
|
635
|
+unit that will eventually be produced from that channel.
|
635
|
636
|
|
636
|
637
|
@<Functions for scripting@>=
|
637
|
638
|
QScriptValue DataqSdkDevice_newChannel(QScriptContext *context, QScriptEngine *engine)
|
|
@@ -644,4 +645,154 @@ QScriptValue DataqSdkDevice_newChannel(QScriptContext *context, QScriptEngine *e
|
644
|
645
|
setChannelProperties(object, engine);
|
645
|
646
|
}
|
646
|
647
|
return object;
|
647
|
|
-}
|
|
648
|
+}
|
|
649
|
+
|
|
650
|
+@ In order to configure supported devices within Typica, a set of configuration
|
|
651
|
+controls is required. First there is the base device configuration widget.
|
|
652
|
+
|
|
653
|
+@<Class declarations@>=
|
|
654
|
+class DataqSdkDeviceConfWidget : public BasicDeviceConfigurationWidget
|
|
655
|
+{
|
|
656
|
+ Q_OBJECT
|
|
657
|
+ public:
|
|
658
|
+ Q_INVOKABLE DataqSdkDeviceConfWidget(DeviceTreeModel *model,
|
|
659
|
+ const QModelIndex &index);
|
|
660
|
+ private slots:
|
|
661
|
+ void updateAutoSelect(bool automatic);
|
|
662
|
+ void updateDeviceNumber(int deviceNumber);
|
|
663
|
+ void updatePort(QString portId);
|
|
664
|
+ void addChannel();
|
|
665
|
+ private:
|
|
666
|
+ QStackedWidget *deviceIdStack;
|
|
667
|
+};
|
|
668
|
+
|
|
669
|
+@ The constructor sets up the interface for updating device configuration
|
|
670
|
+settings.
|
|
671
|
+
|
|
672
|
+@<DataqSdkDeviceConfWidget implementation@>=
|
|
673
|
+DataqSdkDeviceConfWidget::DataqSdkDeviceConfWidget(DeviceTreeModel *model,
|
|
674
|
+ const QModelIndex &index)
|
|
675
|
+ : BasicDeviceConfigurationWidget(model, index),
|
|
676
|
+ deviceIdStack(new QStackedWidget)
|
|
677
|
+{
|
|
678
|
+ QVBoxLayout *layout = new QVBoxLayout;
|
|
679
|
+ QCheckBox *autoDetect = new QCheckBox("Automatically select device");
|
|
680
|
+ layout->addWidget(autoDetect);
|
|
681
|
+ QWidget *autoLayerWidget = new QWidget;
|
|
682
|
+ QHBoxLayout *autoLayerLayout = new QHBoxLayout;
|
|
683
|
+ QLabel *autoLabel = new QLabel(tr("Device number"));
|
|
684
|
+ QSpinBox *autoNumber = new QSpinBox;
|
|
685
|
+ autoNumber->setMinimum(1);
|
|
686
|
+ autoNumber->setMaximum(99);
|
|
687
|
+ autoLayerLayout->addWidget(autoLabel);
|
|
688
|
+ autoLayerLayout->addWidget(autoNumber);
|
|
689
|
+ autoLayerWidget->setLayout(autoLayerLayout);
|
|
690
|
+ QWidget *fixedLayerWidget = new QWidget;
|
|
691
|
+ QHBoxLayout *fixedLayerLayout = new QHBoxLayout;
|
|
692
|
+ QLabel *fixedLabel = new QLabel(tr("Device port"));
|
|
693
|
+ QComboBox *portSelection = new QComboBox;
|
|
694
|
+ portSelection->setEditable(true);
|
|
695
|
+ portSelection->addItems(DataqSdkDevice::detectHardware());
|
|
696
|
+ fixedLayerLayout->addWidget(fixedLabel);
|
|
697
|
+ fixedLayerLayout->addWidget(portSelection);
|
|
698
|
+ fixedLayerWidget->setLayout(fixedLayerLayout);
|
|
699
|
+ deviceIdStack->addWidget(autoLayerWidget);
|
|
700
|
+ deviceIdStack->addWidget(fixedLayerWidget);
|
|
701
|
+ layout->addWidget(deviceIdStack);
|
|
702
|
+ QPushButton *addChannelButton = new QPushButton(tr("Add Channel"));
|
|
703
|
+ layout->addWidget(addChannelButton);
|
|
704
|
+ @<Get device configuration data for current node@>@;
|
|
705
|
+ for(int i = 0; i < configData.size(); i++)
|
|
706
|
+ {
|
|
707
|
+ node = configData.at(i).toElement();
|
|
708
|
+ if(node.attribute("name") == "autoSelect")
|
|
709
|
+ {
|
|
710
|
+ autoDetect->setChecked(node.attribute("value") == "true" ? true : false);
|
|
711
|
+ }
|
|
712
|
+ else if(node.attribute("name") == "deviceNumber")
|
|
713
|
+ {
|
|
714
|
+ autoNumber->setValue(node.attribute("value").toInt());
|
|
715
|
+ }
|
|
716
|
+ else if(node.attribute("name") == "port")
|
|
717
|
+ {
|
|
718
|
+ int index = portSelection->findText(node.attribute("value"));
|
|
719
|
+ if(index > -1)
|
|
720
|
+ {
|
|
721
|
+ portSelection->setCurrentIndex(index);
|
|
722
|
+ }
|
|
723
|
+ else
|
|
724
|
+ {
|
|
725
|
+ portSelection->setEditText(node.attribute("value"));
|
|
726
|
+ }
|
|
727
|
+ }
|
|
728
|
+ }
|
|
729
|
+ updateAutoSelect(autoDetect->isChecked());
|
|
730
|
+ updateDeviceNumber(autoNumber->value());
|
|
731
|
+ updatePort(portSelection->currentText());
|
|
732
|
+ connect(autoDetect, SIGNAL(toggled(bool)), this, SLOT(updateAutoSelect(bool)));
|
|
733
|
+ connect(autoNumber, SIGNAL(valueChanged(int)), this, SLOT(updateDeviceNumber(int)));
|
|
734
|
+ connect(portSelection, SIGNAL(currentIndexChanged(QString)), this, SLOT(updatePort(QString)));
|
|
735
|
+ connect(addChannelButton, SIGNAL(clicked()), this, SLOT(addChannel()));
|
|
736
|
+ setLayout(layout);
|
|
737
|
+}
|
|
738
|
+
|
|
739
|
+@ In addition to setting a value in the device configuration, the choice to
|
|
740
|
+automatically select devices also requires changing which controls in the
|
|
741
|
+configuration widget are presently available. It is recommended that automatic
|
|
742
|
+device selection is only used in cases where there is a single device supported
|
|
743
|
+by the DATAQ SDK present and it will always be the first detected device
|
|
744
|
+regardless of the current virtual COM port number. In cases where multiple
|
|
745
|
+devices must be connected, it is recommended to always plug devices into the
|
|
746
|
+same port and specify the port for each device explicitly.
|
|
747
|
+
|
|
748
|
+@<DataqSdkDeviceConfWidget implementation@>=
|
|
749
|
+void DataqSdkDeviceConfWidget::updateAutoSelect(bool automatic)
|
|
750
|
+{
|
|
751
|
+ if(automatic)
|
|
752
|
+ {
|
|
753
|
+ updateAttribute("autoSelect", "true");
|
|
754
|
+ deviceIdStack->setCurrentIndex(0);
|
|
755
|
+ }
|
|
756
|
+ else
|
|
757
|
+ {
|
|
758
|
+ updateAttribute("autoSelect", "false");
|
|
759
|
+ deviceIdStack->setCurrentIndex(1);
|
|
760
|
+ }
|
|
761
|
+}
|
|
762
|
+
|
|
763
|
+@ Other update methods only need to set a new current value.
|
|
764
|
+
|
|
765
|
+@<DataqSdkDeviceConfWidget implementation@>=
|
|
766
|
+void DataqSdkDeviceConfWidget::updateDeviceNumber(int deviceNumber)
|
|
767
|
+{
|
|
768
|
+ updateAttribute("deviceNumber", QString("%1").arg(deviceNumber));
|
|
769
|
+}
|
|
770
|
+
|
|
771
|
+void DataqSdkDeviceConfWidget::updatePort(QString portId)
|
|
772
|
+{
|
|
773
|
+ updateAttribute("port", portId);
|
|
774
|
+}
|
|
775
|
+
|
|
776
|
+@ The Add Channel button creates a new configuration node.
|
|
777
|
+
|
|
778
|
+@<DataqSdkDeviceConfWidget implementation@>=
|
|
779
|
+void DataqSdkDeviceConfWidget::addChannel()
|
|
780
|
+{
|
|
781
|
+ insertChildNode(tr("Channel"), "dataqsdkchannel");
|
|
782
|
+}
|
|
783
|
+
|
|
784
|
+@ These configuration widgets are registered with the configuration system.
|
|
785
|
+
|
|
786
|
+@<Register device configuration widgets@>=
|
|
787
|
+app.registerDeviceConfigurationWidget("dataqsdk", DataqSdkDeviceConfWidget::staticMetaObject);
|
|
788
|
+
|
|
789
|
+@ A |NodeInserter| is also added to provide access to
|
|
790
|
+|DataqSdkDeviceConfWidget|, but only on Windows.
|
|
791
|
+
|
|
792
|
+@<Register top level device configuration nodes@>=
|
|
793
|
+#ifdef Q_OS_WIN32
|
|
794
|
+inserter = new NodeInserter(tr("DATAQ SDK Device"), tr("DATAQ Device"),
|
|
795
|
+ "dataqsdk", NULL);
|
|
796
|
+topLevelNodeInserters.append(inserter);
|
|
797
|
+#endif
|
|
798
|
+
|