How can I cast a DB_ANY to a plc datatype in order to get symbolic access to the DB members? It's standard access DB's. In other words I want to indirectly access a DB of a specific type AND get symbolic access to the DB members.
Asked
Active
Viewed 1,017 times
0
-
I'm not sure what you are saying. I assume you are working with TIA? "want to indirectly access a DB of a specific type". DBs aren't a specific type. They contain specific types. Did you want to cast a member of a DB of type DB_Any to a specific type? – mrsargent Feb 13 '19 at 13:51
-
Yes its TIA. You can define a DB as an instance of a specific plc datatype. – krakers Feb 24 '19 at 10:01
1 Answers
0
short answer in SCL style:
DB_in : DB_ANY (really of type UDT1)
DB_Variant : Variant
Destination : UDT1
DB_Variant := DB_ANY_TO_VARIANT(DB_in)
IF TypeOf(DB_Variant) = UDT1 THEN
VariantGet(SRC:= DB_Variant, DST => Destination);
END_IF;
you can now acces symbolics of your DB as UDT. If you want to manipulate values inside the DB you have to get it into your function as Variant, skip the DB_ANY_TO_VARIANT line and write it back with VariantPut(SRC:=LokalVar, DST :=DB_in)

Simon
- 115
- 2
- 6