Currently I am facing the following issue:
I receive several UDINT Values via Modbus TCP which contains Information as characters.
E.g. the UDINT for the Network Carrier from the Modem I use is 1093730304 which means ‘A1’ as an ASCII String. If I format this value in the watch-window in Automation Studio it shows me the ‘A1’ String. But how can I convert this UDINT Number so I can use it as the ‘A1’ String e.g. in the VC4 Visualisation?
this can be done using brsmemcpy
Simply copy the UDINT to a STRING this way.
This of course doesn’t perform any checks if the numbers are actually in the range but at least gets you somewhere.
Edit: The only way I can come up with to check the UDINT for validity is extract every single byte and check if it’s in the proper ASCII range, so >= 32 and <= 127) before copying them to the string
Thank you so much for your quick reply, I will test it asap.
How can I access every single byte from an UDINT? I think it is not like UDINT.B0 etc…
Thank you
I wasn’t quick enough with editing, therefore here my example I wanted to give, although you already made it work it seems
Example added:
mySTRING := '';
FOR i := 0 TO SIZEOF(myUDINT) - 1 DO
tmpUDINT := SHR(myUDINT, (3 - i) * 8) AND 16#FF;
IF tmpUDINT >= 32 AND tmpUDINT <= 127 THEN
brsstrcat(ADR(mySTRING), ADR(tmpUDINT));
END_IF
END_FOR
This will only add valid visible characters to the string. If you need any explanation, please feel free to ask further.
It’s not giving you any error messages etc rn but it converts your example just fine. Datatypes of my variables should be obvious
this example comes without brsmemcpy but uses brsstrcat