|
1)PC,如果是异步通讯,接收的数据没有组的概念了,异步串口面向的就是字符,你收到的就是字符流。如何区别一组完整的数据,要根据数据的特征来区分。
2)停止位不关软件的事情
3)线程里肯定是死循环的,不过导致cpu100%的肯定错了,你的串口不是利用event的吗?俺大批量收115200的数据,线程占用的cpu也不超过1%,主程序处理数据才导致了20%的cpu。
- DWORD __stdcall
- CommIoThread( LPVOID lpParam )
- {
- DWORD dwEvents, dwBytesRead;
- size_t i;
- while( g____bComm_Open )
- {
- if( WaitCommEvent( g____hComm, &dwEvents, NULL ) )
- {
- if( EV_RXCHAR == dwEvents )
- {
- dwBytesRead = ReadCommBlock( g____Buf, sizeof( g____Buf ) );
- if( dwBytesRead )
- {
- for( i = 0; i < dwBytesRead; i++ )
- {
- *( g____IO_Buf + g____Receivep++ ) = g____Buf[ i ];
- }
- g____Receivep1 = g____Receivep;
- ResetEvent( g____hEvent_Buffer_Empty );
- WaitForSingleObject( g____hEvent_Buffer_Empty, INFINITE );
- }
- }
- }
- else
- {
- if( 995 != GetLastError() )
- {
- ShowError();
- }
- return 0;
- }
- }
- return 1;
- }
复制代码
|
|