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

Multiple slaves on the same port. #740

Open
phu251099 opened this issue Mar 19, 2024 · 1 comment
Open

Multiple slaves on the same port. #740

phu251099 opened this issue Mar 19, 2024 · 1 comment

Comments

@phu251099
Copy link

Currently I am facing the following problem:

I have 3 slaves with 3 IDs 1, 2, 3 connected to 1 modbus rtu COM port.

I don't know how to read and write data to 3 devices.

When using the following functions, communication with only 1 address is possible:
ctx = modbus_new_rtu("/dev/ttyS3", 115200, 'N', 8, 1);
modbus_set_slave(ctx, 1);
modbus_read_registers(ctx, 0, 2, tab_reg);

@mhei
Copy link
Contributor

mhei commented Mar 19, 2024

What about using?

ctx = modbus_new_rtu("/dev/ttyS3", 115200, 'N', 8, 1);
modbus_set_slave(ctx, 1);
modbus_read_registers(ctx, 0, 2, tab_reg);
...
modbus_set_slave(ctx, 2);
modbus_read_registers(ctx, 0, 2, tab_reg);
...
modbus_set_slave(ctx, 3);
modbus_read_registers(ctx, 0, 2, tab_reg);
...

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