Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: ryanastiefes on May 25, 2022, 06:29:13 PM

Title: Move UDT values to Modbus
Post by: ryanastiefes on May 25, 2022, 06:29:13 PM
I've setup a UDT for a project I'm working on. I've created Memory Blocks containing the UDT which works great. Now I would like to monitor a few of the values, mainly the bits in the first DWord over modbus. I've tried the MEMCOPY and MOVER but it throws an error.
I just need to move the first DWORD (which are all bits) in the UDT strucutre into two modbus registers or 32 coils


Attached is the UDT Memory Layout.
Title: Re: Move UDT values to Modbus
Post by: RBPLC on May 25, 2022, 06:41:38 PM
MOVE or COPY
Title: Re: Move UDT values to Modbus
Post by: Greg on May 26, 2022, 10:25:10 AM
I've setup a UDT for a project I'm working on. I've created Memory Blocks containing the UDT which works great. Now I would like to monitor a few of the values, mainly the bits in the first DWord over modbus. I've tried the MEMCOPY and MOVER but it throws an error.
I just need to move the first DWORD (which are all bits) in the UDT strucutre into two modbus registers or 32 coils


Attached is the UDT Memory Layout.
To do this you need to modify your AnalogGate UDT Structure. Right now, the only access to your 20 bits is via the structure member names for each individual bit (e.g. .FieldAuto, .FieldHand, etc.) You need to add at least a double-word structure member manually, that occupies the same memory space as your 20 bits. To do this:
Now notice that your zero field has been expanded. It shows not only your 20 bits, but it also has a new double-word name occupying the same memory space. This new name that you gave it, this double-word will contain your 20 bits. You can now use it in your ladder logic as a double-word containing your 20 bits. But you can also still use your individual bits. So using this new name that contains your 20 bits, it can be MOVE'd like any other double-word to anywhere you like.

But here's an important thing you also need to know. Are all those 20 bits just "status" bits (i.e. input)? Or are some of them "control" bits (i.e. output)? If all of them are one or the other then what I just showed you is fine. However, if some of them are status and some control, you may want to group those bits together at byte boundaries. And use that Manual (Advanced) option to define those bytes, words, etc., so that you can better use them in meaningful ways.
Title: Re: Move UDT values to Modbus
Post by: franji1 on May 26, 2022, 11:05:44 AM
If you want even more detail, this post shows some built-in examples of doing "unions" with your structures (specifically built-in Date/Time structure with bytes/words combined into single DWORDs, and PeerLink structure with status bits and control bits combined into single WORDs)

https://forum.hosteng.com/index.php?topic=3627.msg27471#msg27471
Title: Re: Move UDT values to Modbus
Post by: ryanastiefes on May 26, 2022, 12:02:03 PM
Thanks Greg and franji1.
Thats exactly what I wanted!