simonvetter / modbus

Go modbus stack (client and server)
MIT License
280 stars 89 forks source link

Signed integer support missing? #12

Closed stevedh closed 2 years ago

stevedh commented 2 years ago

Unless I am missing something, the documentation mentions supporting reading signed integers; but there's no ReadInt16/ReadInt32 method in the client.

simonvetter commented 2 years ago

Hi Stephen,

wouldn't simply using a cast work in this case? This is how I usually do it:

var  reg uint16

err, reg = client.ReadRegister(0x1000, modbus.HOLDING_REGISTER)

if err != nil { ... }

fmt.Printf("unsigned value: %v, signed value: %v\n", reg, int16(reg))

var setpoint int16

setpoint = -100

err = client.WriteRegister(0x1000, uint16(setpoint))

Hope this helps,

-Simon

simonvetter commented 2 years ago

Closing this for inactivity. Feel free to reopen if needed.