LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array pointer from dll

Rolf,

 

Thanks for the VI, it works great.  When it comes to allocating the memory in C code, it is done with the following command:

 

char* data = 0;

data = new char[TraceHeaderSize + 2*pointspertrace];

 


The size of the Trace Header is constant at 40 bytes but the points per trace will vary.  I don't have much experience with C, so how many bytes are these commands allocating? Let's say the pointspertrace is 100, is it 240 bytes?  If I wire an I32 variable = 240 to my bufbytesz input on my Call Library node, will it allocate 240 bytes or 240*4 as you mentioned in the previous post??

 

Any and all help is greatly appreciated, sorry for being such a rookie, and thanks again for helping me learn.

 

Adam

 

 

0 Kudos
Message 31 of 36
(1,390 Views)

@AdamBlues wrote:

Rolf,

 

Thanks for the VI, it works great.  When it comes to allocating the memory in C code, it is done with the following command:

 

char* data = 0;

data = new char[TraceHeaderSize + 2*pointspertrace];

 


The size of the Trace Header is constant at 40 bytes but the points per trace will vary.  I don't have much experience with C, so how many bytes are these commands allocating? Let's say the pointspertrace is 100, is it 240 bytes?  If I wire an I32 variable = 240 to my bufbytesz input on my Call Library node, will it allocate 240 bytes or 240*4 as you mentioned in the previous post??

 

Any and all help is greatly appreciated, sorry for being such a rookie, and thanks again for helping me learn.

 

Adam

 

 


Well since the datatype that gets created is char the number is actually bytes. But then the 2 in that expression would indicate that the data elements are not int32 but really int16 (or uInt16) elements.

 

But where in that expression comes the numberOfTraces that your LabVIEW VI uses?

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 32 of 36
(1,379 Views)

A "char" is one byte, equivalent to a U8 in LabVIEW. The C++ code you show (C doesn't have a "new" keyword) allocates TraceHeaderSize + 2*PointsPerTrace bytes, so if pointspertrace is 100, it will allocate 240 bytes and you should wire 240 to bufbytesz. The array that you initialize should be of type U8, not I32 (that's the type of the input to Initialize Array).

 

Personally I would make buf a 1D array instead of a 2D array. Then you can also configure the CLFN for a 1D array with the minimum size of buf set the bufbytesz (not necessary, but possible helpful).

Message 33 of 36
(1,375 Views)

Hey Forum,

 

I really appreciate all the help that you have given me in the past week, it's allowed me to make some big advances with my VI.

 

Currently, I have my VI initializing an array of UINT8 that is populated with individual byte values when I run my read function.  Now, I need to take those bytes and convert them to meaningful data.  For example, I need to take the first two bytes and convert them to a UINT16.  I've tried doing this with the Typecast, join numbers, swap bytes, etc, but haven't had any luck.  I know that the first value represented by the first two bytes should be 40 so I can use this to test my byte manipulation methods.  

 

Is UINT8 in LabVIEW the equivalent of 'char' in C++?

 

Any advice?

0 Kudos
Message 34 of 36
(1,360 Views)

Hi Adam,

 

Could you post a screenshot of your code?  It would help to see exactly how you are going about trying to do the conversion.

 

 

James K.
National Instruments
Applications Engineer
0 Kudos
Message 35 of 36
(1,342 Views)

Well Join Numbers should definitely work. Also since you say the number should be 40 you should actually see a 40 in the first byte and a 0 in the second byte. If you don't then the function either does not return the data you think it should return or the data you think should be returned is wrong.

 

Since the rest of the data is appearently also 16 bit numbers (the factur 2 in the calculation it may be easier to create the entire array as (u)int16 from the beginning (and adjust the size of the array accordingly of course). But you have the Vi's the library and the hardware, so you will have to do the legwork. Smiley Very Happy

Rolf Kalbermatter
My Blog
0 Kudos
Message 36 of 36
(1,332 Views)