-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Proxy - modbus_proxy function #70
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
base: master
Are you sure you want to change the base?
Conversation
The modbus_proxy function takes a request from a master context passes it to a slave context and then sends the confirmation back to the master.
The modbus_proxy function takes a request from a master context passes it to a slave context and then sends the confirmation back to the master.
Conflicts: src/modbus.c
Does it still issues on this proxy code? |
Proxy code is working well for all standard modbus queries. The problem was with non standard modbus frames (unknown to modbus_receive in libmodbus) with function codes 0x64 and 0x67. In my opinion, to be 100% safe and eliminate potential SIGSEGV for unknown frames, it will be nice to add some check for l<0 in this calculation before memcpy:
But again, for standard modbus frames with known function codes works very well. |
modbus_proxy, as any other function on the library, assumes it is receiving valid pointers and a valid request length. Adding the check proposed by sebastiangajda may cause the function to fail silently and then it will be harder to debug errors as the one he had in which non standard frames caused modbus_receive to fail. I think is better to check, in the program that uses the library, if the frame received by modbus_receive is valid before passing it to modbus_proxy and, if it is not valid, then report that situation in the program's most convenient way. |
Hi, I have the same problem with the function - int tcp_bs = modbus_receive(tcp_ctx, tcp_buf);
|
I solved this problem.
;) |
I tried this with latest libmodbus on Windows and it is working fine. The conflict is trivial to resolve (EXPORT was renamed to MODBUS_API). Is there still any reason why it cannot be merged? |
The PR hasn't be updated to handle non standard modbus frames and I can't read the code sample from @hanusek (#include lines are empty). |
FYI, I'm using this patch for a project and was getting a segfault when testing with unit-test-server and unit-test-client. Seemed to be caused by |
Anyone interested to update this PR? |
Hello there.
Maybe you won't remember by now but about 4 months ago you rejected a pull request of mine because of formatting issues and also because all the changes were made on master instead of branches (I was a new git user). There were two main issues addressed on those changes:
From those features you seemed interested on the proxy one so here I'm sending you another pull request about that one (you can also grab the echo hardware stuff from my echohw branch, if interested).
I finally found the time this weekend to work on this project again and as you suggested I deleted the old fork an moved the changes to a new branch.
This function was developed to solve the following problem: I have a Single Board Computer (SBC) that acts as the master of a MODBUS/RS485 bus and also has an Ethernet port and I wanted to use it as a bridge between Ethernet and RS485 so that is possible to send MODBUS requests from Ethernet to the devices on the RS485 bus.
The following is the program I used to test the function, this one runs on the SBC to connect the Ethernet and RS485 contexts:
Now from any other device connected to the Ethernet network I can read the devices on the RS485 by setting the slave address on the TCP context.