LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I process serial port strings as bits

In response to my commands, my instrument is sending bytes to my serial
port. In one instance, 2 bytes are received. I want to treat these 2 bytes
as a group of 16 bits.

The VISA and Compatibility Serial functions return these bytes from the
serial port to Labview clearly labelled a "string".

Everything I can find in the way of Labview functions and .vis don't want to
do bit twiddling, bit swapping, and bit dropping, with "string" data.

I thought "hex string to number" could be used here, but I can't find a way.
The 2 Bytes in question can be represented as hex, but the data are not the
ASCII codes for the hex representation of a binary number, they are the
binary number. This "hex string to number" seems to want ASCII c
odes.

You can feed a hex number typed into a "control" box wired into "hex string
to number" and you get a meaningful number. You can feed the 2 bytes from
the serial port into an "indicator" set to read in hex and you get a hex
number that is a correct representation. But that is Labview handing them
around to itself. I need to get my "hands" on them.

I can't feed those same bytes that show up as a correct hex representation
in an indicator into the "hex string to number" or anything else, so far,
and get a number that is useful for further processing.

I thought "variant to data", but I can't find enough reference material to
understand how to use it. A boolean array seems like a bit of a weird
approach, so I thought I'd ask before I looked into that.

I'm used to dealing directly with binary numbers on the processor stack, I
call them whatever I want, and turn them into anything I feel like.
..
I'm sure I'm staring the solution in the face, but I can't find any way to
persuade
Labview to treat this "string" data as 16 bits.

I've got the 16 bits, which is better than not having them, but I don't have
much hair left.
0 Kudos
Message 1 of 5
(3,177 Views)
In another words, you want to create a VI in which the input is 2 strings (i.e. AB) and the output is the converted array bits (e.g. 1010101010101010)?
0 Kudos
Message 2 of 5
(3,177 Views)
In Case I understood what you wanted, here is one way to get the strings represented as bits....you can configure the connectors in this VI to meet your needs and use it in your application!
Best wishes
0 Kudos
Message 3 of 5
(3,177 Views)
The two bytes would come from a serial port read.vi in Labview, classed as a
string. For instance, D3 and 02. The output would swap the two bytes, i.e.
to 02 and D3, consider the two swapped bytes as 16 bits, drop the six most
significant bits, and output the ten bits that are left as an integer
classed by Labview as some kind of number, not a string.

Your example StringToBits_Converter.vi I found on the ni.com site
unfortunately gives an error message and refuses to open on my system saying
it comes from a newer version of Labview 6 than I am running. Mine says
6.0.1b3. Thank you very much anyway.

"FightOnSCTrojan" wrote in message
news:50650000000500000033150100-1042324653000@exchange.ni.com...
> In another words, you want to create
a VI in which the input is 2
> strings (i.e. AB) and the output is the converted array bits (e.g.
> 1010101010101010)?
0 Kudos
Message 4 of 5
(3,177 Views)
duh, well I finally discovered the "Unflatten from String" function. A guy
just feeds in the bytes he's collected from his serial port that Labview
thinks are a "string", and out come lovely little unsigned 16 bit numbers,
or whatever other type of number he wants to turn the bytes into. And there
are great little bit twiddlers available after that, like "swap bytes", and
you can mask out bits with the logic operators, why this is fun. There's
nothing like being a moron...... fly me to the moon...................
: )

"David Lewis" wrote in message
news:bh1mse01anm@enews2.newsguy.com...
> The two bytes would come from a serial port read.vi in Labview, classed as
a
> string. For instance, D3 and 02. The output wou
ld swap the two bytes,
i.e.
> to 02 and D3, consider the two swapped bytes as 16 bits, drop the six most
> significant bits, and output the ten bits that are left as an integer
> classed by Labview as some kind of number, not a string.
>
> Your example StringToBits_Converter.vi I found on the ni.com site
> unfortunately gives an error message and refuses to open on my system
saying
> it comes from a newer version of Labview 6 than I am running. Mine says
> 6.0.1b3. Thank you very much anyway.
>
> "FightOnSCTrojan" wrote in message
> news:50650000000500000033150100-1042324653000@exchange.ni.com...
> > In another words, you want to create a VI in which the input is 2
> > strings (i.e. AB) and the output is the converted array bits (e.g.
> > 1010101010101010)?
>
>
0 Kudos
Message 5 of 5
(3,177 Views)