Cloud-Automation / node-modbus

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

How to write int16 values #284

Closed ricott closed 3 years ago

ricott commented 3 years ago

Hi,

Using this package to communicate with a Victron Cerbo GX device. I am able to read all values I want, so this part is great! Writing values works fine as long as I don't try to write a negative value - ie int16. Can you share some info on how I can write a negative value via modbus? This is what I use today and what works for uint16 values client.writeSingleRegister(2706, power)

ricott commented 3 years ago

Answering myself, guess this is one way

let buffer = Buffer.alloc(2);
buffer.writeInt16BE(power);
return this.client.writeMultipleRegisters(2700, buffer) ....