| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
VISAInstrument.h
Go to the documentation of this file.
1// Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
10
11#pragma once
12
13// External tools
14#include "../resources/visatype.h"
15#include "../resources/visa.h"
16
17// Standard includes
18#include <iterator>
19
20// Personal includes
21#include "IEEE488Instrument.h"
22#include "VISAInstrumentTypes.h"
23#include "SCPIInstrumentBuffer.h"
24#include "Synchronization.h"
25
26 using namespace MTL::Synchronization;
27
28 namespace MTL {
29 namespace Instrument {
30 //----------------------------------------------------------------------//
35 std::string StatusDescription(ViSession Session, ViStatus Status);
36
37 //----------------------------------------------------------------------//
39 class CVISAResourceManager: public CIEEE488ResourceManager
40 {
41 private:
42 ViSession m_DefaultRM;
43
44 public:
45 // Constructors / destructors
46 CVISAResourceManager();
47 virtual ~CVISAResourceManager();
48
49 // Initialization / Info
50 virtual bool Initialize();
51 ViStatus Status();
52
56 virtual std::string StatusDescription (I32 Status);
57
58 const ViSession & Session();
59 virtual bool Timeout();
60
61 // Resource utilities
66 virtual bool FindResources(CResourceList & rList, std::string Filter = "?*");
67
72 bool FindResources(CParsedResourceList & rList, std::string Filter = "?*");
73
79 bool ResourceInfo(tResourceName & rRsrc, eInterfaceType & rIntfType, tInterfaceNumber & rIntfNumber);
80
85 bool ResourceInfo(tResourceName & rRsrc, VISAResourceInfo & rReturnedInfo);
86 };
87
88 //----------------------------------------------------------------------//
90 class CVISAInstrument: public CIEEE488Instrument
91 {
92 private:
93 ViSession m_InstrSession;
94 bool m_ExclusiveLock;
95
96 public:
97 // Constructors / destructors
101 CVISAInstrument(CVISAResourceManager & rRM, tResourceName Rsrc);
102 virtual ~CVISAInstrument();
103
104 // Connexion
107 virtual bool Open(void);
108
113 bool Open(eOpenAccessMode AccessMode, ViUInt32 Timeout_ms = 0);
114
115 virtual void Close();
116 virtual bool IsOpen();
117
118 // Info
122 virtual std::string StatusDescription (I32 Status);
123
124 const ViSession & Session();
125 virtual bool Timeout();
126
127 // Write / Read
131 virtual bool Write(const char * Str);
132
136 virtual bool Write(const std::string & rStr);
137
141 virtual bool Write(const CSCPIBuffer & rBuf);
142
147 bool Write(const ViBuf WriteBuf, ViUInt32 BuffLen);
148
153 virtual bool Read(CSCPIBuffer & rBuf, bool Append = false);
154
160 bool Read(ViPBuf ReadBuf, ViUInt32 ReadLen, ViUInt32 & rRetLen);
161
162 // Other operations
166 virtual bool SetTimeout(ViUInt32 Timeout);
167
168 virtual bool Clear();
169
173 virtual bool ReadSTB(ViUInt16 & rSTB);
174
177 virtual bool AssertTrigger(void);
178
182 bool AssertTrigger(eTriggerProtocol Protocol);
183
184 // Lock / Unlock
188 virtual bool LockExclusive(U32 Timeout);
189
195 bool LockShared(ViUInt32 Timeout, ViKeyId RequestedKey, ViChar AccessKey[]);
196
197 virtual bool Unlock();
198
199 virtual bool LockedExclusive();
200
201 // Events
204 virtual bool EnableEvent (void);
205
208 virtual bool DisableEvent (void);
209
213 virtual bool WaitOnEvent (U32 Timeout);
214
217 virtual bool DiscardEvents (void);
218
223 bool EnableEvent(eEventType Type, eEventMechanism Mechanism);
224
229 bool DisableEvent(eEventType Type, eEventMechanism Mechanism);
230
235 bool WaitOnEvent(eEventType Type, ViUInt32 Timeout);
236
240 bool WaitOnAllEvents(ViUInt32 Timeout);
241
246 bool DiscardEvents(eEventType Type, eEventMechanism Mechanism);
247
248 // Attributes
253 bool GetAttribute(ViAttr Attribute, void * Value);
254
255 // USB
265 bool UsbControlIn(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViUInt16 & rretCnt);
266
275 bool UsbControlOut(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf);
276
277 // Serial
281 bool ConfigSerialPort(const sSerialPortSettings & rPortSettings);
282 };
283
284}} // namespace MTL::Instrument
IEEE488Instrument.h
Abstract IEEE488 instrument class: interface definition.
I32
int I32
32-bit signed integer.
Definition OSDefines.h:27
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
SCPIInstrumentBuffer.h
IEEE488.2 / SCPI instrument I/O: Instrument buffer management.
Synchronization.h
Synchronization primitives.
VISAInstrumentTypes.h
C++ wrapper for NI-VISA: type definitions.
MTL::Instrument::CIEEE488Instrument::Status
I32 Status(void)
Definition IEEE488Instrument.h:93
MTL::Instrument::CIEEE488Instrument::CIEEE488Instrument
CIEEE488Instrument(CIEEE488ResourceManager &rRM, tResourceName Rsrc)
Constructor.
Definition IEEE488Instrument.h:79
MTL::Instrument::CIEEE488ResourceManager::CIEEE488ResourceManager
CIEEE488ResourceManager()
Definition IEEE488Instrument.h:30
MTL::Instrument::CParsedResourceList
Parsed resource information for a list of instruments.
Definition VISAInstrumentTypes.h:252
MTL::Instrument::CResourceList
List of VISA resource names.
Definition IEEE488InstrumentTypes.h:26
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition SCPIInstrumentBuffer.h:44
MTL::Instrument::CVISAInstrument::Unlock
virtual bool Unlock()
Unlock the session.
Definition VISAInstrument.cpp:645
MTL::Instrument::CVISAInstrument::Open
virtual bool Open(void)
Open a session to this VISA instrument.
Definition VISAInstrument.cpp:362
MTL::Instrument::CVISAInstrument::Session
const ViSession & Session()
Return instrument session identifier.
Definition VISAInstrument.cpp:422
MTL::Instrument::CVISAInstrument::~CVISAInstrument
virtual ~CVISAInstrument()
Destructor.
Definition VISAInstrument.cpp:353
MTL::Instrument::CVISAInstrument::LockExclusive
virtual bool LockExclusive(U32 Timeout)
Obtain an exclusive lock for this session.
Definition VISAInstrument.cpp:610
MTL::Instrument::CVISAInstrument::Read
virtual bool Read(CSCPIBuffer &rBuf, bool Append=false)
Read from a VISA instrument: SCPI buffer class variant.
Definition VISAInstrument.cpp:475
MTL::Instrument::CVISAInstrument::Timeout
virtual bool Timeout()
Last operation timed out.
Definition VISAInstrument.cpp:428
MTL::Instrument::CVISAInstrument::Clear
virtual bool Clear()
Clear the instrument.
Definition VISAInstrument.cpp:533
MTL::Instrument::CVISAInstrument::ReadSTB
virtual bool ReadSTB(ViUInt16 &rSTB)
Read status byte.
Definition VISAInstrument.cpp:542
MTL::Instrument::CVISAInstrument::LockedExclusive
virtual bool LockedExclusive()
Check whether session is locked exclusively.
Definition VISAInstrument.cpp:663
MTL::Instrument::CVISAInstrument::DiscardEvents
virtual bool DiscardEvents(void)
Discard service requests.
Definition VISAInstrument.cpp:682
MTL::Instrument::CVISAInstrument::WaitOnAllEvents
bool WaitOnAllEvents(ViUInt32 Timeout)
Wait for all events.
Definition VISAInstrument.cpp:734
MTL::Instrument::CVISAInstrument::Close
virtual void Close()
Close session to this VISA instrument.
Definition VISAInstrument.cpp:388
MTL::Instrument::CVISAInstrument::IsOpen
virtual bool IsOpen()
Check whether a session to this instrument is open.
Definition VISAInstrument.cpp:401
MTL::Instrument::CVISAInstrument::ConfigSerialPort
bool ConfigSerialPort(const sSerialPortSettings &rPortSettings)
Set all the instrument attributes to configure the serial communication.
Definition VISAInstrument.cpp:839
MTL::Instrument::CVISAInstrument::AssertTrigger
virtual bool AssertTrigger(void)
Assert a trigger.
Definition VISAInstrument.cpp:594
MTL::Instrument::CVISAInstrument::Write
virtual bool Write(const char *Str)
Write to a VISA instrument: C string variant.
Definition VISAInstrument.cpp:437
MTL::Instrument::CVISAInstrument::SetTimeout
virtual bool SetTimeout(ViUInt32 Timeout)
Set the timeout for this instrument session.
Definition VISAInstrument.cpp:521
MTL::Instrument::CVISAInstrument::DisableEvent
virtual bool DisableEvent(void)
Disable service requests.
Definition VISAInstrument.cpp:674
MTL::Instrument::CVISAInstrument::UsbControlIn
bool UsbControlIn(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViUInt16 &rretCnt)
Performs a USB control pipe transfer from the instrument.
Definition VISAInstrument.cpp:789
MTL::Instrument::CVISAInstrument::LockShared
bool LockShared(ViUInt32 Timeout, ViKeyId RequestedKey, ViChar AccessKey[])
Obtain a shared lock for this session.
Definition VISAInstrument.cpp:628
MTL::Instrument::CVISAInstrument::UsbControlOut
bool UsbControlOut(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf)
Performs a USB control pipe transfer to the instrument.
Definition VISAInstrument.cpp:813
MTL::Instrument::CVISAInstrument::WaitOnEvent
virtual bool WaitOnEvent(U32 Timeout)
Wait for a service request.
Definition VISAInstrument.cpp:678
MTL::Instrument::CVISAInstrument::GetAttribute
bool GetAttribute(ViAttr Attribute, void *Value)
Retrieves the state of an attribute.
Definition VISAInstrument.cpp:769
MTL::Instrument::CVISAInstrument::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition VISAInstrument.cpp:408
MTL::Instrument::CVISAInstrument::CVISAInstrument
CVISAInstrument(CVISAResourceManager &rRM, tResourceName Rsrc)
Constructor.
Definition VISAInstrument.cpp:348
MTL::Instrument::CVISAInstrument::EnableEvent
virtual bool EnableEvent(void)
Enable service requests.
Definition VISAInstrument.cpp:670
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition VISAInstrument.h:40
MTL::Instrument::CVISAResourceManager::~CVISAResourceManager
virtual ~CVISAResourceManager()
Destructor.
Definition VISAInstrument.cpp:75
MTL::Instrument::CVISAResourceManager::Initialize
virtual bool Initialize()
Initialize the Resource Manager.
Definition VISAInstrument.cpp:84
MTL::Instrument::CVISAResourceManager::Session
const ViSession & Session()
Return Resource Manager session identifier.
Definition VISAInstrument.cpp:129
MTL::Instrument::CVISAResourceManager::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition VISAInstrument.cpp:115
MTL::Instrument::CVISAResourceManager::CVISAResourceManager
CVISAResourceManager()
Constructor.
Definition VISAInstrument.cpp:70
MTL::Instrument::CVISAResourceManager::Timeout
virtual bool Timeout()
Last operation timed out.
Definition VISAInstrument.cpp:135
MTL::Instrument::CVISAResourceManager::Status
ViStatus Status()
Return Resource Manager status.
Definition VISAInstrument.cpp:110
MTL::Instrument::CVISAResourceManager::ResourceInfo
bool ResourceInfo(tResourceName &rRsrc, eInterfaceType &rIntfType, tInterfaceNumber &rIntfNumber)
Get the interface type and number for the given VISA resource name.
Definition VISAInstrument.cpp:259
MTL::Instrument::CVISAResourceManager::FindResources
virtual bool FindResources(CResourceList &rList, std::string Filter="?*")
Find VISA resources.
Definition VISAInstrument.cpp:144
MTL::Instrument::VISAResourceInfo
Information about a VISA resource.
Definition VISAInstrumentTypes.h:191
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition IEEE488InstrumentTypes.h:22
MTL::Instrument::eEventMechanism
eEventMechanism
Event mechanisms.
Definition VISAInstrumentTypes.h:56
MTL::Instrument::StatusDescription
std::string StatusDescription(ViSession Session, ViStatus Status)
Return user-readable description of the given status code.
Definition VISAInstrument.cpp:42
MTL::Instrument::tInterfaceNumber
ViUInt16 tInterfaceNumber
Interface number.
Definition VISAInstrumentTypes.h:35
MTL::Instrument::eOpenAccessMode
eOpenAccessMode
Access modes for VISA resources.
Definition VISAInstrumentTypes.h:49
MTL::Instrument::eInterfaceType
eInterfaceType
VISA interface types.
Definition VISAInstrumentTypes.h:25
MTL::Instrument::eTriggerProtocol
eTriggerProtocol
Trigger protocols.
Definition VISAInstrumentTypes.h:103
MTL::Instrument::eEventType
eEventType
Event types.
Definition VISAInstrumentTypes.h:64
MTL::Synchronization
Definition Synchronization.h:12
MTL
Definition THM1176.h:73
MTL::Instrument::sSerialPortSettings
Serial port settings.
Definition VISAInstrumentTypes.h:167