I have a DINT tag being read in from an OPC source. What I want to do is to take the DINT and actually show the full 32 bits as 1's and 0's. I have a UDT set up for the tag. First question is would it be better to create another tag within the UDT that converts it from a DINT to BOOL array or have a label object which takes the tag in and converts it via an expression. Second question is whats the best way to do it? Would it be reading in the DINT and then creating a FOR loop which advances through each bit in the DINT and then concatenates it into a string for example?
Show it where?
I want to show it on a vision screen. I am replicating a screen from an HMI and they use the DINT to show 1's and 0's from the value of the DINT
There's a toBinary
expression that should make this pretty trivial.
Thanks. I figured there was a function to do this already. Only thing I ran into was having 0 show up when the value was zero instead of 32 0's.
To test I did the following and worked great.
You can use stringFormat
to do the padding as well, so you only have a single operation:
So stringFormat(toBinary({tag}), "%032d")
or maybe just "%32d"
.
stringFormat should lighten the load, and maybe look a bit cleaner.
stringFormat('%032d %032d %032d',
toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST})),
toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST1})),
toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST2}))
)
Post code, man, not pictures of code! Post code!
See Wiki - how to post code on this forum. It means we can copy and use it or edit it in our replies. Thanks!
Haha this is true. Will do next time.