Where to set parameters of a device in a function block?

flaviom
2022-03-30
2022-03-30
  • flaviom - 2022-03-30

    Hello!

    I'm currently developing a functionblock for a simple temperature sensor. The functionblock has the possibility to be used for different sensor types and therefore has internal minimum and maximum variables that need to be set when the FB is used.

    I've tried the solution with FB_Init which works fine until I use FB_TemperatureSensor in another FB. E.g.: The FB_TemperatureSensor is used within FB_TemperatureController to provide the controller with actual values.
    I create two instances of FB_TemperatureController: fbControllerOne and fbControllerTwo both instances use different temperature sensors. The FB_Init method doesn't allow me to individually set fbControllerOne's temperature sensor maximum limit, as the FB_Init values are already set in the creation of FB_TemperatureController.

    Should I create a settings method which sets all the min and max values?

    I'd be thankful for any advice :)

     
  • fajean - 2022-03-30

    FB_Init is itself a method, you can call fbControllerOne's FB_Init from within FB_TemperatureController's own FB_Init and supply it with the appropriate values along with the additional standard arguments FB_Init has but are not visible in variable declarations. Please note that this means fbControllerOne's FB_Init would be called twice, but due to the order of execution, your "manual" call would be performed last.

    You could also, as you hint to, create a method to set the limits and call that method from FB_TemperatureController's FB_Init. You could chose to call it from the application that uses the function block too, if limits are application-specific.

    In that latter case, i.e. if FB_TemperatureController itself needs to be configurable for each application, it could receive the settings as arguments to FB_Init (which would be relayed to fbControllerOne using its FB_Init or a method) or be initialized through a method in FB_TemperatureController that in turn calls a method on fbControllerOne.

    You could certainly come up with other initialization strategies. Which design is best is going to be dependent on your intended uses, the structure of your existing code, etc.

     

Log in to post a comment.