Jump to content

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


Recommended Posts

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

 

How do I create a VISA resource name in C++ and pass as uintptr_t* to the DLL?  

 

Is there a macro or helper function in "extcode.h" that can make life easy?  

 

Or should we rebuild the DLL's to use a more common string type?

 

Example DLL Function:

 

void __cdecl MeasureDCvolts(uintptr_t *VISAResourceName,  int32_t ChannelNumber,                             LVBoolean *MonitorResult, double *MeasuredVoltage, TD1 *errorOut); 

 

 

Thanks in advance for any advice or direction,

 

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

 

 

 

 

Link to comment

Please mention in the future if you do a crosspost as that helps potential people who want to answer, to see if they can add anything beneficial that hasn't already been answered in the other thread.

 

There is no way to create a LabVIEW VISA resource in your calling C code AFAIK. The VISA resource is an internal LabVIEW datatype handle that contains both the underlaying VISA session as well as the name of the VISA Resource as used to open that resource and possibly other LabVIEW internal information. The only entity that knows how to create this resource is in the LabVIEW kernel. But your C application does not link to the LabVIEW kernel at all, and there is no easy way to determine which LabVIEW kernel your DLL uses to link to it. Even if you knew how to link to the LabVIEW kernel (runtime engine) that the DLL uses, there are no documented function in there to deal with VISA resources. Basically what you want to do is doomed.

 

Instead you should replace the VISA resource Name control by a string control. Then you can configure it as string in the DLL interface and treat it as such in your C code. The only possible drawback is that in the DLL VI the VISA resource will be looked up every time you call that function, as the LabVIEW kernel will have to find any already opened session with that name or create a new one if it doesn't yet exist.

 

A little search magic on the NI forum would have given you that answer too.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.