Modbus Sample VB
The beginning is where I am looking for Sample program VB.net of Modbus TCP’s communication. And then I found a sample project in CodeProject.com, here:
This is a VB.net project for Modbus TCP’s communication built with C# language, by Stephan Stricker.
The problem is I feel comfortable with VB language. So, when I open the script, I feel a little bit confuse. It is very important to convert the script to my “mother language” because from this project I will develop a more complex application.
Then I searching for translator from C# to VB script with google, and I get a good result, a nice site DeveloperFusion.com can do my wish, here is:
The original project contain of 2 projects. I open all of that and convert with site above.
Then I make a new project with VB language. I choose .Net 2.0 framework. This new project named Modbus Sample VB.
In my new project, I just create one project, which is consist of one form and one module. I move Modbus TCP class to module ModbusTCP, and I copy all objek in frmStart and paste it on frmStart in my new project.
It amazing, the translated script is almost perfect, only a few lines error.
Picture below shows the error lines in ModuleTCP, event OnReceive, on the code ElseIf… I don’t know yet how to fix this line, so I change the line to only Else.
In form frmStart more line should be fixed. I remarks unused Import, and Imports ModbusTCP changed to Imports Modbus_Sample_VB.ModuleTCP.
I remark Namespace and End Namespace, and all line between declaration of data and event frmStart_Load.
In button event btnConnect also there some modification.
There is one Warning, but I think it can be ignored.
And my new project is done, Modbus TCP client built in VB language.
I try to connect to Modbus Simulator with local IP 127.0.0.1, and successfully, it can read and write registers.
Here is a preview of Modbus Simulator.
And here is a preview of Modbus Sample VB.
The executable file of this project can be downloaded here..
if you need source of this project click here..