Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Function in LabView 6i to access U2C_SpiReadWriteSS transfer routine used by Diolan interface adapter only returns the first byte from the SPI Slave

I'm using the Call Library Function in LabView 6i to access the i2cbrdg.dll library for the U2C-12 USB-I2C/SPI/GPIO Interface Adapter from Diolan.com. I'm trying to use the U2C_SpiReadWriteSS transfer routine. The write function works but the read function only returns the first byte from the SPI Slave device. I've attached the LabView test program that I'm using for development. Do you have any suggestions as to what the problem might be? Thanks for any help you can provide!

0 Kudos
Message 1 of 17
(4,813 Views)
Hi Paul,
 
I was not able to find much information on this topic.  I did find the product page, and Diolan offers email support, so I would suggest asking them if they know if any issues with that dll.
 
 
 
Regards,
 
Kevin H
 
National Instruments
WSN/Wireless DAQ Product Support Engineer
0 Kudos
Message 2 of 17
(4,793 Views)

Hi Kevin,

Thanks for the reply. I've already sent an email to Diolan but haven't gotten a response yet.

Best Regards,

 

Paul

0 Kudos
Message 3 of 17
(4,791 Views)
Simple. You're running the loop only once because you've wired a 1 to the "N" input. And, since you're auto-indexing the "Send Data", it's only pulling off the first array element. If you auto-index a for-loop the "N" should not be wired. You should read the LabVIEW documentation on for-loops.

That function is not indended to be used the way you're using it. In fact, you should have no loop.

Also, you seem to still be programming based on, presumably, using the continuous run button. I noted this in my previous response.
Message 4 of 17
(4,767 Views)
Thank you for the information. As I mentioned before I'm new to LabView, so I appreciate your patience with my ignorance. I tried removing the input to "N" but this causes multiple messages to be sent when I send more than a one byte message. You said I should not use a loop for this function. How do I connect a source type of an array to a sink type of an unsigned byte without using a loop? I get a data type mismatch error when not using a loop. Thanks again for you help.
0 Kudos
Message 5 of 17
(4,747 Views)
You need to change the "Type" for the arg2 parameter from "Numeric" to "Array". Likewise for the one that's supposed to be the output. You will need to allocate memory for the output by precreating an array and feeding it to the left side. Check the examples that ship with LabVIEW. There's a very detailed example that shows you how to use the Call Library Function with various types of data.


Message Edited by smercurio_fc on 01-31-2008 11:19 AM
0 Kudos
Message 6 of 17
(4,743 Views)
When I change the data type to array and run it, an error is generated that causes LabVIEW to shut down. I've looked at the examples that come with LabVIEW and have not found them helpful in solving this problem. As I mentioned earlier the write to the SPI device works fine. The problem is with reading the SPI devices response. For some reason only the first byte is returned. When I monitor the SPI line both the sent and received bytes are there.
0 Kudos
Message 7 of 17
(4,734 Views)
Did you set the argument for the output to be an array as well? Did you pre-allocate the memory for it like I indicated? When you call a DLL that fills in an array you must allocate the array in LabVIEW and pass it to the function. I don't use the U2C_SpiReadWriteThis is the code I have for the U2C_SpiReadWriteSS function. I use the separate Write and Read functions. This is my SPI Read, and it works every time:

Note that the array is being preallocated.

Also, in your example you are passing in 1 for the length, which is based on the value of the "Bytes Sent" control. The length in your case should be based on the size of the "Send Data" array, not an arbitrary control value.



Message Edited by smercurio_fc on 01-31-2008 05:19 PM
0 Kudos
Message 8 of 17
(4,727 Views)
Thank you so much for your patience and help. As the saying goes a picture is worth a thousand words. The U2C_SpiReadWriteSS function is now working just fine because of your assistance. Caulk another one up for smercurio_fc!
0 Kudos
Message 9 of 17
(4,714 Views)
Glad you got it working.

I'm not sure which examples you looked at for using the Call Library Function, but the example I had in mind was the "Call DLL" example. If you open the Example Finder (Help->Find Examples), switch to the search tab, and enter DLL in the search box, you will see it listed. It contains many examples, including one for 1D arrays. Just run the VI, select the row and click the "Open Example VI for the Current Datatype".
0 Kudos
Message 10 of 17
(4,711 Views)