使用readfile()解码串行端口数据

问题描述:

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");
}



当我运行上述功能时,我无法从串行端口解码数据.我想知道Windows 32 API中是否有任何功能可以比较数据字符串或将数据字符串替换为数组以简化解码数据.

谢谢



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

') { printf(" ,buffRead); } 其他 { printf(" ); }
') { printf("%s",buffRead); } else { printf("data not found"); }



当我运行上述功能时,我无法从串行端口解码数据.我想知道Windows 32 API中是否有任何功能可以比较数据字符串或将数据字符串替换为数组以简化解码数据.

谢谢



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


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==''