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: 

How do I convert an array of BYTES (where each BYTE represents a bit) into a single Hex number?

I am reading a signal from a USB-8451. This signal is stored as an array where each element represents a bit in the signal, but is stored in the array as a byte. How do I convert this array into a single Hex number. I attatched what I have so far, there are a few extra things to help me see what ia going on. One code uses Queue and the other uses arrays, let me know if you can help.

 

Download All
0 Kudos
Message 1 of 9
(3,729 Views)

What device are you trying to communicate with? You seem to be trying to perform some sort of bit-banging to emulate an I2C interface.

 

As to your question: how many bits? What's the bit-size of the hex number? 8, 16, 32, 64?

0 Kudos
Message 2 of 9
(3,715 Views)

Have you tried using the DAQ Assistant on the Measurement I/O page?  When I try to read a bunch of bits from an NI USB 6009, the Assistant takes the bits I ask it to read and gives them to me directly as an array of booleans (i.e. as a "bit array").  Once you have it as an array of bits, you can use the Array to Number function on the Boolean palette to give you a U32, which you can display as a Hex if you want.  Note that you can probably wire a U8 instead of a U32, since Array to Number, by default, seems to "adapt to source" (which I think means "If I only see 8 bits, only spit out a byte").

 

Bob Schor 

0 Kudos
Message 3 of 9
(3,709 Views)

@BOB Schor wrote:

Have you tried using the DAQ Assistant on the Measurement I/O page?  


Can't use the DAQ Assistant with the 8451. That's an I2C/SPI device, not a DAQ device. Smiley Wink

0 Kudos
Message 4 of 9
(3,702 Views)

The final signal will contain 304 bits converted to a Hex number in order to make it easier to read and compare. The chip I am reading from is an I2C device, but I need to read it while mounted on the bord with other devices. So we need to be able to read it passivley without inputing any voltage to the circuit (I have the write outputs set up for simulation purposes only). Not sure what bit banging is, but that is probably what I am doing. I'm reading a clock triggerd digital signal.

0 Kudos
Message 5 of 9
(3,665 Views)

There is no 304-bit number in the universe I live in. Not sure about yours. So, please explain what you mean by 304 bits converted to a hex number. Are you talking about 76 4-bit numbers? 38 8-bit numbers? 19 16-bit numbers?

 

I also don't understand what you mean by "read it passivley without inputing any voltage to the circuit". If you don't power the chip how are you going to read from it? Are you referring to stimulus? If so, what does that have to do with reading from the device? Reading information over the I2C is separate from what the chip does.

 

You still have not mentioned the device you are talking to.

0 Kudos
Message 6 of 9
(3,658 Views)

I am reading 304 bits from a digital signal. Need to convert them to hex values, they can be 16bit words in hex, just need enough to include 304 bits. The circuit is power by another source, I have to verify that when the circuit is powered on that the signal that is sent is correct, so we can't introduce any other forms of signals or power into the circuit other than what the circuit already has. Trithfully I don't really know how I2C devices work, but my mentor here says that we can't use an I2C method becuase it will introduce voltage into the circuit and may damage out TCON chip.

0 Kudos
Message 7 of 9
(3,653 Views)

Hi mkssnwbrd,

 

If you already have the bit array, try something similar to this (It currently generates an array to parse through).

Cheers!

TJ G
0 Kudos
Message 8 of 9
(3,629 Views)

@mkssnwbrd wrote:

... so we can't introduce any other forms of signals or power into the circuit other than what the circuit already has. Trithfully I don't really know how I2C devices work, but my mentor here says that we can't use an I2C method becuase it will introduce voltage into the circuit and may damage out TCON chip.


That makes absolutely no sense. What do you think is happening when you write the digital lines? You're setting a pin high. That voltage is being generated by the 8451x. I think you're not understanding what your mentor is saying. If it's an I2C device then you should be able to use the I2C function to simply talk to it. You still have not indicated what the device is, so there's little more I can say about that aspect of it.

 

As far as the conversion is concerned, you basically need loop through your array of "bits", taking 16 at time since you said you have 16-bit values. It's not clear from your code whether your eventual goal is to get a numeric value or a string. This does not appear to be a subVI, so a simply numeric indicator formatted to display in hex format should be quite adequate. The array you are generating is an array of rings, whose datatype is I32, but they will have values of 0 or 1. You can use the example just posted, or you can use the attached variation.

0 Kudos
Message 9 of 9
(3,613 Views)