Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C99中的ReadFile函数从串行端口读取数据_C_Winapi_Serial Port_C99 - Fatal编程技术网

使用C99中的ReadFile函数从串行端口读取数据

使用C99中的ReadFile函数从串行端口读取数据,c,winapi,serial-port,c99,C,Winapi,Serial Port,C99,我需要发送一个数据使用串行端口,我有一个小问题。当我使用ReadFile函数接收数据时,任何数据都将作为有符号字符而不是无符号字符获取 我的数据以十六进制发送 0 - 7 1 - 8f 2 - 54 3 - 59 4 - 50 5 - 1 6 - 6b 7 - ff 终端接收的数据,用于检查任何位是否正确发送 程序使用ReadFile接收的数据 0 - 7 1 - f 2 - 54 3 - 59 4 - 50 5 - 1 6 - 6b 7 - 7f 文件处理程序 HANDLE hComm;

我需要发送一个数据使用串行端口,我有一个小问题。当我使用ReadFile函数接收数据时,任何数据都将作为有符号字符而不是无符号字符获取

我的数据以十六进制发送

0 - 7
1 - 8f
2 - 54
3 - 59
4 - 50
5 - 1
6 - 6b
7 - ff
终端接收的数据,用于检查任何位是否正确发送

程序使用ReadFile接收的数据

0 - 7
1 - f
2 - 54
3 - 59
4 - 50
5 - 1
6 - 6b
7 - 7f
文件处理程序

HANDLE hComm;
hComm = CreateFile(
    p_port, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL
);
从串行端口读取数据的函数

void
getMessage(HANDLE hComm, unsigned char * dataStorage, int storageSize)
{
    DWORD dNoBytesToRead;
    ReadFile(hComm, dataStorage, storageSize, &dNoBytesToRead, NULL);
}

编辑:这不是WinApi的问题。-示例项目显示。

与ReadFile无关,它的行为不是这样的。它将是端口配置-它可能被设置为7位,或者类似的。我不熟悉API,但可能SetCommState?
ReadFile
不知道或不关心数据类型。它只是读取一个八位字节流。由应用程序来解释这些字节。这看起来也不像是有符号/无符号类型不匹配。看起来MSB已被剥离(请参见字节1和7)。听起来更像是串行端口的配置问题,但由于我对串行端口一无所知,所以我无法帮助您解决这个问题。是的,我创建了一个简单的应用程序来检查它,所有这些都可以正常工作。WinAPi没有问题。调用SetCommState()来配置串行端口以匹配设备设置从来都不是可选的。在启动程序之前,您必须使用MODE命令,几乎没有人这样做。您在问题中发布的代码与您所说的示例项目中的代码完全相同。请澄清你的问题是什么,并张贴一个帖子。