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
 				scale.setParity(driverReference.parity);
628
 				scale.setParity(driverReference.parity);
629
 				scale.setStopBits(driverReference.stopbits);
629
 				scale.setStopBits(driverReference.stopbits);
630
 				scale.setFlowControl(driverReference.flowcontrol);
630
 				scale.setFlowControl(driverReference.flowcontrol);
631
+				scale.setWeighCommand(driverReference.weighcommand);
632
+				scale.setCommandTerminator(driverReference.commandterminator);
631
 				scale.open(3);
633
 				scale.open(3);
632
 				window.scales.push(scale);
634
 				window.scales.push(scale);
633
 			}
635
 			}

+ 12
- 6
src/moc_scale.cpp View File

22
        6,       // revision
22
        6,       // revision
23
        0,       // classname
23
        0,       // classname
24
        0,    0, // classinfo
24
        0,    0, // classinfo
25
-       4,   14, // methods
25
+       6,   14, // methods
26
        0,    0, // properties
26
        0,    0, // properties
27
        0,    0, // enums/sets
27
        0,    0, // enums/sets
28
        0,    0, // constructors
28
        0,    0, // constructors
35
  // slots: signature, parameters, type, tag, flags
35
  // slots: signature, parameters, type, tag, flags
36
       60,   12,   12,   12, 0x0a,
36
       60,   12,   12,   12, 0x0a,
37
       67,   12,   12,   12, 0x0a,
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
        0        // eod
42
        0        // eod
41
 };
43
 };
43
 static const char qt_meta_stringdata_SerialScale[] = {
45
 static const char qt_meta_stringdata_SerialScale[] = {
44
     "SerialScale\0\0weight,unit\0"
46
     "SerialScale\0\0weight,unit\0"
45
     "newMeasurement(double,Units::Unit)\0"
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
 void SerialScale::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
53
 void SerialScale::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
55
         case 0: _t->newMeasurement((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< Units::Unit(*)>(_a[2]))); break;
59
         case 0: _t->newMeasurement((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< Units::Unit(*)>(_a[2]))); break;
56
         case 1: _t->tare(); break;
60
         case 1: _t->tare(); break;
57
         case 2: _t->weigh(); break;
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
         default: ;
65
         default: ;
60
         }
66
         }
61
     }
67
     }
93
     if (_id < 0)
99
     if (_id < 0)
94
         return _id;
100
         return _id;
95
     if (_c == QMetaObject::InvokeMetaMethod) {
101
     if (_c == QMetaObject::InvokeMetaMethod) {
96
-        if (_id < 4)
102
+        if (_id < 6)
97
             qt_static_metacall(this, _c, _id, _a);
103
             qt_static_metacall(this, _c, _id, _a);
98
-        _id -= 4;
104
+        _id -= 6;
99
     }
105
     }
100
     return _id;
106
     return _id;
101
 }
107
 }

+ 13
- 6
src/moc_typica.cpp View File

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

+ 32
- 10
src/scale.cpp View File

1
 /*1008:*/
1
 /*1008:*/
2
-#line 131 "./scales.w"
2
+#line 135 "./scales.w"
3
 
3
 
4
 #include "scale.h"
4
 #include "scale.h"
5
 #include <QStringList> 
5
 #include <QStringList> 
11
 }
11
 }
12
 
12
 
13
 /*:1008*//*1009:*/
13
 /*:1008*//*1009:*/
14
-#line 149 "./scales.w"
14
+#line 153 "./scales.w"
15
 
15
 
16
 void SerialScale::dataAvailable()
16
 void SerialScale::dataAvailable()
17
 {
17
 {
25
 else
25
 else
26
 {
26
 {
27
 /*1010:*/
27
 /*1010:*/
28
-#line 189 "./scales.w"
28
+#line 193 "./scales.w"
29
 
29
 
30
 QStringList responseParts= QString(responseBuffer.simplified()).split(' ');
30
 QStringList responseParts= QString(responseBuffer.simplified()).split(' ');
31
 if(responseParts.size()> 2)
31
 if(responseParts.size()> 2)
35
 }
35
 }
36
 double weight= responseParts[0].toDouble();
36
 double weight= responseParts[0].toDouble();
37
 Units::Unit unit= Units::Unitless;
37
 Units::Unit unit= Units::Unitless;
38
-if(responseParts[1]=="lb")
38
+if(responseParts[1].compare("lb",Qt::CaseInsensitive)==0)
39
 {
39
 {
40
 unit= Units::Pound;
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
 unit= Units::Kilogram;
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
 unit= Units::Gram;
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
 unit= Units::Ounce;
52
 unit= Units::Ounce;
53
 }
53
 }
54
 emit newMeasurement(weight,unit);
54
 emit newMeasurement(weight,unit);
55
 
55
 
56
 /*:1010*/
56
 /*:1010*/
57
-#line 161 "./scales.w"
57
+#line 165 "./scales.w"
58
 
58
 
59
 responseBuffer.clear();
59
 responseBuffer.clear();
60
 }
60
 }
62
 }
62
 }
63
 
63
 
64
 /*:1009*//*1011:*/
64
 /*:1009*//*1011:*/
65
-#line 220 "./scales.w"
65
+#line 224 "./scales.w"
66
 
66
 
67
 void SerialScale::tare()
67
 void SerialScale::tare()
68
 {
68
 {
71
 
71
 
72
 void SerialScale::weigh()
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
 /*:1011*/
99
 /*:1011*/

+ 68
- 6
src/scales.w View File

115
 	public slots:
115
 	public slots:
116
 		void tare();
116
 		void tare();
117
 		void weigh();
117
 		void weigh();
118
+		void setWeighCommand(const QString &command);
119
+		void setCommandTerminator(const QString &terminator);
118
 	signals:
120
 	signals:
119
 		void newMeasurement(double weight, Units::Unit unit);
121
 		void newMeasurement(double weight, Units::Unit unit);
120
 	private slots:
122
 	private slots:
121
 		void dataAvailable();
123
 		void dataAvailable();
122
 	private:
124
 	private:
123
 		QByteArray responseBuffer;
125
 		QByteArray responseBuffer;
126
+		QByteArray weighCommand;
127
+		QByteArray commandTerminator;
124
 };
128
 };
125
 
129
 
126
 #endif
130
 #endif
195
 }
199
 }
196
 double weight = responseParts[0].toDouble();
200
 double weight = responseParts[0].toDouble();
197
 Units::Unit unit = Units::Unitless;
201
 Units::Unit unit = Units::Unitless;
198
-if(responseParts[1] == "lb")
202
+if(responseParts[1].compare("lb", Qt::CaseInsensitive) == 0)
199
 {
203
 {
200
 	unit = Units::Pound;
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
 	unit = Units::Kilogram;
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
 	unit = Units::Gram;
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
 	unit = Units::Ounce;
216
 	unit = Units::Ounce;
213
 }
217
 }
225
 
229
 
226
 void SerialScale::weigh()
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
 @ This must be available to the host environment.
257
 @ This must be available to the host environment.
380
 		void updateParity(int index);
406
 		void updateParity(int index);
381
 		void updateFlowControl(int index);
407
 		void updateFlowControl(int index);
382
 		void updateStopBits(int index);
408
 		void updateStopBits(int index);
409
+		void updateWeighCommand(const QString &command);
410
+		void updateCommandTerminator(const QString &terminator);
383
 	private:
411
 	private:
384
 		PortSelector *port;
412
 		PortSelector *port;
385
 		BaudSelector *baud;
413
 		BaudSelector *baud;
386
 		ParitySelector *parity;
414
 		ParitySelector *parity;
387
 		FlowSelector *flow;
415
 		FlowSelector *flow;
388
 		StopSelector *stop;
416
 		StopSelector *stop;
417
+		QLineEdit *weighcommand;
418
+		QComboBox *commandterminator;
389
 };
419
 };
390
 
420
 
391
 @ This is very similar to other configuration widgets.
421
 @ This is very similar to other configuration widgets.
395
                                              const QModelIndex &index)
425
                                              const QModelIndex &index)
396
 : BasicDeviceConfigurationWidget(model, index),
426
 : BasicDeviceConfigurationWidget(model, index),
397
   port(new PortSelector), baud(new BaudSelector), parity(new ParitySelector),
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
 	QFormLayout *layout = new QFormLayout;
431
 	QFormLayout *layout = new QFormLayout;
401
 	layout->addRow(tr("Port:"), port);
432
 	layout->addRow(tr("Port:"), port);
415
 	layout->addRow(tr("Stop Bits:"), stop);
446
 	layout->addRow(tr("Stop Bits:"), stop);
416
 	connect(stop, SIGNAL(currentIndexChanged(int)),
447
 	connect(stop, SIGNAL(currentIndexChanged(int)),
417
 	        this, SLOT(updateStopBits(int)));
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
 	@<Get device configuration data for current node@>@;
459
 	@<Get device configuration data for current node@>@;
419
 	for(int i = 0; i < configData.size(); i++)
460
 	for(int i = 0; i < configData.size(); i++)
420
 	{
461
 	{
448
 		{
489
 		{
449
 			stop->setCurrentIndex(stop->findData(node.attribute("value")));
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
 	updatePort(port->currentText());
502
 	updatePort(port->currentText());
453
 	updateBaudRate(baud->currentText());
503
 	updateBaudRate(baud->currentText());
454
 	updateParity(parity->currentIndex());
504
 	updateParity(parity->currentIndex());
455
 	updateFlowControl(flow->currentIndex());
505
 	updateFlowControl(flow->currentIndex());
456
 	updateStopBits(stop->currentIndex());
506
 	updateStopBits(stop->currentIndex());
507
+	updateWeighCommand(weighcommand->text());
508
+	updateCommandTerminator(commandterminator->currentText());
457
 	setLayout(layout);
509
 	setLayout(layout);
458
 }
510
 }
459
 
511
 
485
 	updateAttribute("stopbits", stop->itemData(index).toString());
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
 @ The configuration widget is registered with the configuration system.
550
 @ The configuration widget is registered with the configuration system.
489
 
551
 
490
 @<Register device configuration widgets@>=
552
 @<Register device configuration widgets@>=

Loading…
Cancel
Save