09-04-2013 12:11 PM
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);
}
09-04-2013 06:33 PM
relevant thread that the forum search easily could have provided using some of the words in the topic title
09-04-2013 07:54 PM
09-05-2013 12:58 AM - edited 09-05-2013 01:06 AM
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.