03-24-2015 02:33 PM
Hi all,
I am trying to send a target command to a controller (integer values 0-4095), however the way it sends is very strange.
For example, say you want to send an integer target of 3229. In binary, this is 110010011101. From here, you take the last 5 digits (the ones in blue), and add a 110 to the front to make the first value you send 11011101. Then, you take the first 7 digits (ones in red) and add a zero in front to make the second value you send 01100100.
I have a code that works if I manually input these values, shown below. The "sent string" outputs the binary array of 11011101, 01100100 in hexadecimal (0xDD, 0x64, and the trailing zeroes do not cause it to fail) which then sends to the controller.
The problem, as you might suspect, is that I have to manually put in the binary values that I need to send. I want to build a code that does the rearranging of the binary for me, so that it will be more user friendly for people who use this code down the line. I attempted to make a code to do this, but I can't figure out how to get the ASCII strings into a format that can correctly go into the byte array. This code is posted below.
This code outputs the following (the substringLow and substringHigh were just placeholders for me to see what it was doing):
So my question is this: is there a way to convert the "BinaryLow" and "BinaryHigh" ASCII strings into a format that can be read as a binary input into the Byte Array block or should I be approaching this issue differently?
I tried to be complete in my explanation of what I need, but if I left anything out or if anything is vague, let me know and I will do my best to explain it.
Thanks in advance.
03-24-2015 02:37 PM - edited 03-24-2015 02:37 PM
You are dealing with typecasting, not formatting. Just use the upper code and replace the diagram constant with controls.
If you have further problems, please attach your Vi instead of pictures.
03-24-2015 02:40 PM
Thanks for the quick response. Could you go into a bit more detail about what that means? I am not very strong with LabVIEW.
I will attach my codes to this post though. (Ignore the title "DecToBinary", when I named it, I didn't realize there was a difference between decimal formatting and integers)
03-24-2015 03:04 PM
03-24-2015 03:05 PM - edited 03-24-2015 03:18 PM
Try something like this....
(note that the diagram constants are formatted in binary for simplicity. It might be more efficient to mask after the split operation.
03-24-2015 03:11 PM - edited 03-24-2015 03:12 PM
I was thinking along the same lines as GerdW. I may have your send byte order swapped.