Say, the PLC program uses a State Machine design and an array of boolean bits to indicate what is the current "state", Is there a way to read off the array which bit is latched at any time?
In terms of implementation, a DINT bit array would be more efficient, however, the implementation of using boolean arrays is fixed and cannot change. The boolean array contains 128 elements to reflect 128 possible "states".
I have tried to create another routine (Report_Current_State) that would loop thru all 128 elements to detect which bit is latched and hence report the current "state" on the HMI. However, this method is not efficient and have serious bugs. I briefly explains as follows
1. The "Report_Current_State" would progress thru each element once once every scan. The PLC program would have transited thru a few "states" before the "Report_Current_State" even go thru all the 128 elements. The result is some "states" would go unreported.
For HMI display purpose, it is ok and not an issue. However, if I want to log a "State History" for debugging purposes, this becomes a very serious bug.
2. I tried to use the LBL and JMP instruction in the "Report_Current_State" routine to loop within the routine so that it will always report a valid state within one scan cycle of the main PLC program. However, this method results in a controller fault due to some timeout error as the scan doesn't complete within a specified duration.
Appreciate if anyone can offer some advise and/or solution. Thank you. I'm quite new to AB PLC and control logix programming.
In terms of implementation, a DINT bit array would be more efficient, however, the implementation of using boolean arrays is fixed and cannot change. The boolean array contains 128 elements to reflect 128 possible "states".
I have tried to create another routine (Report_Current_State) that would loop thru all 128 elements to detect which bit is latched and hence report the current "state" on the HMI. However, this method is not efficient and have serious bugs. I briefly explains as follows
1. The "Report_Current_State" would progress thru each element once once every scan. The PLC program would have transited thru a few "states" before the "Report_Current_State" even go thru all the 128 elements. The result is some "states" would go unreported.
For HMI display purpose, it is ok and not an issue. However, if I want to log a "State History" for debugging purposes, this becomes a very serious bug.
2. I tried to use the LBL and JMP instruction in the "Report_Current_State" routine to loop within the routine so that it will always report a valid state within one scan cycle of the main PLC program. However, this method results in a controller fault due to some timeout error as the scan doesn't complete within a specified duration.
Appreciate if anyone can offer some advise and/or solution. Thank you. I'm quite new to AB PLC and control logix programming.