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

📄 remotecfg.~pas

📁 GPRS/CDMA DTU数据中心源代码,基于DataCenterX控件开发.
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
    CMD_DNSMAXWAIT:
    begin
     if get6500time(valuestr)<>''  then    r:=SetDNSMAXWAIT(get6500time(valuestr))
     else r:=-3;
    end;
    //---------------count values -----
    CMD_ATLOSSMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetATLOSSMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_GSMLOSSMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetGSMLOSSMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_GPRSLOSSMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetGPRSLOSSMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_CENTERLOSSMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetCENTERLOSSMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_LOGINFAILMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetLOGINFAILMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_TCPWINSIZE:
    begin
     if getcountval(valuestr)<>''  then    r:=SetTCPWINSIZE(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_TCPOVT_RESENDCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetTCPOVT_RESENDCOUNT(getcountval(valuestr))
     else r:=-3;
    end;
    CMD_DNSFAILMAXCOUNT:
    begin
     if getcountval(valuestr)<>''  then    r:=SetDNSFAILMAXCOUNT(getcountval(valuestr))
     else r:=-3;
    end;


    {
    CMD_MODULELOSETIME:
    begin
     if getlosetime(valuestr)<>''  then    r:=SetModuleLoseTime(getlosetime(valuestr))
     else r:=-3;
    end;
    CMD_GSMLOSETIME:
    begin
     if getlosetime(valuestr)<>''  then    r:=SetGSMLoseTime(getlosetime(valuestr))
     else r:=-3;
    end;
    CMD_GPRSLOSETIME:
    begin
     if getlosetime(valuestr)<>''  then    r:=SetGPRSLoseTime(getlosetime(valuestr))
     else r:=-3;
    end;
    }


  end;

  if  r=0 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置成功]';
  if  r=-1 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置失败]';
  if  r=-2 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置失败,设备无响应!]';
  if  r=-3 then
  begin
    frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置失败,输入了非法内容!]';
  end;
  frmremotecfg.memo1.Lines.Add(frmremotecfg.StatusBar1.Panels[3].Text);

  result:=r;
end;

procedure writeitemvalue;
var listitem:tlistitem;
    r:integer;
    valuestr:string;
begin
  if frmremotecfg.ListView1.Selected<>nil then
  begin
    listitem:=frmremotecfg.ListView1.selected;
  end
  else exit;

  if frmremotecfg.gedit.visible then   valuestr:=frmremotecfg.gedit.text;
  if frmremotecfg.gcombobox.visible then   valuestr:=frmremotecfg.gcombobox.text;

  r:=WriteParamValue(listitem.Caption,valuestr);
  if r=-3 then
  begin
    //listitem.SubItems[1]:='';
    if frmremotecfg.gedit.visible then   frmremotecfg.gedit.text:='';
    if frmremotecfg.gcombobox.visible then   frmremotecfg.gcombobox.text:='';
  end
  else if r=0 then
  begin
   listitem.SubItems[1]:=valuestr;
  end;
end;

procedure TfrmRemoteCfg.suiButton2Click(Sender: TObject);
begin
  panel1.Enabled:=false;
  writeitemvalue;
  panel1.Enabled:=true;
end;

procedure TfrmRemoteCfg.ListView1DblClick(Sender: TObject);
begin
  if frmremotecfg.gedit.Visible  then frmremotecfg.gedit.SetFocus;
  if frmremotecfg.gcombobox.Visible  then frmremotecfg.gcombobox.SetFocus;  
end;

procedure TfrmRemoteCfg.GComboBoxKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  key:=0;
end;

procedure TfrmRemoteCfg.GComboBoxKeyPress(Sender: TObject; var Key: Char);
begin
  key:=chr(0);
end;

procedure TfrmRemoteCfg.N1Click(Sender: TObject);
var r:integer;
begin
 if MessageBox(self.Handle,'真的要恢复出厂默认设置吗?','提示',IDOK)=IDOK then
 begin
   r:=SetDefaultCfg;
   if  r=0 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置成功]';
   if  r=-1 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置失败]';
   if  r=-2 then frmremotecfg.StatusBar1.Panels[3].Text:='[参数设置失败,设备无响应!]';
   if  r=-3 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备失败,非法的返回串!]';
 end;
 frmremotecfg.Memo1.Lines.Add(frmremotecfg.StatusBar1.Panels[3].Text);
end;

procedure  RefreshValue(cmd:integer;param:string);
var s:string;
    listitem:tlistitem;
begin
   s:=hextostr(cmd);
   listitem:=frmremotecfg.ListView1.FindCaption(0,s,false,true,false);

   if listitem<>nil then
   begin
     listitem.SubItems[1]:=''; sleep(10);applicaTion.ProcessMessages;
     case cmd of
      CMD_KEYCHR:
      begin
//        listitem.SubItems[1]:=hextostr(ord(param[1]));
//        G_KEYCHR:=ord(param[1]);
        G_KEYCHR:=param;
        if ord(param[1])=0 then
        begin
         listitem.SubItems[1]:=hextostr(ord(param[2]));
        end
        else
        begin
         listitem.SubItems[1]:='';
        end;
      end;

      CMD_WORKMODE:
      begin
        if ord(param[1])=0 then listitem.SubItems[1]:='透明传输模式';
        if ord(param[1])=1 then listitem.SubItems[1]:='用户控制模式';
        if ord(param[1])=2 then listitem.SubItems[1]:='工业MODEM模式';        
      end;
      CMD_SOCKETTYPE:
      begin
        if ord(param[1])=0 then listitem.SubItems[1]:='TCP';
        if ord(param[1])=1 then listitem.SubItems[1]:='UDP';
      end;

      CMD_APN,CMD_APNUSERNAME,CMD_APNPWD,CMD_BAUDRATE,CMD_CENTER1DN,CMD_CENTER2DN,CMD_CENTER3DN,CMD_LOGINPWD,CMD_DTUPHNO,CMD_DTUID:  listitem.SubItems[1]:=param;
      CMD_DNSIP,CMD_CENTER1IP,CMD_CENTER2IP,CMD_CENTER3IP:
                listitem.SubItems[1]:=inttostr(ord(param[1]))+'.'+
                                            inttostr(ord(param[2]))+'.'+
                                            inttostr(ord(param[3]))+'.'+
                                            inttostr(ord(param[4]));


      //CMD_LOCALPORT,CMD_CENTERPORT,CMD_BEATTIME,CMD_MODULELOSETIME,CMD_GSMLOSETIME,CMD_GPRSLOSETIME,CMD_KEYTIME: listitem.SubItems[1]:=inttostr(ord(param[1])*256+ord(param[2]));
      CMD_LOCALPORT,CMD_CENTERPORT,CMD_BEATTIME,CMD_KEYTIME: listitem.SubItems[1]:=inttostr(ord(param[1])*256+ord(param[2]));

      CMD_ATMONTIME,CMD_ATMAXWAIT,CMD_GPRSMONTIME,CMD_GPRSMAXWAIT,CMD_BEATMAXWAIT,CMD_LOGINMAXWAIT,CMD_TCPOVT_RESENDBEGINTIME,CMD_DNSMAXWAIT:listitem.SubItems[1]:=inttostr(ord(param[1])*256+ord(param[2]));
      CMD_ATLOSSMAXCOUNT,CMD_GSMLOSSMAXCOUNT,CMD_GPRSLOSSMAXCOUNT,CMD_CENTERLOSSMAXCOUNT,CMD_LOGINFAILMAXCOUNT,CMD_TCPWINSIZE,CMD_TCPOVT_RESENDCOUNT,CMD_DNSFAILMAXCOUNT:listitem.SubItems[1]:=inttostr(ord(param[1]));
     end;

   end;
end;

procedure ParseParamValue(s:string);
var len:integer;
    cmd:byte;
    param:string;
    i:integer;
begin
  try
    while s<>'' do
    begin
     len:=ord(s[1])*256+ord(s[2]);
     cmd:=ord(s[3]);
     param:=copy(s,4,len-1);
     RefreshValue(cmd,param);
     s:=copy(s,len+3,length(s));
    end;
  except
  end;
end;

procedure TfrmRemoteCfg.N2Click(Sender: TObject);
var s:string;
    len,acc:word;
    i:integer;
    a,b:string;
begin
  mainmenu1.Items[1].enabled:=false;

  frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取中,请稍候...]';
  s:=GetParamValue('');

  if s='' then
  begin
    frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,设备无响应!]';
    frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
    mainmenu1.Items[1].enabled:=true;
    exit;
  end;

  {
  if ((s[1]<>chr(FRAME_HEAD1)) or (s[2]<>chr(FRAME_HEAD2))) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包头非法!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;
  }
  if s[1]<>chr(CMD_REPLYCONFIG) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包命令字非法!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;
  {
  len:=ord(s[3])*256+ord(s[4]);

  ACC:=0;
  for I:=3 to LENGTH(S)-2 do
  BEGIN
     ACC:=ACC+ord(S[I]);
  END;

  if acc<>ord(s[length(s)-1])*256+ord(s[length(s)]) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包校验错!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;

  a:=copy(s,6,len-3);
  }
  a:=copy(s,2,length(s)-1);
  ParseParamValue(a);

  //---get super param----------------------------------

//  s:=GetParamValue(chr(CMD_LOCALPORT)+chr(CMD_CENTERPORT)+chr(CMD_MODULELOSETIME)+chr(CMD_GSMLOSETIME)+chr(CMD_GPRSLOSETIME));

  s:=GetParamValue(chr(CMD_ATMONTIME)+chr(CMD_ATMAXWAIT)+chr(CMD_GPRSMONTIME)+chr(CMD_GPRSMAXWAIT)+chr(CMD_BEATMAXWAIT)+
                   chr(CMD_LOGINMAXWAIT)+chr(CMD_TCPOVT_RESENDBEGINTIME)+chr(CMD_DNSMAXWAIT)+
                   chr(CMD_ATLOSSMAXCOUNT)+chr(CMD_GSMLOSSMAXCOUNT)+chr(CMD_GPRSLOSSMAXCOUNT)+chr(CMD_CENTERLOSSMAXCOUNT)+chr(CMD_LOGINFAILMAXCOUNT)+
                   chr(CMD_TCPWINSIZE)+chr(CMD_TCPOVT_RESENDCOUNT)+chr(CMD_DNSFAILMAXCOUNT));


  if s='' then
  begin
    frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,设备无响应!]';
    frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
    mainmenu1.Items[1].enabled:=true;
    exit;
  end;

  {
  if ((s[1]<>chr(FRAME_HEAD1)) or (s[2]<>chr(FRAME_HEAD2))) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包头非法!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;
  }
  if s[1]<>chr(CMD_REPLYCONFIG) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包命令字非法!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;
  {
  len:=ord(s[3])*256+ord(s[4]);

  ACC:=0;
  for I:=3 to LENGTH(S)-2 do
  BEGIN
     ACC:=ACC+ord(S[I]);
  END;

  if acc<>ord(s[length(s)-1])*256+ord(s[length(s)]) then
  begin
     frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取失败,返回数据包校验错!]';
     frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
     mainmenu1.Items[1].enabled:=true;
     exit;
  end;
  b:=copy(s,6,len-3);
  }
  b:=copy(s,2,length(s)-1);
  ParseParamValue(b);


  frmremotecfg.StatusBar1.Panels[3].Text:='[参数读取完毕]';

//  sleep(300);
  frmremotecfg.memo1.Lines.add(frmremotecfg.StatusBar1.Panels[3].Text);
  mainmenu1.Items[1].enabled:=true;
end;

procedure TfrmRemoteCfg.GEditKeyPress(Sender: TObject; var Key: Char);
begin
  if geditmask='' then exit;
  if key=chr(8) then exit;
  if pos(key,geditmask)=0 then key:=chr(0);
end;

procedure TfrmRemoteCfg.N6Click(Sender: TObject);
var r:integer;
begin
 if MessageBox(self.Handle,'真的要复位设备吗?','提示',IDOK)=IDOK then
 begin
   r:=Reset;
   if  r=0 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备成功]';
   if  r=-1 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备失败]';
   if  r=-2 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备失败,设备无响应!]';
   if  r=-3 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备失败,非法的返回串!]';
   if  r=-4 then frmremotecfg.StatusBar1.Panels[3].Text:='[复位设备失败,返回帧校验错误!]';
 end;
 frmremotecfg.Memo1.Lines.Add(frmremotecfg.StatusBar1.Panels[3].Text);
end;

procedure TfrmRemoteCfg.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
  key:=chr(0);
end;

procedure TfrmRemoteCfg.ComboBox2KeyPress(Sender: TObject; var Key: Char);
begin
  key:=chr(0);
end;

procedure TfrmRemoteCfg.ComboBox3KeyPress(Sender: TObject; var Key: Char);
begin
 key:=chr(0);
end;

procedure TLineGet.Init;
begin
  Buf:='';
end;

procedure TLineGet.SendLine;
begin
end;

procedure TLineGet.ProcChar(C:Char);
begin
end;

procedure TfrmRemoteCfg.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if key=chr(1) then    //ctrl-A
  begin
     maskedit3.Visible:=true;
     maskedit3.SetFocus;
  end;
end;

procedure TfrmRemoteCfg.MaskEdit3KeyPress(Sender: TObject; var Key: Char);
begin
  if key=chr(13) then
  begin
    if maskedit3.text='super' then
    begin
      G_SuperFlag:=true;
      AddParamItems;
      maskedit3.Visible:=false;
      maskedit3.text:='';
    end
    else maskedit3.text:='';
  end;
end;

procedure TfrmRemoteCfg.Edit3KeyPress(Sender: TObject; var Key: Char);
var editmask:string;
begin
  editmask:='0123456789ABCDEF';
  if key=chr(8) then exit;
  if pos(key,editmask)=0 then key:=chr(0);
end;

procedure TfrmRemoteCfg.Edit4KeyPress(Sender: TObject; var Key: Char);
var editmask:string;
begin
  editmask:='0123456789ABCDEF';
  if key=chr(8) then exit;
  if pos(key,editmask)=0 then key:=chr(0);
end;

function  TDTUCOM.readstring(var s:string):boolean;
var i,len:integer;
    ws:widestring;
    p:pchar;
begin
  len:=dataocx.GetRemoteLen(DTUID,remotetype);
  if len<=0 then result:=false
  else
  begin
   setlength(ws,len);
   dataocx.RemoteRead(DTUID,ws,len,remotetype);
   p:=@ws[1];

   s:='';
   for i:=1 to Len do s:=s+p[i-1];
   result:=true;
  end;
end;

procedure TDTUCOM.sendstring(s:string);
var ws:widestring;
    k:integer;
    p:pchar;
begin
  setlength(ws,length(s));
  p:=@ws[1];
  for k:=1 to  length(s) do p[k-1]:=s[k];
  dataocx.RemoteSend(DTUID,ws,length(s),remotetype);
end;


end.

⌨️ 快捷键说明

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