From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Import dll callback function

Solved!
Go to solution

Having trouble with this line "void   (*m_callback)(_t_pciCommand *cmd);" in PciApi.h file. I have replaced it with NULL and was able to import 2 functions, PciAllocCommand and PciSendCommand. I was then able to get valid information using GetValueByPointer.VI, but crash most of the time.

 

typedef struct _t_pciCommand

{

                t_pciCommandType                      m_command;

                t_commandError                          m_error;

                long                                               m_gpVal;

                void                                                (*m_callback)(_t_pciCommand *cmd);

                long                                              m_param[MAX_PCI_PARAMS];

                int                                               m_state;

                int                                               m_retries;

                int                                               m_expected;           

                long                                            m_origParam[MAX_PCI_PARAMS];

} t_pciCommand;

 

All files attached. Based on this callback funtion, I can't seem to resolve 2 functions, called PciAllocCommand and PciSendCommand.

 

Thanks,

 

John

0 Kudos
Message 1 of 6
(3,629 Views)
Solution
Accepted by topic author johnnyLabVIEWlongtime

LabVIEW can't support callbacks through Call Library Nodes. You will need to write a wrapper DLL in C/C++ that translates the callback function into a LabVIEW user event. Search for PostLVUserEvent here and on LAVA to find discussions and examples about this.

 

Beware: some sound C programming knowledge will be definitely required to understand this stuff and adapt it to your use case.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(3,596 Views)

Rolf, I kind of expected this answer after going through this forum. My C skills are not that strong but I can modify exsisting code. I would like to take a different approach by removing the callback from the exsisting code. The callback function isn't required so I replaced it with NULL in the DLL.

 

What I need help with is to properly configure the VI. Using the references you pointed out in other posts, I was able to modify what Labview generated, but would like some verification that it is done properly.

0 Kudos
Message 3 of 6
(3,572 Views)

Feel free to upload a VI and the description and C prototype of the function and its datatypes. I'll have a look at them then.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(3,563 Views)

The manual is "pci_api_manual_jb.doc", The funtion I care most about is PciAllocCommand and the #1 issue I have is how to pass "m_param[0]" , "m_param[1]" and "m_param[2]" to the dll. The original h file is "PciApp(original).h" . The second issue would be if removing the callback functionality I need a VI to poll the status of "t_PciCommand "Function without writing to it.

 

For example, PciAllocCommand(c_baudrate, NULL, 0). How do I set baud = m_param[0]?

 

Also I am adding a TestApp.exe example of what I want to do in Labview, focusing on the Param1 and Param2

Download All
0 Kudos
Message 5 of 6
(3,556 Views)

Up to rev 9 with better results and no crashing. I believe the remaining issue is how to poll "t_pciCommand".

0 Kudos
Message 6 of 6
(3,489 Views)