当前位置: 技术问答>linux和unix
串口发送一大堆数据
来源: 互联网 发布时间:2016-05-04
本文导语: 请问如何实现串口发送一大串的数据,就是一次没发完,第二次接着发送剩余的数据? | INT32 WriteComPort (INT32 ComPort, const UINT8 * data, INT32 datalength) { INT32 retval, len = 0, tot...
请问如何实现串口发送一大串的数据,就是一次没发完,第二次接着发送剩余的数据?
|
INT32 WriteComPort (INT32 ComPort, const UINT8 * data, INT32 datalength)
{
INT32 retval, len = 0, total_len = 0;
FD_ZERO (&fs_write);
FD_SET (fd[ComPort], &fs_write);
tv_timeout.tv_sec = 0;//TIMEOUT_SEC (datalength, GetBaudrate ());
tv_timeout.tv_usec = 150000;//TIMEOUT_USEC;
// tcflush (fd[ComPort], TCOFLUSH);
for (total_len = 0, len = 0; total_len 0)
{
total_len += len;
tcflush (fd[ComPort], TCOFLUSH);
}
}
else
{
tcflush (fd[ComPort], TCOFLUSH);
break;
}
}
return (total_len);
}
一般使用select这样写
{
INT32 retval, len = 0, total_len = 0;
FD_ZERO (&fs_write);
FD_SET (fd[ComPort], &fs_write);
tv_timeout.tv_sec = 0;//TIMEOUT_SEC (datalength, GetBaudrate ());
tv_timeout.tv_usec = 150000;//TIMEOUT_USEC;
// tcflush (fd[ComPort], TCOFLUSH);
for (total_len = 0, len = 0; total_len 0)
{
total_len += len;
tcflush (fd[ComPort], TCOFLUSH);
}
}
else
{
tcflush (fd[ComPort], TCOFLUSH);
break;
}
}
return (total_len);
}
一般使用select这样写