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

📄 unit2.pas

📁 用Delphi语言实现的串口通讯
💻 PAS
字号:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, SPComm;

type
  TForm2 = class(TForm)
    GroupBox1: TGroupBox;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    ComboBoxCom: TComboBox;
    Label2: TLabel;
    ComboBoxB: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    Comm1: TComm;
    ComboBoxBytesize: TComboBox;
    ComboBoxStopBits: TComboBox;
    Label5: TLabel;
    ComboBoxParity: TComboBox;
    CheckBoxParityCheck: TCheckBox;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBoxParityCheckClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.BitBtn1Click(Sender: TObject);
begin
  with form1 do
  begin
    CurrentComPort       := ComboBoxCom.text;
    CurrentBaudRate      := StrToInt(ComboBoxB.Text);
    CurrentBytesize      := TByteSize(ComboBoxBytesize.itemIndex);
    CurrentStopBits      := TStopBits(ComboBoxStopBits.itemIndex);
    if CheckBoxParityCheck.Checked then
    begin
       CurrentParityCheck := true;
       CurrentParity      := TParity(ComboBoxParity.ItemIndex);
    end
    else
    begin
       CurrentParityCheck := false;
       CurrentParity      := None;
    end;

    //////////
    CurrentOutx_CtsFlow  := false;
    CurrentOutx_DsrFlow  := false;
    CurrentOutx_XonXoffFlow := False;
    //////////
    InitCom;
  end;
  Close;
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
  ComboBoxCom.ItemIndex := 0;
  ComboBoxB.ItemIndex   := 3;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  //Init Show
  with Form1 do
  begin
    ComboBoxBytesize.ItemIndex := Byte(CurrentBytesize);
    ComboBoxStopBits.ItemIndex := Byte(CurrentStopBits);
    if CurrentParityCheck then
    begin
      CheckBoxParityCheck.Checked := true;
      ComboBoxParity.Enabled      := true;
      ComboBoxParity.ItemIndex := Byte(CurrentParity);
    end
    else
    begin
      CheckBoxParityCheck.Checked := false;
      ComboBoxParity.Enabled      := false;
      ComboBoxParity.ItemIndex := Byte(CurrentParity);
    end;
  end;
end;                            

procedure TForm2.CheckBoxParityCheckClick(Sender: TObject);
begin
  if CheckBoxParityCheck.Checked then
     ComboBoxParity.Enabled := true
  else
     ComboBoxParity.Enabled := false;
end;

end.

⌨️ 快捷键说明

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