MorphuisOGrady
Member
Hi Guys,
I have a problem with this code and I have spent a week trying to figure it out( I didnt write it) . I am hoping someone can put me in the right direction.
The function basicially copies a PLC array of three words M1_HMI_Status_Tag[3] into a SCADA tag array of bools. Every once in a while element M1_HMI_Status[22] of the bool array gets set which in turns triggers an unwanted event. I am 100% sure this trigger does not occur in the PLC. From setting bits in the PLC INT array, the corresponding bits in the SCADA array are correct and the function behaves as expected. Its just this "random" bit that must get set which is causing the problem.
Note that the tags are quite similar to avoid confusion:
M1_HMI_Status_Tag[3] -PLC Array
M1_HMI_Status[63]- SCADA Booleen array tag.
The function is run of an event every 2 seconds.
INT DecNum2[16], Decode2[16];
DecNum2[0] = 32768;
DecNum2[1] = 16384;
DecNum2[2] = 8192;
DecNum2[3] = 4096;
DecNum2[4] = 2048;
DecNum2[5] = 1024;
DecNum2[6] = 512;
DecNum2[7] = 256;
DecNum2[8] = 128;
DecNum2[9] = 64;
DecNum2[10] = 32;
DecNum2[11] = 16;
DecNum2[12] = 8;
DecNum2[13] = 4;
DecNum2[14] = 2;
DecNum2[15] = 1;
Decode2[0] = 32768;
Decode2[1] = 16384;
Decode2[2] = 8192;
Decode2[3] = 4096;
Decode2[4] = 2048;
Decode2[5] = 1024;
Decode2[6] = 512;
Decode2[7] = 256;
Decode2[8] = 128;
Decode2[9] = 64;
Decode2[10] = 32;
Decode2[11] = 16;
Decode2[12] = 8;
Decode2[13] = 4;
Decode2[14] = 2;
Decode2[15] = 1;
FUNCTION
Mask_Status_M1()
INT wordind1, statNum, num1, temp_word1;
wordind1 = 0;
statNum = 15;
num1 = 0;
WHILE wordind1 < 3 DO
temp_word1 = M1_HMI_Status_Tag[wordind1];
IF temp_word1 < 0 THEN
temp_word1 = 65536 - Abs(temp_word1);
ELSE
temp_word1 = temp_word1;
END
WHILE num1 < 16 DO
IF temp_word1 >= Decode2[num1] THEN
M1_HMI_Status[statNum] = 1;
temp_word1 = temp_word1 -Decode2[num1];
ELSE
M1_HMI_Status[statNum] = 0;
END;
statNum = statNum - 1;
num1 = num1 + 1;
END;
IF wordind1 = 0 THEN
statNum = 31;END;
IF wordind1 = 1 THEN
statNum = 47;END;
IF wordind1 = 2 THEN
statNum = 63;END;
IF wordind1 = 3 THEN
statNum = 79;END;
IF wordind1 = 4 THEN
statNum = 95;END;
IF wordind1 = 5 THEN
statNum = 111;END;
IF wordind1 = 6 THEN
statNum = 127;END;
IF wordind1 = 7 THEN
statNum = 143;END;
IF wordind1 = 8 THEN
statNum = 159;END;
IF wordind1 = 9 THEN
statNum = 175;END;
IF wordind1 = 10 THEN
statNum = 191;END
wordind1 = wordind1 + 1;
num1 = 0;
END;
Can anyone see the bug which is causing me problems. I cannot trace it.
Thanks in advance.
I have a problem with this code and I have spent a week trying to figure it out( I didnt write it) . I am hoping someone can put me in the right direction.
The function basicially copies a PLC array of three words M1_HMI_Status_Tag[3] into a SCADA tag array of bools. Every once in a while element M1_HMI_Status[22] of the bool array gets set which in turns triggers an unwanted event. I am 100% sure this trigger does not occur in the PLC. From setting bits in the PLC INT array, the corresponding bits in the SCADA array are correct and the function behaves as expected. Its just this "random" bit that must get set which is causing the problem.
Note that the tags are quite similar to avoid confusion:
M1_HMI_Status_Tag[3] -PLC Array
M1_HMI_Status[63]- SCADA Booleen array tag.
The function is run of an event every 2 seconds.
INT DecNum2[16], Decode2[16];
DecNum2[0] = 32768;
DecNum2[1] = 16384;
DecNum2[2] = 8192;
DecNum2[3] = 4096;
DecNum2[4] = 2048;
DecNum2[5] = 1024;
DecNum2[6] = 512;
DecNum2[7] = 256;
DecNum2[8] = 128;
DecNum2[9] = 64;
DecNum2[10] = 32;
DecNum2[11] = 16;
DecNum2[12] = 8;
DecNum2[13] = 4;
DecNum2[14] = 2;
DecNum2[15] = 1;
Decode2[0] = 32768;
Decode2[1] = 16384;
Decode2[2] = 8192;
Decode2[3] = 4096;
Decode2[4] = 2048;
Decode2[5] = 1024;
Decode2[6] = 512;
Decode2[7] = 256;
Decode2[8] = 128;
Decode2[9] = 64;
Decode2[10] = 32;
Decode2[11] = 16;
Decode2[12] = 8;
Decode2[13] = 4;
Decode2[14] = 2;
Decode2[15] = 1;
FUNCTION
Mask_Status_M1()
INT wordind1, statNum, num1, temp_word1;
wordind1 = 0;
statNum = 15;
num1 = 0;
WHILE wordind1 < 3 DO
temp_word1 = M1_HMI_Status_Tag[wordind1];
IF temp_word1 < 0 THEN
temp_word1 = 65536 - Abs(temp_word1);
ELSE
temp_word1 = temp_word1;
END
WHILE num1 < 16 DO
IF temp_word1 >= Decode2[num1] THEN
M1_HMI_Status[statNum] = 1;
temp_word1 = temp_word1 -Decode2[num1];
ELSE
M1_HMI_Status[statNum] = 0;
END;
statNum = statNum - 1;
num1 = num1 + 1;
END;
IF wordind1 = 0 THEN
statNum = 31;END;
IF wordind1 = 1 THEN
statNum = 47;END;
IF wordind1 = 2 THEN
statNum = 63;END;
IF wordind1 = 3 THEN
statNum = 79;END;
IF wordind1 = 4 THEN
statNum = 95;END;
IF wordind1 = 5 THEN
statNum = 111;END;
IF wordind1 = 6 THEN
statNum = 127;END;
IF wordind1 = 7 THEN
statNum = 143;END;
IF wordind1 = 8 THEN
statNum = 159;END;
IF wordind1 = 9 THEN
statNum = 175;END;
IF wordind1 = 10 THEN
statNum = 191;END
wordind1 = wordind1 + 1;
num1 = 0;
END;
Can anyone see the bug which is causing me problems. I cannot trace it.
Thanks in advance.
Last edited: