<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Please help with Modbus Master code STRUCTURE</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f4492c2567/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f4492c2567/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/f4492c2567/</id><updated>2020-02-27T13:49:17.368000Z</updated><subtitle>Recent posts to Please help with Modbus Master code STRUCTURE</subtitle><entry><title>Please help with Modbus Master code STRUCTURE</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f4492c2567/?limit=25#2321" rel="alternate"/><published>2020-02-27T13:49:17.368000Z</published><updated>2020-02-27T13:49:17.368000Z</updated><author><name>boompy</name><uri>https://forge.codesys.com/u/boompy/</uri></author><id>https://forge.codesys.com3cb1cea2ea5a609a6f783201f7d051e934c2c90e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;I've been agonizing over the most appropriate structure for my programs structure / architecture. I'm pretty new to this arena.&lt;/p&gt;
&lt;p&gt;I'm using a Wago PFC and their associated Modbus TCP master library (not the GUI) in eCockpit - Codesys V3.5.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;What I'm concerned about is my program structure.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;The master returns an array 'awData' with the respective Mb register data, which could be populated with say 80 variables of interest.&lt;/p&gt;
&lt;p&gt;The same PGM is then used to map individual device parameters from the awData array to variables.&lt;/p&gt;
&lt;p&gt;ParamA := awData&lt;span&gt;[1]&lt;/span&gt;;&lt;br/&gt;
ParmaB := awData&lt;span&gt;[5]&lt;/span&gt;;&lt;br/&gt;
ParamC := awData&lt;span&gt;[77]&lt;/span&gt;; , etc&lt;/p&gt;
&lt;p&gt;These parameters are then manipulated to produce useful data (scaling, type conversion, etc) and then mapped to global variables.&lt;/p&gt;
&lt;p&gt;This seems a little messy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;First Question:&lt;/strong&gt;&lt;br/&gt;
Should I be using another FB to do the mapping and data manipulation, rather than using the same PGM?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Second Question:&lt;/strong&gt;&lt;br/&gt;
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.&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Any help or examples would be greatly appreciated.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>