📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Grids, ValEdit, CPort, ExtCtrls;
type
TForm1 = class(TForm)
ComboBox_PortList: TComboBox;
ComboBox_BaudRate: TComboBox;
ComboBox_ByteSize: TComboBox;
ComboBox_Parity: TComboBox;
ComboBox_StopBit: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label5: TLabel;
GroupBox1: TGroupBox;
Button_OpenCom: TButton;
Button_CloseCom: TButton;
GroupBox2: TGroupBox;
Button3: TButton;
Button4: TButton;
TabSheet1: TTabSheet;
Label4: TLabel;
GroupBox3: TGroupBox;
Memo_SciTransArea: TMemo;
Memo_SciReceArea: TMemo;
Label6: TLabel;
Label7: TLabel;
Button_SciClearRece: TButton;
Button_SciClearTrans: TButton;
Button_SciTrans: TButton;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
PageControl: TPageControl;
StatusBar1: TStatusBar;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
GroupBox4: TGroupBox;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Label8: TLabel;
GroupBox5: TGroupBox;
Label9: TLabel;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
GroupBox6: TGroupBox;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
ComboBox6: TComboBox;
StringGrid3: TStringGrid;
Button14: TButton;
Button15: TButton;
Button16: TButton;
GroupBox7: TGroupBox;
Button17: TButton;
Button18: TButton;
Button19: TButton;
Button20: TButton;
Button21: TButton;
GroupBox8: TGroupBox;
StringGrid4: TStringGrid;
StaticText1: TStaticText;
Button22: TButton;
Button23: TButton;
ListBox1: TListBox;
Button24: TButton;
Label17: TLabel;
Button25: TButton;
Button26: TButton;
GroupBox9: TGroupBox;
ScrollBox1: TScrollBox;
ScrollBox2: TScrollBox;
StaticText3: TStaticText;
GroupBox10: TGroupBox;
Edit1: TEdit;
Label18: TLabel;
Button27: TButton;
Button28: TButton;
Button29: TButton;
Button30: TButton;
GroupBox11: TGroupBox;
ComPort1: TComPort;
TabSheet6: TTabSheet;
GroupBox12: TGroupBox;
ListBox2: TListBox;
GroupBox13: TGroupBox;
GroupBox14: TGroupBox;
Button_AddComm: TButton;
Button32: TButton;
GroupBox15: TGroupBox;
GroupBox16: TGroupBox;
Memo4: TMemo;
Memo5: TMemo;
Label20: TLabel;
Button33: TButton;
Button34: TButton;
Button35: TButton;
Button36: TButton;
Label22: TLabel;
Edit3: TEdit;
Label23: TLabel;
ComboBox1: TComboBox;
Edit2: TEdit;
Label19: TLabel;
Timer1: TTimer;
Timer2: TTimer;
Edit_Klinetest_AddComm: TEdit;
Label_AddCommStatus: TLabel;
procedure StringGrid1Click(Sender: TObject);
procedure Form1_Create(Sender: TObject);
procedure Button_OpenComClick(Sender: TObject);
procedure Button_CloseComClick(Sender: TObject);
procedure Button_SciTransClick(Sender: TObject);
procedure Button_SciClearTransClick(Sender: TObject);
procedure Button_SciClearReceClick(Sender: TObject);
procedure ComPortRxChar(Sender: TObject; Count: Integer);
procedure Button_AddCommClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Klinetest_EditAddComm_TextPrevious: String;
implementation
{$R *.dfm}
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
Form1.StringGrid1.Cells[0,0]:='Hello';
{Form1.ComPort1.CustomBaudRate }
end;
procedure TForm1.Form1_Create(Sender: TObject);
begin
EnumComPorts(ComboBox_PortList.Items);
// do some stuff
if ComboBox_PortList.ItemIndex > -1 then
ComPort1.Port := ComboBox_PortList.Items[ComboBox_PortList.ItemIndex];
Form1.ComPort1.CustomBaudRate := 10400;
Form1.ComPort1.BaudRate:= brCustom;
Form1.ComboBox_BaudRate.Items.Add('9600');
Form1.ComboBox_BaudRate.Items.Add('10400');
Form1.ComboBox_BaudRate.Items.Add('19200');
Form1.ComboBox_BaudRate.Items.Add('38400');
Form1.ComboBox_BaudRate.Items.Add('57600');
Form1.ComboBox_BaudRate.Items.Add('115200');
Form1.ComboBox_ByteSize.Items.Add('5');
Form1.ComboBox_ByteSize.Items.Add('6');
Form1.ComboBox_ByteSize.Items.Add('7');
Form1.ComboBox_ByteSize.Items.Add('8');
Form1.ComboBox_Parity.Items.Add('None');
Form1.ComboBox_Parity.Items.Add('Odd');
Form1.ComboBox_Parity.Items.Add('Even');
Form1.ComboBox_Parity.Items.Add('Mark');
Form1.ComboBox_Parity.Items.Add('Space');
Form1.ComboBox_StopBit.Items.Add('1');
Form1.ComboBox_StopBit.Items.Add('1.5');
Form1.ComboBox_StopBit.Items.Add('2');
Klinetest_EditAddComm_TextPrevious := '';
Form1.ShowHint := True;
Application.ShowHint := True;
end;
procedure TForm1.Button_OpenComClick(Sender: TObject);
begin
Form1.ComPort1.Port := Form1.ComboBox_PortList.Text;
Form1.ComPort1.CustomBaudRate := StrtoInt(Form1.ComboBox_BaudRate.Text);
Form1.ComPort1.BaudRate:= brCustom;
Form1.ComPort1.DataBits := StrtoDatabits(Form1.ComboBox_ByteSize.Text);
Form1.ComPort1.StopBits := StrtoStopbits(Form1.ComboBox_StopBit.Text);
Form1.ComPort1.Parity.Bits := StrtoParity(Form1.ComboBox_Parity.Text);
if not Form1.ComPort1.Connected then
Form1.ComPort1.Open;
end;
procedure TForm1.Button_CloseComClick(Sender: TObject);
begin
if Form1.ComPort1.Connected then
Form1.ComPort1.Close;
end;
procedure TForm1.Button_SciTransClick(Sender: TObject);
begin
Form1.ComPort1.WriteStr(Form1.Memo_SciTransArea.Text);
end;
procedure TForm1.Button_SciClearTransClick(Sender: TObject);
begin
Form1.Memo_SciTransArea.Text := '';
end;
procedure TForm1.Button_SciClearReceClick(Sender: TObject);
begin
Form1.Memo_SciReceArea.Text := '';
end;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin
Form1.ComPort1.ReadStr(Str, Count);
Form1.Memo_SciReceArea.Text := Form1.Memo_SciReceArea.Text + Str;
end;
procedure TForm1.Button_AddCommClick(Sender: TObject);
var
I,J,Len,InputErrorFlag: Integer;
SpaceCharIndex: array of Integer;
CommAdjustStr: String;
begin
Len := Length(Form1.Edit_Klinetest_AddComm.Text);
SetLength(SpaceCharIndex, 20);
for I := 1 to len do
begin
if Form1.Edit_Klinetest_AddComm.Text[I] <> ' ' then
begin
if not (Form1.Edit_Klinetest_AddComm.Text[I] in ['0'..'9','a'..'f','A'..'F']) then
InputErrorFlag := 1;
end
else
InputErrorFlag := 0;
end;
if InputErrorFlag = 1 then
begin
Form1.Edit_Klinetest_AddComm.Color := clRed;
Form1.Label_AddCommStatus.Caption := 'INPUT ERROR!';
end
// Form1.Edit2.Text := InttoStr(I);
else
begin
Form1.Edit_Klinetest_AddComm.Color := clWindow;
Form1.Label_AddCommStatus.Caption := '';
end;
if InputErrorFlag = 0 then
begin
J := 1;
{
for I := 1 to len do
begin
if Form1.Edit_Klinetest_AddComm.Text[I] = ' ' then
begin
SpaceCharIndex[J] := I;
J := J + 1;
end
end;
Form1.Edit2.Text := InttoStr(J);
}
for I := 1 to len do
begin
if Form1.Edit_Klinetest_AddComm.Text[I] <> ' ' then
begin
CommAdjustStr[J] := Form1.Edit_Klinetest_AddComm.Text[I];
J := J + 1;
if J mod 3 = 0 then
begin
CommAdjustStr := CommAdjustStr + ' ';
J := J + 1;
end
end
end;
Form1.Edit_Klinetest_AddComm.Text := InttoStr(J);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -