Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Link VISA library with Qt

Solved!
Go to solution

Hi,

 

I’m developing a GUI with Qt to control some oscilloscopes from LeCroy. For communication via Ethernet I want to use the VISA library.

 

I’ve written some code to test the communication channel but it just won’t compile. Here a short list of what I’ve already tried to make it run:

- copied project to C:\Temp to avoid space problems within the path

- used visa32.lib and visa64.lib

- copied libraries to the project folder

- linked libraries static and dynamic

 

The result or the copied library into the project folder is:

Fehler: No rule to make target 'C:/path…', needed by 'debug\KommunikationOszi3.exe'. Stop.

 

And the result with the “original” library is:

Fehler: error: Files/IVI: No such file or directory

Fehler: error: Foundation/VISA/Win64/Lib_x64/msc/: No such file or directory

 

The link commands in the project files are:

 lib within project folder

win32: LIBS += -L$$PWD/ -lvisa32

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

 

lib in the original folder:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc/ -lvisa32
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc/ -lvisa32d

INCLUDEPATH += $$PWD/../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc
DEPENDPATH += $$PWD/../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc

 

And some code examples from my program:

Header file of the oscilloscope class

#ifndef LECROYWAVESURFER_H
#define LECROYWAVESURFER_H

#include <string>
#include <sstream>
#include <iomanip>

#include "visa.h"

class LeCroyWavesurfer
{
public:
    LeCroyWavesurfer(ViSession *defaultRM, std::string name = "", std::string ip = "0.0.0.0");
    ~LeCroyWavesurfer();

    // communication functions
    void write(std::string command, std::string logMsg);
    std::string read(std::string command, std::string logMsg, ViUInt32 datLength);

    // configuring oscilloskop
    void autoSetup(std::string channel);


private:
    std::string name;

    // for VISA-communication
    ViSession *defaultRM;        // connection to main VISA driver
    ViSession session;          // connection to device
    ViStatus status;            // communication status
    ViUInt32 retCount;          // retur count from string I/O

};

#endif // LECROYWAVESURFER_H

 

Some extracts frome the CPP file of the oscilloscope class

#include "leCroyWavesurfer.h"

/***************************************************************************************/
// Includes for code completion
/***************************************************************************************/
#include <QDebug>


/****************************************************************************************/
// Constructor
/****************************************************************************************/
LeCroyWavesurfer::LeCroyWavesurfer(ViSession *defaultRM, std::string name, std::string ip)
{
    this->name = name;
    this->defaultRM = defaultRM;

    qDebug() << "Connection to Wafesurfer" << name.c_str();
    std::string geraet = "VICP::" + ip;
    status = viOpen(*defaultRM, (ViRsrc)geraet.c_str(), VI_NULL, VI_NULL, &session);
    if (status < VI_SUCCESS) qDebug() << "Connecting to" << name.c_str() << "failed";

    qDebug() << "Setting time out for communication with" << name.c_str();
    status = viSetAttribute(session, VI_ATTR_TMO_VALUE, 500);
    if (status < VI_SUCCESS) qDebug() << "Setting time out failed";

}

/****************************************************************************************/
// Destructor
/****************************************************************************************/
LeCroyWavesurfer::~LeCroyWavesurfer()
{
    qDebug() << "Disconnecting from" << name.c_str();
    status = viClose(session);
    if (status < VI_SUCCESS) qDebug() << "Disconnecting from" << name.c_str() << "failed";

    delete this;
}

/****************************************************************************************/
// Writing command to oscilloscope
/****************************************************************************************/
void LeCroyWavesurfer::write(std::string command, std::string logMsg)
{
    // creating log message for debugging
    qDebug() << logMsg.c_str();
    qDebug() << "Sent command:" << command.c_str();

    status = viWrite(session, (ViBuf)command.c_str(), command.length(), &retCount);
    if (status < VI_SUCCESS) qDebug() << logMsg.c_str() << "failed";

}

/****************************************************************************************/
// activating auto setup for chosen channel
/****************************************************************************************/
void LeCroyWavesurfer::autoSetup(std::string channel)
{
    // command syntax: <channel> : Auto_SETup [FIND]
    // <channel> : = {C1, C2, C3, C4}
    // If the FIND keyword is present, gain and offset adjustments will be performed
    //  only on the specified channel.
    // In the absence of the FIND keyword, the normal auto-setup will be performed,
    //  regardless of the <channel> prefix.

    std::string command = "C" + channel + " : Auto_SETup FIND";
    std::string logMsg = "Setting auto setup for channel " + channel;
    write(command,logMsg);
}

 

Qt 5.2.1 runs under Win7. I have a user account not an admin account.

 

 

Does anyone know how to fix this problem?

0 Kudos
Message 1 of 3
(10,863 Views)
Solution
Accepted by topic author Munin

I don't know why, but with a direct path it works. Should look like this:

 

# Library for VISA functions
win32: LIBS += "C:/Program Files (x86)/IVI Foundation/VISA/WinNT/lib/msc/visa32.lib"

 

If you also add the include folder you don't need to copy the visa.h into your project folder.

 

INCLUDEPATH += "C:/Program Files/IVI Foundation/VISA/Win64/Include"
DEPENDPATH += "C:/Program Files/IVI Foundation/VISA/Win64/Include"

 

Message 2 of 3
(10,721 Views)

BRO you saved me XD 

0 Kudos
Message 3 of 3
(1,516 Views)