Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Reading data type UNION and BIT with OPC-UA

Reading data type UNION and BIT with OPC-UA

NickOS
Member

In an Indralogic project we have a union of DWORD and a 32 element structure of type BIT. For example:

TYPE UN_CONTROL :
UNION
   Word : WORD;
   Bits : ST_CTRL_BITS;
END_UNION
END_TYPE

TYPE ST_CTRL_BITS:
STRUCT
   b0 : BIT;
   b1 :  BIT;
   ...
   ...
   b31 : BIT;
END_STRUCT
END_TYPE;

We have this because some legacy HMI used words to communicate, but within the PLC itself it is nice to be able to address variables as control.bits.b<whatever name>.

This works within indralogic, no problem. The trouble is, when trying to access this word via OPC-UA (UA-client, Web-IQ, etc) it neither appears as the bits or the word, it is like it has completely dissappeared.

I know I could re-write the code to switch between WORDs and, say, a BOOL structure, but I was hoping to find a neater solution utilising the UNION. Any suggestions?

p.s. in an integration with a 3rd-party (UniOP device), I shared the XML schema and XML file with the project variables, and the developer could read and manipulate the BIT!

8 REPLIES 8

webiq-sk
Frequent Contributor

This sounds to me more like an issue with Indralogic than with WebIQ. I understand that you're not even seeing the item in UA Expert, is that correct?

Hi, yes you are quite right. Now that I explore further it seems any UNION is not visible.

I guess I could move this on to another forum.

CodeShepherd
Community Moderator
Community Moderator

Moved this thread from Smart HMI - WebIQ Designer and Server to Communication forum.

CodeShepherd
Community Moderator
Community Moderator

Could you please give us some more information about your project?

  • Which control/PLC are you using?
  • Which OPCUA server are you using?

We are at the moment working on a feature for the access to complete structures via OPCUA. And also the access to the data type BIT is in preparation.

I tested it with LTE version ctrlX 1.12.9 and it works like expected. What I wonder, that you have only a WORD variable (16 bit).
There are 2 ways how to use unions:
1. Use identical RAM by storing different data types/value types in the same place. => You must store somewhere the info how to interprete the address in the RAM:
2. Use BIT's instead of BOOL's
3. Combination of 1 + 2

When I read your request you are using option 3.
This means in the

  • PLC you use the Bits of the Union for easy programming
  • HMI you use the variable Word to access the variables, where you have to change data type to DWORD (32 bit)

 

TYPE UN_CONTROL :
UNION
   dwValue: DWORD;  // must be DWORD to access all 32 bits of variable Bits
   Bits:    ST_CTRL_BITS;
END_UNION
END_TYPE

 

The structure ST_CTRL_BITS is not a standard data type, therefore it is visible in OpcUA browse but with unknown (=empty) data type. Therefore you can not access it.

HmiGuide_1-1669026022506.png

You can access the bits via the union variable Word, but you must adapt the data type to DWORD, to access all 32 bits of the union variable Bits. To access bits in WebIQ you add a prefix to the item: bit[bitNo]:item e.g. bit[0]:SInt

 

@HmiGuide , you assume correctly. I apologise for my typo in the OP (I didn't copy from live code), but my actual code is size-matched. I have tried WORD and 16-bit structures; DWORD and 32-bit structures; WORD and INT (just to check it wasnt my bit structures), none of this works.

I should add though, @CodeShepherd , this is an MLC75 running IW14v22 rather than a CtrlX processor. And although I originally brought this up in a WebIQ forum, it seems even the UA-Client cannot read this data. So it suggests the issue lies in MLC/IW platform, perhaps the OPCUA server.

HmiGuide
Community Moderator
Community Moderator

@NickOS in the MLC version you are using there is an older CoDeSys version than in ctrlX.

 There is an easy workaround to access the variable. Just add a refence which points to your structure. I tested it with IW 14V22 P5.

 

VAR_GLOBAL
  stTest:  UN_CONTROL;
  // reference MUST be initialized to export it into symbol file
  refDWord: REFERENCE TO DWORD REF= stTest.dwValue;
END_VAR

 

 

Thanks @HmiGuide , I think I can work with that for now. 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist