previous page next page reference home emBASIC home page

12.13 Process IO

The main drawback in using standard languages for process control compared to PLC “languages” like SIEMENS STEP5 or IEC1131 is the difficult access of process-i/o (i.e. digital and analog inputs and outputs, counters and encoders).

EmBasic has overcome this drawback by using i/o variable that are initially assigned some hardware port and further can be used just like a common variable, for example

state = myMotor
IF mySwitch == true THEN CALL Light() or shorther:
IF mySwitch CALL light()

12.14 Using the IO datatype to access process I/O devices

emBASIC relies on external support for IO. For standard hardware (TSM, DinX, EVA900) mCAT comes with “Express-i/o” support - providing this same functionality to C and emBASIC programmers.
Express-I/O will allow opening for instance a digital input, giving it a name and subsequently accessing that input with a simple io_variable access.
First, to start using IO declare a variable, using the IO datatype. Details can be found in the datatype chapter.
In the following example a variable myMotor is assigned to digital output one on the module (external module = $TSMBUS, CPU-internal-i/o: $CPUBUS) with its address set to 3:

DECL myMotor AS DIGITAL OUTPUT ($TSMBUS, 3, 1)

After that, the output can be used like a variable, switching it on simply by assigning it a 1:

myMotor = 1

On other hand, to read an input, create it for example using input 2 on the digital input module with the switch address set to 0:

DECL mySwitch AS DIGITAL INPUT ($CPUBUS, $DIN, 2)
switchState = mySwitch

12.15 Vector access

Express-I/O allows vector access of all inputs or outputs of a module at the same time. emBASIC provides a mechanism to use these functions, for example assigning all inputs to a bitmap using the VECTOR keyword on variable declaration:

DECL VECTOR mySwitches AS DIGITAL INPUT ($CPUBUS, $DIN, 0)

Note that you cannot declare an array, e. g. use a dimension specifier in vector declaration mode.

### How to access counter vectors then? To be implemented

The third argument to the i/o-variable declaration does not make sense and is not used. Vector has the LWORD datatype and could be manipulated using bitwise operations:

IF mySwitches & 0x01
CALL firstActive()
ELSEIF mySwitches & 0x02
CALL secondActive()
END

12.16 Simulated functions

In a background process called every few milliseconds; Express-I/O simulates higher level I/O functionality like counting on standard inputs, waiting for a level change or, for standard outputs, retarded switching with settable ON times. These so called Express programs (XP) are made available to the emBASIC user through the XP datatype declaration.
To bind an XP program to the desired IO variable provide its name in the USING clause.
Example:

DECL Pulse AS DIGITAL OUTPUT ($CPUBUS, $DOUT, 0) USING “PULSE”


12.17 Configuring IO

To configure an Express-I/O driver, use the CFG function. For allowed commands see the mCAT Express-I/O driver reference. Most of mentioned parameters exist as system constants for convenient access. The CFG statements aren’t position dependent. You can use them in any part of program code to change configuration of the hardware.
Example:

DECL Pulse AS DIGITAL OUTPUT ($CPUBUS, $DOUT, 0) USING “PULSE”

CFG(Pulse, $XP_CFG_SET_INVERSION, true)
CFG(Pulse, $XP_CFG_SET_TRIGGER_MODE, $TRG_SINGLE)
CFG(Pulse, $XP_CFG_SET_HIGHTIME, 0)
CFG(Pulse, $XP_CFG_SET_LOWTIME, 100)


12.18 Softbus

To simplify communication with visualization systems through for example OPC, Express-I/O offers access to process-I/O to the OPC server. While access from OPC passes by emBASIC and directly act on the underlying mCAT i/o-system, software can create variables that can be set and read from both sides to make conditioned data available (like filtered analog values or status values showing the sanity of a process).

### Command to be described