Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / XML
Tip/Trick

Modbus TCP class

Rate me:
Please Sign up or sign in to vote.
4.89/5 (84 votes)
23 May 2014CPOL 1.7M   60.4K   154   171
A Modbus TCP class.

The project has moved to GIT

https://github.com/stephan1827/modbusTCP

Please download and ask questions from there.

License

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


Written By
Systems Engineer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Modbus Framework for .NET Pin
Flavi18-Nov-13 1:51
Flavi18-Nov-13 1:51 
QuestionIllegal Data Address Pin
softwaremonkey3-Oct-13 3:43
softwaremonkey3-Oct-13 3:43 
AnswerRe: Illegal Data Address Pin
softwaremonkey3-Oct-13 4:16
softwaremonkey3-Oct-13 4:16 
GeneralRe: Illegal Data Address Pin
Mehmet Ali Dalaklı16-Jan-14 7:53
Mehmet Ali Dalaklı16-Jan-14 7:53 
Questionmodbus message response is not receiving in same order Pin
Uma Mahes17-Sep-13 20:10
Uma Mahes17-Sep-13 20:10 
AnswerRe: modbus message response is not receiving in same order Pin
Stephan Stricker18-Sep-13 3:30
Stephan Stricker18-Sep-13 3:30 
GeneralRe: modbus message response is not receiving in same order Pin
Uma Mahes21-Jan-14 1:48
Uma Mahes21-Jan-14 1:48 
SuggestionCan not read/write Address more than 32767. Edited conversion Pin
hadihidayat9-Sep-13 15:52
hadihidayat9-Sep-13 15:52 
Hello..

I have a problem when trying to Read and Write address more than Integer limit (32767).

On function CreateReadHeader and CreateWriteHeader There is a problem when convert Start Address to byte, in this line of code :

(this is VB conversion code. from here: http://hadiscada.blogspot.com/2013/07/modbus-sample-vb-engllish-version.html[^])

VB
Dim _adr As Byte() = BitConverter.GetBytes(CShort(IPAddress.HostToNetworkOrder(CShort(startAddress))))
data(8) =  _adr(0)
' Start address
data(9) = _adr(1)
' Start address


I solved my problem with this edited code :

VB
'Dim _adr As Byte() = BitConverter.GetBytes(CShort(IPAddress.HostToNetworkOrder(CShort(startAddress))))
data(8) = startAddress \ 256 ' _adr(0)
' Start address
data(9) = startAddress Mod 256 ' _adr(1)
' Start address



Thanks..

modified 17-Sep-13 5:14am.

GeneralMy vote of 5 Pin
陳志杰25-Aug-13 17:49
陳志杰25-Aug-13 17:49 
SuggestionSome improvements necessary Pin
muharrem27-Jul-13 13:17
muharrem27-Jul-13 13:17 
GeneralRe: Some improvements necessary Pin
Stephan Stricker29-Jul-13 7:10
Stephan Stricker29-Jul-13 7:10 
GeneralRe: Some improvements necessary Pin
muharrem30-Jul-13 4:51
muharrem30-Jul-13 4:51 
Questionasp.net and ModbusTCP class Pin
enfrost15-Jul-13 8:57
enfrost15-Jul-13 8:57 
AnswerRe: asp.net and ModbusTCP class Pin
Stephan Stricker15-Jul-13 11:10
Stephan Stricker15-Jul-13 11:10 
QuestionMore simple sample, please!) Pin
Voodoo902-Jul-13 1:57
Voodoo902-Jul-13 1:57 
NewsModbus TCP Sample (VB.net) Pin
hadihidayat2-Jul-13 0:36
hadihidayat2-Jul-13 0:36 
QuestionNot able to read from Modbus TCP simulator Pin
MayurShah.in28-Jun-13 21:51
MayurShah.in28-Jun-13 21:51 
AnswerRe: Not able to read from Modbus TCP simulator Pin
Stephan Stricker29-Jun-13 20:55
Stephan Stricker29-Jun-13 20:55 
QuestionModbus RTU over TCP Pin
JosepLluis17-Jun-13 10:18
JosepLluis17-Jun-13 10:18 
AnswerRe: Modbus RTU over TCP Pin
Stephan Stricker17-Jun-13 13:33
Stephan Stricker17-Jun-13 13:33 
GeneralRe: Modbus RTU over TCP Pin
JosepLluis18-Jun-13 2:31
JosepLluis18-Jun-13 2:31 
GeneralRe: Modbus RTU over TCP Pin
kenselvia@gmail.com21-Jun-13 23:21
kenselvia@gmail.com21-Jun-13 23:21 
QuestionSlave_ID and Slave_Address Pin
SBerube13-Jun-13 2:04
SBerube13-Jun-13 2:04 
AnswerRe: Slave_ID and Slave_Address Pin
Stephan Stricker14-Jun-13 3:51
Stephan Stricker14-Jun-13 3:51 
Questionvalues of message Pin
monkar22-May-13 7:08
monkar22-May-13 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.