|
|
@ -14,7 +14,7 @@ MainWindow::MainWindow(QWidget *parent) |
|
|
|
ui->writeTable->addItem(tr("Holding Registers"), 3); |
|
|
|
|
|
|
|
// the thread starts the event loop and blocks waiting for events
|
|
|
|
// connect(modBusObj, &modBusMaster::modbusConnectionState, this, &MainWindow::connectionState);
|
|
|
|
// connect(modBusObj, &modBusMaster::modbusConnectionState, this, &MainWindow::connectionState);
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
@ -26,15 +26,15 @@ MainWindow::~MainWindow() |
|
|
|
|
|
|
|
void MainWindow::on_connectButton_clicked() |
|
|
|
{ |
|
|
|
qDebug() << " QThread::currentThreadId() MainWindow on_connectButton_clicked" <<QThread::currentThreadId() ; |
|
|
|
qDebug() << " QThread::currentThreadId() MainWindow on_connectButton_clicked" <<QThread::currentThreadId() ; |
|
|
|
if( ui->connectButton->text()==tr("Disconnect")) |
|
|
|
{ |
|
|
|
modBusWrapperObj.stopWrapper(); |
|
|
|
modBusWrapper.stop(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
qDebug() << "on_connectButton_clicked else ui " << QThread::currentThreadId(); |
|
|
|
modBusWrapperObj.initWrapper(ui->portEdit->text(),ui->serverEdit->value()); |
|
|
|
qDebug() << "on_connectButton_clicked else ui " << QThread::currentThreadId(); |
|
|
|
modBusWrapper.init(ui->portEdit->text(),ui->serverEdit->value()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -45,14 +45,14 @@ void MainWindow::on_readButton_clicked() |
|
|
|
// do not go beyond 10 entries
|
|
|
|
int numberOfEntries = qMin(ui->readSize->currentText().toInt(), 10 - startAddress); |
|
|
|
switch (ui->writeTable->currentData().toInt()) { |
|
|
|
case 0: printCoilsDataFromSlave(modBusWrapperObj.getCoilWrapper(startAddress,static_cast<quint16>(numberOfEntries))); |
|
|
|
case 0: printCoilsDataFromSlave(modBusWrapper.getCoil(startAddress,static_cast<quint16>(numberOfEntries))); |
|
|
|
break; |
|
|
|
// case 1: printCoilsDataFromSlave(modBusObj->getInputCoil(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
// case 2: printRegisterDataFromSlave(modBusObj->getInputRegister(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
// case 3: printRegisterDataFromSlave(modBusObj->getHoldingRegister(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
// case 1: printCoilsDataFromSlave(modBusObj->getInputCoil(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
// case 2: printRegisterDataFromSlave(modBusObj->getInputRegister(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
// case 3: printRegisterDataFromSlave(modBusObj->getHoldingRegister(startAddress,static_cast<quint16>(numberOfEntries)));
|
|
|
|
// break;
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -100,11 +100,11 @@ void MainWindow::on_writeButton_clicked() |
|
|
|
{ |
|
|
|
uiCoils.setBit(0,ui->coilData1->isChecked()); |
|
|
|
uiCoils.setBit(1,ui->coilData2->isChecked()); |
|
|
|
// modBusObj->setMultipleCoil(startAddress, numberOfEntries, uiCoils);
|
|
|
|
// modBusObj->setMultipleCoil(startAddress, numberOfEntries, uiCoils);
|
|
|
|
} |
|
|
|
else if (numberOfEntries==1) |
|
|
|
{ |
|
|
|
// modBusObj->setSingleCoil(startAddress, ui->coilData1->isChecked());
|
|
|
|
// modBusObj->setSingleCoil(startAddress, ui->coilData1->isChecked());
|
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
@ -113,11 +113,11 @@ void MainWindow::on_writeButton_clicked() |
|
|
|
{ |
|
|
|
uiholdingRegisters[0]=ui->textEdit1->toPlainText().toUInt(); |
|
|
|
uiholdingRegisters[1]=ui->textEdit2->toPlainText().toUInt(); |
|
|
|
// modBusObj->setMultipleRegister(startAddress, numberOfEntries, uiholdingRegisters);
|
|
|
|
// modBusObj->setMultipleRegister(startAddress, numberOfEntries, uiholdingRegisters);
|
|
|
|
} |
|
|
|
else if (numberOfEntries==1) |
|
|
|
{ |
|
|
|
// modBusObj->setSingleRegister(startAddress, ui->textEdit1->toPlainText().toUInt());
|
|
|
|
// modBusObj->setSingleRegister(startAddress, ui->textEdit1->toPlainText().toUInt());
|
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|