📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ExtCtrls,declaredll,strutils, ComCtrls,Unit2;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label8: TLabel;
commindex: TComboBox;
Button7: TButton;
GroupBox3: TGroupBox;
Label11: TLabel;
Label12: TLabel;
Edit_edc: TEdit;
Button_caledc: TButton;
Edit_edc_cal: TEdit;
Button_updata: TButton;
GroupBox1: TGroupBox;
Button1: TButton;
Edit1: TEdit;
GroupBox4: TGroupBox;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
Button2: TButton;
Edit2: TEdit;
Edit4: TEdit;
GroupBox2: TGroupBox;
Label5: TLabel;
Label9: TLabel;
Label10: TLabel;
Label19: TLabel;
Button3: TButton;
Edit3: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit8: TEdit;
GroupBox6: TGroupBox;
Label20: TLabel;
Label24: TLabel;
Label25: TLabel;
Button6: TButton;
Edit12: TEdit;
Edit16: TEdit;
CheckBox1: TCheckBox;
GroupBox7: TGroupBox;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label26: TLabel;
Button8: TButton;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Edit17: TEdit;
CheckBox2: TCheckBox;
GroupBox8: TGroupBox;
Label27: TLabel;
Button9: TButton;
Edit18: TEdit;
CheckBox3: TCheckBox;
GroupBox9: TGroupBox;
Label28: TLabel;
Button10: TButton;
Edit21: TEdit;
Edit19: TEdit;
GroupBox10: TGroupBox;
Label29: TLabel;
Label30: TLabel;
Button11: TButton;
Edit20: TEdit;
Edit22: TEdit;
grp1: TGroupBox;
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
btn1: TButton;
edt_1: TEdit;
edt_2: TEdit;
edt_3: TEdit;
lv1: TListView;
edt_4: TEdit;
procedure Button_updataClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure myproc();
private
{ Private declarations }
public
{ Public declarations }
timeconitue:Boolean;
end;
var
Form1: TForm1;
Comport_Handle:thandle;
startxbh:integer;
endxbh:integer;
midxbh:integer;
zqs:integer;
sjjg:integer;
thread0:lsthread;
implementation
{$R *.dfm}
function isrightint(textls:string):boolean;stdcall;
begin
//
try
if(strtoint(textls) =0) then
begin
end;
result := True;
except
result := False;
exit;
end;
end;
procedure TForm1.Button_updataClick(Sender: TObject);
var
i:byte;
j:byte;
begin
j := 0;
commindex.Clear() ;
for i := 1 to 9 do
begin
Comport_Handle := PortOpen(i);
if(INVALID_HANDLE_VALUE <> Comport_Handle) then
begin
if(j=0) then
begin
j := i;
end;
commindex.AddItem('COM'+IntToStr(i),Sender);
PortClose(Comport_Handle);
end;
end;
if(commindex.Items.Count >0) then
begin
commindex.ItemIndex := 0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
strls:string;
status:integer;
lll:array[0..99] of char;
jhls:pchar;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
jhls := lll;
status := GetDeviceNo(comport_handle,jhls); //读设备号
PortClose(comport_handle);
if(status =0) then
begin //成功
Edit1.Text := jhls;
Edit2.Text := Edit1.Text;
Edit6.Text := Edit1.Text;
Edit16.Text := Edit1.Text;
Edit17.Text := Edit1.Text;
Edit18.Text := Edit1.Text;
Edit19.Text := Edit1.Text;
Edit22.Text := Edit1.Text;
end
else
begin
Edit1.Text := '没读到机号';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
strls:string;
status:integer;
lll:array[0..99] of char;
jhls:pchar;
begin
if(Length(Edit2.Text) = 0) then
begin
Application.MessageBox('原设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit2.SelectAll();
exit;
end;
if(not isrightint(Edit2.Text)) then
begin
Application.MessageBox('原设备号中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit2.SetFocus();
Edit2.SelectAll();
exit;
end;
if(Length(Edit4.Text) = 0) then
begin
Application.MessageBox('新设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit4.SelectAll();
exit;
end;
if(not isrightint(Edit4.Text)) then
begin
Application.MessageBox('新设备号中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit4.SetFocus();
Edit4.SelectAll();
exit;
end;
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
status := SetDeviceNo(comport_handle,StrToInt(Edit2.Text),StrToInt(Edit4.Text)); //读设备号
PortClose(comport_handle);
if(status =0) then
begin //成功
strls := '机号设定成功,现在的机号为' + Edit4.Text + '!';
Application.MessageBox(PChar(strls), '提示', MB_OK+MB_ICONINFORMATION);
exit;
end
else
begin
Application.MessageBox('机号设定失败!', '提示', MB_OK+MB_ICONINFORMATION);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:byte;
j:byte;
begin
j := 0;
commindex.Clear() ;
for i := 1 to 9 do
begin
Comport_Handle := PortOpen(i);
if(INVALID_HANDLE_VALUE <> Comport_Handle) then
begin
if(j=0) then
begin
j := i;
end;
commindex.AddItem('COM'+IntToStr(i),Sender);
PortClose(Comport_Handle);
end;
end;
if(commindex.Items.Count >0) then
begin
commindex.ItemIndex := 0;
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if(btn1.Caption = '开始轮询') then
begin
Close();
end
else
begin
Application.MessageBox('请先终止轮询!', '警告', MB_OK+MB_ICONINFORMATION);
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
strls:string;
status:integer;
lll:array[0..99] of char;
jhls:pchar;
jihao:integer;
beepforxms:integer;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(CheckBox1.Checked) then
begin
jihao := 0;
end
else
begin
if(Length(Edit16.Text) = 0) then
begin
Application.MessageBox('设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit16.SetFocus();
exit;
end;
if(not isrightint(Edit16.Text)) then
begin
Application.MessageBox('设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit16.SetFocus();
Edit16.SelectAll();
exit;
end;
jihao := StrToInt(Edit16.Text);
end;
if(Length(Edit12.Text) = 0) then
begin
Application.MessageBox('声长输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit12.SetFocus();
exit;
end;
if(not isrightint(Edit12.Text)) then
begin
Application.MessageBox('声长输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit12.SetFocus();
Edit12.SelectAll();
exit;
end;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
beepforxms := StrToInt(Edit12.Text);
SetBeep(comport_handle,jihao,beepforxms);
PortClose(comport_handle);
end;
procedure TForm1.Button8Click(Sender: TObject);
var
strls:string;
status:integer;
lll:array[0..99] of char;
jhls:pchar;
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(CheckBox1.Checked) then
begin
jihao := 0;
end
else
begin
if(Length(Edit17.Text) = 0) then
begin
Application.MessageBox('设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit17.SetFocus();
exit;
end;
if(not isrightint(Edit17.Text)) then
begin
Application.MessageBox('设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit17.SetFocus();
Edit17.SelectAll();
exit;
end;
jihao := StrToInt(Edit17.Text);
end;
if(Length(Edit13.Text) = 0) then
begin
Application.MessageBox('声长输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit13.SetFocus();
exit;
end;
if(not isrightint(Edit13.Text)) then
begin
Application.MessageBox('声长输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit13.SetFocus();
Edit13.SelectAll();
exit;
end;
beepforxms := strtoint(Edit13.Text);
if(Length(Edit14.Text) = 0) then
begin
Application.MessageBox('停顿输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit14.SetFocus();
exit;
end;
if(not isrightint(Edit14.Text)) then
begin
Application.MessageBox('停顿输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit14.SetFocus();
Edit14.SelectAll();
exit;
end;
unbeepforxms := strtoint(Edit14.Text);
//次数
if(Length(Edit15.Text) = 0) then
begin
Application.MessageBox('循环次数输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit15.SetFocus();
exit;
end;
if(not isrightint(Edit15.Text)) then
begin
Application.MessageBox('循环次数输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit15.SetFocus();
Edit15.SelectAll();
exit;
end;
times := strtoint(Edit15.Text);
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
SetBeep(comport_handle,jihao,beepforxms);
SetBeepEx(comport_handle,jihao,beepforxms,unbeepforxms,times);
PortClose(comport_handle);
end;
procedure TForm1.Button9Click(Sender: TObject);
var
strls:string;
status:integer;
lll:array[0..99] of char;
jhls:pchar;
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
begin
if(commindex.Items.Count<1) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -