Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

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

Use datalayer to read a struct type

Use datalayer to read a struct type

pjbonestroo
Established Member

I will use a very simple example to show my problem.
I created a DUT (data unit type) named MY_COMPLEX in the PLC as follows:

TYPE MY_COMPLEX :
STRUCT
p1:INT;
p2:INT;
END_STRUCT
END_TYPE

I created a variable in structured text by:

my_complex: MY_COMPLEX:=(p1:=1,p2:=2);

Now I'm able to read the value of 'p1' using Python and ctrlx_datalayer by:

address = "/plc/app/Application/sym/PLC_PRG/my_complex/p1"
result, data = client.read_sync(address)
value = data.get_int16()
# value == 1

But I would like to read both values, p1 and p2, at once.
I do not want to use the BulkRead possibilities, because when the number of addresses increase it will get much slower than a single read.
Should I investigate the flatbuffers type? If so, how to create this in the PLC?
Are there other possibilities?
Note that in my real application I would like to have an array of DUT types, and I would use both read and write.
Ideally I would do conversions at Python side to convert to/from bytes, and send bytes using the datalayer.

4 REPLIES 4

MauroRiboniMX
Contributor

Hello, 

Flatbuffers is what you need. There is a simple example here:

https://github.com/boschrexroth/ctrlx-automation-sdk/tree/main/samples-iec61131

Mauro 🙂

Thanks for pointing me in this direction. I will try this soon.

I'm trying to follow the readme in `ctrlx-automation-sdk/samples-iec61131/fbs-read-write` but I stuck at the following:

* Select PLC node Application, right click and select context menu item 'Import from Flatbuffers File...'

I cannot find the "Import from Flatbuffers File ..." menu item. When I right click the PLC node Application I can Login or Add an object but nothing related to a Flatbuffers file.

Any idea what I'm doing wrong?

Currently I have ctrlx WORKS version 1.20, but I should have ctrlx WORKS version >= 2.3
I have another question posted here:
https://developer.community.boschrexroth.com/t5/ctrlX-PLC/Where-to-download-ctrlX-WORKS-version-2-3/...

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