jscom1.pas

来自「串口调试助手源码」· PAS 代码 · 共 62 行

PAS
62
字号
unit JsCom1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ToolWin, ComCtrls, ImgList, StdCtrls, ExtCtrls;

type
  TJsCom1 = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;

implementation
  uses
     comm1;

{ Important: Methods and properties of objects in VCL can only be used in a
  method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TJsCom1.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TJsCom1 }

procedure TJsCom1.Execute;
var
dwEvtMask:DWORD;
Wait,SendOk:Boolean;
  Read_Os:Toverlapped;      
begin
  { Place thread code here }
  fillchar(Read_Os,sizeof(toverlapped),0);
  While True do
  Begin
    //waitforsingleobject(post_event,infinite);
    //resetevent(post_event);
    dwEvtMask:=0;
    Wait:=WaitCommEvent(hcom,dwEvtMask,@Read_Os);
    if Wait Then
    Begin
        if (dwEvtMask and Ev_Rxchar)=Ev_Rxchar then
        begin
            SendOk:=PostMessage(Form1.Handle,WM_COMMNOTIFY,0,0);
            if not SendOk then ShowMessage('串口监视线程无法与主线程通讯!');
        end;
    end;
  end;
end;


end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?