正常来说不会出现你说的那用情况,既使window是多任务的,但只要不存在那种阻塞进程,普通端口速率是不会有问题的,你的端口速率有多少?再看看你的算法吧
解决方案 »
- 请教一个基础问题DELPHI2007编译一程序出错
- 可能很简单,大家不要打脸
- Button上的快捷键的问题
- 有关Tchart控件的问题
- 有谁能看懂这个函数吗 function auto_init(port: smallint;baud:longint): longint; stdcall;far;external 'MWIC_32.DLL' name 'auto_in
- 很急的问题,大家帮忙啊!
- 请教有关图形图像问题
- 我的新书——《Delphi高手突破》最新消息
- SQL Server库怎么无法读。
- TChart问题,怎样增加图形显示的颜色种类
- 这个sql句子怎么写?
- 三层结构中如何实现多帐套功能?
[email protected]
据说windows的时间片段分割最小为50ms(这一点可以从Timer定时器可以看出,响应100次50ms定时的OnTimer和响应100次1ms的OnTimer几乎花的是一样的时间),所以,如果想在windows下实现响应小于50ms的时间,正常的方式是不行的。我想如果能够做到驱动程序这一级,应该可以解决这个问题,但这超过我的范围了。
Dos和Unix等不存在这样的问题。
ADDRESS : 要发往的端口
INTEGER : 波特率
数据位 : 8BIT
校验 : NONE
停止位 : 1BIT
TODO: 通讯模块DLL
COPY 读取话单 STRSEN+回车+空格
PRASE 删除密码信息
ADDC 增加密码
ERASE 删除所有信息
BARSE 删除话单信息
TIME 读取时间和设置时间
*******************************************************}uses
SysUtils, Windows,
Classes,PortIO;
{$R *.RES}
Function communication(Strsend:pchar;address:integer;baud:integer):pchar;stdcall;
var
i:integer; //发送字符长度
b:integer; //判断是否可以接收发送
s,r:string; //发送字符长度
bS:Boolean;// bs始终为True
timeNow:longword;//超时
DLPortIO: TDLPortIo;
begin
Result:='';
DLPortIO:=TDLPortIo.Create(nil); //create
// Driver is in the same directory as the demo.exe file!
DLPortIO.DriverPath:=ExtractFileDir(ParamStr(0));
// Open the DriverLINX driver
DLPortIO.OpenDriver();
DLPortIO.Port[Address+3]:=$80; //置DLAB
DLPortIO.Port[Address]:=lo(1843200 DIV 16 DIV baud);
DLPortIO.Port[Address+1]:=hi(1843200 DIV 16 DIV baud);
DLPortIo.Port[address+3]:=$03; //无寄偶校验 数据长度为8; 停止位1位
s:=strpas(strsend);
S:=s+char($0d); //加上回车
timenow:=gettickcount; //得到当前时间
bs:=True;
i:=1; case copy(s,1,1)[1] of
'T': if length(s)<6 then //读取时间
while bs do
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) and (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=20 then break;
end;
if (gettickcount-timenow)>100 then break;
end
else while bs do //设置时间
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) and (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=length(s) then break;
end;
if (gettickcount-timenow)>100 then break;
end;
'A': while bs do //ADDC 增加密码
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) AND (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=length(s) then break;
end;
if (gettickcount-timenow)>100 then break;
end;
'E': while bs do //ERASE 删除所有信息
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) AND (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=length(s) then break;
end;
if (gettickcount-timenow)>100 then break;
end;
'B': while bs do //BRASE 删除所有话单信息
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) AND (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=length(s) then break;
end;
if (gettickcount-timenow)>100 then break;
end;
'P': while bs do //PRASE 删除所有密码
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) AND (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1; timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
timenow:=gettickcount;
if length(R)=length(s) then break;
end;
if (gettickcount-timenow)>100 then break;
end;
'C': begin //COPY读取话单
s:=s+char($20);
while bs do
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) and (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01;
if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
if (copy(R,length(R)-1,1)[1]='D')and(ord(copy(R,length(R),1)[1])=$0D)
then break;
timenow:=gettickcount;
end;
if (gettickcount-timenow)>1000 then break;
end;
end;
else while bs do //默认
begin
b:=DlPortIo.Port[Address+5] and $20;
if (b=$20) and (i<=length(s)) then
begin
DLPortIO.Port[Address]:=ord(s[i]);
i:=i+1;
timenow:=gettickcount;
end;
b:=DlPortIo.Port[Address+5] and $01; if b=1 then
begin
R:=R+char(DLPortIO.Port[Address]);
{ if (copy(R,length(R)-1,1)[1]='D')and(ord(copy(R,length(R),1)[1])=$0D)
then break;}
timenow:=gettickcount;
end;
if (gettickcount-timenow)>100 then break;
end; end;
Try
if ord(copy(R,1,1)[1])=$0d then R:=copy(R,2,length(R)-1);
except
end;
DLPortIO.Free;
Result:=pchar(R);
end;
exports
communication;
end.