Obtaining size of data in bytes

Mr Modbus

Member
Join Date
Jan 2014
Location
Lincoln
Posts
24
Does anyone know of a way of obtaining the size of a data type (actually a UDT) or tag in bytes? Similar to the sizeof() operation in 'c'.
For example if I had a UDT called MyUDT which consisted of an array of 5 INTS and 5 REALS, I would want a fuction / operator to return 30 (5*2 + 5*4), which is the size of the tag / data type in bytes. The SIZE operator is of no use as that returns the size of the array in elements not the size of the data type / tag in bytes.
 
The UDT dialog box where you define the UDT shows the number of bytes that the UDT requires.
 
Thaks for that. However, I want to access this information during runtime in code e.g. SizeOf(MyUDT, UDTSize); Where the SizeOf puts the value in the UDTSize variable.
 
The size of the UDT is a set value. Only changes if you change the actual UDT. Could you multiple out the size of the Array by the known UDT size (as a constant) to get the value you are looking for?

Or are you looking for a universal solution that just gets dropped into any piece of code with any unknown UDT size?
 
Probably a silly question, but what platform are we talking about?
 
OK I will try to answer all the questions in one hit.
The platform is RSlogix 5000 V28 using an L73 CPU.
I want a universal solution for unknown UDT size.

Thinking about it, the reason I want to do this is maybe moot.

I am passing in an array of a specific UDT. I wanted to get the code in the add-on instruction to check that the parameter being passed in is of the expected type.

The way I was going to do this was to divide the array definition size in bytes by the UDT size in bytes and I would expect to get a whole number if the parameter being passed in was of the correct type (UDT). I.e. it would be whole number of UDT's in size.

The reason for doing it this was that it was a port of some software from the S7 world whereby the passed in parameter was an ANY pointer that pointed to the array of UDT's.
Now as the ANY pointer can point to data of any type, it needed some form of check to validate that the correct data type was being pointed at. I realise that the check is not foolproof, but it is better than nothing.

So it was my intention of trying a similar thing on the ported code in the bradley.

So parameter passed in is UDT[n] where n is unknown.
The AOI has the input type of UDT[1].
The AOI then goes round a loop of n copying each array element to a local tag of type UDT. Now this I have already tested. I can get n using the SIZE operator and the COP operator can access all the array parameters (even though the input is defined as [1]).

However I want to prevent someone calling the AOI with a tag that is not an array of UDT (i.e. passing in a incorrect parameter type).
But having just tried it, I have discovered that the compilation will fail unless the parameter is of the correct type.

So I think that I don't need to find the size of the array in bytes or the size of the UDT in bytes as the paremeter has to be of the correct type for it to compile.
 

Similar Topics

Hello Friends, I'm starting a new job soon, towards the end of September, that will be using all Beckhoff equipment. I have programming...
Replies
4
Views
1,027
I have an ME Station with just a runtime file on it. Its a versaview and from what I have been told and seen Industrial PCs dont show up on...
Replies
5
Views
2,003
Hi, I have a Redlion G306 and its GSM Modem add on which I have successfully managed to send and receive texts from. I'm interested to know...
Replies
0
Views
2,161
I have a question regarding the ScadaPACK32 being identified by a MAC address. I present to you a fictitious scenario that I have been...
Replies
4
Views
1,895
Hello, I am using Factorytalk VS and would like to create a listbox that enables you to choose which graphics display you wish to open. Only the...
Replies
1
Views
1,476
Back
Top Bottom