LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Call Library Function Node To Return C++ Structure Information

I'm currently on LabVIEW 2012, but if you can save back a version I'd be happy to look at it.

 

See the help: a cluster is always passed by pointer, and the Data Format settings has no effect for a cluster. Make sure you have chosen the correct calling convention. Also note (perhaps you've already done this, can't see your VI) that you must replace the embedded arrays with clusters containing the correct number of elements; you cannot replace a fixed-size array with a LabVIEW array.

Message 11 of 30
(2,367 Views)

Thanks Nathan.

 

I have resaved this VI for LabVIEW 2012.  If you still have issues viewing it let me know and I will send out screenshots.

 

Thanks again.

0 Kudos
Message 12 of 30
(2,354 Views)

Again, you must replace fixed-sized arrays with CLUSTERS containing the same number of elements. A string won't work. Also, the correct calling convention for this DLL is almost definitely "C" and not "WINAPI". See modified VI attached.

Message 13 of 30
(2,346 Views)

Thanks Nathan.  That did the job Smiley Wink

 

Where in the LabVIEW help section for the Call Library Function Node does it explain that you must replace fixed-sized array with CLUSTERS?  I think in the regular LabVIEW help this information is missing.

0 Kudos
Message 14 of 30
(2,317 Views)

It's not in the help for Call Library Function Node, but it is in many of the forum posts on this topic (as well as in my earlier post in this thread). The relevant help information is "How LabVIEW Stores Data in Memory" combined with an understanding of how a C program stores structs. The help for Call Library Function assumes some understanding of C, as it would be impractical for the help to provide a sufficiently detailed lesson in C to cover every possible complicated structure that might be passed to a DLL. I haven't tried it recently but apparently the DLL import tool has gotten better at automatically generating LabVIEW equivalents for some complex structs, so you could try that too and see if it works.

Message 15 of 30
(2,310 Views)

Nathan,

 

Thanks for your help.

 

I have one more example CLFN VI that I am having trouble with.  This dll function reads the specified number of bytes from an addressed I2C slave device:

 

FT_STATUS I2C_DeviceRead (FT_HANDLE handle, uint32 deviceAddress, uint32 sizeToTransfer, uint8 *buffer, uint32 *sizeTransferred, uint32 options)

 

Parameters:

In = handle (Handle of channel)

In = deviceAddress (7 bit address of the I2C slave)

In = sizeToTranfer (Number of bytes to be read)

Out = buffer (Pointer to the buffer where data is to be read)

Out = sizeTransferred (Pointer to variable containing the number of bytes read)

In = options

 

I keep on getting an error from the dll saying the slave device is not found found.

 

I have attached my VI.  Can you please take a look at it?  I would really appreciate it.

 

Thanks so much for your help!

0 Kudos
Message 16 of 30
(2,287 Views)

You took the description of the function way to literally. Eventhough it says "pointer to the buffer" the function really needs an entire buffer preallocated by the caller to write into.

 

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 17 of 30
(2,283 Views)

rolfk,

 

Thanks for your help.  That makes sense.  Is there a reason you connected the Options parameter also into the Initial Array dimension size?  Shouldn't it be the sizeTransferred parameter connected to the dimension size input?

0 Kudos
Message 18 of 30
(2,272 Views)

Oops, a typo! or how do you call this in LabVIEW speak? Smiley LOL

But no it shouldn't be "size transfered" but "Size To Transfer"!

 

And you should arrange the parameters in the correct order!!!!

 

FT_STATUS I2C_DeviceRead (FT_HANDLE handle, uint32 deviceAddress, uint32 sizeToTransfer, uint8 *buffer, uint32 *sizeTransferred, uint32 options)

 

 

options is the last parameter in the parameter list

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 19 of 30
(2,267 Views)

Rolfk,

 

I want to use the FT_I2C_DeviceWrite function in the dll library as well using the CLFN function in LabVIEW.  The dll function is as follows:

 

FT_STATUS I2C_DeviceWrite (FT_HANDLE handle, uint32 deviceAddress, uint32 sizeToTransfer, uint8 *buffer, uint32 *sizeTransferred, uint32 options)

 

In (handle) = Handle of channel

In (deviceAddress) = Device Address

In (sizeToTransfer) = Number of bytes to be written

Out (buffer) = Pointer to buffer from where data is to be written

Out (sizeTransferred) = Pointer to variable containing the number of bytes written

In (tranferOptions) = Data tranfer options

 

I'm pretty sure I know how to do this based on the FT_I2C_ReadDevice function.  I have attached the VI to this post.

 

Could you take a look at it and make sure I set up everything right?

 

Thanks so much for your help!

0 Kudos
Message 20 of 30
(2,244 Views)