• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3645
  • Last Modified:

Read 8 bit binary data from the Serial Port (RS232)

Dear All,

I want to write a code in C to read data packets of 8bit binary, from an RS232 with one start bit, no parity, no stop bits. I also need to store the data in a text file. It would be really helpful if oyu could send me any sample code in C. The program will operate in Windows.

Many thanks,

Michalaros
0
michalaros
Asked:
michalaros
1 Solution
 
KocilCommented:
DOS or Windows or Linux ?
0
 
CHENSHILIHCommented:
Hi michalaros :
   There are so many possible solution, in DOS/Win95/Win98/WinMe/Win2000/WinXP. For example, you can use Moxa Rs232 Driver. There are two choices, one is use
the rs232 port of PC, and the other is add-on rs232 card.
you can visit the following site :

    http://web2.moxa.com.tw/services/download/download.asp

    It supports : DOS/Windows/Linux Driver, and You need to installed the driver and library, then write your applications.



0
 
sharptekCommented:
If you're running on DOS/win95/win98 then you can write 'C' code to interface directly with  the rs232 chip registers - which is very flexible and fast. If on the other hand you are running an NT based OS -WinNT,win2000,winXP then you will need to interface with an RS232 driver  less efficient but possibly more stable.. Which is your preferred approach?
I've got some code knocking about somewhere for the former if thats what you need I'll dig it out :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
honey_hamsterCommented:
Try the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_functions.asp

To start, you'll need to look at the following Windows API functions:
CreateFile()   - opens the COM port
GetCommState()
SetCommState() - sets baud rate and other config
WriteFile()    - writes serial data
ReadFile()     - reads serial data

Hope this helps.
0
 
rajeev_devinCommented:
Currently i do not remember the interrups that are used for that purpose. Then also you can consult the book titled ADVANCED MS-DOS PROGRAMMING. There you will get sample code and all with correct interrupt numbers.

Hope that it may help you
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by honey_hamster [grade B] (may lead to a solution).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now