|
@@ -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@>=
|