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

📄 unit1.pas

📁 这是一个用DELPHI编写的串行接口控制程序
💻 PAS
字号:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    MSComm1: TMSComm;
    RadioButton2: TRadioButton;
    Timer1: TTimer;
    RadioButton1: TRadioButton;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    procedure Label9Click(Sender: TObject);
    procedure Label12Click(Sender: TObject);
    procedure Label11Click(Sender: TObject);
    procedure Label10Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure MSComm1Comm(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
//pp:integer;
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Label9Click(Sender: TObject);
begin
if RadioButton1.Checked =true then
   begin
     MSComm1.CommPort :=1;
     MSComm1.PortOpen :=true;
     MSComm1.RTSEnable :=false;
     MSComm1.DTREnable :=false;
   end
   else if RadioButton1.Checked =false then
 begin
 ShowMessage('你没选择端口系统自动帮你选择COM1了');
 RadioButton1.Checked :=true;
 MSComm1.CommPort :=1;
     MSComm1.PortOpen :=true;
     MSComm1.RTSEnable :=false;
     MSComm1.DTREnable :=false;

 //MSComm1.PortOpen :=false;


   //  MSComm1.RTSEnable :=false;
    // MSComm1.DTREnable :=false;

 end;
Label11.Enabled :=false;
Label10.Enabled :=true;
end;

procedure TForm1.Label12Click(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.Label11Click(Sender: TObject);
begin
Shape1.Brush.Color := RGB(255,255,255);
Shape2.Brush.Color := RGB(255,255,255);
Shape3.Brush.Color := RGB(255,255,255);
Shape4.Brush.Color := RGB(255,255,255);
Shape5.Brush.Color := RGB(255,255,255);
Shape6.Brush.Color := RGB(255,255,255);
Shape7.Brush.Color := RGB(255,255,255);
Shape8.Brush.Color := RGB(255,255,255);
MSComm1.DTREnable := False ;
MSComm1.RTSEnable := False ;
end;

procedure TForm1.Label10Click(Sender: TObject);

begin
MSComm1.PortOpen :=false;
Label9.Enabled :=true;
Label11.Enabled :=true;
Label10.Enabled :=false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
label9.Font.Color:=rgb(random(60),random(0),random(250));
label12.Font.Color:=rgb(random(60),random(0),random(250));

end;

procedure TForm1.MSComm1Comm(Sender: TObject);
begin
case MSComm1.CommEvent of
comEvCD:
begin
 if MSComm1.CDHolding  then
    begin
        if MSComm1.CommPort = 1 then
           shape1.Brush.Color := RGB(175,237,245)
        else
        shape5.Brush.Color := RGB(175,237,245);
        MSComm1.DTREnable := true;
        MSComm1.RTSEnable := true;
    end
 else
    begin
       Shape1.Brush.Color := RGB(255,255,255);
       Shape5.Brush.Color := RGB(255,255,255);
       MSComm1.RTSEnable := False;
       MSComm1.DTREnable := False;
    end;
end;
comEvDSR:
begin
  If MSComm1.DSRHolding Then
    begin
        if MSComm1.CommPort = 1 then
           shape2.Brush.Color := RGB(175,237,245)
        else
           shape6.Brush.Color := RGB(175,237,245);
        MSComm1.DTREnable := true;
        MSComm1.RTSEnable := true;
     end
  else
    begin
      Shape2.Brush.Color:= RGB(255,255,255);
      shape6.Brush.Color := RGB(255,255,255);
      MSComm1.DTREnable  := False ;
      MSComm1.RTSEnable   := False ;
    end;
end;
comEvCTS:
begin
  If MSComm1.CTSHolding Then
     begin
        if MSComm1.CommPort = 1 then
           shape3.Brush.Color := RGB(175,237,245)
        else
           shape7.Brush.Color := RGB(175,237,245);
        MSComm1.DTREnable := true;
        MSComm1.RTSEnable := true;

     end
else
  begin
  Shape3.Brush.Color := RGB(255,255,255);
    Shape7.Brush.Color := RGB(255,255,255);
    MSComm1.DTREnable  := False;
    MSComm1.RTSEnable  := False;
  End;
end;
comEvRing:
begin
    if MSComm1.CommPort = 1 Then
        Shape4.Brush.Color := RGB(175,237,245)
    Else
       Shape8.Brush.Color := RGB(175,237,245);
    MSComm1.DTREnable  := true;
    MSComm1.RTSEnable  :=true;
end;
end;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
if RadioButton2.Checked =true then
   begin
   ShowMessage('不好意思你只能选择COM1');
    // MSComm1.CommPort:=2;
    // MSComm1.PortOpen :=true;
    // MSComm1.RTSEnable :=false;
    // MSComm1.DTREnable :=false;
   end ;
end;

end.

⌨️ 快捷键说明

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