SlimLine Raspberry library eCDSSystem8Core

After making our first project in CODESYS (See article) we can go into using the library eCDSS8CoreMng. This library contains all the function objects and FBs for managing the extension modules of SlimLine, library download, the program SimpleStartUp described in this article can be found in the PTP161 (Download).

Library installation

To use the library, install it in the library repository on your PC. Download the library from the menu Gestore libreria select Repository librerie and choose Installa it will be possible to browse the disk and search for the library file which will be transferred to the "C:\ProgramData\CODESYS\Managed Libraries\Elsist Srl\".

Library use

Create a new project as indicated in this article, add the library to the project.

I2C management of expansion modules

The CPU module manages the extension modules with a connection in I2C, so the management driver must be installed. With the right mouse button on the device I2C choose the item Aggiungi dispositivo, and select the device I2C master. The value to be set on the device is /dev/i2c-4.

The device will be added to the project tree and as seen from the photo the variable will be created I2C_master of type i2cMaster. The name of the variable is important because it will be communicated to the system management FB.

Examples

How to use the examples.

All the objects (Functions and FB) useful for accessing the various modules are available in the library, consult the library documentation for a list. Now you can write the program, inside "PLC_PRG" we have to instantiate and execute the function block SysCoreManager (System manager) to which we must pass the address of the I2C bus manager. Enabling the FB activates the ready signal on the extension bus and the hardware watch dog circuit and all modules connected to the extension bus are initialized.

LogicLab (Ptp161)
PROGRAM PLC_PRG
VAR
  DInp: ARRAY[ 0..2 ] OF DWORD; //Digital input value
  DOut: ARRAY[ 0..2 ] OF DWORD; //Digital output value
  LpTime: ARRAY[ 0..1 ] OF UDINT; //Loop time (uS)
  TimeBf: ARRAY[ 0..3 ] OF UDINT; //Time buffer (uS)
  S8Core: eS8Core.SysCoreManager; //System 8 core manager
  AnInp: ARRAY[ 0..1 ] OF eS8Core.SysGetAnInp; //Analog input acquisition
  AnOut:  ARRAY[ 0..1 ] OF eS8Core.SysSetAnOut; //Analog output management
END_VAR

// -------------------------------------------------------------------------
// EXECUTION TIME CALCULATION AUSILIARES
// -------------------------------------------------------------------------
// Here the reference time is saved.

LpTime[0]:=eS8Core.SysGetSysTime(TRUE); //Loop time (uS)

// -------------------------------------------------------------------------
// SYSTEM 8 CORE MANAGEMENT
// -------------------------------------------------------------------------
// PConsole defines TCP port to which it's possible to connect by telnet
// HWDogTm defines watch dog refresh time.
// pI2CManager defines the I2C driver used to manage the extension bus.

S8Core(Enable:=TRUE, PConsole:=10000, HWDogTm:=0, pI2CManager:=ADR(I2C_master));
IF NOT(S8Core.Ready) THEN RETURN; END_IF;

// Put here some initializations if needed.

// IF (S8Core.Init) THEN END_IF;

// -------------------------------------------------------------------------
// DIGITAL I/O MODULES MANAGEMENT
// -------------------------------------------------------------------------
// Here are managed all the digital I/O modules. The function reads digital
// inputs and writes digital outputs.

SysDIOModule(0, ADR(DInp[0]), ADR(DOut[0])); //Modulo "0"

// -------------------------------------------------------------------------
// BLINK OUTPUTS
// -------------------------------------------------------------------------
// Here outputs 0 and 1 of module 0 are blinking.

IF ((eS8Core.SysGetSysTime(TRUE)-TimeBf[0]) > 100000) THEN
  TimeBf[0]:=eS8Core.SysGetSysTime(TRUE); DOut[0].0:=NOT(DOut[0].0);
END_IF;

IF ((eS8Core.SysGetSysTime(TRUE)-TimeBf[1]) > 200000) THEN
  TimeBf[1]:=eS8Core.SysGetSysTime(TRUE); DOut[0].1:=NOT(DOut[0].1);
END_IF;

// -------------------------------------------------------------------------
// ANALOG I/O MODULES MANAGEMENT
// -------------------------------------------------------------------------
// Here are managed some analog I/Os on the module 0.

AnOut[0](Address:=0, Channel:=0, Mode:=AO_MODE.DA_VOLT_0_10);
AnInp[0](Address:=0, Channel:=0, Mode:=AI_MODE.AD_VOLT_0_10_COMMON);
 
AnOut[1](Address:=0, Channel:=1, Mode:=AO_MODE.DA_VOLT_0_10);
AnInp[1](Address:=0, Channel:=1, Mode:=AI_MODE.AD_VOLT_0_10_COMMON);

// Every 5 Secs a random voltage (Range 0.0 to 10.0) is set on outputs.

IF ((eS8Core.SysGetSysTime(TRUE)-TimeBf[3]) > 5000000) THEN
  TimeBf[3]:=eS8Core.SysGetSysTime(TRUE); //Time buffer (uS)
  AnOut[0].Value:=SysGetRandom(TRUE)*10.0; //Analog output value (Volt)
  AnOut[1].Value:=SysGetRandom(TRUE)*10.0; //Analog output value (Volt)
END_IF;

// -------------------------------------------------------------------------
// CALCULATES THE EXECUTION TIME
// -------------------------------------------------------------------------
// Here is calculated the time needed to execute the program. The value in
// uS is stored in LpTime[1] variable.

LpTime[1]:=eS8Core.SysGetSysTime(TRUE)-LpTime[0]; //Loop time (uS)

// [End of file]
Was this article helpful?