byte[] reb = new byte[0x400];
reb = myCom.Read(0x400);
就是这个读取串口数据的函数
public byte[] Read(int NumBytes)
{
byte[] lpBuffer = new byte[NumBytes];
if (this.hComm == -1)
{
throw new ApplicationException("串口没有打开");
}
OVERLAPPED lpOverlapped = new OVERLAPPED();
int lpNumberOfBytesRead = 0;
ReadFile(this.hComm, lpBuffer, NumBytes, ref lpNumberOfBytesRead, ref lpOverlapped);
byte[] destinationArray = new byte[lpNumberOfBytesRead];
Array.Copy(lpBuffer, destinationArray, lpNumberOfBytesRead);
return destinationArray;
}
做了个计时,差不多每次读取数据都要4秒,不管数据长短,需要怎么处理下能缩短读取时间?
我串口的通讯速率是2400,用的winapi操作串口