我想从 uClinux 上的串口获取数据。工作原理:我有想要进入引导加载程序模式的外围设备。为此,我必须发送数据 i2500$,这意味着它处于引导加载程序模式。不幸的是,我只能读取 >i2,如果我使用我的方法,它不再返回数据,或者如果我重置设备并重复开始跳转到引导加载程序
int TEnforaUpdate::ReadFromComport (unsigned long timeouta, unsigned long size)
{
FD_SET(fdCom, &read_fds);
int retValue = 0;
// Set timeout to x microseconds
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 1000 * timeouta;
// Wait for input to become ready or until the time out; the first parameter is
// 1 more than the largest file descriptor in any of the sets
if ((select (fdCom + 1, &read_fds, &write_fds, &except_fds, &timeout) == 1)
&& (FD_ISSET(fdCom,&read_fds)))
{
//read max
retValue = read (fdCom, RxBuffer, RX_BUFFER_SIZE);
printf ("Read %d bytes: ", retValue);
int i;
for (i = 0; i < retValue; i++)
printf ("[%02x]", RxBuffer[i]);
printf ("\n");
}
else
return 1;
if (retValue > 2)
{
strcpy (answer, (char*) RxBuffer);
//remove trashes from buffer
memset (RxBuffer, 0x00, RX_BUFFER_SIZE);
printf ("Comport answers: %s \n", answer);
}
FD_CLR(fdCom, &read_fds);
tcflush (fdCom, TCIFLUSH);
return retValue;
}