LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

byte conversion

I have a read function that collects a vector of nbytes of data from an external memory device using memory addresses.  These bytes are an amalgamation of multiple data types (U16, U32, doubles) that need to be parsed into their respective variables.  I'm doing this by taking the corresponding elements in the vector, flipping them to the correct for endianess, and type casting the multiple bytes to a single value.

 

To speed up the data transfer process, I can transfer multiple vectors of nbytes as a matrix.  However, my speed up in reading the data from the device is thwarted since I have to move through the data one vector at a time to parse it into values (cannot type cast a 2D array).

 

The bytes allotted for each vector are as follows:

 

U16

U16

U32

U32

U32

Double

Double

U32

U16

U16

 

If there are any suggestions you may offer, I would greatly appreciate them.  Thank you for your time.

 

Adam

0 Kudos
Message 1 of 10
(3,871 Views)

Create a cluster with the correct datatypes in the correct order and use descriptive element labels. Now simply unflatten to that cluster and unbundle later as needed. Maybe you could use an array of such clusters.

 

See this old example (posted here)

 

 

Can you show us some typical code?

Message 2 of 10
(3,858 Views)

Wow, this is great, I knew that making a structure with the data types had a role in solving the problem. Thanks!

 

Will this work for a matrix of byte data with the vector of nbytes along one row of the matrix?  How can I adapt it to act on the matrix instead of the vector?

 

Adam

0 Kudos
Message 3 of 10
(3,848 Views)

Here is an .vi that I have working now, but it's the hard way around the problem that I explained before.  I'm not sure if I can get a string out of my read function, maybe you could take a look at it and get back to me.  Thank you for all your help.

 

Aadm

0 Kudos
Message 4 of 10
(3,842 Views)

Can you run your VI so the "Byte array" indicator contains data, then right-clich the terminal and create constant. Delete everything else except the constant and the conversion code. (alternativley, do the same with the 1D array a few steps earlier)

 

You have way too many local variables and associated hidden indicators. "Tracematrix" and "trace" belong in shift registers. No hidden indicators needed. Why do you read "trace" twice in parallel in the last inner frame? Why not read once and branch the wire?

 

(For reference, here my earlier code, but dealing with arrays)

Message 5 of 10
(3,824 Views)

Thank you for your help.  My poor LabVIEW skills aside, it works, and you're helping me make it better.  

 

I'll get a filled byte array and post it shortly, but in the meantime:

 

Is there an automated way to vary the size of the template cluster?

 

The first 40 bytes are always the same in my application, the remaining bytes are all I16 data that will vary in length depending on how I set up the data collection.  Is there a way to create a template with a variable number of I16 slots at the end, and then replicate that template depending on the number of vectors I would like to read?

 

I'm amazed at your rapid responses and I think I'm really close to figuring this out, thanks again for your time.

 

Kind Regards,

Adam

0 Kudos
Message 6 of 10
(3,819 Views)

@AdamBlues wrote:

 

The first 40 bytes are always the same in my application, the remaining bytes are all I16 data that will vary in length depending on how I set up the data collection.  Is there a way to create a template with a variable number of I16 slots at the end, and then replicate that template depending on the number of vectors I would like to read?


I would probably split the string at 40 bytes and parse the first part as above. Then unflatten the rest as I16 array. Still much simpler.

 

 

0 Kudos
Message 7 of 10
(3,814 Views)

Here is a .vi that I have working using the flatten and unflatten to string functions.  Also, this version has a constant (buf) saved that contains typical data streaming out from the device.  I'm not sure why I need to have a different endianess for the later part of the data, but that's the only way I can get the data to make any sense.  I tried producing a string directly from my read function so I wouldn't have to flatten the data to a string first, but I got LV Error #47 from the unflatten from string function regardless of the endianess I chose.

 

I appreciate any help you can offer to me in solving this problem. Thank you for your time.

 

Adam

0 Kudos
Message 8 of 10
(3,789 Views)

Notice the coercion dot on the cluster terminal? Your indicator is a very different cluster compared to the casting constant. That's not good.

 

constant: U16 U16 U32 U32 U32 DBL DBL U32 U16 U16

indicator:  U16 U16 U32 U32 DBL DBL U16 U16 U32 U32

 

0 Kudos
Message 9 of 10
(3,773 Views)
Yes, I've fixed that. Everything is working great now and its super efficient given your advice. Thank you.

Adam
0 Kudos
Message 10 of 10
(3,767 Views)