LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI code to LabVIEW

I am reading a binary string from a UDP port and am trying to convert it to numeric data.  A colleage is doing this in CVI and I am just trying to convert his code into LabVIEW code.
Below is the CVI code:
next=(0x00ff0000&(buf[4*x+1]<<16))|(0xff000000&( buf[4*x+0]<<24))|
       (0x000000ff&( buf[4*x+3]))|(0x0000ff00&( buf[4*x+2]<<8));
                  ff=(double)next; //*16.0; 
                     g_waveform[x]= ff/65536.0;
 
Attached is a picture of my LabVIEW code.
 
I am not getting the correct data.
 
Can anyone see an obvious problem?
0 Kudos
Message 1 of 13
(4,726 Views)
Look at the coercion dots. You have mismatched numeric representations. Your four elements from the index array operation are all U8 and after shifting a U8 by 8, 16, or 24 bits, there isn't much left. 😉
 
I am not much of a CVI guy, so I cannot really read the text code very well. Can you explain in english what it is supposed to do? Do you have some typical sample data and corresponding output?
 
Maybe all you need to do is remove the FOR loop and typecast your string to an U32 array instead? Just guessing.... 🙂
0 Kudos
Message 2 of 13
(4,706 Views)
Unfortunately, there is a language barrier between my colleage and I so I don't understand what he is trying to do in English. Smiley Sad
 
About all I know is that "buf" is a char array.  And I have a binary file from him but it is 4 mb.
 
I have pulled all of my hair out on this one.
0 Kudos
Message 3 of 13
(4,701 Views)
I do know that the first few numbers in the binary file should be...
3.270294, 3.224457, 3.253937...
Can you see anyway to reverse this process/conversion?
0 Kudos
Message 4 of 13
(4,697 Views)
The CVI code suggests that you're taking 4 8-bit elements at a time from "buf" and rearranging them such that the order is buf[0] buf[1] buf[2] buf[3] as a 32-bit integer, with buf[0] in the high byte.  That said, I'd write it very differently in LabVIEW.  Unfortunately I don't have LabVIEW on this computer so I hope a text explanation will be clear enough.

Use the decimate array to split your incoming buffer into 4 arrays.  Pass all 4 arrays into the for loop and enable auto-indexing.  Within the for loop, use "Join Numbers" three times - combine elements 0 and 1, and 2 and 3, and then combine those to get a 32-bit unsigned integer.  Convert that result to a double and divide by 65536, then wire that out of the for loop.  Does this produce the result you expect?

As a side note, I recommend leaving the conversion and division inside the for loop; in my experience that's faster.  If you do the conversion outside the loop you allocate both an array of integers and an array of doubles; if you do it inside the loop your integer is a scalar and you build only an array of doubles.

EDIT: No need even to do the decimate array and recombine; just typecast the array of U8 into an array of U32.

Message Edited by nathand on 04-13-2007 10:09 PM

0 Kudos
Message 5 of 13
(4,693 Views)


@DTR wrote:
I do know that the first few numbers in the binary file should be...
3.270294, 3.224457, 3.253937...
Can you see anyway to reverse this process/conversion?

That won't really help unless you also give us a chunk of the beginning of the binary file. 😉 Can you e.g. attach the first few hundred bytes?

I have a pretty good idea what needs to be done, but would like to test it first.

0 Kudos
Message 6 of 13
(4,691 Views)
Thanks for the help.
nathand - Attached is the LV that you suggested.  But the results didn't come out as expected.
 
altenbach - Also attached is the first 200 bytes of binary.
 
Thanks.
Download All
0 Kudos
Message 7 of 13
(4,675 Views)

Once you save it as a MS word document (*.doc") all useful information is lost. Just attach the entire binary file if you have problems splitting it. A word processor is not the right tool to operate on binary files. ;)!

nathand's code is probably much more complex than needed.

What is your LabVIEW version?

Message Edited by altenbach on 04-13-2007 07:53 PM

0 Kudos
Message 8 of 13
(4,664 Views)
Flying completely blind, here's a quick attempt at a solution. Maybe you need to add a few tweaks here and there.
 
(The string is set to display hex format. The "ToDBL" is not really needed, it would coerce automatically. That cross shaped thing is "typecast" from the "numeric...data manupulation" palette. The blue object is an empty array constant of type U32)
 
 
 
 

Message Edited by altenbach on 04-13-2007 07:58 PM

0 Kudos
Message 9 of 13
(4,659 Views)

altenbach,

I tried only attaching the binary file but when I tried to "submit post" from this forum, I got an error saying that only files of specific extensions are allowed.

0 Kudos
Message 10 of 13
(4,650 Views)