Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

OOP modeling with Oscat Network

Mox
2016-11-09
2016-11-11
  • Mox - 2016-11-09

    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.

    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??
    Sorry for the length of the post, but I tried to explain as much as possible the project.

    Mox.

    IMG: Bild

    IMG: Bild

    IMG: Bild

    IMG: Bild

    IMG: Bild

    IMG: Bild

    IMG: Bild

     
  • Anonymous - 2016-11-11

    Originally created by: scott_cunningham

    Variables defined in methods are temporary is scope. As soon as the method ends, they disappear. So in your new FB, the variables IP_CONTROL2_1 and Channel_1_P in Primary_meth and Minor_meth are actually temporary.

    Declare them in FUNCTION_BLOCK Moxa_new_FB instead. Then they will maintain existence from PLC scan to PLC scan.

    (I learned this the hard way when I tried to declare a counter inside a method - always started at 0, incremented to 1 and repeated).

     
  • Mox - 2016-11-11

    Hello scott and thanks for your reply.

    I moved the declaration of all variable from both methods Minor_meth and Primary_meth inside the FB Moxa_new_FB. And it works my object was filled correctly.
    Thanks a lot scott.

    Regards,
    Mox.

     

Log in to post a comment.