News:

SMF - Just Installed!

Main Menu

Using Functions

Started by Jon, June 07, 2015, 10:01:58 AM

Previous topic - Next topic

Jon

Hi
First time I have tried using functions so a question:

Using ladder as a trial I drew a function titled Track. The function is true when two variables are true. All three are bool

In the main sequence I made a function call coil. It found the function Track but the returned parameter option showed void and clicking on the variable button had no effect. In the manual the variables available a the example seem quite standard so what am I doing wrong, or perhaps more correctly, what am I trying to do?

My understanding is that the testing of a function if true can be I putted into the main sequence, so, for example, if Track is true that function can be used as a variable in the main sequence (a sort of sub-routine).
So I would like Track true to have an effect on the process in the main sequence.
Thanks

EasyPLC_Master

Hello Jon;

As is explained in the EasyPLC User Manual:

Functions can return a value or not. Only the functions written in Script language can return a value, using the return
keyword. The functions written in Ladder or Function Blocks can't return any value.


Anyway if you can use functions in Ladder returning a value, you can use the variables. A Ladder fucntion can write the result in a global variable, then read it outside the function.

Perhaps a copy of your program could be useful in order to understand better what you want to do.

Jon

Hi Rafael
I've moved forward a little bit, realising the function coil works in the function sequence. But then I got stuck again. By email I have sent the program and further explanations about what I am trying to achieve.

Once again, a big thank you.
Jon

EasyPLC_Master

OK Joh!, now I think I understand what you want to do!
Several points:

1) Be careful, in your program you're doing a recursive call (a function that call itself), this is very dangerous in PLC programs because can block the PLC running, then must be avoid (although EasyPLC lets do it, because is a C language feature).

2) The checkboxes linked to a digital input (albeit simulated) are 'read entities', this means that you must to activate them clicking in the digital inputs, not in the checkboxes, that always are reading the digital inputs states (and only can change by hardware), please see the attached screen-shot.

I also attach your program with the requested functionality, in the Track function, is changed the state of a global variable (TP1R) that changes according to the value of the inputs 0.0 and 0.1.
See how this funcion is called in the ladde sequence of the Main Loop.

Hope help you!


[attachment deleted by admin]

Jon

Hi Rafael
Thank you so much. I understand what you have said, except the point about functions being script based in your first response. Is there a script in here somewhere?

EasyPLC_Master

Sure with this simple example you will understand.



[attachment deleted by admin]

Jon

Yes, I see how this works.
Once again, thank you Rafael.

It seems that the collaborative working issue may be a big problem for us as a team. We have some large data to write and hoped we could all contribute a few sequences each week to a summed project. the inability to import and export main sequences is meaning we are reluctantly assessing other solutions.

EasyPLC_Master

OK, I understand.
I can anticipate you that in the next version will be possible to import & export sequences (possibly to be released next month)  :D

EasyPLC_Master

Hello.

Is ready to download the new version release v.5.6.
Now is possible to Export / Import Sequences and Functions.