9 Visa::Visa(std::string resource,
unsigned int connection_timeout_ms)
14 auto error_code = make_error_code(std::errc::not_connected);
15 throw system_error(error_code,
"Error loading visa shared library");
19 if (!openDefaultResourceManager())
21 auto error_code = make_error_code(std::errc::not_connected);
22 throw system_error(error_code,
"Error retrieveing VISA default Resource Manager.");
26 if (!openInstrument(resource, connection_timeout_ms))
28 closeResourceManager();
31 auto error_code = make_error_code(std::errc::not_connected);
32 throw system_error(error_code,
"Error connecting to instrument");
40 closeResourceManager();
53 ViAttrState value = -999;
66 bool Visa::readData(
unsigned char* buffer, std::size_t bufferSize, std::size_t* readSize)
78 bool Visa::writeData(
const unsigned char* data, std::size_t dataSize, std::size_t* writeSize)
93 return status >= VI_SUCCESS;
113 ViChar description[1000];
124 return std::string();
128 return std::string(description);
134 return _status < VI_SUCCESS;
138 bool Visa::isResourceManager()
const
140 return _resource_manager != VI_NULL;
144 bool Visa::openDefaultResourceManager()
151 bool Visa::closeResourceManager()
154 if (!isResourceManager())
161 ViObject rm_obj = ViObject(_resource_manager);
162 _status = _visa.
viClose(rm_obj);
170 _resource_manager = VI_NULL;
175 bool Visa::isInstrument()
const
177 return _instrument != VI_NULL;
181 bool Visa::openInstrument(std::string resource,
unsigned int timeout_ms)
184 _resource = resource;
187 ViRsrc visaResource = ViRsrc(_resource.c_str());
188 ViUInt32 visaMode = VI_NULL;
201 bool Visa::closeInstrument()
211 ViObject instrument_obj = ViObject(_instrument);
212 _status = _visa.
viClose(instrument_obj);
220 _instrument = VI_NULL;
std::vector< unsigned char > * buffer()
VI_OPEN_PTR viOpen
Function pointer to VISA function viOpen
VI_OPEN_DEFAULT_RM_PTR viOpenDefaultRM
Function pointer to VISA function viOpenDefaultRM()
VI_SET_ATTRIBUTE_PTR viSetAttribute
Function pointer to VISA function viSetAttribute
bool isVisa() const
Checks if VISA was loaded.
VI_READ_PTR viRead
Function pointer to VISA function viRead
VI_CLOSE_PTR viClose
Function pointer to VISA function viClose
VI_WRITE_PTR viWrite
Function pointer to VISA function viWrite
VI_GET_ATTRIBUTE_PTR viGetAttribute
Function pointer to VISA function viGetAttribute
VI_STATUS_DESC_PTR viStatusDesc
Function pointer to VISA function viStatusDesc
bool setAttribute(ViAttr name, ViAttrState value)
set VISA attribute
virtual ~Visa()
Destructor.
virtual std::string statusMessage() const
Returns a human-friendly message for the current ViStatus value.
ViStatus status() const
Returns current ViStatus value.
virtual std::string endpoint() const
Visa(std::string resource, unsigned int connection_timeout_ms=2000)
Constructor.
virtual bool readData(unsigned char *buffer, std::size_t bufferSize, std::size_t *readSize=nullptr)
virtual bool writeData(const unsigned char *data, std::size_t dataSize, std::size_t *writeSize=nullptr)
virtual int timeout_ms() const
virtual bool setTimeout(int timeout_ms)
bool attribute(ViAttr name, ViAttrState *value) const
get VISA attribute
bool isError() const
Checks if there is a visa error.
std::system_error system_error
System error exception.