02-12-2017 05:21 AM
I convert an array of bytes in a character string with the following expression:
Locals.String += Chr( Locals.U8[RunState.LoopIndex])
How to convert a character string into an array of bytes in TS (similar to the LV function of String To Byte Array). TS function Asc () returns only the first character in the string.
Solved! Go to Solution.
02-12-2017 03:14 PM
Hi Alex,
Looking at your bytetochar.seq file, I think you were very nearly there, but it looks like the Mid() wasn't indexed correctly; 0 was used instead of RunState.LoopIndex.
You could acheive the String To Byte Array all in a single Statement Step using the following expressions:
Loop While Expression
RunState.LoopIndex < Len(Locals.String)
Pre-Expression
SetNumElements(Locals.U8, Len(locals.String))
Post-Expression
Locals.U8[RunState.LoopIndex] = Asc(Mid(Locals.String, RunState.LoopIndex))
You could also do the String To Byte Array conversion in a sub sequence if you wanted to use this many times on different strings and just maintain one method to do it.
I've attached example sequences for both ways of implementing this.
Regards,
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
02-13-2017 12:17 PM
Thanks for reply, Charlie.
Your solution helped me. But I have another problem. Array Byte to String conversion function Chr() removes the numeric value 0x00, believing that this is the end of the string. As a result, the function Asc () does not return a numeric value 0x00. How can I avoid this? I've added an example.