Solved

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

Posted on 1997-12-31
1
516 Views
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 |
GENERIC_WRITE,0,NULL,OPEN_EXISTING,
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,nBytesToRead,&nBytesRead,NULL).
&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
read.
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.
0
Comment
Question by:jrmcg
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1177301
Try this:

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


/*lpNumberOfBytesRead

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

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

820 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