procedure TForm1.FormCreate(Sender: TObject);
begin
with MSComm1 do
begin
CommPort:=3; //使用Com3
Settings:='9600,n,8,1'; //设置通信口参数
InputLen:=22; //设置Input一次从接受缓冲区读取全部字节
InBufferCount:=0; //清除接受缓冲区
OutBufferCount:=0; //清除发送缓冲区
InBufferSize:=512; //设置接受缓冲区为50字节
//设置发送缓冲区为2字节
RThreshold:=1; //设置接受一个字节就产生OnComm事件
InputMode:=comInputModeBinary; // 设置接受数据模式为文本
PortOpen:=True ;
end;
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
begin
sleep(50); / /这里的值最少可以设置成多少
edt1.Text:=MSComm1.input;
MSComm1.InBufferCount:=0; //清除接受缓冲区
mscomm1.OutBufferCount:=0; //清除发送缓冲区
end;
begin
with MSComm1 do
begin
CommPort:=3; //使用Com3
Settings:='9600,n,8,1'; //设置通信口参数
InputLen:=22; //设置Input一次从接受缓冲区读取全部字节
InBufferCount:=0; //清除接受缓冲区
OutBufferCount:=0; //清除发送缓冲区
InBufferSize:=512; //设置接受缓冲区为50字节
//设置发送缓冲区为2字节
RThreshold:=1; //设置接受一个字节就产生OnComm事件
InputMode:=comInputModeBinary; // 设置接受数据模式为文本
PortOpen:=True ;
end;
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
begin
sleep(50); / /这里的值最少可以设置成多少
edt1.Text:=MSComm1.input;
MSComm1.InBufferCount:=0; //清除接受缓冲区
mscomm1.OutBufferCount:=0; //清除发送缓冲区
end;