Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.Packager #2

Open
ailen1002 opened this issue Nov 6, 2023 · 2 comments
Open

client.Packager #2

ailen1002 opened this issue Nov 6, 2023 · 2 comments

Comments

@ailen1002
Copy link

st := modbus.NewSerialTransporter("COM3")
st.Mode = serial.Mode{BaudRate: 19200}
defer func() { _ = st.Close() }()
// slave1
c1 := modbus.NewClient(modbus.NewRtuPackager(1), st)
_, results1, err1 := c1.ReadHoldingRegisters(1, 10)

// change slave ID
c1.Packager.SlaveId = 2

// slave2
_, results2, err2 := c1.ReadHoldingRegisters(1, 10)

// change slave ID
c1.Packager.SlaveId = 3

// slave3
_, results3, err3 := c1.ReadHoldingRegisters(1, 10)

client.Packager Can modify SlaveId externally with uppercase first letter. Communicate with different slave stations

@hi-way
Copy link
Owner

hi-way commented Nov 6, 2023

change slave ID
c2 := modbus.NewClient(modbus.NewRtuPackager(2), st)

@ailen1002
Copy link
Author

I have modified my usage code according to your method, and everything seems to be working well now, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants