Click here to Skip to main content
15,662,823 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want to connect a Energy meter to PC and want to receive electrical data on excel files using VB code. the protocol supported by energy meters is MODBUS RTU. need a sample code to do this task.
Thank you in advance
Sergey Alexandrovich Kryukov 26-Aug-14 2:49am    
Excel... Oh, gosh... Anyway, you don't need the sample code. What would be the use of it if it supports different devices? You need documentation on your meter, RTU, on MODBUS, frame format (ASCII? TCP?) and the MODBUS hardware you use, and some MODBUS library...

Please see my comment to the question.

In principle, you can wrap the available C library MODBUS library using .NET P/Invoke:[^],[^].

But you can find available native .NET library. Please see:[^],[^],[^],[^].

See also these CodeProject articles:
Simple Modbus Protocol in C# / .NET 2.0[^],
Modbus TCP class[^].

I hope you are not going the make a problem because of having C# code instead of VB.NET; it does not really matter; developers of serious library hardly will deal with non-standard language like VB.NET.

Share this answer
Hi, I'm using the same code for this on .Net <<([^])>>. I have a PLC connected to a PC through Modbus RTU (RS485). Between PLC and PC I have a RS485-RS232-USB converter.

I'd like to know how this program could read and write memory registers of 4 bytes (2 words) size. I need to handle memory registers with float data type and others with negative values. I have a PLC with the next registers (dropbox image) that I need to read and write, so I'll be very pleased if you could give me some help with this.

This is the link with the PLC registers <<([^])>>

Share this answer
CHill60 7-Oct-15 9:39am    
Please don't post questions as solutions to old posts. If you have a question of your own then use the red "Ask a Question" link. Do remember to read the posting guidelines that are shown to the right after you press the link.

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