LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

More String CIN examples/help

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;
    }

0 Kudos
Message 1 of 7
(3,331 Views)
Unless you're doing something that specifically requires a CIN you should try to stick with a standard DLL, as CINs are somewhat old and not widely used. Have you taken a look at the "Call DLL" example that ships with LabVIEW? Open the Example Finder (Help -> Find Examples) and search for "dll". That example shows how to call a DLL using a wide variety of datatypes. The C code is provided in the example directory as well. I would suggest starting there.
0 Kudos
Message 2 of 7
(3,328 Views)

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?

0 Kudos
Message 3 of 7
(3,323 Views)

Try this:

 

LStrPrintf(String, "%s", "Hello LabView"];

 

instead of:  *String = "Hello LabView";

 

 

George Zou

http://www.geocities.com/gzou999

Message Edited by zou on 08-19-2008 11:38 AM
George Zou
0 Kudos
Message 4 of 7
(3,322 Views)

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.

Message Edited by Nickerbocker on 08-19-2008 12:53 PM
0 Kudos
Message 5 of 7
(3,303 Views)

Change your .cpp to .c

 

George

http://www.geocities.com/gzou999

 

Message Edited by zou on 08-19-2008 02:32 PM
George Zou
0 Kudos
Message 6 of 7
(3,292 Views)
Hey!  That worked very well.  I wish I understood the reasons why... i need to learn more about what I'm doing, lol.
0 Kudos
Message 7 of 7
(3,280 Views)