📄 dl645lib.~pas
字号:
end else if DI0L= '1' then begin
if Length(Data) < (4 +3) then begin
raise Exception.Create('长度错');
exit;
end;
S:=buf1toByte(Data[9]);
F:=buf1toByte(Data[10]);
H:=buf1toByte(Data[11]);
result.T:=EncodeTime(h,f,s,0);
end;
end;
///////////////////////////////////////////////////////
/// 解析 电表参数
/////////////////////////////////////////////////////////
Function PaserC02_(DI0L:char;Data:String):TC02_;
begin
case DI0L of
'0': result.B1:= ord(Data[5])-$33;
'1': result.B2:= ord(Data[5])-$33;
'2': result.B3:= ord(Data[5])-$33;
'F': begin
result.B1:= ord(Data[5])-$33;
result.B2:= ord(Data[6])-$33;
result.B3:= ord(Data[7])-$33;
end;
end;
end;
Function PaserC03_(DI0L:char;Data:String):TC03_;
var buf3:Tbuf3; b6:Tbuf6;
begin
case DI0L of
'0': begin
copymemory(@buf3[0],@data[5],3);
result.Pkwh:=buf3toDword(buf3);
end;
'1': begin
copymemory(@buf3[0],@data[5],3);
result.Qkwh:=buf3toDword(buf3);
end;
'2': begin
copymemory(@b6[0],@data[5],6);
result.BH:= Buf6ToStr(b6);
end;
'3': begin
copymemory(@b6[0],@data[5],6);
result.UseID:= Buf6ToStr(b6);
end;
'4': begin
copymemory(@b6[0],@data[5],6);
result.DEVID:= Buf6ToStr(b6);
end;
'F': begin
copymemory(@buf3[0],@data[5],3);
result.Pkwh:=buf3toDword(buf3);
copymemory(@buf3[0],@data[8],3);
result.Qkwh:=buf3toDword(buf3);
copymemory(@b6[0],@data[11],6);
result.BH:= Buf6ToStr(b6);
copymemory(@b6[0],@data[17],6);
result.UseID:= Buf6ToStr(b6);
copymemory(@b6[0],@data[23],6);
result.DEVID:= Buf6ToStr(b6);
end;
end;
end;
Function PaserC11_(DI0L:char;Data:String):TC11_;
var buf:Tbuf4;
begin
case DI0L of
'1': result.PmT:=Buf1ToByte(data[5]);
'2': result.DelayT:=Buf1ToByte(data[5]);
'3': result.LoopT:=Buf1ToByte(data[5]);
'4': result.DisT:=Buf1ToByte(data[5]);
'5': result.DLDot:=Buf1ToByte(data[5]);
'6': result.PmDot:=Buf1ToByte(data[5]);
'7': result.ReadDDHH := inttohex( (ord(data[6])-$33 ),2)+'日'
+ inttohex( (ord(data[5])-$33 ),2)+'时';
'8': result.FHDay:=Buf1ToByte(data[5]);
'9': begin
copyMemory(@buf[0],@data[5],4);
result.P_kWh0:= buf4ToDword(buf) /100;
end;
'A': begin
copyMemory(@buf[0],@data[5],4);
result.Q_kWh0:= buf4ToDword(buf) /100;
end;
'F': begin
result.PmT:=Buf1ToByte(data[5]);
result.DelayT:=Buf1ToByte(data[6]);
result.LoopT:=Buf1ToByte(data[7]);
result.DisT:=Buf1ToByte(data[8]);
result.DLDot:=Buf1ToByte(data[9]);
result.PmDot:=Buf1ToByte(data[10]);
result.ReadDDHH := inttohex( (ord(data[12])-$33 ),2)+'日'
+ inttohex( (ord(data[11])-$33 ),2)+'时';
result.FHDay:=Buf1ToByte(data[13]);
copyMemory(@buf[0],@data[14],4);
result.P_kWh0:= buf4ToDword(buf) /100;
copyMemory(@buf[0],@data[18],4);
result.Q_kWh0:= buf4ToDword(buf) /100;
end;
end;
end;
Function PaserC21_(DI0L:char;Data:String):TC21_;
var buf :Tbuf2;
begin
case DI0L of
'1': begin
copyMemory(@buf[0],@data[5],2);
result.PWms:=buf2Toword(buf);
end;
'2': begin
result.PA:= ord(data[5]) -$33;
result.P1:= ord(data[6]) -$33;
result.P2:= ord(data[7]) -$33;
result.P3:= ord(data[8]) -$33;
end;
end;
end;
Function PaserC31_(DI0L:char;Data:String):TC31_;
begin
case DI0L of
'0': result.P := buf1ToByte(data[5]) ;
'1': result.q := buf1ToByte(data[5]) ;
'2': result.m := buf1ToByte(data[5]) ;
'3': result.k := buf1ToByte(data[5]) ;
'4': result.n := buf1ToByte(data[5]) ;
'F': begin
result.P := buf1ToByte(data[5]) ;
result.q := buf1ToByte(data[6]) ;
result.m := buf1ToByte(data[7]) ;
result.k := buf1ToByte(data[8]) ;
result.n := buf1ToByte(data[9]) ;
end;
end;
end;
Function PaserC32_(DI0L:char;Data:String):TC32_;
var i,k:Integer; bf:Tbuf3;
begin
case DI0L of
'1'..'E': begin
i:=Strtoint('$'+DI0L);
copyMemory(@bf[0],@data[5],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+DI0L +'时区__'
+' 起始日期:'+ inttoHex( bf[2],2)+'月'
+inttoHex( bf[1],2)+'日'
+ ' 时段表号:' + inttoHex( bf[0],2) ;
end;
'F': begin
for i:=1 to 14 do begin
copyMemory(@bf[0],@data[5+(i-1)*3],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+inttostr(i) +'时区__'
+' 起始日期:'+ inttoHex( bf[2],2)+'月'
+inttoHex( bf[1],2)+'日'
+ ' 时段表号:' + inttoHex( bf[0],2) ;
end;
end;
end;
end;
Function PaserC33_(ID:string;DI0L:char;Data:String):TC33_;
var mi,i,k:Integer; bf:Tbuf3;
begin
Mi:=strtoint('$'+ID[3])-2;
case DI0L of
'1'..'A': begin
i:=Strtoint('$'+DI0L);
copyMemory(@bf[0],@data[5],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+inttostr(mi) +'时段表__'
+ ' 第'+inttostr(i) +'时段__'
+ ' 费率号:' + intToHex( bf[0],2)
+' 起始时间:'+ intToHex( bf[2],2)+'时'
+intToHex( bf[1],2)+'分'
end;
'F': begin
for i:=1 to 10 do begin
copyMemory(@bf[0],@data[5+(i-1)*3],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+inttostr(mi) +'时段表__'
+ ' 第'+inttostr(i) +'时段__'
+ ' 费率号:' + intToHex( bf[0],2)
+' 起始时间:'+ intToHex( bf[2],2)+'时'
+intToHex( bf[1],2)+'分'
end;
end;
end;
end;
Function PaserC41_(DI0L:char;Data:String):TC41_;
var i,k:Integer; bf:Tbuf3;
begin
case DI0L of
'1'..'D': begin
i:=Strtoint('$'+DI0L);
copyMemory(@bf[0],@data[5],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+DI0L +'公共假期__'
+' 日期:'+ inttoHex( bf[2],2)+'月'
+inttoHex( bf[1],2)+'日'
+ ' 日时段表号:' + inttoHex( bf[0],2) ;
end;
'E': result[i]:='周休日采用的日时段表号:'+ inttoHex( ord(Data[5]) -$33 ,2) ;
'F': begin
for i:=1 to 13 do begin
copyMemory(@bf[0],@data[5+(i-1)*3],3);
for k:=0 to 2 do bf[k]:=bf[k]-$33;
result[i]:=' 第'+inttostr(i) +'公共假期__'
+' 日期:'+ inttoHex( bf[2],2)+'月'
+inttoHex( bf[1],2)+'日'
+ ' 日时段表号:' + inttoHex( bf[0],2) ;
result[14]:='周休日采用的日时段表号:'+ inttoHex( ord(Data[5+13*3] )-$33 ,2) ;
end;
end;
end;
end;
///////////////////////////////////////////////////////
/// 设置 电表参数
////////////////////////////////////////////////////////
Function GetSTX(ADR:string;var CS0:Byte):string;
var i:byte; adds:string[12];
var Buf8:array[0..7] of Byte;
begin
setlength(result,8);
adds:=rightstr('00000000000000'+ADR,12);
buf8[0]:=$68;
buf8[1]:=StrToInt('$'+ adds[11]+adds[12]); //A0
buf8[2]:=StrToInt('$'+ adds[9]+adds[10]); //A1
buf8[3]:=StrToInt('$'+ adds[7]+adds[8]); //A2
buf8[4]:=StrToInt('$'+ adds[5]+adds[6]); //A3
buf8[5]:=StrToInt('$'+ adds[3]+adds[4]); //A4
buf8[6]:=StrToInt('$'+ adds[1]+adds[2]); //A5
buf8[7]:=$68; //stx for DL meter read
CopyMemory(@Result[1],@buf8[0],8);
CS0:=0;
for i:=0 to 7 do CS0:=CS0+ buf8[i];
end;
//设置日期及时间
Function GetCmdC01( ADR:string;aC01:TC01_; PA,P1,P2,P3:Byte;
var STX:string;var CS0:Byte; var Size:Integer):TBuf200;
var YY,MM,DD,WW,HH,FF,SS,MS:Word;
i:Integer; CS:Byte;
begin
STX:= GetSTX(ADR,CS0);
CopyMemory(@Result[0],@STX[1],8); //0__7
Result[8] := CtlWriteCS; //控码 =4
Result[9] := 2 + 4 + 7 ; //L=2(标识)+4(密码)+m(实际数据)
/////// 以上不需加 $33 ///////////////////
Result[10] := $1F ; //DI0 +$33 标识
Result[11] := $C0 ; //DI1 +$33 标识
Result[12] := PA; //密码
Result[13] := P1;
Result[14] := P2;
Result[15] := P3;
WW:=WeekOf(aC01.D);
DecodeDate(aC01.D,YY,MM,DD);
DecodeTime(aC01.T,HH,FF,SS,MS);
YY:=YY mod 100;
Result[16] := BCDToHex(WW)+$33; // WW
Result[17] := BCDToHex(DD)+$33; // DD
Result[18] := BCDToHex(MM)+$33; // MM
Result[19] := BCDToHex(YY)+$33; // YY
Result[20] := BCDToHex(SS)+$33; // SS
Result[21] := BCDToHex(FF)+$33; // FF
Result[22] := BCDToHex(HH)+$33; // HH
Result[23] := $AA; // HH
CS:=CS0;
for i:=8 to 23 do CS:=CS+ Result[i] ;
Result[24] := CS;
Result[25] := $16;
Size:=26;
end;
// 广播校时 本命令无应答
Function GetCmdBrdTime(t:TdateTime; var Size:Integer):TBuf200;
var STX:string; CS0:Byte;
var YY,MM,DD,HH,FF,SS,MS:Word;
i:Integer; CS:Byte;
begin
STX:= GetSTX('999999999999',CS0);
CopyMemory(@Result[0],@STX[1],8); //0__7
Result[8] := CtlBrdTime; //控码 =8
Result[9] := 6 ; //
/////// 以上不需加 $33 ///////////////////
DecodeDateTime(t,YY,MM,DD,HH,FF,SS,MS);
YY:=YY mod 100;
Result[10] := BCDToHex(SS) +$33; // SS
Result[11] := BCDToHex(FF) +$33; // FF
Result[12] := BCDToHex(HH) +$33; // HH
Result[13] := BCDToHex(DD) +$33; // DD
Result[14] := BCDToHex(MM) +$33; // MM
Result[15] := BCDToHex(YY) +$33; // YY
CS:=CS0;
for i:=8 to 15 do CS:=CS+ Result[i] ;
Result[16] := CS;
Result[17] := $16;
Size:=18;
end;
//写设备地址 本命令有应答(只有正常应答)
Function GetCmdWriteADR(NewADR:string; var STX:string;var CS0:Byte;var Size:Integer):TBuf200;
var i:Integer; CS:Byte;
begin
STX:= GetSTX('999999999999',CS0);
CopyMemory(@Result[0],@STX[1],8); //0__7
Result[8] := CtlWriteADR; //控码 =10
Result[9] := 6 ; //
/////// 以上不需加 $33 ///////////////////
STX:= GetSTX(NewADR,CS0); //STX 为应答帧的地址头
// CS0 为应答帧的地址头的和
CopyMemory(@Result[10],@STX[2],6);
// Result[10] := STX[2]=A0
//......STX 的地址域为该命令的数据域
//Result[15] := STX[7] =A5 STX[8]=$68
for i:=10 to 15 do Result[i] := Result[i] +$33; // 数据域
CS:=CS0;
for i:=8 to 15 do CS:=CS+ Result[i] ;
Result[16] := CS;
Result[17] := $16;
Size:=18;
end;
Function BpsToZ(bps:TBps;var BpsInt:Integer):Byte;
begin
Case Bps of
Bps300: begin Result:= $02; BpsInt:= 300; end;
Bps600: begin Result:= $04; BpsInt:= 600; end;
Bps2400: begin Result:= $10 ; BpsInt:= 2400; end;
Bps4800: begin Result:= $20; BpsInt:= 4800; end;
Bps9600: begin Result:= $40; BpsInt:= 9600; end;
end;
end;
//写通信速率 本命令有应答(有正常应答,否认应答)
Function GetCmdUpdateBPS(ADR:string; Bps:TBps;
var STX:string; var CS0:Byte;var Size:Integer):TBuf200;
begin
STX:= GetSTX(ADR,CS0);
CopyMemory(@Result[0],@STX[1],8); //0__7
Result[8] := CtlUpDateBps; //控码 =12
Result[9] := 01 ; // 1个 Z 字节
/////// 以上不需加 $33 ///////////////////
Result[10] := BpsToZ(Bps,Size)+$33; // Z
Result[11] :=CS0+ Result[8]+ Result[9]+ Result[10] ; // CS;
Result[12] := $16;
Size:=13;
end;
// /写密码
Function GetCmdUpdatePass(ADR:string;PA0,P10,P20,P30,PAN,P1N,P2N,P3N:Byte;
var STX:string; var CS0:Byte;var Size:Integer):TBuf200;
VAR CS,i:Byte;
begin
STX:= GetSTX(ADR,CS0);
CopyMemory(@Result[0],@STX[1],8); //0__7
Result[8] := CtlUpDatePass; //控码 =15
Result[9] := 08 ; // 4+4
/////// 以上不需加 $33 ///////////////////
Result[10] := PA0+$33 ;
Result[11] := P10+$33 ;
Result[12] := P20+$33 ;
Result[13] := P30+$33 ;
Result[14] := PAN+$33 ;
Result[15] := P1N+$33 ;
Result[16] := P2N+$33 ;
Result[17] := P3N+$33 ;
CS:=CS0;
for i:=8 to 17 do CS:=CS+ Result[i] ;
Result[18] :=CS;
Result[19] := $16;
Size:=20;
end;
//广播冻结
Function GetCmdBrdFrz(var Size:Integer):TBuf200;
var Stx:string; cs0:Byte;
begin
stx:=getStx('999999999999',cs0);
copymemory(@result[0],@Stx[1], 8);
result[8]:=09;
result[9]:=00;
result[10]:=CS0 + result[8] + result[9] ; //cs
result[11]:=$16;
Size:=12;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -