OOP modeling with Oscat Network

Begonnen von Mox, 10. November 2016, 09:10:51

Vorheriges Thema - Nächstes Thema

0 Mitglieder und 2 Gäste betrachten dieses Thema.

Mox

Hello,

I am trying to model Ethernet switches (Moxa EDS-508), and remote I/O (Wago Coupler 750-352) with an OOP approach thanks to Codesys. I am a beginner in Automation in general. Firstly, I succeed to fill these objects with different information through Modbus/TCP Slaves. Which are present in the Codesys Device Tree.

But I wanted to have more flexibility with the modeling. So I imported both libraries OSCAT BASIC v3.3.3 and OSCAT NETWORK v1.2 in Codesys v3.5 SP9. By the way thanks for these great tools.

http://store.codesys.com/oscat-basic.html

http://store.codesys.com/oscat-network.html

My client is the target PLC a Raspberry-Pi, and it sends a Modbus TCP/IP request to the server, a Moxa switch. The switch only works with FC4 and UDP doesn't seem to work. (Error of timeout,16#FF00, is returned).
I choose to make an ST FB based on MB_CLIENT, from Oscat Network. I will use it to read registers and fill the objects. Moreover, I decided to make different FB with different size of data output.

Read_Channel_FB_0 reads a unique Modbus TCP/IP register and release a word output (data_out). It possesses two methods: Read_Parameters_Affec() and Data_Builder().



Read_Channel_FB_1 reads a Modbus TCP/IP register and release an array of two words output (data_out). It possesses two methods: Data_Builder() and Read_Parameters_Affec() (Same method as Read_Channel_FB_0).



A Moxa is modelled by a FB, and composed with two structures: REFERENCE TO Minor_Information, REFERENCE TO Primary_Information. The information represent data more or less important from the Moxa, so the request Modbus TCP/IP are not at the same speed rate between information. Plus Moxa_FB gets a FB_Init to initialize its parameters from a GVL.



Now we build the object Moxa in a program thanks to IP_CONTROL2, from Oscat Network:



When I call the different Read_Channel_FB in a program, there is no error code. And the Moxa_FB is filled correctly.



I wanted to add the Read_Channel_FB inside a new FB: Moxa_new_FB. There are two methods Primary_meth() and Minor_meth().
Plus I removed the use of a GVL for a FB_Init in this FB.



Here is the call in a program:



But the affection didn’t occur. And I don’t have any errors.

I need help, can someone explain me why the object doesn't fill correctly??

Mox.

annD

Hello,

I cannot follow all of your examples. But do you know that there is a Modbus RTU/TCP configurator integrated in Codesys?
https://www.codesys.com/products/codesys-fieldbus/modbus-tcp-rtu.html

You can add the ethernet port or Serial port in the device tree and add your modbus devices then. You do not need some function blocks therefore.

Best annD

mattsches

Hi Mox,

For what I know, you need to declare and call the FB instances accessed in your methods in the main FB code. At least if these FBs are running acyclically (i. e. the method is called several times and the FB instance within takes a couple of cycles/calls to complete).

During my work with 3S's interpretation of OOP, I found that an FB instance declared in a method gets destroyed when the method is finished, pretty much like VAR_TEMP variables (to be precise, its allocated memory gets freed and might be used by some other FB/program/whatever). Thus, it cannot preserve data from one cycle to another. If you want to control the FB instance's behavior, set a variable declared in the FB's main section in the method and assign it to the FB instance. Or write to the FB instance's I/O variables directly from within the method.

But as annD said, using the Modbus master object in Codesys is far more convenient to access the data of a Modbus device.

Regards,
mattsches

Mox

Hello and  thanks for your quick replies.

   annD, I wasn't clear enough, but I already tried to model Moxa and Wago with the RTU/TCP integrated in Codesys.
I need to make a project in which the user doesn't have to manage the Modbus slaves.
Like that he doesn't have to build a Master/Slave tree, an add Channels corresponding to data registers.
For instance, he gives an array of the equipments' IP present on the network to Codesys, and gets an access of each equipments data.
Thus the access of data is made automatically. And the user can handle data without knowing for example, the Modbus register corresponding to the Power Status of a Wago.

   mattsches, I understand now why I can't monitor a sub FB instance, in a main FB method. That also explains the interrogation points instead of data when I login to the PLC.
I will apply your advice for the project, and move the declaration of variable for sub FB instance to the main FB.

Regards,
Mox.

Mox

I moved the declaration of all the variables for the methods, inside the main FB, and it works !
Thanks a lot mattsches, I can continue the project without using GVL.
I didn't realise that the location of variable declaration could have this importance

Regards,
Mox.