Solved

How do I communicate with the RS232 port in VC++ 6.0

Posted on 1998-10-14
4
327 Views
Last Modified: 2012-06-21
I´m working on a project including communication with external processors via the Serial RS232-port. The problem is, I don´t really know how to communicate with the serial port using VC++ at all! soo if anyone knows how to just read the info on the port using normal 19.2 kBaud should be enoungh to start with...

Thanks!
_____________________________
Ulf Andersson
Microlab Systems Co.
Gothenburg, Sweden.
0
Comment
Question by:uffe78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Accepted Solution

by:
jbalagop earned 50 total points
ID: 1175097
hi, you would need 2 threads for listening to the port and for reading from the port. the below pseudo-code, is just some of the funtions you might use. let me know if you need more than this.

    //
    // open communication port handle
    //
CreateFile( gszPort, GENERIC_READ | GENERIC_WRITE, 0, 0,
                                      OPEN_EXISTING,
                                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
                                      0);
GetCommTimeouts();
 
// set comm buffer sizes
SetupComm();

// raise DTR

EscapeCommFunction()

    //
    // start threads and set initial thread state to not done
    //
    AfxBeginThread()

    //
    // set overall connect flag
    //
 
0
 

Expert Comment

by:jbalagop
ID: 1175098
The above is a comment. Also, since you used CreateFile() it retuerns a handle to the communication port. You may read or write using this handle. Make sure you have status checking in your reader and writer threads, because the connection may be reset and you have to make sure it isn;t so before writing , etc/
0
 

Author Comment

by:uffe78
ID: 1175099
Since I haven´t got into this language yet, could you please rewrite the code so that it matches 19.2kBaud on serial comport 2 The transfer is standard 8bit, 1 stop-bit and without parity...

/Ulf
0
 

Expert Comment

by:jbalagop
ID: 1175100
hi uffe78, all the above functions have detailed examples in the help files or check out the msdn.microsoft.com (the library).
i believe that they even have a serial communication example.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question