News:

  • October 13, 2025, 10:21:38 PM

Login with username, password and session length

Author Topic: Move UDT values to Modbus  (Read 1446 times)

ryanastiefes

  • Sr. Member
  • ****
  • Posts: 67
Move UDT values to Modbus
« 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.

RBPLC

  • Hero Member
  • *****
  • Posts: 585
Re: Move UDT values to Modbus
« Reply #1 on: May 25, 2022, 06:41:38 PM »
MOVE or COPY

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: Move UDT values to Modbus
« Reply #2 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:
  • Goto, System Configuration --> Memory Configuration, Structs (Built-In/UDT) tab
  • Double-click on your AnalogGate structure. This pulls up "Edit User Data Type Definition" dialog.
  • Click the <Add> button. This pulls up the "Edit User Data Type Field Definition" dialog.
  • Give it a Field Name for your 20 bits (i.e. 32 bits really because 12 are unused yet are still part of dw0 in your structure).
  • Change the Data Type to Signed DWord
  • In the bottom right, in the Memory Layout box, click on Manual (Advanced), and make sure the DWORD Offset: is 0 (zero), because that is where your 20 bits are located according to your picture.
  • Press <OK> button. This will take you back to the "Edit User Data Type Definition" dialog.
  • Now press the <View Memory Layout> button at the top right.
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.
« Last Edit: May 26, 2022, 10:39:31 AM by Greg »
There are two types of people in the world; those that can extrapolate from incomplete data sets.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: Move UDT values to Modbus
« Reply #3 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

ryanastiefes

  • Sr. Member
  • ****
  • Posts: 67
Re: Move UDT values to Modbus
« Reply #4 on: May 26, 2022, 12:02:03 PM »
Thanks Greg and franji1.
Thats exactly what I wanted!