正常来说不会出现你说的那用情况,既使window是多任务的,但只要不存在那种阻塞进程,普通端口速率是不会有问题的,你的端口速率有多少?再看看你的算法吧

解决方案 »

  1.   

    这个控件在哪里有?你可以给我一个么?谢谢
    [email protected]
      

  2.   

    我听说过一点,不一定可靠,也说出来参考一下:
        据说windows的时间片段分割最小为50ms(这一点可以从Timer定时器可以看出,响应100次50ms定时的OnTimer和响应100次1ms的OnTimer几乎花的是一样的时间),所以,如果想在windows下实现响应小于50ms的时间,正常的方式是不行的。我想如果能够做到驱动程序这一级,应该可以解决这个问题,但这超过我的范围了。
        Dos和Unix等不存在这样的问题。
      

  3.   

    描述:  STRSEND  : 要发送的字符串   STRSEND+CHAR(13)  在要发的字符串后+回车
           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.
      

  4.   

    windows的timer控件都是一个原理,他的最小分辨率是17.6ms,这由bios中断延时决定的,你的程序如果用的是timer进行轮询接收,那就要看看你的发送间隔和这个精度的关系了。你可以不用timer直接用windows的api函数(有3个,很不常用),但精度可以达到1ms
      

  5.   

    大哥我用的是死循环! 不是Timer!