Teach you from entry to proficiency in C# Modbus communication

insert image description here

Foreword:

In the field of industrial communication, Modbus communication is a widely used communication protocol. There are generally three types of Modbus, namely ModbusRTU, ModbusASCII, and ModbusTCP. Among them, ModbusRTU and ModbusASCII are protocols applied to serial links. It uses the serial port. In layman’s terms, ModbusTCP uses the network port. The author has been working in the field of automation for many years, and has done countless Modbus projects. He has also earned tens of thousands of part-time jobs by relying on Modbus communication. After all, let me use a ModbusSlave with bare hands. A Modbus debugging tool is not a problem for me. For example, the Modbus debugging assistant you see in the above picture is written by me. The ancients said that reading thousands of books is not as good as traveling thousands of miles, and traveling thousands of miles is not as good as being guided by a famous teacher, so the fastest way to get started must be to find a senior to imitate him, and you must invest in yourself when you are young! Buying books, buying courses and learning are the fastest ways for you to improve yourself. There is no other way to become a master. Study hard + imitate masters, and you will surely achieve something in the future! A book or a course costs tens of dollars, but the money you will earn in the future must be dozens, hundreds, thousands, or even more of these costs! If you are an ordinary person without a strong background, you must continue to learn. Continuous learning is the only way for ordinary people to counterattack! If you want to be proficient in Modbus programming, basic knowledge of c# grammar is essential. Subscribe to my column " C# Modbus Communication from Beginner to Master " and get e-books "C# Essence" and "C# Graphical Tutorial". In short, as long as you learn Modbus communication with me, you will definitely be able to become an invincible Modbus player . If I ask you the following questions, you can answer them, and you will be considered a master. Otherwise, how can you easily earn 300,000+ annual salary? Of course, these I will introduce the knowledge in detail in my column " C# Modbus Communication from Getting Started to Mastering ".
Question 1: How many kinds of Modbus are there?
Question 2: Does Modbus RTU use the serial port or the network port?
Question 3. Does Modbus RTU need to be verified?
Question 4. Does Modbus TCP need verification?
Question 5. What function codes does Modbus support? What is the specific meaning of each function code?
Question 6. How to solve the problem of multi-thread communication in ModbusRTU communication?
Question 7. How to solve the problem of disconnection and reconnection in ModbusTCP communication?
If you can't master all the above questions I asked, I suggest you come to my column " C# Modbus Communication from Beginner to Master " system to learn it!
This column will explain in detail how these three protocols are applied in C# program development, including protocol principles, message formats, and C# source code implementation.

1. " C# Modbus communication from entry to proficiency " column catalog

Click the article link below to go to this article:
1. C# Modbus communication from entry to proficiency (1) - the use of virtual serial port debugging tools
2. C# Modbus communication from entry to proficiency (2) - Principle of Modbus RTU protocol
3. C# Modbus communication from entry to proficiency (3)——Modbus RTU (0x01 function code)
4. C# Modbus communication from entry to proficiency (4)——Modbus RTU (0x02 function code)
5. C# Modbus communication from entry to Proficient (5)——Modbus RTU (0x03 function code)
6. C# Modbus communication from entry to master (6)——Modbus RTU (0x04 function code)
7. C# Modbus communication from entry to proficiency (7)——Modbus RTU (0x05 function code)
8. C# Modbus communication from entry to proficiency (8) - Modbus RTU (0x06 function code)
9. C# Modbus communication from entry to proficiency (9) - Modbus RTU (0x0F function code)
10. C# Modbus communication from entry to proficiency (10) - Modbus RTU (0x10 function code)
11, C# Modbus communication from entry to proficiency (11) - the use of debugging software Modbus Slave and Modbus Poll
12,C# Modbus communication from entry to proficiency (12)——Modbus ASCII protocol principle
13, C# Modbus communication from entry to proficiency (13)——Modbus ASCII (0x01 function code)
14, C# Modbus communication from entry to proficiency (14)— —Modbus ASCII (0x02 function code)
15. C# Modbus communication from entry to master (15) —— Modbus ASCII (0x03 function code)
16. C# Modbus communication from entry to master (16) —— Modbus ASCII (0x04 function code)
17. C# Modbus communication from entry to proficiency (17) - Modbus ASCII (0x05 function code)
18. C# Modbus communication from entry to proficiency (18) - Modbus ASCII (0x06 function code)
19. C# Modbus communication from entry to Proficient (19)——Modbus ASCII (0x0F function code)
20. C# Modbus communication from entry to master (20)——Modbus ASCII (0x10 function code)
21. C# Modbus communication from entry to proficiency (21)——Modbus TCP Protocol principle
22. C# Modbus communication from entry to proficiency (22) - Modbus TCP (0x01 function code)
23. C# Modbus communication from entry to proficiency (23) - Modbus TCP (0x02 function code)
24. C# Modbus communication from entry to proficiency (24)——Modbus TCP (0x03 function code)
25. C# Modbus communication from entry to proficiency (25)——Modbus TCP (0x04 function code)
26. C# Modbus communication from entry to Proficient (26)——Modbus TCP (0x05 function code)
27. C# Modbus communication from entry to master (27)——Modbus TCP (0x06 function code)
28. C# Modbus communication from entry to proficiency (28)——Modbus TCP (0x0F function code)
29. C# Modbus communication from entry to proficiency (29) - Modbus TCP (0x10 function code)

2. Why study this column?

Why do I recommend learning the column " C# Modbus Communication from Entry to Mastery "? There are several reasons:
1) Mastering the Modbus protocol is a necessary skill for a PC software engineer, and it is required to master the Modbus protocol in the recruitment requirements. It is difficult to get a high salary for PC software development without mastering the Modbus protocol!
2) This column systematically introduces the principles and C# implementation of the three protocols of Modbus RTU, Modbus ASCII, and Mobus TCP. You cannot find C# tutorials on the market that introduce these three protocols at the same time. Most of them are about the principles. Yes, if there are some training courses, you know the price of the training courses.
3) This column provides the source code of the Modbus debugging assistant developed by me (supporting three protocols: Modbus RTU, Modbus ASCII, and Mobus TCP), which is not only convenient for you to debug when doing Modbus projects, but also beneficial for you to master the Modbus communication class developed by me. How the library is used.
4) The Modbus class library developed by me supports multiple function codes such as reading input coils, reading output coils, reading holding registers, reading input registers, writing single coils, writing multiple coils, and writing multiple holding registers.
5) The Modbus class library developed by me supports reading and writing of various data types, including int16 signed integers, uint16 unsigned integers, and float decimals.
6) The Modbus class library developed by me supports timeout setting, reading times setting, abnormal cause return, disconnected reconnection, multi-threading and other functions 7) The
Modbus class library developed by me is stable and has been applied in many projects , to avoid detours for novices
8) Some people say that there are some third-party libraries available on the market, so why learn it? The experience of being a senior engineer is that mastering the underlying code is the only way for you to become a master. If there is a problem, you will know how to troubleshoot it. Do you understand Modbus communication? One interviewer said that he had encapsulated the Modbus protocol, and another interviewer said that I would use a library written by someone else. As the interviewer, who do you choose to admit?

3. Introduction of Modbus debugging assistant

In order to facilitate students to quickly learn Modbus, I have also developed a Modbus master debugging tool that supports the three protocols of ModbusRTU, ModbusASCII, and ModbusTCP, as follows:

3.1 Modbus debugging assistant interface

3.1.1 Protocol selection interface

When the software is started, the protocol selection interface will pop up. Depending on the selected protocol, different interfaces will appear on the main interface.
insert image description here

3.1.2 Debug interface

3.1.2.1 ModbusRTU debugging interface

insert image description here

3.1.2.2 ModbusASCII debugging interface

insert image description here

3.1.2.3 ModbusTCP debugging interface

insert image description here

3.2 Functions supported by Modbus debugging assistant

The function codes supported by this tool are:
0x01 (read output coil)
0x02 (read input coil)
0x03 (read multiple/single holding register)
0x04 (read multiple/single input register)
0x05 (write single coil)
0x06 (write single Holding register)
0x0F (write multiple coils)
0x10 (write multiple holding registers)
The above function codes are commonly used function codes in our development. Of course, Modbus also supports other function codes. If students find that they need to support more If you have more function codes, you can also ask me, and I will improve its functions.

3.3 Part of the source code display of the Modbus debugging assistant

insert image description here
Since the partial structures of ModbusRTU, ModbusASCII, and ModbusTCP messages are similar, I declared an abstract class Modbus class during design, and then defined many function code operation methods in the abstract class, and then targeted ModbusRTU, ModbusASCII, and ModbusTCP. The three protocols can be used to implement the methods defined in the abstract class. The three classes ModbusRTU, ModbusASCII, and ModbusTCP in the figure above all implement the methods defined in the Modbus abstract class. Some codes of the Modbus abstract class are as follows:
insert image description here

4. ModbusRTU

The article catalog of the ModbusRTU series is as follows (click the link to go to the article):
1. C# Modbus communication from entry to proficiency (1) - the use of virtual serial port debugging tools
2. C# Modbus communication from entry to proficiency (2) - Modbus Principle of RTU protocol
3. C# Modbus communication from entry to proficiency (3) - Modbus RTU (0x01 function code)
4. C# Modbus communication from entry to proficiency (4) - Modbus RTU (0x02 function code)
5. C# Modbus communication From entry to proficiency (5) - Modbus RTU (0x03 function code)
6. C# Modbus communication from entry to proficiency (6) - Modbus RTU (0x04 function code)
7. C# Modbus communication from entry to proficiency (7) - —Modbus RTU (0x05 function code)
8. C# Modbus communication from entry to master (8) —— Modbus RTU (0x06 function code)
9. C# Modbus communication from entry to master (9) —— Modbus RTU (0x0F function code)
10. C# Modbus communication from entry to proficiency (10) - Modbus RTU (0x10 function code)
11. C# Modbus communication from entry to proficiency (11) - the use of debugging software Modbus Slave and Modbus Poll

五、ModbusASCII

The article directory of the ModbusASCII series is as follows (click the link to go to the article):
12. C# Modbus communication from entry to mastery (12) - Modbus ASCII protocol principle
13. C# Modbus communication from entry to mastery (13) - Modbus ASCII ( 0x01 function code)
14. C# Modbus communication from entry to proficiency (14) - Modbus ASCII (0x02 function code)
15. C# Modbus communication from entry to proficiency (15) - Modbus ASCII (0x03 function code)
16. C# Modbus Communication from entry to proficiency (16) - Modbus ASCII (0x04 function code)
17. C# Modbus communication from entry to proficiency (17) - Modbus ASCII (0x05 function code)
18. C# Modbus communication from entry to proficiency (18) ——Modbus ASCII (0x06 function code)
19. C# Modbus communication from entry to proficiency (19) ——Modbus ASCII (0x0F function code)
20. C# Modbus communication from entry to proficiency (20) ——Modbus ASCII (0x10 function code )

六、ModbusTCP

The article catalog of the ModbusTCP series is as follows (click the link to go to the article):
21. C# Modbus communication from entry to proficiency (21) - Modbus TCP protocol principle
22. C# Modbus communication from entry to proficiency (22) - Modbus TCP ( 0x01 function code)
23. C# Modbus communication from entry to proficiency (23) - Modbus TCP (0x02 function code)
24. C# Modbus communication from entry to proficiency (24) - Modbus TCP (0x03 function code)
25. C# Modbus Communication from entry to proficiency (25) - Modbus TCP (0x04 function code)
26. C# Modbus communication from entry to proficiency (26) - Modbus TCP (0x05 function code)
27. C# Modbus communication from entry to proficiency (27) ——Modbus TCP (0x06 function code)
28. C# Modbus communication from entry to proficiency (28) ——Modbus TCP (0x0F function code)
29. C# Modbus communication from entry to proficiency (29) ——Modbus TCP (0x10 function code )

Guess you like

Origin blog.csdn.net/qq_34059233/article/details/130875321