Custom data type from Modbus registers

Hi

I’m trying to create a custom data type based on a set of Modbus registers, which are somehow asymmetric, coming from C structures (all visible in the OPC resource tree).

Actually what I do have is a Modbus/TCP device, where I have mapped an array of structures into an array of registers. I have turned

struct {
uint8 param1;
uint32 param2;
uint16 param3;
float param4;
} EXAMPLE;

into

uint16 registers[1 + 2 + 1 + 2]; so that first register is an extended version of “param1”, second and third are used for “param2” and so on. To summarize, 6 registers for each instance.

I could use the Device addressing configuration to have access to each field of each EXAMPLE, but considering I have an array of N EXAMPLEs, creating a type which only needs to know the starting offset in the array of registers would be far easier.

What I can do now is to define N areas in the Modbus driver configuration so that each one references the starting register of a EXAMPLE, assuming there’s a way to create a data type capable of decoding the information that’s been received after this offset.

And the question, is there any way to do something like that?

Regards

I think this will be straightforward if you just forget the address configuration page exists and go create an Ignition UDT with an offset parameter and these 4 OPC tags as members.

Their addresses (OPC Item Path) will be something like [{deviceName}]HRUS{offset}, [{deviceName}]HRUI{offset+1}, [{deviceName}]HRUS{offset+5}, [{deviceName}]HRF{offset+6}

Hopefully I’m not inventing UDT functionality we don’t have when I suggest this :rolling_eyes:

1 Like

Ok, this solves half of the problem.

Now I have the offset parameter defined as String in order to fill it with the OPC Item Path, like
ns=1;s=[DEVICE]1.EXAMPLES0

This is the path of the first register involved (out of 6). However, whether I use this path or [DEVICE]1.EXAMPLES0, I can see an error icon on each field of the instance if I expand the Tag tree to show the fields.

What am I doing wrong?

Regards

I’m not sure what’s wrong given the information. If your UDT is setup correctly, maybe check the logs to see if there’s an error reading these registers. I’ve attached an example of what the UDT might look like.

Ok, now it seems to work.

There’s a small change I’ve had to do to make it work in order to have the chance to indicate the Unit ID:

  • At “OPC Item Path” use {deviceName}XXX instead of [{deviceName}]XXX (properties of the fields)
  • The parameter “deviceName” has to be [modbus]1. if the Unit ID is 1 (as stated in the Modbus section of the documentation). Otherwise the requests are sent by default to the Unit ID 0 even though you configure the value properly in the “Addresses” section of the Device.

Next stage, create a custom template to show this information :smile:

Thanks and regards

1 Like