CODESYS is an IDE for application development on programmable logic controllers (PLCs) distributed by the CODESYS Group in Germany. Use this tag only for questions about CODESYS installation and usage as well as related CODESYS software like CODESYS Control Runtime System and CODESYS Automation Server. Use the tags [structured-text], [ladder-logic], and [sfc], for (ide-agnostic) questions about [plc] or [servo] programming.
Questions tagged [codesys]
240 questions
1
vote
4 answers
union bit mapping of BOOL and WORD
I'm tryng to map some bit in a single word , but I see for the compile the size of bool is equal to an byte. When I see the code in execution every BOOL is 8 bit size. How can I specify a bit field in struct or union?
That is my code:
TYPE…

Hyugs
- 25
- 4
1
vote
1 answer
PLC_OPEN MC_MoveAbsolute with same position
sometimes it may happen that MC_MoveAbsolute is called with the same current position of the axis, in this case the "done" or "busy" states cannot be used to manage the end of the function because the function must not perform any movement.
I'm a…

Hyugs
- 25
- 4
1
vote
1 answer
Casting function block
I'm using Wago PFC200 for my home automation. I got base function block:
FUNCTION_BLOCK ABSTRACT Room
and two the interface:
INTERFACE IBlinds
- BlindsUp
- BlindsDown
and
ILights
-TurnOffLights
-TurnOnLights
My room's instances looks like…

Dawid Rutkowski
- 2,658
- 1
- 29
- 36
1
vote
2 answers
No matching FB_Init method found when it's in a block
Running Ecostruxure machine expert which is CodeSys 3.5
I've got the following program structure:
Main: two blocks, Init and Step0 linked by a transition.
In the vars of that main:
VAR
My_Encoder : ENC_REF_M262;
...
END_VAR
So then in my…

David Boshton
- 2,555
- 5
- 30
- 51
1
vote
0 answers
What can be the reason of a TCP Server connection failure?
I am trying to connect a Wago PFC200 controller to the mosquitto broker I have running on my laptop using the MQTT_Client library by Stefan Rossmann Engineering Solutions.
I get "Connecting to TCP-Server Timed out" error and I'm having trouble…

sashilio
- 11
- 1
1
vote
1 answer
Is the whole function block really stored in RETAIN memory?
In the CodeSys manual we can read that:
"If you declare a local variable in a function block as RETAIN, CODESYS stores the complete instance of this function block in the Retain range (all data of the function block); however, only the declared…

Dawid Rutkowski
- 2,658
- 1
- 29
- 36
1
vote
1 answer
Codesys LD: how to jump from a process to other process
I am new to Codesys Ladder programming. We are converting our Ladder application to Codesys LD. Our application has several processes. Each process handles different subjects. Each process is activated by a Jump To Subprocess element from another…

user12585338
- 11
- 2
1
vote
2 answers
can two different OPC server share same port?
I am trying to connect robot controler CODESYS program with OPC Expert through OPC UA server and that's listening 4840 port and on OPC Expert I'm getting like opc.tcp://hp-nb:4840/uadiscovery. I also installed freeopcua in my machine and that's…

SHAKIR SHOWMIK
- 11
- 2
1
vote
2 answers
Is there a cleaner way to check for a condition to set a variable then to use a bunch of IF statements?
I am looking to possibly shorten my code. It seems super redundent but I am not sure how else I would be checking for a specific condition to set a variable besides a large IF statement?
IF MaxContaminationCode := -2 THEN
ContaminationClass…

lt123
- 117
- 1
- 2
- 8
1
vote
1 answer
Get String value of a Enum in Twincat 3
In Twincat 3 I have a Enum like this:
TYPE ENUM_FUNCTIONS :
(
EMPTY :=0,
MOTOR_SPEED_INPUT_1 :=1,
MOTOR_SPEED_INPUT_2 :=2,
MAIN_SHAFT_SPEED_MONITOR_3 :=3,
MAIN_SHAFT_SPEED_MONITOR_1 …

Adrian Garcia
- 788
- 10
- 14
1
vote
1 answer
POINTER bit size
The CODESYS documentation says
The result of the difference between two pointers is of type DWORD, even on 64-bit platforms, when the pointers are 64-bit pointers.
From this, I guessed that pointers in codesys are 32-bit on x86 platforms, and…

Guiorgy
- 1,405
- 9
- 26
1
vote
1 answer
Persistent Vars list with function blocks with FB_Init
I am trying to persist a function block (POU) in CODESYS 3.5.16, but I am getting C0138: No matching 'FB_Init' method found for instantiation of POU error.
PersistentVars:
VAR_GLOBAL PERSISTENT RETAIN
PLC_PRG.p: POU;
// PLC_PRG.p: POU(val…

Guiorgy
- 1,405
- 9
- 26
1
vote
2 answers
Prevent local variable retention
Suppose I have a function block POU1 which has local variables val1: INT and val2: INT, e.g.
FUNCTION_BLOCK POU1
VAR
val1: INT := 1;
val2: INT := 1;
END_VAR
Now suppose the user of the FB declares it as RETAIN, e.g.
VAR RETAIN
p1:…

Guiorgy
- 1,405
- 9
- 26
1
vote
1 answer
Retain a Function Block with FB_Init method
If I have a Function Block with an explicitly defined FB_Init method, I can't seem to use the Retain keyword, as I get a C0138: No matching FB_init method found for instantiation of POU error, for example:
FUNCTION_BLOCK POU1
VAR
_val:…

Guiorgy
- 1,405
- 9
- 26
1
vote
4 answers
User defined functions with params
In codesys some functions support what in other languages is usually called 'params', i.e. a function that can take a varied amount of similarly typed variables. For example the ADD Operator (function in ladder).
My question is, if there's any way…

Guiorgy
- 1,405
- 9
- 26