LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How pass VISA resource string from C++ as uintptr_t* to a LabVIEW generated DLL ?

My coworker build a DLL from LabVIEW that I am trying to call from C++.

 

void__cdeclMeasureDCvolts(uintptr_t*VISAResourceName, int32_tChannelNumber,LVBoolean*MonitorResult,double*MeasuredVoltage, TD1*errorOut);

 

Does "extcode.h" define macros or functions for string conversions?  Or should I request my coworker rebuild the VI's to make arguments more C/C++ friendly?

 

Thanks in advance for any tips or direction.  Examples are * much * appreciated.

 

 

-Ed

 

 

TestObjectMeasurement* testObjectMeasurement = m_measurementMap[name];
TestObjectInstrument* testObjectInstrument = m_instrumentMap[selectedInstrumentName];
int slot = 1;
int bank = 1;
int channel = 1;
int channelNumber = 1000 * slot + channel;

char * visaResourceName = testObjectInstrument->visaResourceName().toLatin1().data();

LVBoolean monitorResult = LVBooleanFalse;
double measuredVoltage = -1.0;
TD1 errorOut = {0};


try
{
// void __cdecl MeasureDCvolts(uintptr_t *VISAResourceName,
// int32_t ChannelNumber, LVBoolean *MonitorResult, double *MeasuredVoltage,
// TD1 *errorOut);
MeasureDCvolts(reinterpret_cast<uintptr_t*>(visaResourceName), channelNumber, &monitorResult, &measuredVoltage, &errorOut);
}
catch(...)
{
qDebug() << "Exception thrown by: MeasureDCvolts";
}

QString errorSource = QString::fromUtf8(reinterpret_cast<const char*>(LHStrBuf(errorOut.source)), LHStrLen(errorOut.source));
qDebug() << errorSource;

LStrHandle errorTextHandle = {0};
bool foundErrorText = NIGetOneErrorCode(errorOut.code, &errorTextHandle);
if(foundErrorText)
{
QString errorText = QString::fromUtf8(reinterpret_cast<const char*>(LHStrBuf(errorTextHandle)), LHStrLen(errorTextHandle));
MessageHelper::messageError(errorText, errorSource);
}

0 Kudos
Message 1 of 4
(5,052 Views)

crosspost

 

relevant thread that the forum search easily could have provided using some of the words in the topic title

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 4
(5,044 Views)
I know how to search . I read that before posting. Not a solution. Thank you for your "kind" help.
0 Kudos
Message 3 of 4
(5,039 Views)

Why is it not a solution? It was exactly about what you wanted to do and the solution in the last post is how it can be made to work. There is NO way to ddirectly create a LabVIEW native VISA resource in C code that is not called from within LabVIEW, unless you consider hacking the LabVIEW system and using undocumented functions a solution. But that has very good chances of breaking with future LabVIEW versions.

 

Your only other option is to export another function from the DLL that accepts a String and uses VISA Open to explicitedly open the VISA session in your LabVIEW DLL and returning that VISA session to your C code. This is functionally equivalent to passing a String to your current function but avoids the lookup and potential recreation of the VISA refnum on each call. Something I would only feel bothered if you intend to call this function many thousend times each second, which for VISA communication seems very unlikely.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(5,029 Views)