乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Comport Component For Wince 5.0

       ZLM_圖書(shū)館 2013-12-31
      unit Win32CESerialCom;
      interface
      uses
        Windows, Classes, SysUtils, LResources, ExtCtrls;
       

      type
        TComBuf=array[0..255] of byte;
        TWin32CESerialCom = class(TObject)
        private
          hComm: THandle;
        public
          Connected:Boolean;
          function  OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
          procedure SendString(str:String);
          procedure SendChar(chr:char);
          function  SendData(buf:TComBuf;Bytes:Integer):integer;
          function  ReceiveString:String;
          function  ReadMax(var buf:TComBuf):integer;
          function  WaitForBytes(Count, Ms: cardinal): boolean;
          function  InQue:Integer;
          function  OutQue:Integer;
          procedure PurgeOut;
          procedure PurgeIn;
          procedure ClosePort;
        end;


      implementation

      procedure TWin32CESerialCom.PurgeIn;
      begin
      if not PurgeComm(hComm, PURGE_RXABORT or PURGE_RXCLEAR) then
      raise Exception.Create('Unable to purge com: ');
      end;

      procedure TWin32CESerialCom.PurgeOut;
      begin
      if not PurgeComm(hComm, PURGE_TXABORT or PURGE_TXCLEAR) then
      raise Exception.Create('Unable to purge com: ');
      end;

      function TWin32CESerialCom.InQue: Integer;
      var Errors: DWORD;
      ComStat: TComStat;
      begin
      if not ClearCommError(hComm, Errors, @ComStat) then
      raise Exception.Create('Unable to read com status: ');
      Result := ComStat.cbInQue;
      end;

      function TWin32CESerialCom.OutQue: Integer;
      var Errors: DWORD;
      ComStat: TComStat;
      begin
      if not ClearCommError(hComm, Errors, @ComStat) then
      raise Exception.Create('Unable to read com status: ');
      Result := ComStat.cbOutQue;
      end;

      function TWin32CESerialCom.WaitForBytes(Count, Ms: cardinal): boolean;
      var
        iq:integer;

      begin
        Result:=False;
        if hComm=INVALID_HANDLE_VALUE then exit;
        Ms:=Ms+GetTickCount();
        while (ms>=GetTickCount())and(hComm<>INVALID_HANDLE_VALUE) do begin
          try
          iq:=InQue;
          except
          Exit;
          end;
          if iq>=Count then begin;Result:=True;Break;end;
          sleep(1);
        end;
      end;

      function TWin32CESerialCom.OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
      var
        cc:TCOMMCONFIG;
      {$IFDEF Win32}
        SAnsi:AnsiString;
        Port:LPCSTR;
      {$ENDIF}
      {$IFDEF WinCE}
        SWide:WideString;
        Port:LPCWSTR;
      {$ENDIF}

      begin
      {$IFDEF Win32}
        SAnsi:=ComPort;
        port:=PChar(SAnsi);
      {$ENDIF}
      {$IFDEF WinCE}
        SWide:=ComPort;
        port:=PWideChar(SWide);
      {$ENDIF}
        result:='';
      if not Connected then begin
        Connected:=False;
        hComm:=CreateFile(Port, GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING, 0, 0);
        if (hComm = INVALID_HANDLE_VALUE) then begin
          result:='CreateFile Error!';
          exit;
        end;

        GetCommState(hComm,cc.dcb);
        cc.dcb.BaudRate:=BaudRate;
        cc.dcb.ByteSize:=ByteSize;
        cc.dcb.Parity:=Parity;
        cc.dcb.StopBits:=StopBits;
       
        if not SetCommState(hComm, cc.dcb) then begin
          result:='SetCommState Error!';
          CloseHandle(hComm);
          exit;
        end;
        Connected:=True;
      end;
      end;

      procedure TWin32CESerialCom.SendString(str:String);
      var
        lrc:LongWord;
      begin
        if (hComm=0) then exit;
        try
        PurgeOut;
        except
        Exit;
        end;
        WriteFile(hComm,str,Length(str), lrc, nil);
      end;

      procedure TWin32CESerialCom.SendChar(chr:char);
      var
        lrc:LongWord;
      begin
        if (hComm=0) then exit;
        try
        PurgeOut;
        except
        Exit;
        end;
        WriteFile(hComm,chr,1, lrc, nil);
      end;

      function TWin32CESerialCom.SendData(buf:TComBuf;Bytes:Integer):integer;
      var
        lrc:LongWord;
      begin
        result:=0;
        if (hComm=0) then exit;
        try
        PurgeOut;
        except
        Exit;
        end;
        WriteFile(hComm,buf,Bytes, lrc, nil);
        result:=lrc;
      end;

      Function TWin32CESerialCom.ReceiveString:String;
      var
        inbuff: array[0..2047] of Char;
        nBytesRead, dwError:LongWORD ;
        cs:TCOMSTAT;
      begin
         ClearCommError(hComm,dwError,@CS);
            if cs.cbInQue > sizeof(inbuff) then begin
           PurgeComm(hComm, PURGE_RXCLEAR);
           exit;
         end;
         ReadFile(hComm, inbuff,cs.cbInQue,nBytesRead,nil);
         result:=Copy(inbuff,1,cs.cbInQue);
      end;                             

      function TWin32CESerialCom.ReadMax(var buf:TComBuf):integer;
      var
        nBytesRead, dwError:LongWORD ;
        cs:TCOMSTAT;
      begin
         result:=0;DwError:=0;nBytesRead:=0;
         if hComm=INVALID_HANDLE_VALUE then exit;
         ClearCommError(hComm,dwError,@CS);
         ReadFile(hComm, buf,cs.cbInQue,nBytesRead,nil);
         result:=nBytesRead;
      end;

      procedure TWin32CESerialCom.ClosePort;
      begin
         if Connected then begin
          SetCommMask(hcomm,$0);
          CloseHandle(hComm);
         end;
         Connected:=False;
      end;

      end.

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多