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

Missing Modbus TCP Server Sample #530

Open
napperley opened this issue Apr 9, 2020 · 6 comments
Open

Missing Modbus TCP Server Sample #530

napperley opened this issue Apr 9, 2020 · 6 comments

Comments

@napperley
Copy link

Although there is a C source file showing how to do a Modbus server it covers far too much (it is too complex), and lacks focus on a specific area. To make matters worse the source file isn't extensively documented (especially on memory management, and how to send a response back to the client with register data set in the response), and lacks proper code structure (all logic is done in a enormous sized main function).

The libmodbus library would greatly benefit from having a small Modbus TCP server sample that only focuses on a single area, and shows the minimum required to get a Modbus TCP server implemented.

@watsocd
Copy link

watsocd commented Apr 9, 2020 via email

@napperley
Copy link
Author

That example doesn't work. An error message appears after sending the reply on the server side:

Illegal data address 0x9C44 in read_input_registers

@karlp
Copy link
Contributor

karlp commented Apr 12, 2020

0x9c44 is simply not in range of the registers setup in @watsocd 's example, so it's behaving exactly as expected. They setup 500 holding registers, and no input registers.

@watsocd
Copy link

watsocd commented Apr 12, 2020

Code comment at the top:
Hello World: Modbus slave function. Address node 3, data in registers 40001, 40002, and 40003

Of course no/limited error checking. IT IS a Hello World minimal example for holding (40000) registers.

@alongL
Copy link
Contributor

alongL commented Feb 16, 2023

Caution: this demo server code only serve for one client.
If you want the server serving for multi clients at the same time.
You should see bandwidth-server-many-up.c in tests dir.
or you can try this https://github.com/alongL/modbusServer

@sunasrariyaz
Copy link

The code above gives me segmentation fault during runtime. So does the random-test-server when i access the mb_mapping->tab_registers[0] to print or to assign some value to it. Without accessing the mb_mapping->tab_registers[index] it runs fine. As a sever i want to assign some values in the tab_registers array. Any kind of help is greatly appreciated.

I am running it in rhel 7 with libmodbus-3.1.10 installed.

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

5 participants