我是这样做的
repeat……
until() //死循环
不断去通过一个串口 以站号区分的方式去访问多台plc现在调试(没接plc) 发现 速度会越来越慢请问为什么啊?
我每次在运行一个通信的时候 都先执行
mscomm1.InBufferCount := 0;
mscomm1.OutBufferCount := 0;
repeat……
until() //死循环
不断去通过一个串口 以站号区分的方式去访问多台plc现在调试(没接plc) 发现 速度会越来越慢请问为什么啊?
我每次在运行一个通信的时候 都先执行
mscomm1.InBufferCount := 0;
mscomm1.OutBufferCount := 0;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;type
TDataByte=array of Byte;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
MSComm1: TMSComm;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
s,s1,s2:string;
i:LongInt;
Cadena:TDataByte;
x:LongInt;
label M31_Go;
begin
x:=0;
repeat
Inc(x);
mscomm1.InBufferCount := 0; //清空读取缓冲区
mscomm1.OutBufferCount := 0; //清空发送缓冲区
s:='010342000002D073'; //
for i:=1 to length(s) do
begin
if (s[i] in ['0'..'9','a'..'f','A'..'F'])then
begin
s2:=s2+s[i];
end;
end ;
if length(s2)mod 2=0then
i:=length(s2)div 2
else
i:=length(s2) div 2+1;
SetLength(Cadena,i+2);
for i:=0 to(length(s2)div 2-1)do
begin
Cadena[i]:=StrToint('$'+copy(s2,i*2+1,2));
end; MSComm1.Output:=Cadena;
i:=0;
repeat
//Application.ProcessMessages;
i := i + 1;
If i > 6 Then
begin
goto M31_Go; 超过6次 就发生跳转 实验时 我没接plc end;
Until mscomm1.InBufferCount=6;
M31_Go:Edit1.Text:=' '+IntToStr(x)+'连接失败';
until x=50000;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if MSComm1.PortOpen then
MSComm1.PortOpen:=False;
mscomm1.CommPort := 3; //指定端口
mscomm1.Settings := '19200,N,8,2'; //其它参数
mscomm1.InBufferSize := 1024; //接收缓冲区
mscomm1.OutBufferSize := 1024; //发送缓冲区
mscomm1.InputMode := comInputModeBinary; //接收模式
mscomm1.InputLen := 0; //一次读取所有数据
//MSComm1.RThreshold:=1; //设置接收多少字节开产生oncomm事件
mscomm1.SThreshold := 0; //一次发送所有数据
mscomm1.InBufferCount := 0; //清空读取缓冲区
mscomm1.OutBufferCount := 0; //清空发送缓冲区
mscomm1.PortOpen:=true;
end;end.
用这个程序实验一下 可以看见速度缓缓的慢下来了。。
搞不懂????????
spcomm 要基于事件触发 我要读很多 反馈字节 不同数据啊。。