Browse Source

Extend scale support

Neal Wilson 7 years ago
parent
commit
d921f1d0b8
5 changed files with 127 additions and 28 deletions
  1. 2
    0
      config/Windows/productionroaster.xml
  2. 12
    6
      src/moc_scale.cpp
  3. 13
    6
      src/moc_typica.cpp
  4. 32
    10
      src/scale.cpp
  5. 68
    6
      src/scales.w

+ 2
- 0
config/Windows/productionroaster.xml View File

@@ -628,6 +628,8 @@
628 628
 				scale.setParity(driverReference.parity);
629 629
 				scale.setStopBits(driverReference.stopbits);
630 630
 				scale.setFlowControl(driverReference.flowcontrol);
631
+				scale.setWeighCommand(driverReference.weighcommand);
632
+				scale.setCommandTerminator(driverReference.commandterminator);
631 633
 				scale.open(3);
632 634
 				window.scales.push(scale);
633 635
 			}

+ 12
- 6
src/moc_scale.cpp View File

@@ -22,7 +22,7 @@ static const uint qt_meta_data_SerialScale[] = {
22 22
        6,       // revision
23 23
        0,       // classname
24 24
        0,    0, // classinfo
25
-       4,   14, // methods
25
+       6,   14, // methods
26 26
        0,    0, // properties
27 27
        0,    0, // enums/sets
28 28
        0,    0, // constructors
@@ -35,7 +35,9 @@ static const uint qt_meta_data_SerialScale[] = {
35 35
  // slots: signature, parameters, type, tag, flags
36 36
       60,   12,   12,   12, 0x0a,
37 37
       67,   12,   12,   12, 0x0a,
38
-      75,   12,   12,   12, 0x08,
38
+      83,   75,   12,   12, 0x0a,
39
+     119,  108,   12,   12, 0x0a,
40
+     149,   12,   12,   12, 0x08,
39 41
 
40 42
        0        // eod
41 43
 };
@@ -43,7 +45,9 @@ static const uint qt_meta_data_SerialScale[] = {
43 45
 static const char qt_meta_stringdata_SerialScale[] = {
44 46
     "SerialScale\0\0weight,unit\0"
45 47
     "newMeasurement(double,Units::Unit)\0"
46
-    "tare()\0weigh()\0dataAvailable()\0"
48
+    "tare()\0weigh()\0command\0setWeighCommand(QString)\0"
49
+    "terminator\0setCommandTerminator(QString)\0"
50
+    "dataAvailable()\0"
47 51
 };
48 52
 
49 53
 void SerialScale::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
@@ -55,7 +59,9 @@ void SerialScale::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
55 59
         case 0: _t->newMeasurement((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< Units::Unit(*)>(_a[2]))); break;
56 60
         case 1: _t->tare(); break;
57 61
         case 2: _t->weigh(); break;
58
-        case 3: _t->dataAvailable(); break;
62
+        case 3: _t->setWeighCommand((*reinterpret_cast< const QString(*)>(_a[1]))); break;
63
+        case 4: _t->setCommandTerminator((*reinterpret_cast< const QString(*)>(_a[1]))); break;
64
+        case 5: _t->dataAvailable(); break;
59 65
         default: ;
60 66
         }
61 67
     }
@@ -93,9 +99,9 @@ int SerialScale::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
93 99
     if (_id < 0)
94 100
         return _id;
95 101
     if (_c == QMetaObject::InvokeMetaMethod) {
96
-        if (_id < 4)
102
+        if (_id < 6)
97 103
             qt_static_metacall(this, _c, _id, _a);
98
-        _id -= 4;
104
+        _id -= 6;
99 105
     }
100 106
     return _id;
101 107
 }

+ 13
- 6
src/moc_typica.cpp View File

@@ -7694,10 +7694,10 @@ static const uint qt_meta_data_SerialScaleConfWidget[] = {
7694 7694
        6,       // revision
7695 7695
        0,       // classname
7696 7696
        0,    0, // classinfo
7697
-       5,   14, // methods
7697
+       7,   14, // methods
7698 7698
        0,    0, // properties
7699 7699
        0,    0, // enums/sets
7700
-       1,   39, // constructors
7700
+       1,   49, // constructors
7701 7701
        0,       // flags
7702 7702
        0,       // signalCount
7703 7703
 
@@ -7707,9 +7707,11 @@ static const uint qt_meta_data_SerialScaleConfWidget[] = {
7707 7707
       86,   80,   22,   22, 0x08,
7708 7708
      104,   80,   22,   22, 0x08,
7709 7709
      127,   80,   22,   22, 0x08,
7710
+     155,  147,   22,   22, 0x08,
7711
+     194,  183,   22,   22, 0x08,
7710 7712
 
7711 7713
  // constructors: signature, parameters, type, tag, flags
7712
-     159,  147,   22,   22, 0x0e,
7714
+     239,  227,   22,   22, 0x0e,
7713 7715
 
7714 7716
        0        // eod
7715 7717
 };
@@ -7719,7 +7721,10 @@ static const char qt_meta_stringdata_SerialScaleConfWidget[] = {
7719 7721
     "updatePort(QString)\0rate\0"
7720 7722
     "updateBaudRate(QString)\0index\0"
7721 7723
     "updateParity(int)\0updateFlowControl(int)\0"
7722
-    "updateStopBits(int)\0model,index\0"
7724
+    "updateStopBits(int)\0command\0"
7725
+    "updateWeighCommand(QString)\0terminator\0"
7726
+    "updateCommandTerminator(QString)\0"
7727
+    "model,index\0"
7723 7728
     "SerialScaleConfWidget(DeviceTreeModel*,QModelIndex)\0"
7724 7729
 };
7725 7730
 
@@ -7739,6 +7744,8 @@ void SerialScaleConfWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c
7739 7744
         case 2: _t->updateParity((*reinterpret_cast< int(*)>(_a[1]))); break;
7740 7745
         case 3: _t->updateFlowControl((*reinterpret_cast< int(*)>(_a[1]))); break;
7741 7746
         case 4: _t->updateStopBits((*reinterpret_cast< int(*)>(_a[1]))); break;
7747
+        case 5: _t->updateWeighCommand((*reinterpret_cast< const QString(*)>(_a[1]))); break;
7748
+        case 6: _t->updateCommandTerminator((*reinterpret_cast< const QString(*)>(_a[1]))); break;
7742 7749
         default: ;
7743 7750
         }
7744 7751
     }
@@ -7776,9 +7783,9 @@ int SerialScaleConfWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
7776 7783
     if (_id < 0)
7777 7784
         return _id;
7778 7785
     if (_c == QMetaObject::InvokeMetaMethod) {
7779
-        if (_id < 5)
7786
+        if (_id < 7)
7780 7787
             qt_static_metacall(this, _c, _id, _a);
7781
-        _id -= 5;
7788
+        _id -= 7;
7782 7789
     }
7783 7790
     return _id;
7784 7791
 }

+ 32
- 10
src/scale.cpp View File

@@ -1,5 +1,5 @@
1 1
 /*1008:*/
2
-#line 131 "./scales.w"
2
+#line 135 "./scales.w"
3 3
 
4 4
 #include "scale.h"
5 5
 #include <QStringList> 
@@ -11,7 +11,7 @@ connect(this,SIGNAL(readyRead()),this,SLOT(dataAvailable()));
11 11
 }
12 12
 
13 13
 /*:1008*//*1009:*/
14
-#line 149 "./scales.w"
14
+#line 153 "./scales.w"
15 15
 
16 16
 void SerialScale::dataAvailable()
17 17
 {
@@ -25,7 +25,7 @@ responseBuffer.clear();
25 25
 else
26 26
 {
27 27
 /*1010:*/
28
-#line 189 "./scales.w"
28
+#line 193 "./scales.w"
29 29
 
30 30
 QStringList responseParts= QString(responseBuffer.simplified()).split(' ');
31 31
 if(responseParts.size()> 2)
@@ -35,26 +35,26 @@ responseParts.replace(0,QString("-%1").arg(responseParts[0]));
35 35
 }
36 36
 double weight= responseParts[0].toDouble();
37 37
 Units::Unit unit= Units::Unitless;
38
-if(responseParts[1]=="lb")
38
+if(responseParts[1].compare("lb",Qt::CaseInsensitive)==0)
39 39
 {
40 40
 unit= Units::Pound;
41 41
 }
42
-else if(responseParts[1]=="kg")
42
+else if(responseParts[1].compare("kg",Qt::CaseInsensitive)==0)
43 43
 {
44 44
 unit= Units::Kilogram;
45 45
 }
46
-else if(responseParts[1]=="g")
46
+else if(responseParts[1].compare("g",Qt::CaseInsensitive)==0)
47 47
 {
48 48
 unit= Units::Gram;
49 49
 }
50
-else if(responseParts[1]=="oz")
50
+else if(responseParts[1].compare("oz",Qt::CaseInsensitive)==0)
51 51
 {
52 52
 unit= Units::Ounce;
53 53
 }
54 54
 emit newMeasurement(weight,unit);
55 55
 
56 56
 /*:1010*/
57
-#line 161 "./scales.w"
57
+#line 165 "./scales.w"
58 58
 
59 59
 responseBuffer.clear();
60 60
 }
@@ -62,7 +62,7 @@ responseBuffer.clear();
62 62
 }
63 63
 
64 64
 /*:1009*//*1011:*/
65
-#line 220 "./scales.w"
65
+#line 224 "./scales.w"
66 66
 
67 67
 void SerialScale::tare()
68 68
 {
@@ -71,7 +71,29 @@ write("!KT\x0D");
71 71
 
72 72
 void SerialScale::weigh()
73 73
 {
74
-write("!KP\x0D");
74
+
75
+write(weighCommand+commandTerminator);
76
+}
77
+
78
+void SerialScale::setWeighCommand(const QString&command)
79
+{
80
+weighCommand= command.toAscii();
81
+}
82
+
83
+void SerialScale::setCommandTerminator(const QString&terminator)
84
+{
85
+if(terminator=="CRLF")
86
+{
87
+commandTerminator= "\x0D\x0A";
88
+}
89
+else if(terminator=="CR")
90
+{
91
+commandTerminator= "\x0D";
92
+}
93
+else if(terminator=="LF")
94
+{
95
+commandTerminator= "\x0A";
96
+}
75 97
 }
76 98
 
77 99
 /*:1011*/

+ 68
- 6
src/scales.w View File

@@ -115,12 +115,16 @@ class SerialScale : public QextSerialPort
115 115
 	public slots:
116 116
 		void tare();
117 117
 		void weigh();
118
+		void setWeighCommand(const QString &command);
119
+		void setCommandTerminator(const QString &terminator);
118 120
 	signals:
119 121
 		void newMeasurement(double weight, Units::Unit unit);
120 122
 	private slots:
121 123
 		void dataAvailable();
122 124
 	private:
123 125
 		QByteArray responseBuffer;
126
+		QByteArray weighCommand;
127
+		QByteArray commandTerminator;
124 128
 };
125 129
 
126 130
 #endif
@@ -195,19 +199,19 @@ if(responseParts.size() > 2)
195 199
 }
196 200
 double weight = responseParts[0].toDouble();
197 201
 Units::Unit unit = Units::Unitless;
198
-if(responseParts[1] == "lb")
202
+if(responseParts[1].compare("lb", Qt::CaseInsensitive) == 0)
199 203
 {
200 204
 	unit = Units::Pound;
201 205
 }
202
-else if(responseParts[1] == "kg")
206
+else if(responseParts[1].compare("kg", Qt::CaseInsensitive) == 0)
203 207
 {
204 208
 	unit = Units::Kilogram;
205 209
 }
206
-else if(responseParts[1] == "g")
210
+else if(responseParts[1].compare("g", Qt::CaseInsensitive) == 0)
207 211
 {
208 212
 	unit = Units::Gram;
209 213
 }
210
-else if(responseParts[1] == "oz")
214
+else if(responseParts[1].compare("oz", Qt::CaseInsensitive) == 0)
211 215
 {
212 216
 	unit = Units::Ounce;
213 217
 }
@@ -225,7 +229,29 @@ void SerialScale::tare()
225 229
 
226 230
 void SerialScale::weigh()
227 231
 {
228
-	write("!KP\x0D");
232
+	//write("!KP\x0D");
233
+	write(weighCommand + commandTerminator);
234
+}
235
+
236
+void SerialScale::setWeighCommand(const QString &command)
237
+{
238
+	weighCommand = command.toAscii();
239
+}
240
+
241
+void SerialScale::setCommandTerminator(const QString &terminator)
242
+{
243
+	if(terminator == "CRLF")
244
+	{
245
+		commandTerminator = "\x0D\x0A";
246
+	}
247
+	else if(terminator == "CR")
248
+	{
249
+		commandTerminator = "\x0D";
250
+	}
251
+	else if(terminator == "LF")
252
+	{
253
+		commandTerminator = "\x0A";
254
+	}
229 255
 }
230 256
 
231 257
 @ This must be available to the host environment.
@@ -380,12 +406,16 @@ class SerialScaleConfWidget : public BasicDeviceConfigurationWidget
380 406
 		void updateParity(int index);
381 407
 		void updateFlowControl(int index);
382 408
 		void updateStopBits(int index);
409
+		void updateWeighCommand(const QString &command);
410
+		void updateCommandTerminator(const QString &terminator);
383 411
 	private:
384 412
 		PortSelector *port;
385 413
 		BaudSelector *baud;
386 414
 		ParitySelector *parity;
387 415
 		FlowSelector *flow;
388 416
 		StopSelector *stop;
417
+		QLineEdit *weighcommand;
418
+		QComboBox *commandterminator;
389 419
 };
390 420
 
391 421
 @ This is very similar to other configuration widgets.
@@ -395,7 +425,8 @@ SerialScaleConfWidget::SerialScaleConfWidget(DeviceTreeModel *model,
395 425
                                              const QModelIndex &index)
396 426
 : BasicDeviceConfigurationWidget(model, index),
397 427
   port(new PortSelector), baud(new BaudSelector), parity(new ParitySelector),
398
-  flow(new FlowSelector), stop(new StopSelector)
428
+  flow(new FlowSelector), stop(new StopSelector),
429
+  weighcommand(new QLineEdit("!KP")), commandterminator(new QComboBox)
399 430
 {
400 431
 	QFormLayout *layout = new QFormLayout;
401 432
 	layout->addRow(tr("Port:"), port);
@@ -415,6 +446,16 @@ SerialScaleConfWidget::SerialScaleConfWidget(DeviceTreeModel *model,
415 446
 	layout->addRow(tr("Stop Bits:"), stop);
416 447
 	connect(stop, SIGNAL(currentIndexChanged(int)),
417 448
 	        this, SLOT(updateStopBits(int)));
449
+	layout->addRow(tr("Weigh Command:"), weighcommand);
450
+	connect(weighcommand, SIGNAL(textChanged(QString)),
451
+	        this, SLOT(updateWeighCommand(QString)));
452
+	commandterminator->addItem("CRLF");
453
+	commandterminator->addItem("CR");
454
+	commandterminator->addItem("LF");
455
+	layout->addRow(tr("Command Terminator:"), commandterminator);
456
+	connect(commandterminator, SIGNAL(currentIndexChanged(QString)),
457
+	        this, SLOT(updateCommandTerminator(QString)));
458
+	
418 459
 	@<Get device configuration data for current node@>@;
419 460
 	for(int i = 0; i < configData.size(); i++)
420 461
 	{
@@ -448,12 +489,23 @@ SerialScaleConfWidget::SerialScaleConfWidget(DeviceTreeModel *model,
448 489
 		{
449 490
 			stop->setCurrentIndex(stop->findData(node.attribute("value")));
450 491
 		}
492
+		else if(node.attribute("name") == "weighcommand")
493
+		{
494
+			weighcommand->setText(node.attribute("value"));
495
+		}
496
+		else if(node.attribute("name") == "commandterminator")
497
+		{
498
+			commandterminator->setCurrentIndex(
499
+				commandterminator->findText(node.attribute("value")));
500
+		}
451 501
 	}
452 502
 	updatePort(port->currentText());
453 503
 	updateBaudRate(baud->currentText());
454 504
 	updateParity(parity->currentIndex());
455 505
 	updateFlowControl(flow->currentIndex());
456 506
 	updateStopBits(stop->currentIndex());
507
+	updateWeighCommand(weighcommand->text());
508
+	updateCommandTerminator(commandterminator->currentText());
457 509
 	setLayout(layout);
458 510
 }
459 511
 
@@ -485,6 +537,16 @@ void SerialScaleConfWidget::updateStopBits(int index)
485 537
 	updateAttribute("stopbits", stop->itemData(index).toString());
486 538
 }
487 539
 
540
+void SerialScaleConfWidget::updateWeighCommand(const QString &command)
541
+{
542
+	updateAttribute("weighcommand", command);
543
+}
544
+
545
+void SerialScaleConfWidget::updateCommandTerminator(const QString &terminator)
546
+{
547
+	updateAttribute("commandterminator", terminator);
548
+}
549
+
488 550
 @ The configuration widget is registered with the configuration system.
489 551
 
490 552
 @<Register device configuration widgets@>=

Loading…
Cancel
Save