Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

912 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

24 Experts available now in Live!

Get 1:1 Help Now