LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

The call by reference of pointer for the DLL made by C language

Solved!
Go to solution

(1) My purpose

I am trying to operate AD7190 by using FT4222H and its library called LibFT4222(dll file) under the control of Labview.

The communication protocol is SPI.

 

(2) Problem

I loaded the DLL functions as the library function in the block diagram.
Then I constructed block diagrams with these functions and "Document(LibFT4222)" attached this question.

At this time, I noticed that I must call not data directly but the pointer of data for DLL functions when I proceed the communication via SPI.

The topic named "3.3.5 SPI Master Single Read and Write"(Page.33) of attached Document says like that. 

 

(3) Question

So I thought following three steps may be required.

1. Store the variables with the data which I want to write to or read from AD7190

2. Get the address of variables.

3. Store the pointer with the address and call by reference for DLL function

Can I execute these process on Labview?

Or should I consider any other method...?

 

And I will attach the screenshot of block diagrams divided 3 parts for help you.

Green and blue VIs are functions of LibFT4222 and VIs with FTDI's symbol is API of D2XX driver.

 

Thank you very much for reading.

0 Kudos
Message 1 of 9
(4,239 Views)
Solution
Accepted by topic author sea_of_electron

Sending values by it's pointer is an option in the Call Library Function Node.

 

For (unclustered) values, simply enable it.

0 Kudos
Message 2 of 9
(4,227 Views)

Hello,

 

Thank you for your reply.

As you say, I can call by reference automatically to DLL by write data.
It seemed I had some misunderstanding...

 

Thank you very much

0 Kudos
Message 3 of 9
(4,192 Views)

Hi,

how did you create the spi block?

I'm trying to import the LibFT4222 dll without success.

Thank you.

Best Regards,

Michele

0 Kudos
Message 4 of 9
(4,064 Views)

Hi, Michele.

I will show you how to import and create LibFT4222 VIs include SPI blocks.

And I am afraid that this is really complicated so instructions will be long 😞

In addition, I am not English user so representation of labview option may not be correct completely...

 

[1] HOW TO MAKE VIs YOU WANT

(1) Before you lunch Labview, please create folder which contains "LibFT4222.dll", "LibFT4222.h", "ftd2xx.h", "stdint.h", "xstdint.h".(totally 5 files)

Leading three files are distributed by FTDI website, and you can get remaining two files from any other website.

(2) Next please lunch Labview application and you will see main-manu appeared firstly.

(3) Then click "Tool" tab.

(4) Next You should click "Import""Shared library(.dll)"

(5) Select "Create VIs for shared library" (please do not select remaining one for renew)

(6) Next you must select dll file and h file, so please select "LibFT4222.dll". Then "LibFT4222.h" file may be loaded automatically.(please do not check in the check box)

(7) Click next. And at this time you need not to select pre-processor so just click next again.

(8) Then Labview start syntax analysis. And you can see the list of 46 functions with check-mark.

(9) Click next. And please decide the "project library name" and "project library path" as you like.

    At this time you must create and choose void folder otherwise Labview call error...be careful.

    (and please add check in check box)

(10) Click next and select "simple error processing", and click next.

(11) You can see many editable settings, but default setting is OK so just only click next. 

(12) You can see creating reports and just click next again.

(13) Then Labview starts to create VIs so wait for few minutes.

(14) Add check in "open created library" and click finish.

(15) Then you can see created VIs of LibFT4222 in appeared list.

And you will succeed in making all VIs of LibFT4222 🙂

 

[2] SETTING SPI BLOCKS PROPERLY

***At this section you need the document called "AN_329 User Guide for LibFT4222" distributed by FTDI.***

The default settings of SPI blocks are differ to proper one which indicated in FTDI's document.

And I will show you good example here

(1) Open VI called "FT4222 SPI Master Single Read Write" created in section [1].

(2) Next open the block-diagram.

(3) You can confirm that "readBuffer (out)" and "writeBuffer (out)" is colored pink.

(4) So right click on the library icon and open "component". And select "parameter" tab.

     Here these I/O are defined as "string"... but in document(p.33~34)...these I/O are defined as "unit8*" !!

(4) So next you must change settings like below,

     type : string → array

     data type : unsigned 8 bit integer

     array format : array data pointer

     minimum size : 8194

     (I will send you my improved VIs for example, so please refer to it)

And if you have incorrect default settings listed above at any other blocks, please improve them by referring to (1) ~ (4) or my sample VI.

 

[3] HOW TO ADD CREATED VIs ON PALLET

(1) Back to main-manu and click "Tool".

(2) Next click 2nd option from bottom and select "edit the pallet set"

(3) Then right click on the background of function pallet. 

(4) Click "import" → "sub-pallet" → "link to existed pallet file"

(5) look for .mnu format file and select it. (this file exsits in the folder you created at (9) of [1])

(6) Green and blue VIs called "LibFT4222" are imported in the pallet.

(7) Click "save the changed settings" → "continue".

Finally you can call LibFT4222 VIs in the block-diagram as same as any other VIs(ex. VISA, GPIB, etc...) in your application.

 

That's all and thank you for reading very long senteces.

And I hope that all procedure will be successful...

 

Best Regards,

Yuki

0 Kudos
Message 5 of 9
(4,022 Views)

Hi "Sea" :-),

thank you for your support.

I should use the I2C module, but maybe the procedure is similar.

What do you think?

Thank you.

Regards,

Michele

0 Kudos
Message 6 of 9
(4,016 Views)

Hi, Michele

In conclusion, I think I2C blocks also should be improved by similar procedure as you say.

And just do not forget to implement pull-up resisters on the SDA and SCL lines of your device 🙂

Thank you.

Regards,

Yuki

0 Kudos
Message 7 of 9
(4,010 Views)

ahahahahhha yes pull-up are mandatory

Thank you.

Kind Regards,

Michele

0 Kudos
Message 8 of 9
(3,998 Views)

Dear

 

I have programmed a LabVIEW API for the MCP2210 USB to SPI bridge.

You can connect up to mine SPI devices to it.

Check this out: https://www.digiinst.de/p/labview-r-api-for-the-microchip-r-mcp2210-c-usb-r-to-spi-r-bridge

 

Best regards

 

Martin

0 Kudos
Message 9 of 9
(3,850 Views)