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

📄 xycom.pas

📁 设备巡检操作系统 本程序是专门为某电厂开发的设备巡检系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  v[2] := MI.DJ2Day;
  v[3] := MI.DJPrd;       // 点检周期<=31

  v[4] := MI.CFG;
  v[5] := (MI.LowW and $FF00) shr 8;
  v[6] := MI.LowW and $FF;
  v[7] := (MI.LowA and $FF00) shr 8;
  v[8] := MI.LowA and $FF;
  v[9] := (MI.DefaultV and $FF00) shr 8;
  v[10]:= MI.DefaultV and $FF;
  v[11]:= (MI.UpA and $FF00) shr 8;
  v[12]:= MI.UpA and $FF;

  // v[13]~v[14]  iBAddr
  // v[15]~v[17] 设备名

  // Memo
  v[18] := 0;               // LenMemo

  // MI_NAME
  Wstr := MI.Name;
  c := Length(Wstr);
  if c>maxNAME then c:= maxNAME;
  v[19] := c;
  if c>6 then begin
    v[19]:= c or $80;
    v[20]:= (idxMI and $FF00) shr 8;  // Addr
    v[21]:= idxMI and $FF;
    idxMI := idxMI + c*2;
    k:= 22;
  end else
    k:= 20;
  // 数据(20~): [Name_Addr],[测点名],[iB],[设备名]
  // 测点名
  j := 0;
  pWs := PWideChar(Wstr);
  for i:=0 to c-1 do begin
    wc:= pWs[i];
    t := slFontTbl.IndexOf(wc);
    if t>0 then begin   // 第0字符为NULL, Device遇到时不显示
      v[k+j]  := (t and $FF00) shr 8;
      v[k+j+1]:= t and $FF;
    end else begin           // 记录到待增加字库
      v[k+j]  := 0;
      v[k+j+1]:= 0;
      if sl2AddF.IndexOf(wc)<0 then sl2AddF.Append(wc);
    end;
    j := j+2;
  end;
  k:= k + 2*c;

  // iB
  str := MI.iB;
  t := sliB.IndexOf(str);
  if t >=0 then begin
    lidxiB := StrToInt(sliB_i.Strings[t]);
  end else begin
    // New iB
    v[19] := v[19] or $40;   // b6=1标志传输新的iB
    sliB.Append(str);
    sliB_i.Append(IntToStr(idxiB));
    lidxiB:= idxiB;
    idxiB := idxiB + 32;
  end;
  if MI.iB<>PreiB then begin
    PreiB:= MI.iB;
    v[19]:= v[19] or $40;   // b6=1标志传输新的iB
  end;
  v[13] := (lidxiB and $FF00) shr 8;
  v[14] := lidxiB and $FF;

  // 设备名
  Wstr := MI.EqpName;
  c := Length(Wstr);          // szEQ
  if c>maxNAME then c:= maxNAME;
  v[15] := c or $80;

  str := MI.EqpName;
  t := slEqp.IndexOf(str);
  if t >=0 then begin
    lidxEqp := StrToInt(slEqp_i.Strings[t]);   // lidxEqpp:设备名显示码地址
    v[15] := v[15] and $1F;    // b7=0标志已有设备名
  end else begin
    slEqp.Append(str);
    slEqp_i.Append(IntToStr(idxEqp));
    lidxEqp := idxEqp;

    j := 0;
    pWs := PWideChar(Wstr);
    for i:=0 to c-1 do begin
      wc := pWs[i];
      t := slFontTbl.IndexOf(wc);
      if t>0 then begin
        v[k+j] := (t and $FF00) shr 8;
        v[k+j+1] := t and $FF;
      end else begin
        v[k+j]  := 0;
        v[k+j+1]:= 0;
        if sl2AddF.IndexOf(wc)<0 then sl2AddF.Append(wc);
      end;
      j := j+2;
    end;
    k:= k + 2*c;
    idxEqp:= idxEqp + c*2;
  end;
  // 设备名地址
  v[16] := (lidxEqp and $FF00) shr 8;
  v[17] :=  lidxEqp and $FF;

  // 准备outBuf
  outBuf := VarArrayCreate([0,k+1], varByte);  // 2+64B
  //ShowMessage(InttoStr(VarArrayHighBound(outBuf, 1)));
  outBuf[0]:= cMI;
  outBuf[1]:= k;
  for i:=0 to k-1 do
    outBuf[i+2]:= v[i];

  Comm1.Output := outBuf;
end;

procedure TDjCom.SendaiB;
var
  i,j,c,t: Integer;
  Wstr: WideString;
  ps : PChar;
  pWs: PWideChar;
  wc : WideChar;
  substr: array[0..1] of Char;
  v: array[0..31] of Byte;
begin
  if not EoF(fiB) then begin
    ReadLn(fiB, str);
    slEqp.CommaText := str;
  end;

  // iB
  str:= slEqp.Strings[0];
  ps := PChar(str);
  for i:=0 to 5 do begin
    StrLCopy(substr, ps, 2);
    outBuf[2+i] := StrToInt('$'+ substr);
    ps := ps + 2;
  end;
  t:= StrToInt(slEqp.Strings[1]);
  v[6]:= (t and $FF00) shr 8;
  v[7]:= t and $FF;
  v[8]:= StrToInt(slEqp.Strings[2]);

  // 区域名
  Wstr:= slEqp.Strings[3];
  c := Length(Wstr);
  if c>maxiBNAME then c:= maxiBNAME;
  j := 9;
  pWs := PWideChar(Wstr);
  for i:=0 to c-1 do begin
    wc:= pWs[i];
    t := slFontTbl.IndexOf(wc);
    if t>0 then begin   // 第0字符为NULL, Device遇到时不显示
      v[j] := (t and $FF00) shr 8;
      v[j+1]:= t and $FF;
    end else            // 记录到待增加字库
      if sl2AddF.IndexOf(wc)<0 then sl2AddF.Append(wc);
    j:= j+2;
  end;
  for i:=6 to 31 do
    outBuf[2+i]:= v[i];

  Comm1.Output := outBuf;
end;

procedure TDjCom.SetComm(ComPort: Byte=1);
begin
  Comm1.CommPort := ComPort;     //选择COM1(1-COM1,2-COM2)
  Comm1.Settings := '19200,n,8,1';  //设置波特率为9600,无校验,8个数据位,1个停止位
  //Comm1.Settings := '9600,n,8,1';

  Comm1.InputLen := 0;    //设置为在读操作时读取接收缓冲区的所有数据
  Comm1.InBufferSize := 1024;   //设置接受缓冲区为1024字节
  Comm1.OutBufferSize:= 512;    //设置发送缓冲区为512字节

  Comm1.InputMode  := ComInputModeBinary;  //置为二进制输入方式
  Comm1.RThreshold := 1;        //设置为接收缓冲区每接收一个字符将引发一次OnComm事件
  Comm1.NullDiscard:= False;    // 允许接收&0H

  //Comm1.DTREnable := True;    //置DTR有效
  //Comm1.RTSEnable := True;    //置RTS有效

  Comm1.InBufferCount := 0;     //清除接收缓冲区
  Comm1.OutBufferCount:= 0;     //清除发送缓冲区

  If Not Comm1.PortOpen Then
      Comm1.PortOpen := True;     // 打开串口
end;

procedure TDjCom.SetFonts;
begin
  AssignFile(fHzFont, cFontFile);
  Reset(fHzFont);

  outBuf := VarArrayCreate([0,33], varByte);    // 2+32B

  // cmd, len, data
  outBuf[0] := $80 + cTransFonts;
  outBuf[1] := 32;
  Index := 0;

  if not EoF(fHzFont) then begin
    ReadLn(fHzFont, str);
    slEqp.CommaText := str;
  end;

  Comm1.RThreshold := 2;
  SendaFont;
end;

procedure TDjCom.SetMIs;
var
  strA: TStrArray;
  i,j,t: Integer;
  ps: PChar;
  c: Char;
begin
  // MsrI File: mi.dat
  if foMsrI then CloseFile(fMsrI);
  AssignFile(fMsrI, cfMsrI);
  Reset(fMsrI);
  i := -1;
  while (not EoF(fMsrI)) do begin
    ReadLn(fMsrI, str);
    i := i+1;
  end;
  MICnt := i;
  Reset(fMsrI);
  foMsrI:= True;

  if foiB then CloseFile(fiB);
  AssignFile(fiB, cfiB);
  Reset(fiB);
  i := 0;
  while (not EoF(fiB)) do begin
    ReadLn(fiB, str);
    i := i+1;
  end;
  iBCnt := i;
  Reset(fiB);
  foiB:= True;

  Index := 0;     // MI 索引
  idxMI := 0;

  idxEqp := 0;    // 设备名地址计数
  slEqp.Clear;
  slEqp_i.Clear;

  idxiB := 0;
  sliB.Clear;
  sliB_i.Clear;
  PreiB:= '';
  PreEQ:= '';

  // outBuf
  hCmd := cInitDJ;
  outBuf := VarArrayCreate([0,szInitDJ+1], varByte);
  outBuf[0] := hCmd;
  outBuf[1] := szInitDJ;

  SetTime;    // 对时

  // 工作岗位
  Readln(fMsrI, str);
  for i:=10 to 15 do
    outBuf[i] := 0;
  ps := PChar(str);
  j := 10;
  for i:=0 to 5 do begin
    c:= ps[i];
    t := slFontTbl.IndexOf(c);
    if t>=0 then
      outBuf[j] := t;// and $FF;
    j := j+1;
  end;

  outBuf[16] := iBCnt;  // iBCnt
                        // MICnt
  outBuf[17] :=(MICnt and $FF00) shr 8;
  outBuf[18] := MICnt and $FF;
  t := MonthOf(Date);
  case t of
  1,3,5,7,8,10,12:
    i:= 3;
  4,6,9,11:
    i:=2;
  2:
    if (cYear mod 4)>0 then i:=0 else i:= 1;
  end;                  //DMonADay
  outBuf[19] := (t shl 4) or i;
  outBuf[20] := 0;      // XIdxAdr

  outBuf[21] := 0;      // iBIdx
  outBuf[22] := 0;      // MIIdx
  outBuf[23] := 0;
  // 路线, 班次
  //outBuf[24] := 0;
  outBuf[24] := 0;      // Turns

  Send2Device(outBuf);
end;

procedure TDjCom.GetCur;
begin
  outBuf := VarArrayCreate([0,1], varByte);
  outBuf[0] := cTransCurM;
  outBuf[1] := 0;

  Comm1.Output := outBuf;
end;

procedure TDjCom.GetData;
begin
  if foData then CloseFile(fData);
  AssignFile(fData, cfData);
  Rewrite(fData);
  foData:= True;

  outBuf := VarArrayCreate([0,9], varByte);
  hCmd := cTransData0;
  outBuf[0] := hCmd;
  outBuf[1] := 8;
  SetTime;    // 对时

  Send2Device(outBuf);
end;

procedure TDjCom.SetTime;
var
  i: Integer;
begin
  // 对时时钟
  dt := Now;
  outBuf[2] := StrToInt('$' + IntToStr(SecondOf(dt)));  // 秒/分/时
  outBuf[3] := StrToInt('$' + IntToStr(MinuteOf(dt)));
  outBuf[4] := StrToInt('$' + IntToStr(HourOf(dt)));
  outBuf[5] := StrToInt('$' + IntToStr(DayOf(dt)));     //日/月/星期/年
  outBuf[6] := StrToInt('$' + IntToStr(MonthOf(dt)));
  i := DayOfWeek(dt)-1;
  if (i = 0) then i := 7;
  outBuf[7] := StrToInt('$' + IntToStr(i));
  outBuf[8] := StrToInt('$' + IntToStr(cYear - 2000));
  outBuf[9] := 0;
end;

procedure TDjCom.Setup(cfg :Byte);
begin
  hCmd := cSetup;
  outBuf := VarArrayCreate([0, szSetup+1], varByte);
  outBuf[0] := hCmd;
  outBuf[1] := szSetup;

  SetTime();
  outBuf[10] := cfg;

  Send2Device(outBuf);
end;

procedure TDjCom.SetiBs;
begin
  outBuf := VarArrayCreate([0,33], varByte);    // 2+32B

  // cmd, len, data
  outBuf[0] := $80 + ciB;
  outBuf[1] := 32;
  Index := 0;

  SendaiB();
end;

function TDjCom.ProciBRcd: Boolean;
var
  i, year: Integer;
begin
  ProciBRcd := False;

  // "2002-12-31 14:56"
  year := Floor(cYear/2)*2 or (v[6] and $1);
  ToiBTime:= IntToStr(year) +'-' + IntToHex(v[4],2)+ '-'+ IntToHex(v[3],2)+ ' '+ IntToHex(v[2],2)+ ':'+ IntToHex(v[1],2)+ ':0';//+ IntToHex(v[3],2));

  ProciBRcd:= True;
end;

procedure TDjCom.GetiBData;
begin
  if foiBData then CloseFile(fiBData);
  AssignFile(fiBData, cfiBData);
  Rewrite(fiBData);
  foiBData:= True;

  outBuf := VarArrayCreate([0,1], varByte);
  hCmd := $80 or cTransiB_D;
  outBuf[0] := hCmd;
  outBuf[1] := 0;

  Send2Device(outBuf);
end;

procedure TDjCom.SetSelIs;
begin
  if foiB then CloseFile(fiB);
  AssignFile(fiB, 'SelI.dat');
  Reset(fiB);
  foiB := True;

  outBuf := VarArrayCreate([0,15], varByte);    // 2+32B

  // cmd, len, data
  outBuf[0] := cSetSelI;
  outBuf[1] := 14;
  Index := 0;

  SetaSelI();
  Send2Device(outBuf);
end;

procedure TDjCom.SetaSelI;
var
  i,j,c,k,t: Integer;
  Wstr: WideString;
  ps : PChar;
  pWs: PWideChar;
  wc : WideChar;
  v: array[0..15] of Byte;
begin
  if not EoF(fiB) then begin
    ReadLn(fiB, str);
    slEqp.CommaText := str;
  end;
  v[2]:= StrToInt(slEqp.Strings[0]);
  v[3]:= StrToInt(slEqp.Strings[1]);

  // SelItems
  j := 4;
  for k:=2 to slEqp.Count-1 do begin
    Wstr:= slEqp.Strings[k];
    c := Length(Wstr);
    if c>4 then c:= 4;
    pWs := PWideChar(Wstr);
    for i:=0 to 3 do begin
      if i<c then begin
        wc:= pWs[i];
        t := slFontTbl.IndexOf(wc);
        if t>0 then
          v[j]:= t and $FF
        else            // 记录到待增加字库
          if sl2AddF.IndexOf(wc)<0 then sl2AddF.Append(wc);
      end else
        v[j]:= 0;
      j:= j+1;
    end;
  end;
  for i:=k to 2 do
  begin
    v[j]:= 0;
    v[j+1]:= 0;
    v[j+2]:= 0;
    v[j+3]:= 0;
    j:= j+4;
  end;

  for i:=2 to 15 do
    outBuf[i]:= v[i];
end;

procedure TDjCom.ResetDev;
begin
  if foiB then CloseFile(fiB);
  AssignFile(fiB, 'dev.sys');
  Reset(fiB);
  foiB := True;

  outBuf := VarArrayCreate([0,33], varByte);    // 2+32B

  // cmd, len, data
  outBuf[0] := $80 or cResetDev;
  outBuf[1] := 32;
  Index := 0;

  if not EoF(fiB) then begin
    ReadLn(fiB, str);
    slEqp.CommaText := str;
  end;

  Comm1.RThreshold := 2;
  SendaFont();

  outBuf[0] := cResetDev;
end;

end.

⌨️ 快捷键说明

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