PLC

The PLC receives access to the variable memory areas from the PLC-Run-Time-System after starting the control. The memory is differed in channel and global area.

              pVE[iChannelNr]^.addr              pVEGlob^.addr

To simplify the access to the variable area an additional library TcCncUtilities.lib exists. With functions out of this library, which takes over the management of the variables you can access the V.E.Variables by name (max 20 characters).

PLC 1:

If external variables are configured with user defined variable types, the PLC library TcCncUtilities.lib can not be used. In this case the variable structures should be recreated in the PLC to enable the direct access on the assigned V.E. variable memory by the pointers pVE[iChannelNr]^.addr respectively pVEGlob^.addr (see programming example 2).

Before using the different functions of the library a basic initialization must be accomplished. During this initialization the format description defined in the CNC configuration is automatically transferred to the PLC.

For this propose the SPS and the CNC exchandes the V.E.Varibles descriptions. During the initialization the will be cleared.

Additional the memory ranges, indexes and data types of the different variables will be checked during the initialization. If an error occurs an error message in the Logger is generated. To prevent the access to non-defined storage area in arrays an examination of the memory addresses is carried out. That’s why the size of the data type is passed to the respective function of the library.

For the reading and writing access to the external variables or arrays of external variables pointers to the expected data type will be generated. This pointers in each case will be initialized with the associated address of the variable in HLI memory range. After that you can access the variable with the dereferenced pointer from the PLC.

F.e.:

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

Function

INPUT

RETURN

Description

VeInitialisation()

 

BOOL Status

Initializes the library for the use of V.E variables in the PLC.

 

 

Status

[true/false]

Initialization of the library for access to external variables finished. While this value is not true you can not access the VE variables.

Ve<DatenTyp>()

UINT iChannel

STRING strVeName

UINT ISizeArrayByte

POINTER TO <DatenTyp> pDatatype

These functions deliver the memory address of variables with the data type <data type> identified by the name of variable.

Data types = [Bool, Uns08, Sgn08, Uns16, Sgn16, Uns32, Sgn32, Real32, Real64, String]

 

IChannel

[1 .. nChannel]

 

Number of the channel [1; nChannel] in which the variablewith the name strVeNameis defined.

 

StrVeName

[‚String’]

 

Name of the variables should be accessed. Name consisting out of maximum 20 characters.

 

IsizeArrayByte

[sizeof(Ziel_Pointer^)]

 

Size of the expecting arrays to the examination of the correct memory access. If no array expected, this value is to be initialized with 0.

 

 

PDatatype

[pIntArray ]

Address to the access for accessing V.E. variablesby the name strVeName.

The following example refers on the V.E. configuration from this documentation (see text above chapter 2.3). Before accessing the V.E. variables in a program the HLI interface should be initialized (see [HLI]), TcCncUtilities.lib library in the desired project should be included and the following steps should be done:

Programming example for accessing V.E. variables in the PLC (VeExample1.pro)

VAR  VEInitialisationDone    : BOOL;  I               : INT;pCHANNEL_WR         : POINTER TO ARRAY [0..9] OF INT    
:= 0;pGLOBAL_SWR         : POINTER TO DINT          :=
0;END_VAR(* Accessing VE variables
in the SPS *)IF VEInitialisationDone = FALSE THENVEInitialisationDone := VeInitialisation();IF VEInitialisationDone = TRUE THENpCHANNEL_WR :=
VeSgn32(1,'CHANNEL_WR’,
SIZEOF(pCHANNEL_WR^));pGLOBAL_SWR :=
VeSgn16(1,'GLOBAL_SWR', 0);ELSE   RETURN;END_IFEND_IF       (*
Now there can be a direct access to the Ve variables. For
testing:       -
check the content of pChannel -> 801..802....    - to test the communication to system
manager execute V.E.GLOBAL_SWR=20 to write the variable on CNC.       -
afterwards that the pChannel variable should have the content 0.
*)
IF pCHANNEL_WR <> 0 AND pGLOBAL_SWR <> 0
THEN     (* reading access*)
     IF pGLOBAL_SWR^ = 20 THEN           (* reading
access*)
     FOR I:=0 TO 9 BY 1 DOpCHANNEL_WR^[I] := 0;         (* writing
access*)
     END_FOR    ELSE         FOR I:=0 TO 9 BY 1 DOpCHANNEL_WR^[I] := 800+I; 
(* writing access*)         END_FOR    END_IFpGLOBAL_SWR1^:=0;                 (* writing
access*)

This PLC example shows, how the V.E variables could be used in the PLC by replicating the variable structures. Before accessing the pointers pVE[iChannelNr]^.addr or pVEGlob^.addr the HLI interface must be initialized (s. [HLI - 15.1 Access to HLI elements]).

Programming example 2 VE variable access in PLC without TcCncUtilities.lib library (from version V2.10.1025.00 onwards)

Definition of variable structures for
the V.E. variables:    TYPE VECTOR_T :       STRUCTx : LREAL;y : LREAL;z : LREAL;       END_STRUCT       END_TYPETYPE
TARGET_POINT_T :STRUCT         point : VECTOR_T;         valid : BOOL;       END_STRUCT       END_TYPETYPE TRAJEKTORIE_T :STRUCT   nbr_points :
DINT;   name       : STRING(127);   points     : ARRAY [0..9] OF
TARGET_POINT_T;END_STRUCTEND_TYPEDefinition of struktures for
the complete, entered V.E. memory block:TYPE VE_GLOBAL:STRUCT   var_global_1 :
DINT;END_STRUCTEND_TYPETYPE VE_CHAN_1:  STRUCT   var_chan_1   :
DINT;   array_chan_1 : ARRAY
[0..19] OF INT;   name     :
STRING(127);   Trajektorie  :
TRAJEKTORIE_T;END_STRUCTEND_TYPEPLC program for the access
on the V.E. variables:PROGAM V_E          VARp_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;