PLC

After controller start-up, the PLC run-time system receives access to the shared memory areas for V.E. variables between CNC and PLC A distinction is made between in channel and global memory areas.

pVE[iChannelNr]^.addr

pVEGlob^.addr

To simplify access to memory areas, an additional library TcCncUtilities.lib provides functions which assume the management of created VE variables and also permit access by name.

Notice

notice

If external variables are configured with user-defined variable types, the PLC library TcCncUtilities.lib cannot be used. In this case ,the variable structures should be simulated in the PLC to permit direct access to the various V.E. variable memories by the pointers pVE[iChannelNr]^.addr or pVEGlob^.addr (see programming example 2).

Before using the library, the PLC must execute a basic initialisation. During initialisation, the format description defined in the CNC configuration is automatically adapted by the PLC.

For this purpose, the PLC and the CNC exchange variable descriptions during initialisation. The memory area of the external variables is cleared during initialisation (values = 0).

In addition, the individual formats of the variables are checked for correctness in the memory index and memory area, and any errors are output to the logger. To prevent access to non-defined memory areas in arrays, a destination address check is carried out. The size of the data type is then forwarded to the respective function of the library (see example).

For read and write access to external variables or arrays of external variables, pointers are generated to the expected data structures. The pointers are initialised with the associated address of taken from the HLI memory area. Direct access to the variable strName is then possible using the referenced pointers, e.g.:

POINTER_TO_BOOL = VeBool(1, “Peter”, 0);

POINTER_TO_BOOL^=23;

Function

INPUT

RETURN

Meaning

VeInitialisation()

 

BOOL Status

Initialises the library so that V.E variables can be used in the PLC.

 

 

Status

[true/false]

Initialisation status of the library for access to external variables. No access is possible to V.E. variables as long as this value is false.

Ve<DatenTyp>()

UINT iChannel

STRING strVeName

UINT ISizeArrayByte

POINTER TO <DatenTyp> pDatatype

Functions supply the memory address of a variable of type <DatenTyp> which is identified by specifying a name.

DatenTyp = [Uns08, Sgn08, Uns16, Sgn16, Uns32, Sgn32, Real32, Real64, String]

 

IChannel

[1 .. nChannel]

 

Channel number in which the variable strName is declared.

 

StrVeName

[‘String’]

 

Name of the variables which are to be accessed (no longer than 20 characters)

 

IsizeArrayByte

[sizeof(Ziel_Pointer^)]

 

Size of the expected array for checking correct memory access. If no array expected, this value is to be initialised with 0.

 

 

PDatatype

[pIntArray ]

Access address to the V.E. variable with the name strVeName .

The example below refers to the example configuration of V.E. variables in this documentation (example from chapter). Before using VE access in a program, first initialise the HLI interface (see [HLI]), add the TcCncUtilities.lib library to the required project and execute the following steps:

Programing Example

prg_example

Access VE variables in the PLC (VeExampleDoku.pro))

VAR

  VEInitialisationDone      : BOOL;

  I                         : INT;

  pCHANNEL_WR               : POINTER TO ARRAY [0..9] OF INT   := 0;

  pGLOBAL_SWR               : POINTER TO DINT                  := 0;

END_VAR

(* Access to VE variables in the PLC *)

IF VEInitialisationDone = FALSE THEN

  VEInitialisationDone := VeInitialisation();

  IF VEInitialisationDone = TRUE THEN

       pCHANNEL_WR := VeSgn32(1,'CHANNEL_WR’, SIZEOF(pCHANNEL_WR^));

       pGLOBAL_SWR := VeSgn16(1,'GLOBAL_SWR', 0);

  ELSE

    RETURN;

  END_IF

END_IF

(* Now direct write and read access is possible

   To the variable. Checking:

- Check the content of the variable pChannel in PLC Open -> 801..802....

- When checking in the System Manager, execute V.E.GLOBAL_SWR=20 as the only manual block in order to write this VE variable from the CNC.

- This should then automatically set the pChannel variable in the PLC to 0. *)

IF pCHANNEL_WR <> 0 AND pGLOBAL_SWR <> 0 THEN (* read access*)

    IF pGLOBAL_SWR^ = 20 THEN       (* read access*)

        FOR I:=0 TO 9 BY 1 DO

          pCHANNEL_WR^[I] := 0;     (* write access*)

        END_FOR

ELSE

        FOR I:=0 TO 9 BY 1 DO

          pCHANNEL_WR^[I] := 800+I; (* write access*)

        END_FOR

END_IF

pGLOBAL_SWR1^:=0;                   (* write access*)

This PLC example shows how V.E variables can be used in the PLC by simulating the variable structures. Before accessing the pointers pVE[iChannelNr]^.addr or pVEGlob^.addr, the HLI interface must be initialised (see [HLI//15.1 access to the HLI]).

Programing Example

prg_example

Access to VE variable in the PLC without TcCncUtilities.lib library

(as of CNC Build V2.10.1025.00)

Definition of variable structures for V.E. variables:

TYPE VECTOR_T :

STRUCT

  x : LREAL;

  y : LREAL;

  z : LREAL;

END_STRUCT

END_TYPE

TYPE TARGET_POINT_T :

STRUCT

  point : VECTOR_T;

  valid : BOOL;

END_STRUCT

END_TYPE

TYPE TRAJEKTORIE_T :

STRUCT

  nbr_points : DINT;

  name : STRING(127);

  points : ARRAY [0..9] OF TARGET_POINT_T;

END_STRUCT

END_TYPE

Definition of structures for the complete assigned V.E. memory area:

TYPE VE_GLOBAL:

STRUCT

  var_global_1 : DINT;

END_STRUCT

END_TYPE

TYPE VE_CHAN_1:

STRUCT

  var_chan_1: DINT;

  array_chan_1 : ARRAY [0..19] OF INT;

  name : STRING(127);

  Trajectory: TRAJEKTORIE_T;

END_STRUCT

END_TYPE

PLC program to access V.E. variables:

PROGAM V_E

  VAR

    p_ve_chan_1: POINTER TO VE_CHAN_1;

  END_VAR

p_ve_chan_1 := ADR (pVe[1]^.addr^.AHLI_UNS32_Data);

IF (p_ve_chan_1^.name = ‚’)

THEN

  p_ve_chan_1^.trajektorie.name := ‚My Path!’

  p_ve_chan_1^.trajektorie.nbr_points := 2;

  p_ve_chan_1^.trajektorie.points[0].valid := TRUE;

  p_ve_chan_1^.trajektorie.points[0].point.x := 100.0;

  p_ve_chan_1^.trajektorie.points[0].point.y := 200.0;

  p_ve_chan_1^.trajektorie.points[0].point.z := 300.0;

  p_ve_chan_1^.trajektorie.points[1].valid := TRUE;

  p_ve_chan_1^.trajektorie.points[1].point.x := 200.0;

  p_ve_chan_1^.trajektorie.points[1].point.y := 400.0;

  p_ve_chan_1^.trajektorie.points[1].point.z := 600.0;

END_IF;