Because the PCM and Series 90 PLC CPU are connected by the PLC backplane, PCM MegaBasic programs can transfer data between the PCM and the PLC CPU very efficiently. In order to transfer data, a MegaBasic program must first create an
association between a MegaBasic variable and an area in the PLC memory. This is done with the SYSLINK statement. Once a MegaBasic variable has been associated with PLC data, the PLC data can be copied to or from the MegaBasic variable using the SYSREAD and SYSWRITE statements. The SYSTATUS$ function is used to monitor data transfers between the PCM and PLC. Each of these is described in detail on the following pages.
The maximum number of PLC data areas that can be associated with MegaBasic variables at one time is 32. PLC data areas can be as small as a single point. In Series 90-70 PCMs, the size of each PLC data area is limited to 2048 bytes. In principle, Series 90-30 PLC data areas can be as large as 65,535 bytes, although there were no data areas that large when this manual went to press. MegaBasic arrays or structures can be linked to move multiple data references from or to the PLC CPU in one SYSREAD/SYSWRITE operation, as shown in the following example.
This example assumes that PLC registers 250 through 329 contain 16 character ASCII formatted real numbers. The numbers are read from the PLC CPU, converted from ASCII to binary format, and written back to the PLC, starting at register 1000.
10 Rem This program reads a large string of ascii numbers and 20 Rem converts them to individual real elements of an array.
30 Dim STR1$(160)
140 SYSWRITE REAL_ARR 150 Print STR1$
More than 32 individual PLC data areas can be associated with MegaBasic variables, if necessary, by using the UNLINK statement to disassociate PLC data areas not needed immediately.
A MegaBasic program can read and write any of the PLC data areas shown below using the SYSLINK, SYSREAD and SYSWRITE statements. The names for the areas are shown as they appear in the SYSLINK statement:
%IXXXXX - Input contacts %AIXXXXX - Analog inputs %AQXXXXX - Analog outputs
Note
For information on how to access Series 90-70 %P and %L references from PCM MegaBasic programs, refer to chapter 5, Advanced MegaBasic Programming.
In addition, the PCM can read fault information for %I, %Q, %AI and %AQ references;
override information for %I, %Q and %M references; and, in Series 90-70 PLCs,
transition information for %I, %Q, %M, and %T references. To access this information, a comma followed by an F, O, or T (for fault, override, or transition, respectively) is added to the end of the reference name.
For example, the fault bit for input 39 is accessed as “%I39,F”. The transition bit for temporary coil 15 is accessed as “%T15,T”. Fault, override, and transition bits can be accessed as single bits or groups of bits. They can only be read by the PCM. Any attempt to write to these areas results in an error.
PLC data references may be accessed as single items or arrays. Arrays containing up to 64K bytes of contiguous PLC data may be transferred using a single MegaBasic
statement. At least 256 bytes of large arrays are transferred during each PLC execution sweep.
Data transfers between the PLC CPU and a PCM are most efficient when they contain 256 bytes or less. PLC data which is accessed by PCM programs should be collected into contiguous groups when the PLC program is developed.
There is a PLC status variable, called #SSTAT, which may be read by the PCM. Through this status variable, the PCM can find out information about the PLC state, sweep time, and various other status information. The #SSTAT variable is described in chapter 5, Advanced MegaBasic Programming.
PLC nicknames are not directly accessible from the PCM.
SYSLINK
The SYSLINK statement is used to identify variables located in the PLC CPU.
SYSLINK tells the PCM to establish a link with the CPU, allowing the PCM to access user reference data in the CPU. Before any PLC data can be read or written by the PCM, it must be SYSLINKed.
The SYSLINK statement has the for m:
SYSLINK <local_name>, <cpu_symbol>, [type], [handle]
Argument Description
Local Name This argument contrains the name of the MegaBasic variable to be associated with the PLC data. The MegaBasic variable must be defined in the MegaBasic program before it can be SYSLINKed. It can be a string of any length, an integer, a real, or a numeric array of up to 3 dimensions. String arrays, sub-strings, and individual elements of arrays cannot be SYSLINKed.
CPU Symbol This argument contains the PLC reference with optional suffix for override, transition, or fault data, as described above. It can be either a quoted string (e.g., “%R500”) or a string variable that contains a properly formatted CPU reference.
Type This argument contains the MegaBasic type of the CPU reference, as it exists in the PLC. This type may differ from the type of the local variable defined in the MegaBasic program. For example, a MegaBasic local variable may be defined as an integer, which in MegaBasic is a 32-bit number. If the corresponding CPU variable is a register, which is a 16-bit number, the type argument can be used to convert it to 32-bits when it is read by the MegaBasic program.
If a type is specified, the PCM automatically performs a type conversion between the CPU type and the local type whenever the variable is read or written.
MegaBasic has three “native” data types, 32-bit integers, 64-bit real numbers, and strings. The following PLC CPU data types may be specified:
S BOOL = single bit.
S BYTE = 8 bits.
S INT16 = 16-bit signed integer.
S UINT = 16-bit unsigned integer.
S DINT = 32-bit signed integer.
S REAL32 = 32-bit IEEE real number.
S REAL64 = 64-bit IEEE real number.
If the type argument is omitted, the PCM assumes that the PLC reference is in the same format as the local MegaBasic variable (32-bit integer, 64-bit real number, or string). For numeric data, this is usually not true since the CPU and MegaBasic have different numeric data types. However, there may be some circumstances (e.g., one or more PCMs moving data through the CPU) where numeric data does not have to be converted.
Handle This argument contains an arbitrary, user-specified integer used when backplane interrupts are enabled. (For more information on backplane interrupts, refer to chapter 5, Advanced MegaBasic Programming.) A MegaBasic program may be interrupted when backplane transfers occur, rather than waiting for each transfer.
The handle is used to identify the variable that was transferred. If the handle argument is used, the type argument must also be present, because arguments can be omitted only from right to left.
Example:
In the following example, SYSLINK is used to associate a MegaBasic variable called PUSHBUTTON with input %I100. The variable TEMPERATURE is associated with register %R25:
110 Def integer PUSHBUTTON 120 Def integer TEMPERATURE
130 SYSLINK PUSHBUTTON, “%I100”, BOOL 140 SYSLINK TEMPERATURE, “%R25”, UINT
When the MegaBasic program does a SYSREAD from the PUSHBUTTON variable, the PCM reads %I100, converts it to an integer, which is either 0 or 1, and copies it to the PUSHBUTTON variable.
When the MegaBasic program does a SYSREAD from TEMPERATURE, the PCM reads
%R25 and converts it to an integer between 0 and 65,535. If %R25 is specified as INT16 rather than UINT, the PCM converts it to a number between -32,768 and 32,767.
When the MegaBasic program does a SYSWRITE to PUSHBUTTON, it sets %I100 if PUSHBUTTON is non-zero. If PUSHBUTTON is equal to zero, %I100 is cleared. A SYSWRITE to TEMPERATURE copies the least significant 16 bits of the TEMPERATURE variable to %R25.
Example:
Another useful application of MegaBasic’s automatic type conversion is to convert PLC integers to MegaBasic real numbers. The MegaBasic real numbers can then be operated on with real number arithmetic and copied back to the PLC as integers. For example:
110 Def real CURRENT
120 SYSLINK CURRENT, “%R45”, UINT
A SYSREAD from CURRENT converts %R45 to a real and copies it to the CURRENT variable. It can now be used in real number expressions with no loss of accuracy. A SYSWRITE to CURRENT copies the integer part back to %R45.