Serial Comm. in VC++4.0 ie ReadFile etc..

Posted on 1997-12-31
Medium Priority
Last Modified: 2008-02-01
When writing to and reading from COM2
using GetComm...SetComm...WriteFile...
ReadFile and so on, my ReadFile func.
is returning error #87. Although it's
not a guarantee, I am assuming this is
an invalid parameter error(Error Codes
in on-line help). The following is my
handle initialization:
hCom=CreateFile("COM2",GENERIC_READ |
0,NULL); I can write to the port with
no problem, I know my CommState is
correct. My error is a run-time error
when the ReadFile is attempted. My read
statement is: BOOL rSuccess = ReadFile(hCom,
&data is LPVOID, nB..T..R is DWORD,
&nB..R is LPDWORD, and I am not using
OVERLAPPED operations.
What am I doing wrong??????? As a test
I continuously send one byte 0xff of data
until I receive that data back from another
program which is monitoring COM2. I have
another PC that is watching this
communication and displaying the data that
is sent and received. This PC can see the
0xff sent and 0xff received, but the ReadFile
function is not reading the 0xff. I am not
using any timeout functions. The write func
ends after 1024 attempts for a successful
Is there any other Communications functions
that may be better for me to use? Eventually
I will be using the WaitCommEvent function
to monitor for interrupt messages. Right now
I really need to know why the ReadFile is
not working properly.
Question by:jrmcg
1 Comment
LVL 23

Accepted Solution

chensu earned 600 total points
ID: 1177301
Try this:

BYTE data[8];
DWORD dwBytesRead;
BOOL rSuccess = ReadFile(hCom, data, 1, &dwBytesRead, NULL);


Points to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking.*/


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

597 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