unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls, OleCtrls, MSCommLib_TLB;type
TForm1 = class(TForm)
Comm1: TComm;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
MSComm1: TMSComm;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;function GetCPUTimeCount: Int64;var
Form1: TForm1;implementation{$R *.dfm}function GetCPUTimeCount: Int64;
asm
DB $0F, $31 //rdtsc
end;procedure TForm1.Button1Click(Sender: TObject);
var
sbuf: array [0..7] of char;
i: integer;
t1, t2: int64;
t: double;
begin
Comm1.StartComm;
sleep(50); for I := 0 to 7 do
sbuf[i] := char(i);
t1 := GetCPUTimeCount;
for i:=0 to 199 do
begin
comm1.WriteCommData(sbuf, 8); //假设有200个串口,机子上只有一个口,只好这么弄了
//sleep(1);
end;
t2 := GetCPUTimeCount; t := (t2-t1)/2506000; //主频2.506G memo1.Lines.Add(format('CPU %d', [t1]));
memo1.Lines.Add(format('CPU %d', [t2]));
memo1.Lines.Add(format('%.2fms', [t])); comm1.StopComm;
end;procedure TForm1.Button2Click(Sender: TObject);
var
sbuf: array of byte;
i: integer;
t1, t2: int64;
t: double;
p: OleVariant;
begin
mscomm1.PortOpen := true;
sleep(50); setlength(sbuf, 8);
for I := 0 to 7 do
sbuf[i] := i;
t1 := GetCPUTimeCount;
for i:=0 to 199 do
begin
mscomm1.Output := sbuf; //假设有200个串口,机子上只有一个口,只好这么弄了
//sleep(1);
end;
t2 := GetCPUTimeCount; t := (t2-t1)/2506000; //主频2.506G memo1.Lines.Add(format('CPU %d', [t1]));
memo1.Lines.Add(format('CPU %d', [t2]));
memo1.Lines.Add(format('%.2fms', [t])); mscomm1.PortOpen := false;
end;end.结果如下:
spcomm
CPU 31984759231422
CPU 31984760557834
0.53ms
mscomm
CPU 31986944773834
CPU 31987981952084
413.88msMSCOMM真是不一般的慢
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls, OleCtrls, MSCommLib_TLB;type
TForm1 = class(TForm)
Comm1: TComm;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
MSComm1: TMSComm;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;function GetCPUTimeCount: Int64;var
Form1: TForm1;implementation{$R *.dfm}function GetCPUTimeCount: Int64;
asm
DB $0F, $31 //rdtsc
end;procedure TForm1.Button1Click(Sender: TObject);
var
sbuf: array [0..7] of char;
i: integer;
t1, t2: int64;
t: double;
begin
Comm1.StartComm;
sleep(50); for I := 0 to 7 do
sbuf[i] := char(i);
t1 := GetCPUTimeCount;
for i:=0 to 199 do
begin
comm1.WriteCommData(sbuf, 8); //假设有200个串口,机子上只有一个口,只好这么弄了
//sleep(1);
end;
t2 := GetCPUTimeCount; t := (t2-t1)/2506000; //主频2.506G memo1.Lines.Add(format('CPU %d', [t1]));
memo1.Lines.Add(format('CPU %d', [t2]));
memo1.Lines.Add(format('%.2fms', [t])); comm1.StopComm;
end;procedure TForm1.Button2Click(Sender: TObject);
var
sbuf: array of byte;
i: integer;
t1, t2: int64;
t: double;
p: OleVariant;
begin
mscomm1.PortOpen := true;
sleep(50); setlength(sbuf, 8);
for I := 0 to 7 do
sbuf[i] := i;
t1 := GetCPUTimeCount;
for i:=0 to 199 do
begin
mscomm1.Output := sbuf; //假设有200个串口,机子上只有一个口,只好这么弄了
//sleep(1);
end;
t2 := GetCPUTimeCount; t := (t2-t1)/2506000; //主频2.506G memo1.Lines.Add(format('CPU %d', [t1]));
memo1.Lines.Add(format('CPU %d', [t2]));
memo1.Lines.Add(format('%.2fms', [t])); mscomm1.PortOpen := false;
end;end.结果如下:
spcomm
CPU 31984759231422
CPU 31984760557834
0.53ms
mscomm
CPU 31986944773834
CPU 31987981952084
413.88msMSCOMM真是不一般的慢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货