?? func.pas
字號:
unit func;
interface
uses
filedefine, SysUtils, crcp;
const
CRCHi: array [0..255] of byte =
(
$00, $C1, $81, $40, $01, $C0, $80, $41, $01, $C0, $80, $41, $00,
$C1, $81, $40, $01, $C0, $80, $41, $00, $C1, $81, $40, $00, $C1,
$81, $40, $01, $C0, $80, $41, $01, $C0, $80, $41, $00, $C1, $81,
$40, $00, $C1, $81, $40, $01, $C0, $80, $41, $00, $C1, $81, $40,
$01, $C0, $80, $41, $01, $C0, $80, $41, $00, $C1, $81, $40, $01,
$C0, $80, $41, $00, $C1, $81, $40, $00, $C1, $81, $40, $01, $C0,
$80, $41, $00, $C1, $81, $40, $01, $C0, $80, $41, $01, $C0, $80,
$41, $00, $C1, $81, $40, $00, $C1, $81, $40, $01, $C0, $80, $41,
$01, $C0, $80, $41, $00, $C1, $81, $40, $01, $C0, $80, $41, $00,
$C1, $81, $40, $00, $C1, $81, $40, $01, $C0, $80, $41, $01, $C0,
$80, $41, $00, $C1, $81, $40, $00, $C1, $81, $40, $01, $C0, $80,
$41, $00, $C1, $81, $40, $01, $C0, $80, $41, $01, $C0, $80, $41,
$00, $C1, $81, $40, $00, $C1, $81, $40, $01, $C0, $80, $41, $01,
$C0, $80, $41, $00, $C1, $81, $40, $01, $C0, $80, $41, $00, $C1,
$81, $40, $00, $C1, $81, $40, $01, $C0, $80, $41, $00, $C1, $81,
$40, $01, $C0, $80, $41, $01, $C0, $80, $41, $00, $C1, $81, $40,
$01, $C0, $80, $41, $00, $C1, $81, $40, $00, $C1, $81, $40, $01,
$C0, $80, $41, $01, $C0, $80, $41, $00, $C1, $81, $40, $00, $C1,
$81, $40, $01, $C0, $80, $41, $00, $C1, $81, $40, $01, $C0, $80,
$41, $01, $C0, $80, $41, $00, $C1, $81, $40
) ;
CRCLo: array [0..255] of byte =
(
$00, $C0, $C1, $01, $C3, $03, $02, $C2, $C6, $06, $07, $C7, $05,
$C5, $C4, $04, $CC, $0C, $0D, $CD, $0F, $CF, $CE, $0E, $0A, $CA,
$CB, $0B, $C9, $09, $08, $C8, $D8, $18, $19, $D9, $1B, $DB, $DA,
$1A, $1E, $DE, $DF, $1F, $DD, $1D, $1C, $DC, $14, $D4, $D5, $15,
$D7, $17, $16, $D6, $D2, $12, $13, $D3, $11, $D1, $D0, $10, $F0,
$30, $31, $F1, $33, $F3, $F2, $32, $36, $F6, $F7, $37, $F5, $35,
$34, $F4, $3C, $FC, $FD, $3D, $FF, $3F, $3E, $FE, $FA, $3A, $3B,
$FB, $39, $F9, $F8, $38, $28, $E8, $E9, $29, $EB, $2B, $2A, $EA,
$EE, $2E, $2F, $EF, $2D, $ED, $EC, $2C, $E4, $24, $25, $E5, $27,
$E7, $E6, $26, $22, $E2, $E3, $23, $E1, $21, $20, $E0, $A0, $60,
$61, $A1, $63, $A3, $A2, $62, $66, $A6, $A7, $67, $A5, $65, $64,
$A4, $6C, $AC, $AD, $6D, $AF, $6F, $6E, $AE, $AA, $6A, $6B, $AB,
$69, $A9, $A8, $68, $78, $B8, $B9, $79, $BB, $7B, $7A, $BA, $BE,
$7E, $7F, $BF, $7D, $BD, $BC, $7C, $B4, $74, $75, $B5, $77, $B7,
$B6, $76, $72, $B2, $B3, $73, $B1, $71, $70, $B0, $50, $90, $91,
$51, $93, $53, $52, $92, $96, $56, $57, $97, $55, $95, $94, $54,
$9C, $5C, $5D, $9D, $5F, $9F, $9E, $5E, $5A, $9A, $9B, $5B, $99,
$59, $58, $98, $88, $48, $49, $89, $4B, $8B, $8A, $4A, $4E, $8E,
$8F, $4F, $8D, $4D, $4C, $8C, $44, $84, $85, $45, $87, $47, $46,
$86, $82, $42, $43, $83, $41, $81, $80, $40
);
procedure app_analys(var econfile: teconfile);
function StrToHex(Str1: String; i: Integer): Integer;// 十六進制字符串轉為有符號整數
function StrToHex1(Str1: String; i: Integer): Cardinal;
procedure AppendBlank(var Str1: String; i: Integer);
function framecheck: integer;
procedure asclltoapp(var tempstring: string; var econfile: Teconfile);
function Lrc(const Temp: String): String;
function crc(var dataaddress: byte; datalength: byte): word;
implementation
uses econv230p;
function crc(var dataaddress :byte; datalength: byte): word;
var
hi: byte;
lo: byte;
i: byte;
index: byte;
datadd: pbytearray;
begin
hi := $FF;
lo := $FF;
datadd := @dataaddress;
i := 0;
while (datalength > 0) do
begin
index := hi xor datadd^[i];
i := i + 1;
hi := lo xor crchi[index];
lo := crclo[index];
datalength := datalength - 1;
end;
crc := hi shl 8 or lo;
end;
function StrToHex(Str1: String; i: Integer): Integer;// 十六進制字符串轉為有符號整數
Var
firstInt: smallInt;
SecondInt: Integer;
begin
firstInt := 0;
for SecondInt:=1 To i do
begin
if Str1='' then Str1 := '0000';
case Str1[SecondInt] of
'0'..'9': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 48;
'a'..'f': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 87;
'A'..'F': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 55;
else firstInt := 0;
end;
// if firstInt>32767 then firstInt:=not firstInt +1;
end;
StrToHex := firstInt;
end;
function StrToHex1(Str1: String; i: Integer): Cardinal;
Var
firstInt: Cardinal;
SecondInt: Integer;
begin
firstInt := 0;
for SecondInt:=1 To i do
begin
// form1.caption:=str1;
case Str1[SecondInt] of
'0'..'9': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 48;
'a'..'f': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 87;
'A'..'F': firstInt := firstInt*16 + Ord(Str1[SecondInt]) - 55;
else firstInt := 0;
end;
// if firstInt>32767 then firstInt:=not firstInt +1;
end;
StrToHex1 := firstInt;
end;
{function settime:cardinal;
begin
settime:=Trunc(time*MsecsPerDay)
end; }
procedure AppendBlank(var Str1: String; i: Integer);
var
l, m: integer;
begin
l := i- length(Str1);
for m:=1 to l do
begin
Str1 := Str1 + ' ';
end;
end;
procedure app_analys(var econfile: teconfile);
var
a, k: byte;
i: byte;
j: word;
Hour, Minute, Second, mSecond: word; // SOE 時,分,秒,毫秒
ActDot, ActType: String; // S0E事件記錄動作點,動作類型,動作時間
f: String;
TimeValue: Double;
begin
with econfile do
begin
case econfile.analysbuffer[2] of
1:
begin
for j:=0 to analysbuffer[3]-1 do
begin
a := 1;
for i:=1 to 8 do
begin
k := (analysbuffer[4 + j] and a);
if (j*8 + i)<=readcoilcount then coilstatearray[beginaddress + j*8 + i].value := (k>0);
if (i<>8) then a := a * 2;
end;
end;
displaycoilstate(econfile, mainform.coilstategrid);
end;
2:
begin
for j:=0 to analysbuffer[3]-1 do
begin
a := 1;
for i:=1 to 8 do
begin
k := (analysbuffer[4 + j] and a);
if (j*8 + i)<=readinputcount then econfile.inputstatearray[beginaddress + j*8 + i].value := (k>0);
if (i<>8) then a := a * 2;
end;
end;
displayinputstate(econfile, mainform.inputstategrid);
end;
3:
begin
for i:=1 to (analysbuffer[3] div 2) do
begin
holdregisterarray[beginaddress + i].value :=
inttostr(analysbuffer[4+(i-1)*2]*256 + analysbuffer[5+(i-1)*2]);
end;
{for j:=1 to analysbuffer[3] do
begin
a:=1;
for i:=1 to 8 do
begin
k:=analysbuffer[4+j-1]and a;
coilstatearray[(beginaddress div 8)*8 +j-1+i].value:=(k>0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -