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

how to send a broadcast? #57

Open
gicking opened this issue Feb 23, 2021 · 3 comments
Open

how to send a broadcast? #57

gicking opened this issue Feb 23, 2021 · 3 comments

Comments

@gicking
Copy link

gicking commented Feb 23, 2021

hello,

thanks a lot for this nice library! I am using it for a (very) simple Modbus master to test a RS485 network. So far all worked well. But now I want to send broadcast messages to all connected slaves, and it seems like nothing is sent (checked with oscilloscope).

Specifically in ModbusRtu.h line 55 mentions u8id=0 is intended for broadcast, but line 546 in Modbus::query() returns immediately if u8id==0.

Do I need to call a different method than query() for sending a broadcast and if yes, which one? For a simple example thanks a lot in advance! Have a great day :-)

@gicking
Copy link
Author

gicking commented Feb 23, 2021

FYI, as I have some time pressure I made a quick fix, which seems to work.

change line 546 from
if ((telegram.u8id==0) || (telegram.u8id>247)) return -3;
to
if (telegram.u8id>247) return -3;

and change line 621from
u8state = COM_WAITING;
to
if (telegram.u8id!=0)
u8state = COM_WAITING;
else
u8state = COM_IDLE;

@imanfreeman
Copy link

I need broadcast too. However, your changes didn't work for me.
I change the line 751 from:
if (au8Buffer[ ID ] != u8id ) return 0;
to
if (au8Buffer[ ID ] != u8id && au8Buffer[ ID ] !=0 ) return 0;
and now, the slave accepts 0 id as well.
Although, the slave processes all the funcions with this id (for example read holding registers), it returns response error not a valid one.
Maybe there is a better and concrete solution.

@linjovi168
Copy link

imanfreeman
It is useful to change this code.
Is there a way to cancel the returns response in broadcast ?

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

3 participants