16,472
社区成员
发帖
与我相关
我的任务
分享
请问怎样能查询到各种设备的通讯协议,比如(空压机、机房空调、工业锅炉、变压器、光伏设备)
int ReadData(char* filePath )
{
HANDLE pFile;
DWORD fileSize;
char* buffer, * tmpBuf;
DWORD dwBytesRead, dwBytesToRead, tmpLen;
pFile = CreateFile( filePath/*这个文件名怎么来的*/ , GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, //打开已存在的文件
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( pFile == INVALID_HANDLE_VALUE)
{
printf("open file error!\n");
CloseHandle(pFile);
return FALSE;
}
fileSize = GetFileSize(pFile,NULL); //得到文件的大小
buffer = (char *) malloc(fileSize);
ZeroMemory(buffer, fileSize);
dwBytesToRead = fileSize;
dwBytesRead = 0;
tmpBuf = buffer;
do
{ //循环读文件,确保读出完整的文件
ReadFile(pFile,tmpBuf,dwBytesToRead,&dwBytesRead,NULL);
if (dwBytesRead == 0)
break;
dwBytesToRead -= dwBytesRead;
tmpBuf += dwBytesRead;
} while (dwBytesToRead > 0); // TODO 处理读到的数据 buffer
free(buffer);
CloseHandle(pFile);
return TRUE;
}
这是我网上找的一个,我这个情况好像没有这个filePath文件,我怎么知道接受谁的数据
typedef struct _SerialConfig//串口配置
{
CString SerialName;//串口
CString SerialBaud;//波特率
CString SerialDatabits;//数据位
CString SerialChecksum;//校验
CString SerialStopbits;//停止位
}SerialConfig;
请问串口怎么发送接受数据