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

📄 main.~pas

📁 GPRS/CDMA DTU数据中心源代码,基于DataCenterX控件开发.
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
  begin
    showmessage('请先选中要删除的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
      datacenterx1.DeleteDTU(listview1.Items[i].Caption);
    end;
  end;

  showdtus;
end;

procedure TfrmMain.DELALLDTUClick(Sender: TObject);
var i:integer;
begin
  for i:=0 to listview1.Items.Count-1 do
  begin
      datacenterx1.DeleteDTU(listview1.Items[i].Caption);
  end;
  showdtus;
end;

procedure TfrmMain.CLOSEDTUClick(Sender: TObject);
var i:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要关闭的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
      datacenterx1.CloseDTU(listview1.Items[i].Caption,0);
    end;
  end;
  showdtus;
end;

procedure TfrmMain.CLOSEALLDTUClick(Sender: TObject);
var i:integer;
begin
  for i:=0 to listview1.Items.Count-1 do
  begin
      datacenterx1.CloseDTU(listview1.Items[i].Caption,0);
  end;
  showdtus;
end;

procedure TfrmMain.DATACLEARClick(Sender: TObject);
var i:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要关闭的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
      listview1.Items[i].SubItems[8]:='0';
      listview1.Items[i].SubItems[9]:='0';      
    end;
  end;
end;

procedure TfrmMain.HEX1Click(Sender: TObject);
begin
   hex1.Checked:=not hex1.Checked;
   if hex1.Checked then groupbox2.Caption:='HEX'
   else groupbox2.Caption:='';
   memo2.Clear;
  // panel3.Visible:=hex1.Checked  ;
  // memo6.Visible:=hex1.Checked  ;
end;

procedure TfrmMain.Memo2Change(Sender: TObject);
begin
  memo6.Text:=texttohexstr(memo2.text);
end;

procedure TfrmMain.SpeedButton1Click(Sender: TObject);
begin
  memo2.Text:=memo2.text+chr(strtohex(edit3.text));
end;

procedure TfrmMain.N9Click(Sender: TObject);
var  phoneno,protocol,sin_addr,local_addr, logon_time, update_time:widestring;
     i,sin_port,local_port,status1,sendcount,readcount:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要配置的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
          datacenterx1.RemoteCfg(listview1.Items[i].Caption);
          break;
    end;
  end;

{
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
          frmRemotecfg.xmodem1.DTUID:=listview1.Items[i].Caption;
          frmRemotecfg.xmodem1.remotetype:=CMD_REMOTECFG;

          datacenterx1.GetDTUInfo(frmRemotecfg.xmodem1.DTUID,phoneno,protocol,sin_addr,sin_port,
          local_addr,local_port,logon_time,update_time,status1,sendcount,readcount);

          frmRemotecfg.lbDTUInfo.Caption:='DTUID:'+frmRemotecfg.xmodem1.DTUID+','+'协议:'+protocol+',IP:'+sin_addr;

          if status1=2 then  frmRemotecfg.Show
          else   showmessage('该DTU尚未在线,无法实现远程配置');
    end;
  end;
  }
end;

procedure TfrmMain.DTU7Click(Sender: TObject);
var  phoneno,protocol,sin_addr,local_addr, logon_time, update_time:widestring;
     i,sin_port,local_port,status1,sendcount,readcount:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要升级的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
          datacenterx1.RemoteUpgrade(listview1.Items[i].Caption);
          break;
    end;
  end;
end;

procedure TfrmMain.N10Click(Sender: TObject);
begin
   showmessage(datacenterx1.GetVersion); 
end;

procedure TfrmMain.NDataTipClick(Sender: TObject);
begin
  NDataTip.Checked:=not NDataTip.Checked;
end;

procedure TfrmMain.Memo2KeyPress(Sender: TObject; var Key: Char);
var editmask:string;
begin
 if hex1.Checked then
 begin
  editmask:='0123456789ABCDEFabcdef';
  if key=chr(8) then exit;
  if pos(key,editmask)=0 then key:=chr(0);
 end;
end;

procedure TfrmMain.N16Click(Sender: TObject);
var i:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要收发文件的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
        filesenddtu:=listview1.Items[i].Caption;
        frmfiletest.show;
        exit;
    end;
  end;

end;

procedure TfrmMain.DataCenterX1DTUDataX(Sender: TObject;
  const DTUID: WideString; DataLen: Integer; const DataBuf: WideString);
var ws:widestring;
    i:integer;
    listitem:tlistitem;
    s,hexstr:string;
    p:pchar;
begin
  exit;
  s:=DataBuf;
  
  if hex1.Checked then hexstr:=' {HEX:'+texttohexstr(s)+'}';
  if NDataTip.Checked  then  memo1.lines.Add(datetimetostr(now)+' '+'收到数据包,dtuid='+dtuid+','+'数据内容:'+hexstr+s)
  else memo1.lines.Add(hexstr+s);

  for i:=0 to listview1.Items.Count-1 do
  begin
     if listview1.Items[i].Caption=dtuid then
     begin
       listitem:=listview1.Items[i];
       listitem.ImageIndex:=1;
       if listitem.SubItems[9]='' then listitem.SubItems[9]:='0';
       listitem.SubItems[9]:= inttostr(strtoint(listitem.SubItems[9])+DataLen);
       break;
     end;
  end;

  if frmfiletest.CheckBox1.Checked then
  begin
    PackLen:=DataLen;
    for i:=1 to length(s) do  EEPROMVM[i]:=ord(s[i]);
    BlockWrite(DataFileRecv,EEPROMVM,PackLen,WriteLen);
  end;
end;

procedure TfrmMain.DataCenterX1DTUAlarm(Sender: TObject;
  const DTUID: WideString; AlarmCode: Integer);
var i:integer;
    listitem:tlistitem;
    reason:string;
begin

  if alarmcode=1 then reason:=' 告警代码=01:断电';
  if alarmcode=2 then reason:=' 告警代码=02:正常关机';
  if alarmcode=3 then reason:=' 告警代码=03:电源异常';

  if alarmcode=4 then
  begin
    reason:=' 告警代码=04:DTU心跳超时';
  end;

  if alarmcode<>4 then memo1.lines.Add(datetimetostr(now)+' '+'收到告警,dtuid='+dtuid+reason)
  else memo1.lines.Add(datetimetostr(now)+' '+'告警,dtuid='+dtuid+reason);

  showdtu(dtuid);
  for i:=0 to listview1.Items.Count-1 do
  begin
     if listview1.Items[i].Caption=dtuid then
     begin
       listitem:=listview1.Items[i];
       listitem.ImageIndex:=4;
       break;
     end;
  end;
end;

procedure TfrmMain.DTU1Click(Sender: TObject);
var i:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要配置的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
          datacenterx1.SmsCfg(listview1.Items[i].Caption);
          break;
    end;
  end;
end;

procedure TfrmMain.DTU2Click(Sender: TObject);
var i:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要下线的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
      datacenterx1.EXPDTUDown(listview1.Items[i].Caption,0);
    end;
  end;
  showdtus;
end;

procedure TfrmMain.DTU3Click(Sender: TObject);
var i:integer;
begin
  for i:=0 to listview1.Items.Count-1 do
  begin
      datacenterx1.EXPDTUDown(listview1.Items[i].Caption,0);
  end;
  showdtus;
end;

procedure TfrmMain.DataCenterX1DTUData2(Sender: TObject;
  const DTUID: WideString; DataLen: Integer);
var ws:widestring;
    i:integer;
    listitem:tlistitem;
    s,hexstr:string;
    p:pchar;
begin
  setlength(ws,datalen);
  datacenterx1.ReadData(dtuid,ws,datalen);
  p:=@ws[1];

  s:='';
  for i:=1 to DataLen do s:=s+p[i-1];

  if hex1.Checked then hexstr:=' {HEX:'+texttohexstr(s)+'}';
  if NDataTip.Checked  then  memo1.lines.Add(datetimetostr(now)+' '+'收到DTU串口2数据包,dtuid='+dtuid+','+'数据内容:'+hexstr+s)
  else memo1.lines.Add(hexstr+s);

  for i:=0 to listview1.Items.Count-1 do
  begin
     if listview1.Items[i].Caption=dtuid then
     begin
       listitem:=listview1.Items[i];
       listitem.ImageIndex:=1;
       if listitem.SubItems[9]='' then listitem.SubItems[9]:='0';
       listitem.SubItems[9]:= inttostr(strtoint(listitem.SubItems[9])+DataLen);
       break;
     end;
  end;

  if frmfiletest.CheckBox1.Checked then
  begin
    PackLen:=DataLen;
    for i:=1 to length(s) do  EEPROMVM[i]:=ord(s[i]);
    BlockWrite(DataFileRecv,EEPROMVM,PackLen,WriteLen);
  end;
end;

procedure TfrmMain.N12Click(Sender: TObject);
begin
  memo1.Clear;
end;

procedure TfrmMain.PINGDTU1Click(Sender: TObject);
var i,r:integer;
begin
  if listview1.SelCount=0 then
  begin
    showmessage('请先选中要PING的DTU');
  end;
  for i:=0 to listview1.Items.Count-1 do
  begin
    if listview1.Items[i].Selected then
    begin
          r:=datacenterx1.PingDTU(listview1.Items[i].Caption,20);
          if r=0 then  memo1.Lines.Add(datetimetostr(now)+' PING '+listview1.Items[i].Caption+',等待应答中')
          else  memo1.Lines.Add(datetimetostr(now)+' PING '+listview1.Items[i].Caption+'失败,请确认DTU已登陆');
//          break;
    end;
  end;
end;

procedure TfrmMain.DataCenterX1PingResult(Sender: TObject;
  const DTUID: WideString; Result: Integer);
var i:integer;
    listitem:tlistitem;
    reason:string;
    iconidx:integer;
begin
  if result=0 then
  begin
    memo1.lines.Add(datetimetostr(now)+' '+'收到DTU PING应答,dtuid='+dtuid);
    iconidx:=1;
  end
  else
  begin
    memo1.lines.Add(datetimetostr(now)+' '+'PING 超时,dtuid='+dtuid+reason);
    iconidx:=4;
  end;

  showdtu(dtuid);
  for i:=0 to listview1.Items.Count-1 do
  begin
     if listview1.Items[i].Caption=dtuid then
     begin
       listitem:=listview1.Items[i];
       listitem.ImageIndex:=iconidx;
       break;
     end;
  end;
end;

end.

⌨️ 快捷键说明

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