Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
can some1 tell me How to read single bit from com port using madbus protocol? in C#
Posted 5-Jan-13 19:41pm
Edited 5-Jan-13 19:42pm
v2
Comments
Member 9718310 at 6-Jan-13 3:33am
   
In the referance you provided input reads in the form of bytes. I want to read single bit i.e high or low
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have a look at this article Simple Modbus Protocol in C# / .NET 2.0[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

In Modbus RTU, you always read a byte. Naturally, in Modbus ASCII, you read characters, 8-bit characters, and each byte is a part of number represented as text:
http://en.wikipedia.org/wiki/Modbus#Frame_format[^].
 
So, you either read individual byte or some number and extract an individual bit from the data read. All software developers know how to extract a bit, but… do you need help?
 
—SA
  Permalink  
Comments
Member 9718310 at 7-Jan-13 0:42am
   
thnx all...
 
but problem is that I want to read 4 inputs from serial port in the form of ON/OFF. So what request messge I should write to serial port through modbus in order to read inputs?
 
like Function Code=2,slave address=1 and other?
Sergey Alexandrovich Kryukov at 7-Jan-13 0:47am
   
You did not ask about request message. It depends on your device. The format should be known from the documentation. I answered your question, it should be enough. Are you going to accept it formally (green button)?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Quote:
thnx all...
 
but problem is that I want to read 4 inputs from serial port in the form of ON/OFF. So what request messge I should write to serial port through modbus in order to read inputs?

 
You probably need reading 4 consecutive discrete inputs (or coils) from the device.
Have a look at MODBUS functions 0x02 (read discrete inputs) or 0x01 (read coils) explanations and samples in this document "MODBUS APPLICATION PROTOCOL SPECIFICATION"[^].
 
If you need the CRC computation routine, you may find the C source code at the end of this document: Modicon Modbus Protocol Reference Guide[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

thnx CPallini. It really helped me.
  Permalink  
Comments
CPallini at 8-Jan-13 6:34am
   
You are welcome.

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

  Print Answers RSS
0 Maciej Los 585
1 OriginalGriff 458
2 CPallini 239
3 Sergey Alexandrovich Kryukov 175
4 Peter Leow 175
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,898
2 Maciej Los 3,159
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100