Closed wwhai closed 2 years ago
Hi there,
I think what you're after is the SetUnitId() method. Call it on the client whenever necessary to change the target slave id of any future requests e.g.:
client.SetUnitId(3)
err = client.WriteRegister(0x1000, 0x20)
regs, err = client.ReadRegister(0x1000, modbus.HOLDING_REGISTER)
// both requests above will target slave id # 3
// now select another slave
client.SetUnitId(9)
err = client.WriteRegister(0x1001, 0x30)
err = client.WriteRegister(0x1010, 0x01)
// those writes will target slave id # 9
Hope this helps, -Simon
Hi there,
I think what you're after is the SetUnitId() method. Call it on the client whenever necessary to change the target slave id of any future requests e.g.:
client.SetUnitId(3) err = client.WriteRegister(0x1000, 0x20) regs, err = client.ReadRegister(0x1000, modbus.HOLDING_REGISTER) // both requests above will target slave id # 3 // now select another slave client.SetUnitId(9) err = client.WriteRegister(0x1001, 0x30) err = client.WriteRegister(0x1010, 0x01) // those writes will target slave id # 9
Hope this helps, -Simon
Yes , It's my need, thanks
How to set modbus slaver-Id?