Closed mitchellpontague closed 4 years ago
In that case the crc is actually correct but the composition of the read holding register message is wrong when the data is fetched from the array. Do you agree?
Yeah you are correct, the CRC math is fine but the data is fetched/stored wrong.
Locally I've replaced line 103 linked above with the following
payload.writeUInt16BE(value, 2 + 2*i)
and confirm it works. But prefer not to make a pull to fix as I'm not sure if this is an issue anywhere else, or if this is the most appropriate fix.
Can you run npm test and see if anything fails with your change?
Tests pass, unsure if the error after is related to tests or not.
139 passing (329ms)
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:8888
@mitchellpontague I've created a pull request, can you confirm that this is working.
CRCs seem to be generated wrong on 3.1.3 for 16bit registers. From the below output the crc is being calculated from the bytes cf 03 04 0f 0a 00 00, 0f and 0a of which are from the response proceeding it but are missing the most significant byte for each. The MSB was lost because the response values were stored as the 16bit values into the array value but read back assuming the array contained 8 bit bytes.
https://github.com/Cloud-Automation/node-modbus/blob/ba2a6a1db4975076af67bb30fb4822acf8de3762/src/response/read-holding-registers.js#L103