如何使用select实时监听串口通信
发布网友
发布时间:2023-11-06 13:43
我来回答
共1个回答
热心网友
时间:2024-12-14 03:28
|
INT32 ReadComPort (INT32 ComPort, void *data, INT32 datalength)
{
INT32 retval = 0;
FD_ZERO (&fs_read);
FD_SET (fd[ComPort], &fs_read);
tv_timeout.tv_sec = 0;//TIMEOUT_SEC (datalength, GetBaudrate ());
tv_timeout.tv_usec = 150000;//TIMEOUT_USEC;
retval = select (fd[ComPort] + 1, &fs_read, NULL, NULL, &tv_timeout);
if (retval)
return (read (fd[ComPort], data, datalength));
else
return (-1);
}