|
|
@ -6,6 +6,8 @@ |
|
|
|
enum { NumColumn = 0, CoilsColumn = 1, HoldingColumn = 2, ColumnCount = 3, RowCount = 10 }; |
|
|
|
modBusMaster::modBusMaster(QObject *parent) : QObject(parent) |
|
|
|
{ |
|
|
|
m_coils.resize(2); |
|
|
|
m_holdingRegisters.resize(2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -71,8 +73,10 @@ void modBusMaster::setSingleCoil(int startAddress,bool coilFlag) |
|
|
|
{ |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_coils.clear(); |
|
|
|
m_coils.setBit(1,coilFlag); |
|
|
|
qDebug() << " ---- setSingleCoil " ; |
|
|
|
m_coils.clearBit(2); |
|
|
|
m_coils.setBit(0,coilFlag); |
|
|
|
qDebug() << " ---- setSingleCoil coilFlag " <<coilFlag; |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::Coils, startAddress, 1); |
|
|
|
|
|
|
|
} |
|
|
@ -82,7 +86,6 @@ void modBusMaster::setMultipleCoil(int startAddress, quint16 writeSize, QBitArra |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_holdingRegisters.clear(); |
|
|
|
m_coils.clear(); |
|
|
|
m_coils = someCoilFlags; |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::Coils, startAddress, writeSize); |
|
|
|
} |
|
|
@ -138,7 +141,6 @@ void modBusMaster::getHoldingRegister(int startAddress, quint16 readSize) |
|
|
|
|
|
|
|
void modBusMaster::readRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 readSize) |
|
|
|
{ |
|
|
|
qDebug() << " first of readRequest"; |
|
|
|
auto table =registerType; |
|
|
|
reply=modbusDevice->sendReadRequest(QModbusDataUnit(table, startAddress, readSize), serverId) ; |
|
|
|
if (reply) |
|
|
@ -159,9 +161,11 @@ void modBusMaster::readRequest(QModbusDataUnit::RegisterType registerType, int |
|
|
|
|
|
|
|
void modBusMaster::writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 writeSize) |
|
|
|
{ |
|
|
|
qDebug() << " ---- setSingleCoil coilFlag writeRequest "; |
|
|
|
auto table =registerType; |
|
|
|
Q_ASSERT(startAddress >= 0 && startAddress < 10); |
|
|
|
QModbusDataUnit writeUnit = QModbusDataUnit(table, startAddress, writeSize); |
|
|
|
qDebug() << " ---- writeUnit.valueCount()" << writeUnit.valueCount(); |
|
|
|
for (int i = 0; i < writeUnit.valueCount(); i++) { |
|
|
|
if (table == QModbusDataUnit::Coils) |
|
|
|
writeUnit.setValue(i, m_coils[i + writeUnit.startAddress()]); |
|
|
|