Using predefined FB in ST

plcbp

Member
Join Date
Jul 2012
Location
Norway
Posts
7
I want to use a predefined function block that came in a lib. I'd like to program in structured text. However I am not sure how do this. Any tips to how the syntax should look? I am using CoDeSys

(The FB i want to use is a modbus tcpip server if that matters)
 
In the library you should be able to find a description of the Function Block along with the inputs and outputs it has.

Calling Functions (and Function Blocks) in ST is not particularly comfortable, when I'm using FBs I usually create another small PRG programmed in FB (usually with just one Network) to call it. The graphical representaion makes it much easier to enter all the parameters - especially if there are lots of them! You can then call this new Function Block for example "CALL_my_FB" in the ST-Program with the normal Program Call:

CALL_my_FB();
 
Thanks, I'll try that. How would it have looked if I were to only use ST? For some reason I was asked to do that.
 
Thanks, I'll try that. How would it have looked if I were to only use ST? For some reason I was asked to do that.


It depends a bit on whose implementation of CoDeSys you're using. In the Version I'm using you hit F2 to open a list of all the operators and Functions, FBs and programmes that are available then click on the one you want. That then enters a line of code like the following, without the parameter values after the ":=":

CLLI_SDO_Lesen(Index:= 2000, Subindex:= 1, Laenge:= 8, Handle:= 9, IDIst_RX_SDO:= 583, IDIst_TX_SDO:= 609, Lesen_ausloesen:= Read_ID_9);

and then you can fill the parameter values yourself.

My implementation dosesn't actually enter the function name before the opening bracket, you have to type that in yourself.

There is no shortcut for the outputs in my implementation (ProSyd_1131 from InterControl) you have to do them by hand - something like this:

Byte_1 := CLLI_SDO_Lesen.Data_1;
Byte_2 := CLLI_SDO_Lesen.Data_2;

etc.
 
Last edited:
Beckhoff has many examples of calling function blocks in ST. Their TwinCAT is a version of CoDeSys. Their examples put each parameter on a single line, so it is easier to read. It takes up no more space than a function block diagram (FBD) and gives more room to add comments.

I don't see how showing the same I/O to a function in FBD with a box for the function helps much, but I never bought into the simplicity of LabView either. I understand that FBD shines not in calling functions, but in showing logic diagramatically. Motor control people seem to love it the most.
 
Thank you for your answers. I had misunderstood the way to use the lib. When I got access to some examples it was not very difficult to program. It's working now.
 
In the varlist should be a line with
used1FB : FBname; (* the name in the lib*)

in the ST

used1FB (in1:=varinSTprog,in2:=varinSTprog,out1>:varoutinSTprog);

also possible:
varoutibSTprog:=used1FB.out1;

Use F2 for simpler insert (only change the name of the FB two times)
 

Similar Topics

I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
45
Adding ethernet equipment to an existing panel that has none. We have some solid ethernet cables coming from other remote cabinets that I plan to...
Replies
3
Views
109
I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and...
Replies
7
Views
217
Hi, I'm trying to use the IO Device Library (Product Versions) which is configured to work with the 1756-EN4TR & 1756-EN2TR but my system uses...
Replies
0
Views
54
Hello, As part of our project, we are using an M241 controller. This controller interfaces with an industrial computer and a router via a switch...
Replies
2
Views
99
Back
Top Bottom