我用SPComm做的一个实时串口通信的程序。总觉得效果不理想。
我处理串口通信的代码如下:
const
DELAYBEFOREPROC=200;
var
comm: TComm;
g_sendData: Array[1..100] of char;
procedure executeComm(dataLength: Integer);
begin
if not comm.SendDataEmpty then
sleep(100);
comm.WriteCommData(g_sendData,dataLength);
//iDataLength := 0;
sleep(DELAYBEFOREPROC);
application.ProcessMessages;
end;
请大家帮忙下,怎么样才能提高效率?
我处理串口通信的代码如下:
const
DELAYBEFOREPROC=200;
var
comm: TComm;
g_sendData: Array[1..100] of char;
procedure executeComm(dataLength: Integer);
begin
if not comm.SendDataEmpty then
sleep(100);
comm.WriteCommData(g_sendData,dataLength);
//iDataLength := 0;
sleep(DELAYBEFOREPROC);
application.ProcessMessages;
end;
请大家帮忙下,怎么样才能提高效率?
有事件标示是否已经发送完数据
我本以为是串口名“comm”引起,把所有的comm改成c omm,也没用。
下一个cnpack的组件包吧...cnrs232...用事件就可以了..
sleep(DELAYBEFOREPROC);改成sleep(50)试试。
while not comm.SendDataEmpty do
Application.ProcessMessage;
while not comm.SendDataEmpty do
Sleep(1);这样Sleep的时间和次数是根据实际缓冲区的数据决定,而不是不管3721, 就Sleep 200毫秒, 这样100%会出现,无畏Sleep(200)的情况, 比如:你判断的时候只有一个字节还没发送,和还有100个字节还没发送的时间是不一样的。