Skip to content

Commit

Permalink
fix(protocols/modbus): fix write requests for coils always set to fal…
Browse files Browse the repository at this point in the history
…se (#710) (#711)

* fix(protocols/modbus): fix write requests for coils always set to false (#710)

* fix(protocols/modbus): Reverted modbus bool changed to 7 bit and manually implemented parsing of coil boolean instead (#710)

Co-authored-by: Stein Overtoom <stein.overtoom@triopsys.nl>
  • Loading branch information
SteinOv and Stein Overtoom committed Dec 29, 2022
1 parent 7d368be commit c9a1938
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -272,7 +272,11 @@ protected PlcValue toPlcValue(ModbusPDU request, ModbusPDU response, ModbusDataT
protected byte[] fromPlcValue(PlcTag tag, PlcValue plcValue) {
ModbusDataType tagDataType = ((ModbusTag) tag).getDataType();
try {
if (plcValue instanceof PlcList) {
if (tag instanceof ModbusTagCoil && plcValue instanceof PlcBOOL) {
byte byteValue = (byte) (plcValue.getBoolean() ? 1 : 0);
return new byte[]{byteValue};
}
else if (plcValue instanceof PlcList) {
WriteBufferByteBased writeBuffer = new WriteBufferByteBased(DataItem.getLengthInBytes(plcValue, tagDataType, plcValue.getLength()));
DataItem.staticSerialize(writeBuffer, plcValue, tagDataType, plcValue.getLength(), ByteOrder.BIG_ENDIAN);
byte[] data = writeBuffer.getData();
Expand Down

0 comments on commit c9a1938

Please sign in to comment.