|
@ -84,9 +84,36 @@ QBitArray ModbusMaster::getCoil(int startAddress, quint16 readSize) |
|
|
for(uint i = 0; i < num; i++) |
|
|
for(uint i = 0; i < num; i++) |
|
|
{ |
|
|
{ |
|
|
if(unit.value(static_cast<int>(i)) == 1) |
|
|
if(unit.value(static_cast<int>(i)) == 1) |
|
|
coils.setBit(i); |
|
|
coils.setBit(static_cast<int>(i)); |
|
|
else |
|
|
else |
|
|
coils.clearBit(i); |
|
|
coils.clearBit(static_cast<int>(i)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return coils; |
|
|
|
|
|
} |
|
|
|
|
|
catch(const ServoException& ex) |
|
|
|
|
|
{ |
|
|
|
|
|
qDebug() << ex.what(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
|
|
QBitArray ModbusMaster::getInputCoil(int startAddress, quint16 readSize) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
readRequest(QModbusDataUnit::RegisterType::DiscreteInputs, startAddress, readSize); |
|
|
|
|
|
auto unit = _modbusReplyUnit; |
|
|
|
|
|
|
|
|
|
|
|
QBitArray coils; |
|
|
|
|
|
auto num = unit.valueCount(); |
|
|
|
|
|
coils.resize(static_cast<int>(num)); |
|
|
|
|
|
for(uint i = 0; i < num; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(unit.value(static_cast<int>(i)) == 1) |
|
|
|
|
|
coils.setBit(static_cast<int>(i)); |
|
|
|
|
|
else |
|
|
|
|
|
coils.clearBit(static_cast<int>(i)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return coils; |
|
|
return coils; |
|
|