12-08-2009 11:30 AM
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
12-08-2009 12:00 PM
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.
12-09-2009 02:21 PM
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
12-09-2009 02:42 PM - edited 12-09-2009 02:44 PM
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.
12-09-2009 05:26 PM
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.
12-09-2009 08:08 PM
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.
12-10-2009 01:55 PM
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
12-10-2009 09:55 PM
12-11-2009 10:07 AM
A cluster = struct.
Ofc you can solve your fixed arrays in C with structs, but i dont think you do. 😉
/Y
12-31-2009 09:21 AM
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.