LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Integer to Binary Issues

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.

 

WorkingCode.PNG

 

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.

 

SecondCode.PNG

 

This code outputs the following (the substringLow and substringHigh were just placeholders for me to see what it was doing):

 

FrontPanel.PNG

 

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.

0 Kudos
Message 1 of 6
(3,033 Views)

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.

0 Kudos
Message 2 of 6
(3,029 Views)

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)

Download All
0 Kudos
Message 3 of 6
(3,026 Views)

Hi jrydell,

 

some basic integer math:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 6
(3,011 Views)

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.

 

 

Download All
Message 5 of 6
(3,010 Views)

I was thinking along the same lines as GerdW.  I may have your send byte order swapped.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(3,001 Views)