Solved

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

Posted on 1998-10-14
4
271 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now