Solved

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

Posted on 1997-12-31
1
523 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
[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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
How can i compile this github project?? 2 104
Beginner to Unreal Engine 4 5 120
what type of pointer is this pointer? 3 32
Winapi.Windows.hpp problem 7 46
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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.

759 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