Posted 30 Nov 2020 Hello everyone, In Siemens and Rockwell I am used to transferring a double word to a tag that has a UDT data type of 32 bools. Which the binary bits (31..0) of the double word would align with the bits in a UDT data type of bool. If it was in a function block in Siemens I would call the double word address and move it to Area Register Address and transfer data to a tag of udt data type internal of the function block or could call a Move Block as well which will byte swap the bits but can be fixed with an STL call instruction (CAW). Since I am new to Sysmac Studio, how would I be able to do this? Looking at every Data Movement and Data Type Conversion functions all want a form of an array or elementary type, some wanting source and destination to be the same type. Any ideas? Share this post Link to post Share on other sites
Posted 30 Nov 2020 An image would be nice here but I still can't seem to upload one. You'll need to use a Union found under Data Types. A Union will share the same space between the specified Data Types. Example: u_DWORD Union data DWORD bit ARRAY[0...31] of BOOL Create your variable: MyDWORD of Data Type u_DWORD Use in programming: MyDWORD.data as DWORD MyDWORD.bit[3] as BOOL Share this post Link to post Share on other sites
Posted 30 Nov 2020 Maybe better example of what I am trying to do. Input of the function block is iConfig that is DWORD data type. Input value is DWORD#F for iConfig. Then in Data Types I made a Structure named UDT_Config that has 32 bools, each has a name and comment and in the Internals of the functions block interface I have created a tag named Configuration with UDT_Config as data type. I need the iConfig DWord value of F to move to the Configuration tag to enable the first 4 bits of the Internal tag. DWORD#F = 0000 0000 0000 0000 0000 0000 0000 1111 Configuration = UDT_Configuration STRUCT User Tag_01 BOOL True Tag_02 BOOL True Tag_03 BOOL True Tag_04 BOOL True Tag_05 BOOL False Tag_06 BOOL False Tag_07 BOOL False Tag_08 BOOL False Tag_09 BOOL False Tag_10 BOOL False Tag_11 BOOL False Tag_12 BOOL False Tag_13 BOOL False Tag_14 BOOL False Tag_15 BOOL False Tag_16 BOOL False Tag_17 BOOL False Tag_18 BOOL False Tag_19 BOOL False Tag_20 BOOL False Tag_21 BOOL False Tag_22 BOOL False Tag_23 BOOL False Tag_24 BOOL False Tag_25 BOOL False Tag_26 BOOL False Tag_27 BOOL False Tag_28 BOOL False Tag_29 BOOL False Tag_30 BOOL False Tag_31 BOOL False Tag_32 BOOL False Share this post Link to post Share on other sites
Posted 1 Dec 2020 Union is the way to go.! whilst it an extra step/tag perhaps, it does give a lot of options Share this post Link to post Share on other sites
Posted 1 Dec 2020 (edited) 9 hours ago, lostcontrol said: Union is the way to go.! whilst it an extra step/tag perhaps, it does give a lot of options Union is only allowed 4 elements. There are 32 bools as I mentioned above. Will have to do it the old fashion way I guess which I find elementary. Cannot believe there is no way to write a double word to a tag that has a UDT data type. I see the instruction for NumToEnum, but the double word value will equal to one value of the enumerated type. Looking to have individual bits to be True based on the value of the double word binary value. Edited 1 Dec 2020 by MasterConnection Share this post Link to post Share on other sites
Posted 1 Dec 2020 A union will do exactly what you want. I cannot post an image to illustrate it for you (something is wrong with the site), but you can create a Union that looks like this: Name Base Type TestUnion UNION DWordLevel DWORD BitLevel ARRAY[0..31] OF BOOL Then create a variable (lets call it MyVar) that is of type TestUnion in your global variables. Then you can do a move DWORD#16#F into MyVar.DWordLevel The bits can then be monitored on contacts or coils as MyVar.BitLevel[0] as an example. Share this post Link to post Share on other sites
Posted 1 Dec 2020 3 hours ago, Michael Walsh said: A union will do exactly what you want. I cannot post an image to illustrate it for you (something is wrong with the site), but you can create a Union that looks like this: Name Base Type TestUnion UNION DWordLevel DWORD BitLevel ARRAY[0..31] OF BOOL Then create a variable (lets call it MyVar) that is of type TestUnion in your global variables. Then you can do a move DWORD#16#F into MyVar.DWordLevel The bits can then be monitored on contacts or coils as MyVar.BitLevel[0] as an example. I 3 hours ago, Michael Walsh said: A union will do exactly what you want. I cannot post an image to illustrate it for you (something is wrong with the site), but you can create a Union that looks like this: Name Base Type TestUnion UNION DWordLevel DWORD BitLevel ARRAY[0..31] OF BOOL Then create a variable (lets call it MyVar) that is of type TestUnion in your global variables. Then you can do a move DWORD#16#F into MyVar.DWordLevel The bits can then be monitored on contacts or coils as MyVar.BitLevel[0] as an example. I ended up going this route. Thanks guys. Guess I have found the difference between platforms. Siemens and Rockwell is real simple to achieve this. Wish at least there was a way to write comments in the union array bools. Share this post Link to post Share on other sites
Posted 1 Dec 2020 4 hours ago, MasterConnection said: Wish at least there was a way to write comments in the union array bools. Just move the array[0..31] of bool from your union to your structure that has the comments array[0..31] of bool MyStruct.bArray := MyUnion.bArray Share this post Link to post Share on other sites
Posted 2 Dec 2020 20 hours ago, MasterConnection said: I ended up going this route. Thanks guys. Guess I have found the difference between platforms. Siemens and Rockwell is real simple to achieve this. Wish at least there was a way to write comments in the union array bools. You can comment on the bits. I cannot attach the picture of this as there is something wrong with the website. Go into the global variables after you have created the union and then created the variable of that union type. Double click in the comment field and a little gray button will show up. You can then comment the DWORD and all the BOOLS. 1 person likes this Share this post Link to post Share on other sites
Posted 2 Dec 2020 2 hours ago, Michael Walsh said: You can comment on the bits. I cannot attach the picture of this as there is something wrong with the website. Go into the global variables after you have created the union and then created the variable of that union type. Double click in the comment field and a little gray button will show up. You can then comment the DWORD and all the BOOLS. Wow learn something new everyday! That is really useful. Thanks Mike! Share this post Link to post Share on other sites
Posted 2 Dec 2020 3 hours ago, BITS N BYTES said: Wow learn something new everyday! That is really useful. Thanks Mike! You are quite welcome. This of course works with structure variables and simple arrays. Share this post Link to post Share on other sites
Posted 2 Dec 2020 24 minutes ago, Michael Walsh said: You are quite welcome. This of course works with structure variables and simple arrays. Even better! Share this post Link to post Share on other sites