From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a string of bits to send out through VISA Serial questions, complete noob here...

Solved!
Go to solution

127 decimal = 111111 binary.

 

Try setting the format string on the Format Into String connected to Messages to %b

 

Lynn

Message 11 of 29
(1,207 Views)

This is an interesting way of getting the final character.  What are you trying to do here?

 

If you are after individual bits, you need to convert to a boolean array.


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
Message 12 of 29
(1,194 Views)

@crossrulz wrote:

This is an interesting way of getting the final character.  What are you trying to do here?

 

If you are after individual bits, you need to convert to a boolean array.


Thanks for the reply...

 

I can't find how to convert from a byte array to a boolean array.....suggestions?

 

The earlier poster that showed how a boolean array could be transformed to a byte array using the >0 was interesting....is there another comparison, or other component that I can use to convert from byte array to boolean array....?

 

TIA,

 

cayenne

0 Kudos
Message 13 of 29
(1,178 Views)

cayenne,

 

One issue is just what you want the output array to look like. Do you want a 2D array where each row reperesents the bits in one byte or do you want a 1D array with the booleans concatenated?

 

Here is how you could do the first.

 

Byte array to boolean array.png

 

The other is a bit more involved.

 

Lynn

Message 14 of 29
(1,174 Views)

@johnsold wrote:

cayenne,

 

One issue is just what you want the output array to look like. Do you want a 2D array where each row reperesents the bits in one byte or do you want a 1D array with the booleans concatenated?

 

Here is how you could do the first.

 

Byte array to boolean array.png

 

The other is a bit more involved.

 

Lynn


I believe the 2D array is best way...I could more easily go through each byte at a time to parse them, and act on them.

 

I see in the functions pallete, the number to array component you used in the loop...but where is the boolean array object you're feeding into there? I can't find that.....

 

From your example I'd go something like?

 

byte_array_from_serial_to_boolean_array.png

Thank you,

 

C

 

0 Kudos
Message 15 of 29
(1,169 Views)

It's an indicator.

 

Wire from the Number to Boolean Array to the edge of the For Loop.  You should wind up with an auto-indexing tunnel.  Then right click on that and choose Create Indicator.

 

PS:  You don't need to get the Array Size and wire that to the N node of the loop.  That is taken care of automatically by the auto-indexing input tunnel.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

Message 16 of 29
(1,174 Views)

@Ravens Fan wrote:

It's an indicator.

 

Wire from the Number to Boolean Array to the edge of the For Loop.  You should wind up with an auto-indexing tunnel.  Then right click on that and choose Create Indicator.

 

PS:  You don't need to get the Array Size and wire that to the N node of the loop.  That is taken care of automatically by the auto-indexing input tunnel.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours


Ok...an indicator...that was what was throwing me off.

I'm needing to initially display this into a text box....iterating through the array....converting it to string, and printing each row of bits for each byte, a carriage return , then the next.

I need this  to start out with, to show what I'm receiving on the screen...I'm going to have messages going back and forth eventually...and am trying to use the text box "Messages" (indicator seen on the other vi examples I'd show where I had it totally wrong)...but I was wanting to show each byte array as a row on the text box area indicator and have them scroll by as they were received (will also later put in there what is sent, so I can compare sent to received).

 

Is this closer to what I'm needing to do?

 

byte_array_from_serial_to_boolean_array_2.png

 

I can't connect to the Messages area yet...I'm just not getting how to iterate through this byte array, and convert it to rows to print to the screen...

 

Dislplaying on the Messages area like

11100001

11111111

11111110

 

etc...

 

Thank you for the links...I'm trying to look through all of those now too!!!

 

I've been trying to learn all this from my read through of LabView for Everyone. I'll need to go back to find the chapters on for loops and the index tunnels, etc...looking into all this now.

 

If I can just get this example in my head and vi down...I think I can figure it out....I've just never tried working with bits and bytes before...very confusing, and not nearly as straightforward as working with text/strings, with construction, parsing, regular expressions, etc....

 

cayenne

0 Kudos
Message 17 of 29
(1,167 Views)

cayenne,

 

Based on your last comments I suggest that you take pencil and paper and write down what is on each of the wires in that segment of code.

 

At the output of the VISA Read write down the value of the string - just like it would look on a string indicator.  Use some real data, perhaps simplfied to meake it easy to understand.

 

Then write down the values in the byte array.  Then the boolean array inside the for loop.  And so on.  Make sure that you understand how each transformation works.

 

This may help you understand how all the characters, bytes, bits, and arrays of these work.

 

Even though I have been programmming for more than 40 years, I still do things like this when I think it will help me understand what is going on.

 

Lynn

Message 18 of 29
(1,162 Views)

@johnsold wrote:

cayenne,

 

Based on your last comments I suggest that you take pencil and paper and write down what is on each of the wires in that segment of code.

 

At the output of the VISA Read write down the value of the string - just like it would look on a string indicator.  Use some real data, perhaps simplfied to meake it easy to understand.

 

Then write down the values in the byte array.  Then the boolean array inside the for loop.  And so on.  Make sure that you understand how each transformation works.

 

This may help you understand how all the characters, bytes, bits, and arrays of these work.

 

Even though I have been programmming for more than 40 years, I still do things like this when I think it will help me understand what is going on.

 

Lynn


Thank you. Good advice.  I think I'm a bit closer now, and have done what you said, and I've set a bunch of probes, and breakpoints, to go through and see how things really were working.

 

I'm much closer now, but have a question at the end, where I'm receiving the byte array back..I've successfully converted it back to a boolean array.

 

At this point, I'm trying to use an Array Subset, to grab off the first 8 bits, but it seems to be sending them all for some reason, and I'm a bit stuck.

 

I'm attaching the vi to this point.

 

Here is the section where I"m trying the subarray that isn't working like I thought it would:

byte_array_from_serial_to_boolean_array.png

 

 

 

 

This is the readings on the probes:

 

byte_array_to_bool_array_to_string.png

 

 

 

 

 

0 Kudos
Message 19 of 29
(1,151 Views)

cayenne,

 

I am not sure what you are expecting that you are not getting. The bytes are there. The bits are ordered with the least significant bit on the left. Since 127 has seven 1s the eighth bit is a zero.  It is there because averything is done in 8-bit bytes.

 

Lynn

0 Kudos
Message 20 of 29
(1,141 Views)