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

📄 ucommsg.pas.~6~

📁 用串口发送手机短信 需要GSM Mode设备
💻 ~6~
字号:
unit uComMsg;

interface

uses
  Windows,SysUtils;

type
  TclsComMsg=Class(TObject)

    private

    public
      function SendB(CommPort,tmpBaud:Word;const bytBuf:TBytes) :boolean;
  end;

implementation

function TclsComMsg.SendB(CommPort,tmpBaud:Word;const bytBuf:TBytes) :boolean;
var
  hComm:THandle;
  cc:TCOMMCONFIG;   //Windows引用
  tmp:string;
  iBaud :integer;
begin
  Result := false;
  //设置端口
  if(CommPort=2) then tmp := 'com2'
  else if(CommPort=3) then tmp := 'com3'
  else if(CommPort=4) then tmp := 'com4'
  else tmp := 'com1';

  if tmpBaud=1200 then iBaud :=CBR_1200
  else if tmpBaud=2400 then iBaud :=CBR_2400
  else if tmpBaud=4800 then iBaud :=CBR_4800
  else  iBaud :=CBR_9600;

  hComm := CreateFile(PChar(tmp),Generic_Read or Generic_Write, 0, nil, Open_Existing, 0, 0);//打开串行口
  if(hComm=Invalid_Handle_Value)then begin
    Result := false;
    exit;
  end;

  GetCommState(hComm,cc.dcb);    //获取默认通信参数

  cc.dcb.BaudRate:=iBaud;
  cc.dcb.ByteSize:=8;
  cc.dcb.Parity:= 0;  //NOPARITY = 0; MARKPARITY = 3; SPACEPARITY = 4;
  cc.dcb.StopBits:=ONESTOPBIT;  //ONESTOPBIT = 0;

  if not SetCommState(hComm,cc.dcb) then begin  //设置通信参数
    CloseHandle(hComm);         //关闭串行口
    Result := false;
    exit;
  end;

  CloseHandle(hComm);
  Result := true;
end;

end.

⌨️ 快捷键说明

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