Wago - Codesys adventures, Probably simple answer!

Vanesco

Member
Join Date
Nov 2013
Location
Aarhus
Posts
1
Hello guys,

C# developer here, and I've been dropped into the middle of the PLC programming sea and I need to fix a lifeboat asap ;)

Hardware:
Wago 750-852,
* 750-1400 input boards
* 750-1500 output boards
Codesys 2.3


So, my questions are (CoDeSys):
Is there a way to pass an input to a function (not just the boolean value) ?
Like I see i can get the address of on input with BITADR(IX0.0), but how can i go the other way.

In pseudo Code:

myVal : DWORD;

myVal := BITADR(IX0.0); // Get the address of the input

// read the status of the next input
IF INPUT_FROM_ADDRESS(myVal + 1) = TRUE THEN
// The next input is high, so set output 7 to high.
GET_OUTPUT_FROM_ADDRESS(6) := TRUE;
END_IF

My goal is that when ever a given Input (IX0.0...) changes it's state, I want to run a method that then applies some logic.. and ends up doing what not..

Right now I have the same code copy pasted over and over again to handle the events (with only the input and output variables changed), hopefully this isn't the correct way to do this, and i have to adjust the code every time i setup a plc with more or fewer input boards in..


o_O

Thanks in advance! :)
 
start with the last: you do not have to change code, however every in and output needs to be declared in the global_var list or in the plc configuration (is same principle)
so yes you need to change the configuration and compile, however you dont have to change the program.
GLOBAL_VAR
input1 at %IX0.0 BOOL; (* here you can tell the people what this input is *)
input2 at %IX0.1 BOOL;
etc
END_VAR
now for the program:
function block 1
move all inputs to an inarray [1..last]
just by hand is easiest and according to 61131 (and best readable
inarray[1]:= input1;
inarray[2]:= input2;
etc
end functionblock
same for outputs
output1:=outarray[1];
etc

the main program is not clear to me
however
for a = 1 to last-1 (* you will have to make a test if input is used.*)
if inarray[a+1]= true then
outarray[7]:=true;
END_IF;
END_FOR
this is just a starter
 
If you are under codesys 3.0 then you can use pragma directives to be able to process parts of the program depending on the declarations.

Apart of that, you can always send a pointer to the right input.

Codesys 3.0 will allow you to program in an OOP way natively, which given your background will help you a lot.

Good luck!
 
Typically with PLC code you don't do what you're trying to do. With that said you can increment the address just as you would in c. I used ADR instead of BITADR. They do very different things. I hope that this is what you're looking for...

Good luck

(8{)} :) .)
(Yosi)

-----------------------------------------------------------
PROGRAM PLC_PRG
VAR

(* Define a bunch of variables one after the other. The addresses will be consecutive (1 byte for data TRUE or FALSE) *)
MyBool0 : BOOL; MyBool1 : BOOL; MyBool2: BOOL; MyBool3: BOOL;
MyBool4 : BOOL; MyBool5: BOOL; MyBool6: BOOL; MyBool7 : BOOL;
MyBool8 : BOOL; MyBool9: BOOL; MyBool10: BOOL; MyBool11 : BOOL;
MyBool12: BOOL; MyBool13: BOOL; MyBool14: BOOL; MyBool15: BOOL;
RetBool: BOOL; (* Return value from function *)

END_VAR
------------------------
(* PLC_PRG code *)

(* Call the function that will manipulate the data. Pass it the address of the 1st BOOL. *)
RetBool := MyFunc(ADR(MyBool0));

------------------------------
FUNCTION MyFunc : BOOL
VAR_INPUT
BoolPTR : POINTER TO BOOL;
END_VAR
VAR
i : INT;
END_VAR
------------------------------
(* MyFunc code *)
(* Set all of the BOOLs to TRUE one at a time by incrementing the pointer address *)
FOR i := 0 TO 15 DO
BoolPTR^ := TRUE;
BoolPtr := BoolPtr + 1;
END_FOR;

MyFunc := TRUE; (* Return value. Does nothing. *)
 
i do not like all these pointer things and addresses as this is not very 61131 .
you are relying on the seqeunce of the boolvariables and that needs very carefull programming.
 
i do not like all these pointer things and addresses as this is not very 61131 .
you are relying on the seqeunce of the boolvariables and that needs very carefull programming.

I agree with you absolutely. Regardless he wanted to see how it's done...

Cheers,

Yosi
 

Similar Topics

Hi, I have never used modbus communication in Codesys 2.3, any tips and tricks are much appreciated. The system is a Wago 750-881 that controls...
Replies
3
Views
1,818
Hello, These days I am trying to implement a communication via EthernetIP between a PowerFlex 525 drive and a WAGO PFC200 with EthernetIP...
Replies
7
Views
1,913
Dear people, Is there any way to use native 3Codesys functionalities within a Wago e!****pit ironpython script? I want for example to export...
Replies
0
Views
928
Codesys Ethernet IP Scanner - Won't connect to a Wago 750-353. The Ethernet device and the Ethernet IP Scanner are both running. but then I go...
Replies
2
Views
1,656
Hello, Maybe it is just a simple problem, but I cannot solve it. I have a Wago 750-881 connected to a Beier HMI through IP TCP, the connection is...
Replies
0
Views
888
Back
Top Bottom