⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treadunit.pas

📁 用来模拟PC机的串口
💻 PAS
字号:
unit TreadUnit;

interface

uses Windows,Classes;


type
TSerialThread = class (TThread)
private
  AppHandle:HWND;
  SerialHandle : integer;
  sermes : integer;
protected
  procedure Execute; override;
public
  constructor Create(SerHandle:integer;mes:integer;ApHndl:HWND);
end;

implementation


constructor TSerialThread.Create(SerHandle:integer;mes : integer;ApHndl:HWND);
begin
  AppHandle:=ApHndl;      { Store the handle of the main application            }
  SerialHandle:=SerHandle;{ Store the handle of the serial port                 }
  sermes:=mes;            { Store the user-defined message value. This will be  }
                          { used by the application to check if the message     }
                          { is send by this thread, and thus a serial event has }
                          { ocurred.                                            }

  FreeOnTerminate:= True; { When the thread is done, it will close down and     }
                          { free all of its resources.                          }

  inherited Create (False);{ Call the constructor of the used base-class        }
end;

procedure TSerialThread.Execute;
var
  SerialEvent : Cardinal;
begin
  SetCommMask (SerialHandle,
  EV_CTS or EV_BREAK or EV_DSR or
  EV_ERR or EV_RING or EV_RLSD or
  EV_RXCHAR or EV_RXFLAG or EV_TXEMPTY);
  WaitCommEvent (SerialHandle,SerialEvent,nil);
{ Now, execution is halted, until some event occurs on the      }
{ serial port.                                                  }

  PostMessage (AppHandle,sermes,SerialEvent,0);
{ Send a message to the application, to notify the change in    }
{ state of the serial port.                                     }
end;

begin
end.

⌨️ 快捷键说明

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