LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C code to LabVIEW specifics

Hello, I have a question concerning converting C code into LabVIEW. I have the following two lines of code:

 

HANDLE hDevice; // Handle to the SpaceWire device
unsigned char packet[10]; // The packet to be transmitted 

 

How would I translate this into LabVIEW? 

 

Thanks, 

Andrea 

0 Kudos
Message 1 of 15
(4,470 Views)

A HANDLE type is usually a u32 (ithink unsigned but youy can check the header file) and the char[10] can be created with a 10 element u8 array.

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 15
(4,457 Views)

Hi, Please excuse me for asking very basic questions, I am new to this. 

 

To provide some more background information, the DLL I am using is an API. This handle is to open the USB device. Is the type u32 same as a void pointer? The documentation to the API says it is a void pointer. Would the u32 be output from the DLL, or is it input? 

 

Thanks, 

Andrea 

0 Kudos
Message 3 of 15
(4,426 Views)

I'd expect that the DLL has a call to open the device that will return the handle as an output, and that you'll then use that value as an input to other functions in the library.  A U32 is a unsigned 32bit value, which is the same size as a pointer on a 32-bit architecture.

 

Also, for your array, you should use a cluster of 10 elements in LabVIEW to get the same fixed-size behavior.  Using a LabVIEW array will not work since arrays in LabVIEW are of variable size.

Message Edited by nathand on 12-09-2009 03:44 PM
0 Kudos
Message 4 of 15
(4,420 Views)

nathand wrote: 

Also, for your array, you should use a cluster of 10 elements in LabVIEW to get the same fixed-size behavior.  Using a LabVIEW array will not work since arrays in LabVIEW are of variable size.


That is not correct. I call DLLs that take in arrays and I create the arrays in LabVIEW using Initialize Array all the time. The Initialize Array will return an array of a specified size. 

0 Kudos
Message 5 of 15
(4,394 Views)

smercurio_fc wrote:

That is not correct. I call DLLs that take in arrays and I create the arrays in LabVIEW using Initialize Array all the time. The Initialize Array will return an array of a specified size. 


Thanks for the correction.  As soon as I see a fixed-size array in C I immediately think of it as a LabVIEW cluster, but it's only actually necessary for arrays embedded in structs.

0 Kudos
Message 6 of 15
(4,386 Views)

Okay, I was able to set up the array, fairly simple, thanks! 

 

I've been trying to find an example for this, but typically how is the void handle set up? Currently, I was able to set the dll to the numeric type of unsigned 32-bit integer, and the pass is a pointer to value. I understand that an array is supposed to be passed into this -- typically, how is this array set up? Also, would there be an example I would able to consult? I was not able to find much online, unless I haven't been looking in the right direction. 

 

Thanks, 

Andrea 

0 Kudos
Message 7 of 15
(4,349 Views)
There is an extensive example that ships with LabVIEW that shows you how to call DLLs with various parameters. Open the Example Finder and search for "DLL". The example you're looking for is "Call DLL".
0 Kudos
Message 8 of 15
(4,316 Views)

A cluster = struct.

 

Ofc you can solve your fixed arrays in C with structs, but i dont think you do. 😉

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 15
(4,292 Views)

Hello, going back to this posting from a few weeks ago ... I thought I got it working, but I guess I don't.

 

Here is the line of C code to open the device: 

int USBSpaceWire_Open(HANDLE* phDevice, U32 nDeviceNum);

 

Here is a line of code the HANDLE is going to: 

int CFGSpaceWire_GetNumberLinks(star_device_handle hDevice, U32 *dwNumLinks);

 

Currently, I can get the  int USBSpaceWire_Open(HANDLE* phDevice, U32 nDeviceNum); to operate, the device opens with no problem. Using a Call Library Function Node, I set phDevice to a numeric of an unsigned 32 bit integer, passing in a pointerto value.

 

However, I can't seem to get int CFGSpaceWire_GetNumberLinks(star_device_handle hDevice, U32 *dwNumLinks); to work correctly. I'm trying to pass in the phDevice to hDevice. I've tried setting hDevice to a numeric type of an unsigned 32-bit integer, passing either a value or a pointer to value. They both seem to be giving errors. Am I perhaps misunderstanding this?

 

I've attached a simple code of my explanation. 

0 Kudos
Message 10 of 15
(4,134 Views)