📄 setting.pas
字号:
end;
//Load ID
IDListView.Items.BeginUpdate;
IDListView.Items.Clear;
DM1.ModuleDB.Filter := 'DNO = ' + '''' + DNOstr + '''';
I := 1;
while not DM1.ModuleDB.Eof do
with IDListView do
begin
ListItem := Items.add;
ListItem.Caption := format('%3d',[I]);
ListItem.SubItems.Add(DM1.ModuleDB.FieldByname('UNO').AsString);
ListItem.SubItems.Add('');
ListItem.SubItems.Add('');
DM1.ModuleDB.Next;
I := I + 1;
end;
IDListView.Items.EndUpdate;
end;
procedure TfrmSetup.ClrID_BtnClick(Sender: TObject);
var
I: integer;
rStr,password: string;
begin
frmPromot.Hide;
frmPromot.Promot.Caption := '是否清除集中器通讯号?';
if frmPromot.ShowModal <> mrOK then exit;
activecommand:=true;
for i:=0 to IDlistView.Items.Count-1 do
begin
with IDListView do
begin
Items[I].SubItems.Strings[1] := '';
Items[I].SubItems.Strings[2] := '';
end;
end;
for I := 1 to 3 do
begin
if (PutTXD(_ClrID, _OKlen, rStr, 2000) = True) and (Copy(rStr, 1, 2) = 'OK') then
begin
StatusLab.Caption := '清除集中器通讯号成功!';
activecommand:=false;
exit;
end;
if Copy(rStr, 1, 4) = _Lock then
begin
password:= InputBox('请输入集中器口令', '口令为6个字符','666666');
if PutTXD('PWR'+password+chr(13), 8, rStr, 2000) and (Copy(rStr, 1, 6) = _Unlock) then continue;
end;
end;
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
activecommand:=false;
end;
procedure TfrmSetup.SetID_BtnClick(Sender: TObject);
var
I, J: Integer;
sBuf, rStr,password: string;
begin
if IDListView.Items.Count <= 0 then
begin
WarnAbout.Hide;
WarnAbout.Promot.Caption := '无用户信息,请编辑!';
WarnAbout.ShowModal;
exit;
end;
frmPromot.Hide;
frmPromot.Promot.Caption := '是否装载集中器通讯号?';
if frmPromot.ShowModal <> mrOK then exit;
//Upload ID
IDListView.SetFocus;
activecommand:=true;
for I := 0 to IDListView.Items.Count - 1 do
begin
IDListView.Items[I].Selected := True;
IDListView.Items[I].Focused := True;
sBuf := IDListView.Items[I].SubItems.Strings[0];
if length(sBuf) <> 12 then
begin
repeat
sBuf:='0' + sBuf;
until Length(sBuf) = 12;
end;
sBuf := _SetID + sBuf + _CR;
for J := 1 to 5 do
begin
if (PutTXD(sBuf, _OKlen, rStr, 4000) = True ) and (rStr = _OK) then break;
StatusLab.Caption := '未建立数据链路或未通过口令检测!';
if Copy(rStr, 1, 4) = _Lock then
begin
password:= InputBox('请输入集中器口令', '口令为6个字符','666666');
if PutTXD('PWR'+password+chr(13), 8, rStr, 2000) and (Copy(rStr, 1, 6) = _Unlock) then continue;
activecommand:=false;
exit;
end;
if J = 3 then
begin
StatusLab.Caption := '未建立通信链路或未通过口令检测,或者有重复表号!';
activecommand:=false;
exit;
end;
end;
IDListView.items[I ].Selected := True;
IDListView.items[I ].MakeVisible(True);
StatusLab.Caption := '完成: [' + IntToStr(I + 1) + '/' + IntToStr(IDListView.Items.Count) + ']';
end;
StatusLab.Caption := '装载集中器表号成功';
activecommand:=false;
end;
procedure TfrmSetup.GetID_BtnClick(Sender: TObject);
var
I, Num,ErrorNum: Integer;
rStr,password: string;
ListItem: TListItem;
begin
StatusLab.Caption := '';
ErrorNum := 0;
IDListView.SetFocus;
activecommand:=true;
if (PutTXD(_GetID, 9, rStr, 4000) = False) or (Copy(rStr, 1, 1) <> 'N') or (Copy(rStr, 8, 2) <> _CRLF) then
begin
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
if Copy(rStr, 1, 4) = _Lock then
begin
password:= InputBox('请输入集中器口令', '口令为6个字符','666666');
if PutTXD('PWR'+password+chr(13), 8, rStr, 2000) and (Copy(rStr, 1, 6) = _Unlock) then
StatusLab.Caption := '通过口令检测,请重新操作!'
else
StatusLab.Caption := '未通过口令检测!';
end;
activecommand:=false;
exit;
end;
Num := StrToInt(Copy(rStr, 2, 6));
//if Num > _MaxIDNum, error
if Num > _MaxIDNum then
begin
StatusLab.Caption := '集中器表号超长!';
activecommand:=false;
exit;
end;
//If Num > current items.count, add items
if Num > IDlistView.Items.Count then
begin
with IDListView do
for I := Items.Count + 1 to Num do
begin
ListItem := Items.add;
ListItem.Caption := IntToStr(I);
ListItem.SubItems.Add('');
ListItem.SubItems.Add('');
ListItem.SubItems.Add('');
end;
end;
PrgBar.Visible := True;
PrgBar.Max := Num;
for I := 0 to Num -1 do
begin
if ( GetRXD(15, rStr) = FALSE ) or ( Copy(rStr, 14, 2) <> _CRLF ) then
begin
StatusLab.Caption := '下载数据错误!';
PrgBar.Visible := False;
activecommand:=false;
exit;
end;
IDListView.Items[I].SubItems.Strings[2] := Copy(rStr, 1, 12);
if IDListView.Items[I].SubItems.Strings[2] <> IDListView.Items[I].SubItems.Strings[0] then
begin
IDListView.Items[I].SubItems.Strings[1] := '>>';
ErrorNum := ErrorNum + 1;
end;
IDListView.Items[I].Selected := True;
IDListView.items[I].MakeVisible(True);
PrgBar.Position := I + 1;
StatusLab.Caption := '下栽: [' + IntToStr(I + 1)
+ '/' + IntToStr(Num) + ' ]';
end;
StatusLab.Caption := '成功,' + '有 [' + IntToStr(ErrorNum) + '] IDs 与数据库不一致!';
PrgBar.Visible := False;
activecommand:=false;
end;
procedure TfrmSetup.IDListViewCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
frmRead.DataListViewCompare(Sender,Item1,Item2, Data,Compare);
end;
procedure TfrmSetup.IDListViewColumnClick(Sender: TObject;
Column: TListColumn);
begin
frmRead.DataListViewColumnClick(Sender,Column);
end;
procedure TfrmSetup.BitBtn1Click(Sender: TObject);
var
i: Integer;
rStr: String;
begin
ActiveCommand := TRUE;
//Setup Reading ON/OFF
for I := 1 to 3 do
begin
if Readcb.Text <>'' then
begin
if ReadCB.Text = 'ON' then
if PutTXD('ZOOM' + Chr(13), 4, rStr,1500) and (Copy(rStr, 1, 4) = _OK) then break;
if ReadCB.Text = 'OFF' then
if PutTXD('QUIT' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
begin
if ReadCB.Text = 'ON' then
StatusLab.Caption := '设置抄表开关ON成功'
else
StatusLab.Caption := '设置抄表开关OFF成功';
end
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
//Setup Constant ON/OFF
for I := 1 to 3 do
begin
if CnstCB.Text <>'' then
begin
if CnstCB.Text = 'ON' then
if PutTXD('KC=1' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
if CnstCB.Text = 'OFF' then
if PutTXD('KC=0' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
begin
if CnstCB.Text ='ON' then
StatusLab.Caption := '设置抄读量程常数开关ON成功 '
else
StatusLab.Caption := '设置抄读量程常数开关 OFF 成功 ';
end
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
// Setup Frozen Consumption ON/OFF
for I := 1 to 3 do
begin
if FreCB.Text <> '' then
begin
if FreCB.Text = 'ON' then
if PutTXD('KF=1' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
if FreCB.Text = 'OFF' then
if PutTXD('KF=0' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
begin
if FreCB.Text ='ON' then
StatusLab.Caption := '设置冻结开关 ON 成功'
else
StatusLab.Caption := '设置冻结开关 OFF 成功 ';
end
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
// setup test switch
for I := 1 to 3 do
begin
if TestCB.Text <> '' then
begin
if TestCB.Text = 'ON' then
if PutTXD('KT=1' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
if TestCB.Text = 'OFF' then
if PutTXD('KT=0' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
begin
if TestCB.Text = 'ON' then
StatusLab.Caption := '设置测试开关 ON 成功'
else
StatusLab.Caption := '设置测试开关 OFF 成功';
end
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
//Setup Step
for I := 1 to 3 do
begin
if (Conu_E.Text <> '') and (Skip_E.Text <> '') then
begin
if (Length(Trim(Conu_E.Text)) >= 3) or (Length(Trim(Skip_E.Text)) >= 3) then
begin
WarnAbout.Hide;
WarnAbout.Promot.Caption := '步长必须为2位数字字符!';
WarnAbout.ShowModal;
exit;
end;
if Length(Trim(Conu_E.text)) = 1 then Conu_E.Text := '0' + Conu_E.Text;
if Length(Trim(Skip_E.text)) = 1 then Skip_E.Text :='0' + Skip_E.Text;
if PutTXD('YL' + Conu_E.Text + Skip_E.Text + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
for I := 1 to 3 do
begin
if TARCB.Text <> '' then
begin
if PutTXD('KM=' +TRIM(TARCB.TEXT)+ Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
StatusLab.Caption := '抄表费率设置成功'
else
StatusLab.Caption := '为建立通信链路或未通过口令检测!';
for I := 1 to 3 do
begin
if ARONCB.Text <> '' then
begin
if ARONCB.Text = 'ON' then
if PutTXD('KA=1' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
if TestCB.Text = 'OFF' then
if PutTXD('KA=0' + Chr(13), 4, rStr, 1500) and (Copy(rStr, 1, 4) = _OK) then break;
end;
end;
if I <= 3 then
begin
if TestCB.Text = 'ON' then
StatusLab.Caption := '设置自动抄表日开关 ON 成功'
else
StatusLab.Caption := '设置自动抄表日开关OFF 成功';
end
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!';
//Setup Frozen Time
for I := 1 to 3 do
if (FreTime_E.Text <> '') then
BEGIN
if LENGTH(TRIM(FRETIME_E.Text)) <> 8 then
begin
WarnAbout.Hide;
WarnAbout.Promot.Caption := '冻结时间格式为DD:HH:MM!';
WarnAbout.ShowModal;
exit;
end;
if PutTXD('JF' + COPY(FreTime_E.Text, 1, 2) + COPY(FreTime_E.Text, 4, 2) + COPY(FreTime_E.Text, 7, 2)+Chr(13), 4, rStr, 1500)
and (Copy(rStr, 1, 4) = _OK) then break;
END;
if I <= 3 then
StatusLab.Caption := '设置冻结时间成功'
else
StatusLab.Caption := '未建立通信链路或未通过口令检测!' ;
activecommand:=false;
end;
procedure TfrmSetup.BitBtn2Click(Sender: TObject);
var
rBuf: String;
rStr: String;
i: Integer;
begin
ActiveCommand := TRUE;
rbuf:=frmmain.MSComm.input;
frmMain.MSComm.RThreshold := 0;
frmMain.MSComm.InputLen := 1;
frmMain.MSComm.Output := 'O'+ Chr(13);
i:=0 ;
while i <> 15 do
begin
if not ActiveCommand then break;
Application.ProcessMessages;
if not ActiveCommand then break;
if frmMain.MSComm.InBufferCount >= 1 then
begin
frmsetup.bitbtn2.enabled:=false;
Rbuf := frmMain.MSComm.Input;
if rBuf = Chr(10) then i := i + 1;
rStr := rStr + rBuf;
end;
end;
if Copy(rStr, 8, 1) = '0' then
ReadCB.Text := 'OFF'
else
ReadCB.Text := 'ON';
if Copy(rStr,17, 1) = '0' then
CnstCB.Text := 'OFF'
else
CnstCB.Text := 'ON';
if Copy(rStr, 24, 1) = '0' then
FreCB.Text := 'OFF'
else
FreCB.Text := 'ON';
if Copy(rStr,32, 1) = '0' then
TestCB.Text := 'OFF'
else
TestCB.Text := 'ON';
Conu_E.Text := Copy(rStr, 45, 2);
Skip_E.Text := Copy(rStr, 59, 2);
NUM_E.Text := INTTOSTR(STRTOINT(Copy(rStr, 164, 6)));
TARCB.Text := Copy(rStr, 182, 1);
if Copy(rStr,190, 1) = '0' then
ARONCB.Text := 'OFF'
else
ARONCB.Text := 'ON';
if PutTXD('IF' + Chr(13), 8, rStr, 1500) and (Copy(rStr,7, 1) = Chr(13)) then
FreTime_E.text := Copy(rStr, 1, 2) + ':' + Copy(rStr, 3, 2)+':'+Copy(rStr, 5, 2);
StatusLab.Caption := '读取集中器状态成功!';
activecommand:=false;
frmsetup.bitbtn2.enabled:=true;
end;
procedure TfrmSetup.btnStopSClick(Sender: TObject);
begin
ActiveCommand := FALSE;
bitbtn2.Enabled:=true;
StatusLab.Caption := '停止读取集中器状态';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -