📄 unitparam.pas
字号:
unit unitParam;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, winsock, ComCtrls;
const WM_DTU_PARAM = WM_USER + 100;
type
arr=array[1..256] of char;
TFParam = class(TForm)
Timer1: TTimer;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
CheckBox10: TCheckBox;
CheckBox11: TCheckBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
CheckBox12: TCheckBox;
CheckBox13: TCheckBox;
CheckBox14: TCheckBox;
CheckBox15: TCheckBox;
CheckBox16: TCheckBox;
CheckBox17: TCheckBox;
CheckBox18: TCheckBox;
CheckBox19: TCheckBox;
CheckBox24: TCheckBox;
CheckBox25: TCheckBox;
CheckBox26: TCheckBox;
CheckBox27: TCheckBox;
CheckBox28: TCheckBox;
CheckBox29: TCheckBox;
CheckBox30: TCheckBox;
CheckBox31: TCheckBox;
CheckBox32: TCheckBox;
CheckBox33: TCheckBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Edit16: TEdit;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
Edit23: TEdit;
Edit24: TEdit;
Edit25: TEdit;
Edit26: TEdit;
Edit27: TEdit;
Label28: TLabel;
Label29: TLabel;
BitBtn1: TBitBtn;
CheckBox1: TCheckBox;
Edit28: TEdit;
ComboBox1: TComboBox;
BitBtn2: TBitBtn;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
ComboBox6: TComboBox;
ComboBox7: TComboBox;
ComboBox8: TComboBox;
BitBtn4: TBitBtn;
BitBtn3: TBitBtn;
ComboBox9: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Bevel1: TBevel;
TabSheet6: TTabSheet;
Edit17: TEdit;
Edit18: TEdit;
Edit19: TEdit;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Bevel2: TBevel;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox20: TCheckBox;
BitBtn5: TBitBtn;
CheckBox21: TCheckBox;
Edit20: TEdit;
CheckBox22: TCheckBox;
Edit21: TEdit;
Bevel3: TBevel;
CheckBox23: TCheckBox;
Edit22: TEdit;
CheckBox34: TCheckBox;
Edit29: TEdit;
CheckBox35: TCheckBox;
Edit30: TEdit;
procedure BitBtn1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure ComboBox1DropDown(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Edit6KeyPress(Sender: TObject; var Key: Char);
procedure Edit13KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn3Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure CheckBox8Click(Sender: TObject);
procedure CheckBox9Click(Sender: TObject);
procedure CheckBox10Click(Sender: TObject);
procedure CheckBox11Click(Sender: TObject);
procedure CheckBox12Click(Sender: TObject);
procedure CheckBox13Click(Sender: TObject);
procedure CheckBox14Click(Sender: TObject);
procedure CheckBox15Click(Sender: TObject);
procedure CheckBox16Click(Sender: TObject);
procedure CheckBox17Click(Sender: TObject);
procedure CheckBox18Click(Sender: TObject);
procedure CheckBox24Click(Sender: TObject);
procedure CheckBox25Click(Sender: TObject);
procedure CheckBox26Click(Sender: TObject);
procedure CheckBox27Click(Sender: TObject);
procedure CheckBox28Click(Sender: TObject);
procedure CheckBox29Click(Sender: TObject);
procedure CheckBox30Click(Sender: TObject);
procedure CheckBox31Click(Sender: TObject);
procedure CheckBox32Click(Sender: TObject);
procedure CheckBox33Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure CheckBox19Click(Sender: TObject);
procedure CheckBox4Click(Sender: TObject);
procedure CheckBox5Click(Sender: TObject);
procedure CheckBox6Click(Sender: TObject);
procedure CheckBox20Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure CheckBox21Click(Sender: TObject);
procedure CheckBox22Click(Sender: TObject);
procedure CheckBox23Click(Sender: TObject);
procedure CheckBox34Click(Sender: TObject);
procedure CheckBox35Click(Sender: TObject);
private
{ Private declarations }
curr_action: integer; //0 none, 1 query param, 2 set param
procedure display_param();
function checkparam(): boolean;
procedure ChangeEditColor(cb: TCheckBox; editctr: TEdit);
procedure ChangeCmbColor(cb: TCheckBox; cmbctr: TComboBox);
public
{ Public declarations }
procedure WMdtuparam(var Message: TMessage); message WM_DTU_PARAM;
end;
var
FParam: TFParam;
implementation
uses unit1, dllUnit, unitShowParam;
{$R *.dfm}
{ TForm2 }
procedure TFParam.WMdtuparam(var Message: TMessage);
begin
if ComboBox1.Enabled then
exit;
Timer1.Enabled := false;
BitBtn1.Enabled := true;
BitBtn2.Enabled := true;
BitBtn3.Enabled := false;
BitBtn4.Enabled := true;
BitBtn5.Enabled := true;
ComboBox1.Enabled := true;
CheckBox1.Enabled := true;
if Message.WParam = 1 then
begin
display_param();
MessageBox(Handle, PChar('已完成查询DTU参数'), PChar('OK'), MB_OK or MB_ICONINFORMATION);
end
else if Message.WParam = 2 then
begin
MessageBox(Handle, PChar('收到DTU确认信息,参数设置完成'), PChar('OK'), MB_OK or MB_ICONINFORMATION)
end
else
begin
if curr_action = 1 then
MessageBox(Handle, PChar('DTU无法辨认查询指令,无法查询参数'), PChar('ERROR'), MB_OK or MB_ICONEXCLAMATION)
else
MessageBox(Handle, PChar('收到DTU确认信息,参数有误或无效的指令,无法完成参数设置'), PChar('ERROR'), MB_OK or MB_ICONEXCLAMATION);
end;
end;
procedure TFParam.BitBtn1Click(Sender: TObject);
var
//destip: Longword;
//destport: word;
i: Integer;
dtu: string;
mess: array[0..255] of char;
begin
if ComboBox1.ItemIndex = -1 then
exit;
//destip := 0;
//destport := 0;
dtu := ComboBox1.Items[ComboBox1.ItemIndex];
for i := 0 to form1.ListView1.Items.Count - 1 do
{if dtu = form1.ListView1.Items[i].Caption then
begin
destip := inet_addr(PChar(form1.ListView1.Items[i].SubItems[3]));
destip := ntohl(destip);
//destport := ntohs(StrToInt(form1.ListView1.Items[i].SubItems[4]));
destport := StrToInt(form1.ListView1.Items[i].SubItems[4]);
break;
end;}
//if destip <> 0 then
//begin
//if DoReadParam(destip, destport, PChar(dtu)) = 1 then
if do_read_param(PChar(dtu), 0, mess) = 0 then
begin
curr_action := 1;
BitBtn1.Enabled := false;
BitBtn2.Enabled := false;
BitBtn3.Enabled := true;
BitBtn4.Enabled := false;
BitBtn5.Enabled := false;
ComboBox1.Enabled := false;
CheckBox1.Enabled := false;
if CheckBox1.Checked then
begin
Timer1.Interval := Strtoint(Edit28.Text) * 1000;
Timer1.Enabled := true;
end;
end else begin
MessageBox(Handle, PChar('do_read_param ERROR'), PChar('ERROR'), MB_OK or MB_ICONERROR);
end;
//end;
end;
procedure TFParam.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
if curr_action = 1 then
MessageBox(Handle, PChar('等待DTU上传参数超时,无法查询参数'), PChar('ERROR'), MB_OK or MB_ICONEXCLAMATION)
else
MessageBox(Handle, PChar('等待DTU确认超时,无法完成参数设置'), PChar('ERROR'), MB_OK or MB_ICONEXCLAMATION);
BitBtn1.Enabled := true;
BitBtn2.Enabled := true;
BitBtn3.Enabled := false;
BitBtn4.Enabled := true;
BitBtn5.Enabled := true;
ComboBox1.Enabled := true;
CheckBox1.Enabled := true;
end;
procedure TFParam.CheckBox1Click(Sender: TObject);
begin
ChangeEditColor(Sender as TCheckBox, Edit28);
end;
procedure TFParam.ComboBox1DropDown(Sender: TObject);
var
i: Integer;
begin
ComboBox1.Clear;
for i := 0 to Form1.ListView1.Items.Count - 1 do
ComboBox1.Items.Add(Form1.ListView1.Items[i].Caption);
end;
procedure TFParam.display_param;
var
param: array[0..299] of char;
paramlen: Integer;
two_byte: word;
four_byte: longword;
// baudrate: longword;
addr: in_addr;
// databit, stopbit, paritybit, flowcontrol: byte;
s: string;
i: Integer;
begin
//获取移动服务设置
paramlen := 9;
if GetParam($01, param, paramlen) = 1 then
Edit1.Text := param;
if Edit1.Text = '#777' then
RadioButton2Click(nil)
else
RadioButton1Click(nil);
paramlen := 31;
if GetParam($02, param, paramlen) = 1 then
Edit2.Text := param;
paramlen := 21;
if GetParam($03, param, paramlen) = 1 then
Edit3.Text := param;
paramlen := 25;
if GetParam($04, param, paramlen) = 1 then
Edit4.Text := param;
paramlen := 9;
if GetParam($05, param, paramlen) = 1 then
Edit5.Text := param;
//获取DTU设置
Edit6.Text := ComboBox1.Items[ComboBox1.ItemIndex];
paramlen := 12;
if GetParam($06, param, paramlen) = 1 then
Edit6.Text := param;
paramlen := 2;
if GetParam($07, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit7.Text := inttostr(two_byte);
end;
paramlen := 2;
if GetParam($08, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit8.Text := inttostr(two_byte);
end;
paramlen := 2;
if GetParam($09, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit9.Text := inttostr(two_byte);
end;
paramlen := 2;
if GetParam($0a, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit10.Text := inttostr(two_byte);
end;
paramlen := 1;
if GetParam($0b, param, paramlen) = 1 then
Edit12.Text := inttostr(byte(param[0]));
paramlen := 2;
if GetParam($0c, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit11.Text := inttostr(two_byte);
end;
paramlen := 1;
if GetParam($23, param, paramlen) = 1 then
Edit30.Text := inttostr(byte(param[0]));
//获取数据中心设置
paramlen := 4;
if GetParam($0d, param, paramlen) = 1 then
begin
four_byte := ((Longword(param[0]) shl 24) and $ff000000)
or ((Longword(param[1]) shl 16) and $00ff0000)
or ((Longword(param[2]) shl 8) and $0000ff00)
or (Longword(param[3]) and $000000ff);
addr.S_addr := ntohl(four_byte);
Edit13.Text := inet_ntoa(addr);
end;
paramlen := 129;
if GetParam($0e, param, paramlen) = 1 then
Edit14.Text := param;
paramlen := 2;
if GetParam($0f, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit15.Text := inttostr(two_byte);
end;
paramlen := 2;
if GetParam($10, param, paramlen) = 1 then
begin
two_byte := ((Word(param[0]) shl 8) and $ff00)
or ((Word(param[1])) and $00ff);
Edit16.Text := inttostr(two_byte);
end;
paramlen := 4;
if GetParam($11, param, paramlen) = 1 then
begin
four_byte := ((Longword(param[0]) shl 24) and $ff000000)
or ((Longword(param[1]) shl 16) and $00ff0000)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -