Click here to Skip to main content
15,032,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

My question would be weird so I do apologize for that.

I am going to implement Modbus RTU Master and Modbus TCP Master in an electronic device Called "DiGi Module Connect Me 9210". From this device I will request some data from PIC, data like Nodes and Temperatures and Some other data. I just want to Implement FC 04/03/16 in my device.

The Digi Module is an electronic device so for this purpose I am going to create C# GUI to request data from the PIC Using GUI via DiGi Module because Digi will be connected with PIC using Modbus RTU Protocol. And after getting the data in Digi we will send that data on cloud using Modbus TCP.

From GUI to DIgI I will have TCP/IP and from DIGI to PIC I will have Modbus RTU and between Cloud and DiGi I will have Modbus TCP.

I want to strip out my data in C# so I will just send request from the GUI to PIC via DIGI (so my DIGI would a bridge between GUI and PIC) to configure the node or get node data from PIC. I have to read almost 9999 registers in one go using 80 request or something else to get the data from 3X / 4X registers. Now the questions are.

☺ How can I strip my data in C#.?

☺ How to implement Modbus RTU/TCP same time in a device or a system.?

☺ How can I read all the 9999 registers via GUI because I might want to read all the RunTime data from the 3X registers.?

☺ How can I write/Read all the 4X registers as well.?

We are also implementing the paging technique so it means that page 0 will have 9999 registers and then page 1 will have 9999 registers. So if I want to read temperatures I have to go to page 0 and read the registers and if I want to read Speed values I have to go to page 1 and check all the registers.?

The GUI would look like some thing

User will add Node Number and then Temperature and Submit the request.

Muhammad Azym
Updated 30-Jul-21 0:47am

1 solution

Use NModbus[^]

But you need to see something clear: Modbus/TCP works over TCP/IP, Modbus/RTU works over serial protocols like RS232 and RS485. You can't just mix them. If the digi module is no modbus gateway, it won't work. As I see, the Digi module could be programmed to be a gateway, but do you really want this?
You need to implement on the Digi Modbus/TCP Slave (not master) + Modbus/RTU Master, and Modbus/RTU slave on the PIC - if the PC software will poll the PIC.
However, you could end up much cheaper with a ready-made device. Like this one:[^]. Or even cheaper with these:[^]
Even Digi has it's own gateway:[^]

Of course, if this is your desire, go on, and program the Digi. You can implement both Modbus/RTU and Modbus/TCP stacks on it. As the device can host Embedded linux... you could start from this one:[^], but could be others out there ready to run.

From protocol's point of view you can read all registers at once, if you want. Don't try to reinvent the wheel, as Modbus is a quite old and widely used industry standard pack. Many things are supporting it, but if you try to add your own fancy things, it won't be compliant anymore, and you will struggle in the future.

For testing you can use the "standard" Modscan32[^] - but it's not worth the price (sorry folks) -, better simply implement your with NModbus.

On the other hand, you don't need Modbus/TCP at all, because you can implement higher level services on the ethernet side. If you strictly need industrial standards, implement OPC UA. If not, put a REST API in place. Far simpler to implement, and to adapt - if the goal is non generic data acquisition.
[no name] 25-Sep-15 14:10pm
This is a cool comprehensive/informative answer, a 5.
Zoltán Zörgő 25-Sep-15 15:11pm
Thank you
Muhammad Azym 28-Sep-15 3:18am
Thanks Zoltan,

In case of the TCP/IP between C# GUI and Digi Module I was thinking to make GUI as a client side and Digi as Server side. what do you think should be perfect.?

Zoltán Zörgő 28-Sep-15 3:35am
I got that.
Technically, yes. This is why you would need your digi to be Modbus/TCP slave, as I mentioned.
Still, you should consider other approaches too. If you give us more details about your environment, your business requirements, we could give you other advices.
Muhammad Azym 28-Sep-15 3:52am
We have a product through which we configured different nodes for temperature and speed sensors. It was previously developed in BASIC but now we are actually developing it in C with the help of external GUI. As I have mentioned above the protocol between PIC and DIGI would be ModbusRTU and in the GUI I would have my tcp/ip client to connect with DIGI. In DIGI I will also have ModbusTCP to send the RunTime Data of sensors in the cloud. I don't think so the company will go for another approach for now.
Muhammad Azym 28-Sep-15 3:56am
in the PIC side we have also implementing paging technique for example on page 0 we will node configuration and network setting and on page 1 we will have Alarm configuration. So for example if i send request from GUI to DIGI to get the node data it will actually run some background events like first a thread will go and write the page 0 and appropriate registers in the Modbus so after the acknowledgement it will send the read request from the 4X registers.
Muhammad Azym 28-Sep-15 3:58am
This is what making me panic that how in the background I would read all the 9999 registers from the PIC and will get the data in to DIGI and from DIGI to GUI.?
Zoltán Zörgő 28-Sep-15 4:09am
If IoT and cloud is in scope I don't suggest you to stich to Modbus/TCP on internet side. A REST API would be much-much better. The digi could handle all the Modbus RTU site, and you could get all data from the DIGI in one shot with a single http(s) call.
Muhammad Azym 28-Sep-15 4:19am
That's a good idea to have Rest API not Modbus-TCP. How is it possible to get all the data in on shot from Modbus RTU because what i have check you can not access more than 125 registers in one go. Well this is my first time in Modbus, how is it possible?
Zoltán Zörgő 28-Sep-15 4:24am
First of all: do you need a snapshot of your sensors at the time when PC is polling, or do you need to record all data with a constant frequency?
Muhammad Azym 28-Sep-15 4:28am
I think I need the record of all data with a constant frequency.
Zoltán Zörgő 28-Sep-15 4:39am
That makes a difference, as you can't guarantee continous access on internet side. You simply can't. Thus you need to add buffering with timestamps. I don't think the digi is enough for that. Those 8MB of RAM would last for a minute or two only (dpending on the number of records you need to take). For that you need something more performant. There are tools you might consider, but they could get more expensiver than the DIGI. Are you interested?
Muhammad Azym 28-Sep-15 4:53am
yes, you are definitely right. but how can i read the registers in one shot using gui.?
Zoltán Zörgő 28-Sep-15 5:46am
This is a good documentation for NModbus: As you will see, you can't read input and holding registers in one shot. Simply because they are different functions of the modbus protocol.
Consider something like this too:
Muhammad Azym 28-Sep-15 6:00am
Thank you very much for your help. I really appreciate that. Is that ok with you if I bother you again in future.?
Zoltán Zörgő 28-Sep-15 6:04am
You ar welcome. Try it! :)
Muhammad Azym 28-Sep-15 6:11am
Thanks :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900