Click here to Skip to main content
15,881,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
dwBytesRead = 0;
int nread =32;

if (!ReadFile(hSerial, buffRead, nread, &dwBytesRead, NULL))
{
printf("error reading from input buffer \n");
}
printf("Data read from serial port is \n %s \n",buffRead);

if (buffRead=='$')
{
    printf("%s",buffRead);
}
else
{
    printf("data not found");
}


When I run the above function I was unable to decode data from the serial port. I would like to know if any function in windows 32 api can compare the string of data or replace the string of data into array for simplicity to decode the data.

Thanks
Posted
Updated 12-Nov-10 20:05pm
v5
Comments
Alain Rist 13-Nov-10 3:41am    
How do you define and initialize buffRead?

if (buffRead=='$')

This statement is invalid, you cannot compare an array to the value of a single character and expect a proper result. Assuming that you are looking for a dollar sign as the first character of your array the statement should be:
if (*buffRead=='$')
// or
if (buffRead[0]=='$')

Spend some time rereading how to address the contents of different types of variables and arrays in C++.
 
Share this answer
 
Hi Richard Macutchan,
this is how i declare my variables for the reading of serial port.
i did try to use if (buffRead[0]=='$')inside my program. But i cant decode the data from it.

CSS
HANDLE hSerial;
COMMTIMEOUTS timeouts;
COMMCONFIG dcbSerialParams;
unsigned char buffRead[32];
DWORD dwBytesRead;
 
Share this answer
 
Comments
Richard MacCutchan 13-Nov-10 12:11pm    
What do you mean when you say you can't decode the data? Nobody can guess what the data is supposed to represent or what format it comes in so you need to explain what data you receive and what you expect it to be.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900