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

📄 mscon.pas

📁 串口程序75654274897 9789797897
💻 PAS
字号:
unit mscon;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;

type
  TForm1 = class(TForm)
    MSComm1: TMSComm;
    Label1: TLabel;
    procedure mscomm1_init();
    procedure mscomm1_rece();
    procedure FormCreate(Sender: TObject);
    procedure MSComm1Comm(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  keycode:integer;

implementation

{$R *.dfm}

procedure TForm1.mscomm1_init();
begin
with mscomm1 do
  begin
     If not  PortOpen
     Then  begin
     CommPort := 1;      //指定端口
     Settings := '4800,N,8,1';  //其它参数
     InBufferSize := 10;      //接收缓冲区
     OutBufferSize := 10;     //发送缓冲区
     InputMode := comInputModetext; //接收模式
     InputLen := 0;             //一次读取所有数据
     InBufferCount := 0;        //清空读取缓冲区
     OutBufferCount := 0;       //清空发送缓冲区
     SThreshold := 0;           //一次发送的数据
     RThreshold := 1;  // 1;      //设置接收多少字节开产生oncomm事件
     DTREnable :=  False ;           // False
     RTSEnable :=  True ;           ///False   接收器
     NullDiscard := False;         // False
     PortOpen := true;            //打开端口
     end;
  end;
end;
//////////

procedure TForm1.mscomm1_rece();
var  
    s: string;
    winHwnd:Hwnd;
begin
//   if   (not b_uart)or b_uart_un  or b_poweroff
//   then  exit;
  // MSComm1.RThreshold := 0;
   s := MSComm1.Input;
   //if  s[1]='' then exit;

   //Label1.Caption := s ;    //显示接收的代码

   if  s='' then exit;
   keycode := ord(s[1]);
   Label1.Caption := IntToStr(keycode);  //显示接收的代码 10进制


//  mscomm1.InBufferCount := 0;
//  MSComm1.OutBufferCount := 0;
//  MSComm1.RThreshold := 1;
end;

////////////

procedure TForm1.FormCreate(Sender: TObject);
begin
  //frmuart.form_init();
  mscomm1_init();
end;

procedure TForm1.MSComm1Comm(Sender: TObject);
begin
  case  mscomm1.CommEvent of
        comEvCD:  ;         //CD 线的状态发生变化
        comEvCTS: ;         //CTS 线的状态发生变化
        comEvDSR: ;         // DSR 线的状态发生变化
        comEvRing:;         //Ring Indicator 变化
        comEvSend:; 
        comEvReceive: begin
                      MSComm1.RThreshold := 0;
                      mscomm1_rece();
                      mscomm1.InBufferCount := 0;
                      MSComm1.OutBufferCount := 0;
                      MSComm1.RThreshold := 1;
                      end;
  end;
end;

end.

⌨️ 快捷键说明

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