Click here to Skip to main content
12,695,404 members (25,822 online)
Rate this:
 
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 20:41pm
Updated 5-Jan-13 20:42pm
v2
Comments
Member 9718310 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 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?
   
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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2017
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