Fix modbus receive handling for float types #19697
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Modbus module:
float is 32bit and should be treated like other 32 bit types.
When you call ModbusSend the end of the message is always 0 because the buffer will not be filled.
With this patch there will be valid data.
See the reference output.
Output from development branch:
18:36:26.010 CMD: ModbusSend {"deviceAddress":100, "functionCode":4, "startAddress":0, "type":"float", "count":18, "endian":"msb"}
18:36:26.022 SRC: WebConsole from 192.168.177.212
18:36:26.023 CMD: Grp 0, Cmd 'MODBUSSEND', Idx 1, Len 121, Pld -99, Data '{"deviceAddress":100, "functionCode":4, "startAddress":0, "type":"float", "count":18, "endian":"msb", "RetryReceive": 10}'
18:36:26.036 MQT: stat/solarpowermeter/RESULT = {"ModbusSend":"Done"}
18:36:26.130 MQT: tele/solarpowermeter/RESULT = {"ModbusReceived":{"DeviceAddress":100,"FunctionCode":4,"StartAddress":0,"Length":41,"Count":18,"Values":[231.5265350342,229.1959533691,230.8569641113,0.0619665682,0.0000000000,0.0502408743,3.7392051220,0.0000000000,1.9624860287,9104722578972676672037778.1894,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000]}}
Output with this fix:
18:59:37.664 CMD: ModbusSend {"deviceAddress":100, "functionCode":4, "startAddress":0, "type":"float", "count":18, "endian":"msb"}
18:59:37.677 SRC: WebConsole from 192.168.177.212
18:59:37.678 CMD: Grp 0, Cmd 'MODBUSSEND', Idx 1, Len 101, Pld -99, Data '{"deviceAddress":100, "functionCode":4, "startAddress":0, "type":"float", "count":18, "endian":"msb"}'
18:59:37.690 MQT: stat/solarpowermeter/RESULT = {"ModbusSend":"Done"}
18:59:37.828 MQT: tele/solarpowermeter/RESULT = {"ModbusReceived":{"DeviceAddress":100,"FunctionCode":4,"StartAddress":0,"Length":77,"Count":18,"Values":[231.3769226074,230.4935607910,232.0218963623,0.0602983646,0.0000000000,0.0509612113,3.6130239964,0.0000000000,1.9416227341,12.2808637619,0.0000000000,9.3146982193,-11.7373619080,0.0000000000,-9.1100883484,0.2941994965,0.0000000000,0.2084472030]}}
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass