六月婷婷综合-日韩理论在线-69久久久久-欧色图-蜜桃成人在线视频-色先锋在线-亚洲va中文字幕-香蕉影院在线-av一区免费-强开小嫩苞一区二区三区网站-国产视频九色蝌蚪

寧波市鄞州首南恒宇激光雕刻廠

WINDOWS95與NT下微機與智能化儀的串行通信設計*下*
分享到:

圖2 3構件源程序 ......





圖 2
3 構件源程序
unit comm32;
interface
uses
  Windows,Messages,SysUtils,Classes, Graphics, Controls, Forms, Dialogs;
const
   WMCOMMNOTIFY = WMUSER + 1;
Type{定義屬性用梅舉類型}
   TParity = ( None, Odd, Even, Mark, Space );
   TStopBits = (1, 15, 2 );
   TOncommMode = (evchar,evflag);
   TComPorts=( com1,com2,com3,com4);
  ECommsError = class( Exception );
  TOncommEvent = procedure(Sender: TObject;Buffer:Pointer;BufferLength: Word) of
object;{觸發事件對像}
   Type{創建監視線程類}
  TMyCommWacth = class(TThread)
  private
   PostEvent: Integer;
   { Private declarations }
本文有[www.0574-laser.com]提供,請及時關注[www.0574-laser.com]提供的內容
  protected
   procedure Execute; override;
  Public
  hCommFile: THandle;{串口句柄}
  hCloseEvent: THandle; {事件句柄}
  hComm32Window:THandle;{消息窗句柄}
   Lpoverlapped:TOVERLAPPED;
   ConStructor Create;{構造函數}
  end;
type{創建構件對象}
  Tcomm32 = class(TComponent)
  Private{定義屬性的私有變量}
   MyComThread: TMyCommWacth;
   BaudRates:   Integer;
   comName: TComPorts;
   parity: TParity ;
   Stopbits : TStopBits ;
   DataBits : Byte;
   InPutbuffers: Integer;
   OutPutbuffers: Integer;
commMode: TOncommMode;
OnCommMsg: TOnCommEvent;
procedure CommWndProc( var msg: TMessage );message WMCOMMNOTIFY;
   { Private declarations }
  protected
   procedure OnCommData(Buffer: PChar; BufferLength: Word);
   { Protected declarations }
  public{運行屬性}
   hCommFile:   THandle;
hCloseEvent: THandle;
   hComm32Window:THandle;
Function ComPortOpen : Thandle;
Function ComPortClose : Boolean;
procedure CloseMyComThread;
   Constructor
Create(Aowner:TComponent);override;
   destructor Destroy; override;
   { Public declarations }
published{可視屬性及事件}
property comParity: TParity read Parity Write Parity default None;
property ComPortName:TComPorts read comName Write comName default com2;
property BaudRate:Integer read BaudRates Write BaudRates default 9600 ;
property Stopbit:TStopBits read Stopbits Write Stopbits default1;
property ByteDataBit:Byte read DataBits Write DataBits default 8;
property InBuffersize: Integer read InPutbuffers Write InPutbuffers default 1024;
property OutBuffersize:Integer read OutPutbuffers Write OutPutbuffers default 1024;
property SetComMode:TOncommMode read commMode Write commMode default evChar;
property OnComm:TOnCommEvent read OnCommMsg write OnCommMsg;
end;
procedure Register;
implementation
TMyCommWacth.Create();{監視線程創建}
begin
   inherited Create(False);
   FreeOnTerminate:=True;
end;
{監視線程執行}
procedure TMyCommWacth.Execute;
Var DwTransfer,DwEvtMask:Integer;
begin
  if Comm32.SetComMode = Evchar then
  begin
   if not SetCommMask(hCommFile,
   EVRXCHAR) then Exit;
   While( true) do
   begin
    DwEvtMask:=0;
    WaitCommEvent(hCommFile,
    DwEvtMask,@Lpoverlapped);
    if((DwEvtMaskandEVRXCHAR)
    =EVRXCHAR) then
   begin
    WaitForSingleObject(PostEvent, 1000000);
    ResetEVent(PostEvent);
    PostMessage(hComm32Window ,WMCOMMNOTIFY,hcommfile,0);
    end;
   end;
  end else
  begin
   if not setCommMask(hCommFile,
EVRXFLAG) then Exit;
   While( true) do
   begin
    DwEvtMask:=0;
    WaitCommEvent(hCommFile,DwEvtMask,@comm32.Lpoverlapped);
    if ((DwEvtMask and EVRXFLAG)
    =EVRXFLAG) then
    begin
     WaitForSingleObject(comm32.PostEvent,1000000);
    ResetEVent(comm32.PostEvent);
    PostMessage(hComm32Window,WMCOMMNOTIFY,hCommFile,NULL);
    end;
    end;
  end;
end; {監視線程結束}
{建立通信構件}
Tcomm32.Create(Aowner:Tcomponent);
begin
   inherited Create(aOwner);
   MyComThread:= nil;
   hCommFile := 0;
   hCloseEvent := 0;
   Parity:=None;
   ComName:=com2;
   BaudRates:=9600;
   Stopbits:=1;
   DataBits:=8;
   InPutBuffers:=1024;
   OutPutBuffers:=1024;
   CommMode:=Evchar;
end;
destructor TComm32.Destroy;{構件析構函數}
begin
   if not(csDesigning in ComponentState)then
   DeallocateHWnd(hComm32Window);
   inherited Destroy;
end;
procedure Register;{構件注冊}
begin
本文有[www.0574-laser.com]提供,請及時關注[www.0574-laser.com]提供的內容
  RegisterComponents(’Sample’, [Tcomm32]);
end;
procedure TComm32.OnCommData(Buffer: PChar; BufferLength: Word);
begin
   if Assigned(OnCommMsg) then
     OnCommMsg( self , Buffer, BufferLength);
end;
{構件端口打開方法}
Function TComm32.comPortOpen : Thandle;
var dcbPort:TDCB;
   ComBuff:BOOlean;
   StrCom:string;

聯系我們

地址: 浙江省.寧波市鄞州區寧姜公路(九曲小區二期旁)

郵編: 315040

聯系人: 盛立峰

電話: 0574-87139378

傳真: 0574-87139378

手機: 13867861670

郵箱: 85400329@qq.com

聯系我們
主站蜘蛛池模板: 澎湖县| 青州市| 巴彦县| 吕梁市| 宣武区| 宁海县| 会昌县| 客服| 平远县| 禹城市| 神池县| 汝城县| 阳高县| 舞钢市| 油尖旺区| 宁津县| 新昌县| 西充县| 裕民县| 灵丘县| 湾仔区| 泽州县| 禄丰县| 延庆县| 昆明市| 南华县| 宁蒗| 酒泉市| 古浪县| 金昌市| 旺苍县| 天门市| 上思县| 塔河县| 文水县| 开化县| 宁明县| 泰宁县| 漳州市| 那坡县| 宁陵县|