Use of pointers in CODESYS

i use pointer in pack control for batch recipes, I don’t know how to do so in codesys.
In PacControl I place digital outputs in a pointer table and with a index variable I move one element of pointer table to a pointer variable.
Pac example
//addressing pointer table to digital output
pt_Products_Valves[1]=&do_0101;
pt_Products_Valves[2]=&do_0102;
pt_Products_Valves[3]=&do_0103;
//addressing pointer variable wtih pointer table index
p_Batch_Valve=pt_Products_Valves[n_Operator_BatchProduct_Selection];
TurnOn(*p_Batch_Valve);

Grateful if someone can help me to do this in CODESYS.

To use pointers in Codesys you can use the “Pointer To” Data Type Data Type: POINTER TO

1 Like

There are some major differences in how PAC Control and Codesys use pointers. In codesys there is no concept of a pointer table. pointers are used to point to memory, and reference functions. To use them like this is very difficult, and potentially dangerous due to how memory is allocated and packed. There are some examples of this from Codesys own forums.

I would recommend taking a different approach. I would not try for a 1 to 1 conversion from PAC Control to Codesys. Rather you should utilize the correct tools for the application.

VAR
	prodValve : ARRAY[1..3] OF BOOL;
	prodPump : ARRAY[1..3] OF BOOL;
	n_Operator_BatchProduct_Selection : INT;
	n_Operatot_Commands : BOOL;//Value set through HMI Selection
	tmr : TON;	
END_VAR
//map I/O
%QX0.0 := prodValve[1];
%QX0.1 := prodValve[2];
%QX0.2 := prodValve[3];
%QX1.0 := prodPump[1];
%QX1.1 := prodPump[2];
%QX1.2 := prodPump[3];

TMR(IN := n_Operatot_Commands, PT:= T#5S);

IF n_Operatot_Commands THEN
	prodValve[n_Operator_BatchProduct_Selection] := 1;
	prodPump[n_Operator_BatchProduct_Selection] := 1;	
	IF TMR.Q AND n_Operatot_Commands THEN
		prodValve[n_Operator_BatchProduct_Selection] := 0;
		prodPump[n_Operator_BatchProduct_Selection] := 0;
		n_Operator_BatchProduct_Selection := 0;
		n_Operatot_Commands := 0;
	END_IF
END_IF

2 Likes

Garrick !Great idea, Your code do it well in a simple way
Thanks for your support