IF iAdrOfInsulation =0 THEN
iAdrOfInsulation :=91;
END_IF
IF bSensorCorrectionHMI THEN
eCommandNum := 5;
END_IF
IF bParamAlterHMI THEN
eCommandNum := 7;
END_IF
CASE eCommandNum OF(*SystemTotalData :=1,SubcircuitAnodeToGlobeResistance,ProductParamRead,SubcircuitCathodeToGlobeResistance,SensorCorrection,AddrAlter,ParamAlter*)
SystemTotalData:
wMBAdr := 16#0320;
iLen := 7;
bReadEnable := TRUE;
bWriteEnable :=FALSE;
SubcircuitAnodeToGlobeResistance:
wMBAdr := 16#03E8;
iLen := iSubTotal;
bReadEnable := TRUE;
bWriteEnable :=FALSE;
ProductParamRead:
wMBAdr := 16#0510;
iLen := 5;
bReadEnable := TRUE;
bWriteEnable :=FALSE;
SubcircuitCathodeToGlobeResistance:
wMBAdr := 16#04B0;
iLen := iSubTotal;
bReadEnable := TRUE;
bWriteEnable :=FALSE;
SensorCorrection:
wMBAdr := 16#680;
wWriteDate := 16#7;
bReadEnable := FALSE;
bWriteEnable :=TRUE;
AddrAlter:
bReadEnable := FALSE;
bWriteEnable :=TRUE;
wMBAdr := 16#1218;
IF iWantedAdr <>0 THEN
wWriteDate := UINT_TO_WORD(iWantedAdr);
ELSE
wWriteDate := 16#5B;
END_IF
ParamAlter:
bReadEnable := FALSE;
bWriteEnable :=TRUE;
IF bSubcircuitCAlterHMI THEN
wMBAdr := 16#71A;
wWriteDate := UINT_TO_WORD(iWantedSubcircuitAmount);
END_IF
IF bAlarmLimitSetHMI THEN
wMBAdr := 16#71C;
wWriteDate := UINT_TO_WORD(iWantedResistanceLimit);
END_IF
IF bResistanceCheckRangeSetHMI THEN
wMBAdr := 16#71E;
wWriteDate := UINT_TO_WORD(iWantedResistanceCheckRange);
END_IF
END_CASE
IF NOT bAlter THEN
CASE iState OF
0: fbMBCom.ReadRegs(Execute := FALSE);
istate := istate +1;
1:
fbMBCom.ReadRegs(
UnitID := UINT_TO_BYTE(iAdrOfInsulation), (* 站點地址 *)
Quantity := iLEN,
MBAddr := wMBAdr,
CbLength := iLEN*2,
pMemoryAddr:= ADR(wMemoryDate[1]),
Execute := TRUE AND bReadEnable ,
Timeout := t#5s,
Busy => );
IF NOT fbMBCom.BUSY THEN
fbMBCom.ReadRegs(Execute := FALSE);
IF fbMBCom.Error THEN
iState :=0;
ELSE
istate := istate +1;
END_IF
END_IF
2:
CASE eCommandNum OF
1:
FOR i :=1 TO 7 DO
IF i=3 OR i=4 THEN
iSysTotalDate := WORD_TO_UINT(wMemoryDate AND 16#3FFF);
ELSE
iSysTotalDate := WORD_TO_UINT(wMemoryDate);
END_IF
END_FOR
iSubTotal := iSysTotalDate[2];
IF wMemoryDate[3].14 THEN
bErrList[1] := TRUE;
ELSE
bErrList[1] := FALSE;
END_IF
IF wMemoryDate[4].14 THEN
bErrList[2] := TRUE;
ELSE
bErrList[2] := FALSE;
END_IF
2:
FOR i :=1 TO 5 DO
iProductParam := WORD_TO_INT(wMemoryDate);
END_FOR
3:
FOR i :=1 TO iSubTotal DO
iSubP_EarthR := WORD_TO_INT(wMemoryDate AND 16#3FFF);
IF wMemoryDate.15 THEN
bErrList[2+i] := TRUE;
ELSE
bErrList[2+i] := TRUE;
END_IF
IF wMemoryDate.14 THEN
bErrList[2+iSubTotal+i] := TRUE;
ELSE
bErrList[2+iSubTotal+i] := TRUE;
END_IF
END_FOR
4:
FOR i :=1 TO iSubTotal DO
iSubN_EarthR := WORD_TO_INT(wMemoryDate AND 16#3FFF);
IF wMemoryDate.15 THEN
bErrList[2+2*iSubTotal+i] := TRUE;
ELSE
bErrList[2+2*iSubTotal+i] := TRUE;
END_IF
IF wMemoryDate.14 THEN
bErrList[2+3*iSubTotal+i] := TRUE;
ELSE
bErrList[2+3*iSubTotal+i] := TRUE;
END_IF
END_FOR
END_CASE
FOR i := 1 TO 64 DO
wMemoryDate := 0;
END_FOR
istate :=0;
eCommandNum := eCommandNum +1;
IF eCommandNum >4 THEN
eCommandNum :=1;
END_IF
bAlter := bStopHmi;(*參數(shù)修改ON*)
END_CASE
ELSE
CASE istate OF
0: fbMBCom.WriteSingleRegister(Execute := FALSE);
istate := istate +1;
1:
fbMBCom.WriteSingleRegister(
UnitID := UINT_TO_BYTE(iAdrOfInsulation),
Quantity := 1,
MBAddr := wMBAdr,
CbLength := SIZEOF(wWriteDate),
pMemoryAddr:= ADR(wWriteDate),
Execute := TRUE AND bWriteEnable,
Timeout := t#5000ms,
Busy => );
IF NOT fbMBCom.BUSY THEN
fbMBCom.WriteSingleRegister(Execute := FALSE);
IF fbMBCom.Error THEN
istate := 0;
ELSE
istate :=istate +1;
END_IF
END_IF
2:
CASE eCommandNum OF
5:;
6:
IF iWantedAdr = BYTE_TO_UINT(fbMBCom.InData.D[4]) THEN
iAdrOfInsulation := iWantedAdr;
END_IF
7:;
END_CASE
bWriteEnable :=FALSE;
eCommandNum :=1;
iState :=0;
bAlter := bStopHmi;(*參數(shù)修改OFF*)
END_CASE
END_IF