How to connect cyclic task to application with PM573-ETH
I'm new to this coding platform and are in process of learning prior to buildning the AC500 version of my 800M PLC code.
I'm stuck on cyclic loop of application call that then calls the COM_REC function block.
All help is appreciated
Below is my test project plan performed from Automation Builder and it’s included CoDeSys
- setup hardware in automation builder and connect global variables 573-ETH (done)
- config COM-port for 9600, 8, 1, None (Done)
- com-port reader (a variable to ref COM_REC function) and assign parameters (done)
- create a task to cyclic call the PLC_PRG, where the reader program is called (error here)
- com writer functions waiting for receive and activate sending a mess
- create the mainloop waiting for messages through com-port and then parse them into a switch(myOrder) case ”STAT"
- create a template in a library to use multiple instances / projects from, then create instances
- create 2 and call to a function from main and other functions (create message ?)
- create 2 and call to a function block and calls in between ( check and collect status)
- …… Now I’m on my own
- When that’s done I can start getting my hands dirty and do some heavy coding, specific ...
Voted best answer
What I need is help to understand how to automaticly call the main PLC_PRG and from there call the function block COM_REC to read the COM port.
I want the call to loop no matter what. In the code I'll call the program with com-read function block and if nothing simply drops it, othervise it handles the message.
As I have learn't I need to create a task and set the timing, normally like 40 ms but to catch /see what happens I set it to 1 sec.
The application call to PLC_PRG is also set.
PLC_PRG calls another program where I have a function ref to COM_REC
From the COM_REC I shall assign the DATA to a globall variable (if necessary global) and then parse out commands. The string commming from the PC looks like "GOTO 01, 1243" where GOTO is an action command and 01 is an item to select and the last 1234 is an angle position value where the item is located.
Hi, got the wanted explanation how it all hangs together, including a numeric counter to display that I receive the call. It sounds as if the PLC cpu is running as an OS cpu with its events and the Task configuration is simply an alarm config (time between alarms) and what to do/call every time the alarm sounds
This is how i done it after Jonathan answered.
Add a task to task configuration and specify name and loop time
Right-click on task and application call and point out PLC_PRG (or any other)
Create a new program in the POU and add a variable referencing the COM_REC. ie use as it's type the function block:
" com_reader_ref : COM_REC;" add also variables
in the code part
IF com_reader_ref.ERR THEN
iErrorIndex:= iErrorIndex +1;
And finally from PLC_PRG add the call
Now run and observe the variable iErrorIndex value for each call it increases.