📄 xycom1.pas
字号:
Comm1.RThreshold = 1 + 2 ' 命令字,记录数字...
else
i = szMsrRcd * RcdNum
ReDim rcvArr(i - 1)
Comm1.RThreshold = 1 + i
Timer.Interval = Comm1.RThreshold * 5
end;}
Comm1.Output := outB;
end;
procedure TDjCom.SendaFont;
var i: Integer;
begin
for i:=0 to 31 do
outBuf[2+i]:= StrToInt('$'+slEqp.Strings[i]);
Comm1.Output := outBuf;
end;
procedure TDjCom.SendaMI;
var
i,j,c,k,t: Integer;
Wstr: WideString;
ps : PChar;
chr: Char;
pWs: PWideChar;
wc : WideChar;
substr: array[0..1] of Char;
lidxEqp,lidxiB: Integer;
v: array[0..79] of Byte;
strA: TStrArray;
begin
// 准备 MI 数据
// MsrI File
Readln(fMsrI, str);
strA:= ReadFromStr(str);
// if High(strA)= 13 then begin
//ItemSequ No Name2 EqpNo EqpName CFG MsrType MsrChl DefaultV LowW LowA UpW UpA iB
MI.No := StrToInt(strA[1]);
MI.Name:= strA[2];
MI.EqpNo:= strA[3];
MI.EqpName:= strA[4];
MI.CFG := StrToInt(strA[5]);
MI.MsrType:= StrToInt(strA[6]);
MI.ValType:= StrToInt(strA[7]);
MI.DefaultV:= StrToInt(strA[8]);
MI.LowW:= StrToInt(strA[9]);
MI.LowA:= StrToInt(strA[10]);
MI.UpW:= StrToInt(strA[11]);
MI.UpA:= StrToInt(strA[12]);
MI.iB:= strA[13];
MI.DefaultV := StrToInt('$'+ IntToStr(MI.DefaultV));
MI.UpA := StrToInt('$'+ IntToStr(MI.UpA));
// 准备编码Frame
// MI_No
v[0] := (MI.No and $FF00) shr 8;
v[1] := MI.No and $FF;
dt := MI.DJPLan;
v[2] := DayOf(dt);
v[3] := (MonthOf(dt) shl 4);// or MI.Prd; // 点检周期<=15
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 // 记录到待增加字库
if sl2AddF.IndexOf(wc)<0 then
sl2AddF.Append(wc);
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;
ps := PChar(str);
for i:=0 to 5 do begin
StrLCopy(substr, ps, 2);
v[k+i] := StrToInt('$'+ substr);
ps := ps + 2;
end;
k:= k + 6;
idxiB:= idxiB + 8;
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
if sl2AddF.IndexOf(wc)<0 then
sl2AddF.Append(wc);
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+80B
//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.SetComm;
begin
Comm1.CommPort := 1; //选择COM1(1-COM1,2-COM2)
Comm1.Settings := '19200,n,8,1 '; //设置波特率为9600,无校验,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;
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;
Index := 0; // MI 索引
idxMI := 0;
idxEqp := 0; // 设备名地址计数
slEqp.Clear;
slEqp_i.Clear;
idxiB := 0;
sliB.Clear;
sliB_i.Clear;
// 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] := 01;
outBuf[17] := 01;
// 点检点总数
outBuf[18] :=(MICnt and $FF00) shr 8; // 点检点总数
outBuf[19] := MICnt and $FF;
outBuf[20] := 0; // MIIdx
outBuf[21] := 0;
Send2Device(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;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -