Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
467 stars 174 forks source link

ReadHoldingRegistersResponseBody.fromRequest shouldn't multiply requestBody.start by 2 #336

Closed ameyat2812 closed 4 months ago

ameyat2812 commented 8 months ago

In the spec, for the Read Holding registers request that comes from the Modbus client, byte 3+4 combined forms the 2-byte starting address of the register to start reading from. Please refer to https://www.simplymodbus.ca/FC03.htm

In the ReadHoldingRegistersResponseBody.fromRequest function, requestBody.start is multiplied by 2 to arrive at startByte that I think is not needed, requestBody.start should be treated as starting address in the holding register buffer

ameyat2812 commented 8 months ago

@stefanpoeter Any thoughts

stefanpoeter commented 8 months ago

Hey @ameyat2812 the Modbus Specs define the holding register to be of 2-byte sized absolutes. So a address in modbus for, example 4, is located in a 1-byte based buffer at offset 8.