boompy - 2019-05-26

Hi all

I've been agonizing over the most appropriate structure for my programs structure / architecture. I'm pretty new to this arena.

I'm using a Wago PFC and their associated Modbus TCP master library (not the GUI) in eCockpit - Codesys V3.5.

This provides a Modbus master function block. I have created a PGM which calls this MB master function block perfectly. I can connect to an ancillary device via TCP and read / write data without fault.

What I'm concerned about is my program structure.

The PGM I have created calls the Modbus Master cyclically and has the ability to process multiple requests. They are all timed perfectly, and I can adjust the algorithm to perform 10 requests, 50 requests, perform a write, etc - no overlap.

The master returns an array 'awData' with the respective Mb register data, which could be populated with say 80 variables of interest.

The same PGM is then used to map individual device parameters from the awData array to variables.

ParamA := awData[1];
ParmaB := awData[5];
ParamC := awData[77]; , etc

These parameters are then manipulated to produce useful data (scaling, type conversion, etc) and then mapped to global variables.

This seems a little messy.

First Question:
Should I be using another FB to do the mapping and data manipulation, rather than using the same PGM?

Second Question:
What if I wanted to query 10 different TCP ancillary devices? Under my current model, I'd just create another 10 x PGMs and allow each of these to call another instantiation of the Mb master cyclically also.

Is this accepted / normal practice? Or would you normally have ONE solitary PGM calling a TCP Modbus Master FB to process all requests for ALL devices, then export the data to their respective FB's for processing?

To me, having a single PGM dedicated to one ancillary device makes sense (at least for TCP connections, probably not serial). I'm not sure what is accepted best practice in industry.

At present, everything I have works. That's not to say it's as good as it could be. I'm dying to learn a little more, I've searched everywhere but can't find any definitive guidance.

Any help or examples would be greatly appreciated.