|
@@ -362,10 +362,11 @@ class ModbusNG : public QObject
|
362
|
362
|
public:
|
363
|
363
|
ModbusNG(DeviceTreeModel *model, const QModelIndex &index);
|
364
|
364
|
~ModbusNG();
|
365
|
|
- QList<Channel*> channels;
|
366
|
|
- QList<ModbusScanItem> scanList;
|
367
|
|
- QList<QString> channelNames;
|
368
|
|
- QList<bool> hiddenStates;
|
|
365
|
+ Q_INVOKABLE int channelCount();
|
|
366
|
+ Channel* getChannel(int);
|
|
367
|
+ Q_INVOKABLE QString channelColumnName(int);
|
|
368
|
+ Q_INVOKABLE QString channelIndicatorText(int);
|
|
369
|
+ Q_INVOKABLE bool isChannelHidden(int);
|
369
|
370
|
private slots:
|
370
|
371
|
void sendNextMessage();
|
371
|
372
|
void timeout();
|
|
@@ -378,6 +379,11 @@ class ModbusNG : public QObject
|
378
|
379
|
QTimer *commTimeout;
|
379
|
380
|
int scanPosition;
|
380
|
381
|
QByteArray responseBuffer;
|
|
382
|
+ QList<Channel*> channels;
|
|
383
|
+ QList<ModbusScanItem> scanList;
|
|
384
|
+ QList<QString> channelNames;
|
|
385
|
+ QList<QString> channelLabels;
|
|
386
|
+ QList<bool> hiddenStates;
|
381
|
387
|
};
|
382
|
388
|
|
383
|
389
|
@ One of the things that the old Modbus code got right was in allowing the
|
|
@@ -475,7 +481,9 @@ ModbusNG::ModbusNG(DeviceTreeModel *model, const QModelIndex &index) :
|
475
|
481
|
channelNames.append(channelAttributes.value("column").toString());
|
476
|
482
|
hiddenStates.append(
|
477
|
483
|
channelAttributes.value("hidden").toString() == "true" ? true : false);
|
|
484
|
+ channelLabels.append(model->data(channelIndex, 0).toString());
|
478
|
485
|
}
|
|
486
|
+ messageDelayTimer->start();
|
479
|
487
|
}
|
480
|
488
|
|
481
|
489
|
ModbusNG::~ModbusNG()
|
|
@@ -520,7 +528,6 @@ void ModbusNG::dataAvailable()
|
520
|
528
|
commTimeout->stop();
|
521
|
529
|
if(calculateCRC(responseBuffer) == 0)
|
522
|
530
|
{
|
523
|
|
- qDebug() << responseBuffer;
|
524
|
531
|
quint16 intresponse;
|
525
|
532
|
float floatresponse;
|
526
|
533
|
char *ibytes = (char*)&intresponse;
|
|
@@ -596,4 +603,83 @@ quint16 ModbusNG::calculateCRC(QByteArray data)
|
596
|
603
|
i++;
|
597
|
604
|
}
|
598
|
605
|
return retval;
|
599
|
|
-}
|
|
606
|
+}
|
|
607
|
+
|
|
608
|
+int ModbusNG::channelCount()
|
|
609
|
+{
|
|
610
|
+ return channels.size();
|
|
611
|
+}
|
|
612
|
+
|
|
613
|
+Channel* ModbusNG::getChannel(int channel)
|
|
614
|
+{
|
|
615
|
+ return channels.at(channel);
|
|
616
|
+}
|
|
617
|
+
|
|
618
|
+QString ModbusNG::channelColumnName(int channel)
|
|
619
|
+{
|
|
620
|
+ return channelNames.at(channel);
|
|
621
|
+}
|
|
622
|
+
|
|
623
|
+QString ModbusNG::channelIndicatorText(int channel)
|
|
624
|
+{
|
|
625
|
+ return channelLabels.at(channel);
|
|
626
|
+}
|
|
627
|
+
|
|
628
|
+bool ModbusNG::isChannelHidden(int channel)
|
|
629
|
+{
|
|
630
|
+ return hiddenStates.at(channel);
|
|
631
|
+}
|
|
632
|
+
|
|
633
|
+@ This class must be exposed to the host environment.
|
|
634
|
+
|
|
635
|
+@<Function prototypes for scripting@>=
|
|
636
|
+QScriptValue constructModbusNG(QScriptContext *context, QScriptEngine *engine);
|
|
637
|
+void setModbusNGProperties(QScriptValue value, QScriptEngine *engine);
|
|
638
|
+QScriptValue ModbusNG_getChannel(QScriptContext *context, QScriptEngine *engine);
|
|
639
|
+
|
|
640
|
+@ The host environment is informed of the constructor.
|
|
641
|
+
|
|
642
|
+@<Set up the scripting engine@>=
|
|
643
|
+constructor = engine->newFunction(constructModbusNG);
|
|
644
|
+value = engine->newQMetaObject(&ModbusNG::staticMetaObject, constructor);
|
|
645
|
+engine->globalObject().setProperty("ModbusNG", value);
|
|
646
|
+
|
|
647
|
+@ The constructor takes the configuration model and the index to the device as
|
|
648
|
+arguments.
|
|
649
|
+
|
|
650
|
+@<Functions for scripting@>=
|
|
651
|
+QScriptValue constructModbusNG(QScriptContext *context, QScriptEngine *engine)
|
|
652
|
+{
|
|
653
|
+ QScriptValue object;
|
|
654
|
+ if(context->argumentCount() == 2)
|
|
655
|
+ {
|
|
656
|
+ object = engine->newQObject(new ModbusNG(argument<DeviceTreeModel *>(0, context),
|
|
657
|
+ argument<QModelIndex>(1, context)),
|
|
658
|
+ QScriptEngine::ScriptOwnership);
|
|
659
|
+ setModbusNGProperties(object, engine);
|
|
660
|
+ }
|
|
661
|
+ else
|
|
662
|
+ {
|
|
663
|
+ context->throwError("Incorrect number of arguments passed to "@|
|
|
664
|
+ "ModbusNG constructor.");
|
|
665
|
+ }
|
|
666
|
+ return object;
|
|
667
|
+}
|
|
668
|
+
|
|
669
|
+void setModbusNGProperties(QScriptValue value, QScriptEngine *engine)
|
|
670
|
+{
|
|
671
|
+ setQObjectProperties(value, engine);
|
|
672
|
+ value.setProperty("getChannel", engine->newFunction(ModbusNG_getChannel));
|
|
673
|
+}
|
|
674
|
+
|
|
675
|
+QScriptValue ModbusNG_getChannel(QScriptContext *context, QScriptEngine *engine)
|
|
676
|
+{
|
|
677
|
+ ModbusNG *self = getself<ModbusNG *>(context);
|
|
678
|
+ QScriptValue object;
|
|
679
|
+ if(self)
|
|
680
|
+ {
|
|
681
|
+ object = engine->newQObject(self->getChannel(argument<int>(0, context)));
|
|
682
|
+ setChannelProperties(object, engine);
|
|
683
|
+ }
|
|
684
|
+ return object;
|
|
685
|
+}
|