08-19-2008 11:18 AM
Hi! I am working on a project where I need to interface with a DLL that contains the device driver function code for a piece of equipment. The functions within the DLL use a lot of complex data types (structures). I've tried to get results with the Call Library Function Node, but with little success. Now I'm attempting to get the job done with a CIN.
I cannot find good documentation that goes over the functions and handling of all the different data types LabVIEW is throwing at the C code, and expects the C code to return to it. Specifically, Strings. In the "Using External Code in LabVIEW" there is a howto concatenate two strings. Ok, check. But how do I pass a string to LabVIEW. How do I say "Hello LabVIEW"? I need some more, simple, examples. The reference material is good. So far I've been able to follow the examples, compile them and get them to interface with LabVIEW. I feel like I'm lacking a more complete reference. Topics like how to deal with "Strings", "Array", and "Clusters" should span many pages and aren't very well covered in the specific examples presented in the "Using External Code in LabVIEW". Especially since everything is its own complex data types.
Here is my code:
// CINString_Test.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
/* CIN source file */
#include <extcode.h>
extern "C"{
MgErr CINRun(float64 *Numeric, LStrHandle String);
}
MgErr CINRun(float64 *Numeric, LStrHandle String)
{
*String = "Hello LabView";
return noErr;
}
08-19-2008 11:26 AM
08-19-2008 11:36 AM
That makes sense. So you are suggesting that instead of messing with CINs, what I should do is write and compile a DLL that serves as wrapper functions for the device DLL. My DLL will contain functions that have LabVIEW friendly datatypes and because it is written in C or C++ can then interface with the complex data types of this device DLL. Is that correct?
08-19-2008 11:36 AM - edited 08-19-2008 11:38 AM
Try this:
LStrPrintf(String, "%s", "Hello LabView"];
instead of: *String = "Hello LabView";
George Zou
http://www.geocities.com/gzou999
08-19-2008 12:52 PM - edited 08-19-2008 12:53 PM
Thank you for the reply, zou. That looks like it should be the correct function but I still get the following compile error on that line.
i:\labview\dvr\labview\cinstring_test\cinstring_test\cinstring_test.cpp(15) : error C2664: 'LStrPrintf' : cannot convert parameter 2 from 'const char [3]' to 'CStr'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I've look at the manual entry for the LStrPrintf but there is an utter lack of examples available which is very dissapointing. Searching for "LStrPrintf" on Google does not bring up anything useful either. I've tried:
LStrPrintf(String, "%H", "Hellow LabVIEW"];
and
LStrPrintf(String, "Hello LabVIEW"];
but get similar errors.
I beginning to think that the approach of writing a LabVIEW datatype friendly DLL to interface with my non-datatype friendly DLL is the way to go. Plenty of examples on how to do that task (although I've already spent about 2 days learning about CINS...sigh). I'd prefer not to use an unpopular method just because it is so difficult for others to help you. Blind leading the blind as it would seem.
Edit: Wow...winking smiley fail. I wonder how the LabWindows ppl post their code to this message board.
Any additional help here is appreciated.
08-19-2008 02:31 PM - edited 08-19-2008 02:32 PM
Change your .cpp to .c
George
http://www.geocities.com/gzou999
08-19-2008 04:02 PM