LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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

You need to initialize the BufferToWrite array to the correct length prior to passing it to the function. You can do this by inserting a "Reshape Array" function, or using "Initialize Array" instead of the array control, or by setting the minimum size in the Call Library Function Node configuration. Also, if you care about the data written into the buffer, then you should wire the output side of the buffer to an indicator.

Message 21 of 30
(1,303 Views)

NathanD,

 

Thanks for the quick reply.

 

I updated my VI to the following.  I used the ArraySubset function to determine how many bytes to write.  I've attached the updated VI.

 

How does it look?

 

Thanks so much!

0 Kudos
Message 22 of 30
(1,296 Views)

Sorry, again, can't open your VI - wrong version of LabVIEW. However, your description of what you did sounds wrong. I suggested three ways you could pass an allocated buffer to the DLL, and none of them involve Array Subset. You need to check the DLL documentation to see how large the buffer should be, and you MUST pass an array containing at least that number of bytes, otherwise the DLL calls may write into memory that isn't part of the buffer which will likely corrupt data or cause a crash. You have NO CONTROL over how many bytes the DLL writes to the buffer. The DLL doesn't know the size of the array it receives. It receives only a pointer to the start of that buffer, and it assumes that the buffer is large enough, so your LabVIEW code needs to make sure that the buffer is, in fact, large enough.

 

EDIT: sorry, should have looked more closely at the function. I assume the sizeToTransfer parameter does tell the DLL how large the buffer is. If that's the case, then you need to make sure the buffer matches that size. Also you should know if the sizeToTransfer is in bytes, or some other units (for example a number of 32-bit values) - if it's a different unit than the elements of the buffer, then you'll need to do some math to get everything to match.

Message 23 of 30
(1,291 Views)

Nathand,

 

Thanks for the info.  I have updated my VI and resaved as LabVIEW 2012.  I have attached it here.

 

Can you take a quick look at it?

 

Thanks so much!

 

0 Kudos
Message 24 of 30
(1,283 Views)

That looks fine. Personally I'd replace the "BufferToWrite" control with a constant, since the value is irrelevant.

 

My apologies if my last message came out sounding hasty and aggressive, was trying to write something quickly and didn't edit as I usually would.

Message 25 of 30
(1,280 Views)

NathanD,

 

I'm a bit confused when you say you would personally change the "BufferToWrite" to a constant since its value is irrelevant.  I am assuming that Buffer is the Bytes I want to write to the slave address.  In this case, the slave address registers are 2 bytes long so I chose the "SizeToTranfer" = 2 bytes and the "BufferToWrite" array = The 2 bytes I want to write to the slave address register.  Am I interpretting this wrong?

 

Thanks!

0 Kudos
Message 26 of 30
(1,268 Views)

I'm sorry for the confusing response. Let me try that again, now that I'm not trying to do other work and post to the forum at the same time.

I misread what your function is doing; I thought you were reading from the device, not writing to it. In that case you don't need the indicator for the buffer (it's being used as an input, not an output). Leave the BufferToWrite control alone, as you suggested. You could instead get rid of the SizeToTransfer control, and wire the size of the BufferToWrite array to that input.

Message 27 of 30
(1,252 Views)

Hi,

 

and sorry for reactivation this thread. I also use the libMPSSE.dll and i have a problem with the readDevice-function. I connect a simple EEPROM to a FTDI device and i am not able to read more than 1 byte of the received array. The write function works perfect. The first byte i receive is correct, but all other bytes are zero. I try to resolve the array with the MoveBlock-function, without any success. The dll-methode described in the documention is: FT_STATUS I2C_DeviceRead(FT_HANDLE handle, uint32 deviceAddress, uint32 sizeToTransfer, uint8 *buffer, uint32 *sizeTransferred, uint32 options).

I think the main problem is the correct dereferencing of the parameter *buffer. Do u have any solution?

 

thx and greetings

Stefan

0 Kudos
Message 28 of 30
(1,064 Views)

Stefan,

 

The buffer should be initialized as an array with the number of dimensions = to the Size To transfer.  Please see my screen shot.  Hope this helps.

0 Kudos
Message 29 of 30
(1,047 Views)

Thanks for your answer. I allready tested everything. Also your example and many other in this forum.  Luckily i found out, when i use a older version of libMPSSE.dll everything work fine. Thanks for the support.

 

Stefan

0 Kudos
Message 30 of 30
(1,036 Views)