Known Problems with Fault Table Access
Section 5: Gathering PLC Information from MegaBasic Programs
The UTILITY.PGM package supplies several procedures, as well as several data buffers and flag variables, for gathering system information from the Series 90 CPU.
To use the procedures, data buffers and flag variables supplied in this UTILITY.PGM package, add the line:
xxx Access “utility.pgm”
to the beginning of the MegaBasic program or in the PROLOGUE section of a user written package. The file UTILITY.PGM should have been loaded to the PCM RAM Disk before running the MegaBasic program which accesses it. The file will be located in the \PCOP or \PCOP\EXAMPLES.PCM directory of your hard disk, depending on which version of PCOP or TERMF you use.
During the PROLOGUE processing that takes place as part of the first access to the UTILITY.PGM package, the following interrupts are linked to procedures in the package: BKP_MSG, TIMER1, TIMER2, TIMER3, TIMER4, and TIMER5. The timers associated with these five timer interrupts are also stopped.
If the user changes these interrupt linkages, the original settings can be restored through the UTILITY_INIT procedure described below.
Some of the procedures in the UTILITY.PGM package support a NOWAIT operation.
As a result of the NOWAIT mode of operation, the requested data may not be available immediately after returning from the called procedure. However, there is a global status variable (typically “..._VALID”) that indicates when the data has arrived via the
BKP_MSG interrupt.
The NOWAIT operation also allows some of the procedures in the package to obtain the requested data repetitively. When the procedure has setup a repetitive read operation, one of the timer interrupts listed above may be used in addition to the BKP_MSG interrupt. The data valid flag is incremented every time new data arrives and rolls over from 255 to 1. The only time that the data valid flag is a zero (a logical false) is when the first transfer of the data after the procedure call has not yet taken place.
The procedures found in the UTILITY.PGM package are summarized in the following table.
Table 5-7. UTILITY.PGM Package Procedures
Procedure Description
READ_PLC_STATUS A procedure used to get the PLC status word. The optional parameters for this procedure indicate the method of return: wait for completion of the read operation (default) or return immediately (NOWAIT) with the data valid flag being used to indicate when the actual data has arrived. In addition, for NOWAIT, the command may be automatically repeated at a specified frequency, as fast as possible, or no repeats at all. The PLC status word is placed in the integer variable PLC_STATUS_WORD, and the PLC_STATUS_WORD_VALID integer variable is used to indicate when the status word is updated.
READ_PLC_TIME_
AND_DATE A procedure used to get the time and date information from the PLC CPU. The time value is formatted (hh:mm:ss format) into the 8-byte string variable PLC_TIME, and the date is formatted (mm/dd/yy format) into the 8-byte string variable PLC_DATE. The integer variable PLC_TIME_AND_DATE_VALID is used to indicate when the time and date variables have been updated.
Optional parameters for this procedure are the same as those previously described for READ_PLC_STATUS. READ_PLC_RUN_
STATUS A procedure that gets the PLC run status from the PLC status word and sets the PLC_RUN_STATUS integer variable according to the value found in the PLC status word as follows:
0 = PLC run enabled.
6 = PLC stopped I/O enabled.
The integer variable PLC_RUN_STATUS_VALID is used to indicate when the PLC run status variable has been updated.
Optional parameters for this procedure are the same as those previously described for READ_PLC_STATUS.
READ_PLC_CPU_ID A procedure that gets the PLC ID string from the PLC CPU long status information ( #LSTAT ). The length of the string is adjusted to permit proper printing of the PLC CPU ID (ie, it is converted from zero -terminated ASCII format to MegaBasic string format). The string variable PLC_CPU_ID contains the ID string after it is read, and the integer variable PLC_CPU_ID_VALID indicates when the ID has been read.
The only optional parameter for this procedure is to select NOWAIT mode, if desired.
Table 5-7. UTILITY.PGM Package Procedures (cont’d)
Procedure Description
CHECK_CPU_
HEALTH A procedure that performs a short status read and, if the PLC CPU responds properly, the integer variable CPU_RESPONDING is set to true.
If the PLC CPU does not respond properly after three (3) tries, the CPU_RESPONDING integer variable is set to false. Every time the CPU responds, the local time and date is recorded in string variables TIME_OF_LAST_CPU_RESP and DATE_OF_LAST_CPU_RESP. The validity of the time and date strings is indi cated b y the integer variable TIME_AND_DATE_OF_LAST_CPU_RESP_VALID.
The only optional parameter for this procedure specifies how often to check the PLC CPU’s health, specified in milliseconds. The default selection is to stop checking the CPU’s health. Unlike other
procedures, calling this procedure with no parameters does not perform a one-time check of the CPU’s health.
READ_PLC_
FAULT_BIT A procedure used to obtain the status of a fault summary bit from the PLC CPU. Fault summary bits indicate the presence of one or more faults in a specified rack, slot, bus, or module.
Optional parameters for this procedure include four parameters to indicate the desired fault summary bit and two parameters for the selection of NOWAIT and the repetition rate. The default selection is to return the rack 0 fault summary bit waiting for the response and to do the transfer only once.
UTILITY_INIT A procedure used to (re)initialize the interrupt linkages used for the various timers and backplane interrupts for the proper functioning of the rest of the procedures in this package. This procedure is called automatically in the PROLOGUE section of the package but may also be called at any time to re-establish the interrupt routine linkages and timer states after the execution of other packages/routines using the same interrupt(s) or timer(s) as the UTILITY.PGM package.
Shared constants and variables, defined in the UTILITY.PGM package, are described in the following table:
Table 5-8. UTILITY.PGM Package Shared Constants and Variables
Name Description
TRUE A constant (= 1) used to indicate a logical true condition.
FALSE A constant (= 0) used to indicate a logical false condition.
PLC_STATUS_WORD An integer variable that contains the PLC status word, as last read from the PLC CPU. This word is a set of binary flags and bit fields that indicate various information about the PLC CPU’s state. When numbered so that the LSB is bit 0, the following information is available:
0 = Oversweep flag, valid only if constant sweep mode is enabled.
1 = Constant sweep value was exceeded on last sweep.
0 = Constant sweep value was not exceeded.
Table 5-8. UTILITY.PGM Package Shared Constants and Variables (cont’d)
PLC_STATUS_WORD
(cont’d) 1 = Constant sweep mode setting.
1 = Constant sweep mode is enabled.
0 = Constant sweep mode is disabled.
2 = PLC fault entry changed flag.
1 = PLC fault table has changed since last time the table was read.
0 = Table has not changed.
This value is returned by the FLT_CHANGED% ( PLC_FLT_TBL ) function.
3 = I/O fault entry changed flag.
1 = I/O fault table has changed since last time the table was read.
0 = Table has not changed.
This value is returned by the FLT_CHANGED% function.
4 = PLC fault table entry present flag.
1 = There is a fault record in the PLC fault table.
0 = There is no fault record in the PLC fault table.
This value is returned by the FLT_PRESENT% ( PLC_FLT_TBL ) function.
5 = I/O fault table entry present flag
1 = There is a fault record in the I/O fault table.
0 = There is no fault record in the I/O fault table.
This value is returned by the FLT_PRESENT% function.
6 = Programmer attachment present flag.
1 = There is a programmer attachment for the indicated control program number.
0 = No programmer is attached to that control program.
7 = Enable/Disable switch setting.
1 = Outputs are disabled.
0 = Outputs are enabled.
8 = RUN/STOP switch setting from the front panel.
1 = RUN.
0 = STOP.
9 = Symbol status table changed flag.
1 = Symbol status table has changed, requiring a new resolve of any symbols currently resolved by the MegaBasic program.
Note: This function is not presently used by the system.
10 and 11 = Spare reserved.
12 thru 15 = Current PLC CPU state, as opposed to switch settings or commanded state. Possible values are:
0 = PLC run enabled.
6 = PLC stopped I/O enabled.
Table 5-8. UTILITY.PGM Package Shared Constants and Variables (cont’d)
Name Description
PLC_STATUS_
WORD_VALID An integer variable that is incremented by 1 every time the PLC
status word is read. The value of the variable increments up to 255 and then rolls over to 1. A zero value (false) indicates that the PLC status word has never been read.
PLC_TIME A string variable of length 8 that supplies the PLC time value read as a result of the READ_PLC_TIME_AND_DATE procedure. This string is formatted as hh:mm:ss, with the leading digit of the hours field being set to blank if it is a zero.
PLC_DATE A string variable of length 8 that supplies the PLC date value read as a result of the READ_PLC_TIME_AND_DATE procedure. This string is formatted as mm/dd/yy, with the leading digit of the month field being set to blank if it is a zero.
PLC_TIME_AND_
DATE_VALID An integer variable that is incremented by 1 every time the PLC time and date is read. The value of the variable increments up to 255 and then rolls over to 1. A zero value (false) indicates that the PLC time and date have never been read.
CPU_RESPONDING An integer variable that contains the true/false flag, indicating whether the PLC CPU is responding to the check CPU health requests (ie, short status reads).
TIME_OF_LAST_
CPU_RESP A string variable of length 8 that records the local time ( time$
function) at which the CPU last responded to a health check. This string is formatted as hh:mm:ss, with the leading digit of the hours field being set to blank if it is a zero.
DATE_OF_LAST_
CPU_RESP A string variable of length 8 that records the local date ( date$
function) at which the CPU last responded to a health check. This string is formatted as mm/dd/yy, with the leading digit of the month field being set to blank if it is a zero.
TIME_AND_DATE_
OF_LAST_CPU_
RESP_VALID
An integer variable that indicates (true/false) whether the time and date of last CPU response are valid. Note that the check CPU health procedure must run with a rep. rate greater than zero and successfully get a response before this integer variable is set to true.
PLC_RUN_STATUS An integer variable that contains the PLC run status field from the PLC status word (bits 12-15) that is the result of the
READ_PLC_RUN_STATUS procedure. See the PLC_STATUS_WORD discussion for the coding of the values in this variable.
PLC_RUN_
STATUS_VALID An integer variable that indicates when the run status has been read/updated. The value of this variable increments up to 255 and then rolls over to 1. A zero value (false) indicates that the PLC run status has never been read.
PLC_CPU_ID A string variable of maximum length 8, as a result of the
READ_PLC_CPU_ID procedure. The actual length depends on the current length of the CPU’s ID string.
PLC_CPU_ID_VALID An integer variable that indicates (true/false) whether the PLC CPU ID has been read.
PLC_FAULT_BIT An integer variable that indicates the presence (true) or absence (false) of a fault in the rack, slot, bus, or module selected through the READ_PLC_FAULT_BIT procedure.
PLC_FAULT_BIT_
VALID An integer variable that indicates when the fault summary bit has been read/updated. The value of this variable increments up to 255 and then rolls over to 1. A zero value (false) indicates that the fault summary bit has never been read.