C++ Instrument Catalog
VISAInstrumentTypes.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 // External tools
8 #include "visa.h"
9 
10 // Standard libraries
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 
15 namespace MTL {
16  namespace Instrument
17  {
18  //----------------------------------------------------------------------//
19  // Types //
20  //----------------------------------------------------------------------//
21  typedef std::string tResourceName;
22 
23  class CResourceList : public std::vector<tResourceName>
24  {
25  public:
26  std::string Dump() const
27  {
28  std::string l_RsrcList;
29  for (CResourceList::const_iterator it = this->begin(); it != this->end(); it++)
30  l_RsrcList += *it + '\n';
31  return l_RsrcList;
32  }
33  bool operator==(CResourceList const & other)
34  {
35  if (other.size() != size())
36  return false;
37  for (CResourceList::const_iterator thisit = begin(), otherit = other.begin(); thisit != end(); thisit++, otherit++)
38  {
39  if (*thisit != *otherit)
40  return false;
41  }
42  return true;
43  }
44  bool operator!=(CResourceList const & other)
45  {
46  if (other.size() != size())
47  return true;
48  for (CResourceList::const_iterator thisit = begin(), otherit = other.begin(); thisit != end(); thisit++, otherit++)
49  {
50  if (*thisit != *otherit)
51  return true;
52  }
53  return false;
54  }
55  };
56 
57  enum class eInterfaceType {
58  GPIB = VI_INTF_GPIB,
59  VXI = VI_INTF_VXI,
60  GPIB_VXI = VI_INTF_GPIB_VXI,
61  ASRL = VI_INTF_ASRL,
62  PXI = VI_INTF_PXI,
63  TCPIP = VI_INTF_TCPIP,
64  USB = VI_INTF_USB
65  };
66 
67  typedef ViUInt16 tInterfaceNumber;
68 
69  enum class eResourceClass {
70  INSTR = 0,
71  MEMACC,
72  INTFC,
73  BACKPLANE,
74  SERVANT,
75  SOCKET,
76  RAW
77  };
78 
79  enum class eOpenAccessMode {
80  NoLock = VI_NO_LOCK, // Open session without using an exclusive lock or loading configuration information
81  ExclusiveLock = VI_EXCLUSIVE_LOCK, // Acquire an exclusive lock immediately upon opening a session. If a lock cannot be acquired, the session is closed and an error is returned
82  LoadConfig = VI_LOAD_CONFIG // Configure attributes to values specified by an external configuration utility, such as the following utilities:
83  // - (Windows) Measurement & Automation Explorer
84  // - (Mac OS X) NI - VISA Configuration
85  // - (Linux) visaconf
86  };
87 
88  enum class eEventMechanism {
89  Queue = VI_QUEUE, // Enable the session to queue events
90  Handle = VI_HNDLR, // Enable the session to invoke a callback function
91  Suspendedhandler = VI_SUSPEND_HNDLR, // Enable the session to execute the handler
92  All = VI_ALL_MECH // Enable the session to all events
93  };
94 
95  enum class eEventType : unsigned long {
96  ServiceRequest = VI_EVENT_SERVICE_REQ, // Notifies the application that a service request was received from the device or interface associated with the given session.
97  Trig = VI_EVENT_TRIG, // Notifies the application that a trigger interrupt was received from the device. This may be either a hardware or software trigger, depending on the interface and the current session settings.
98  Clear = VI_EVENT_CLEAR, // Notifies the application that a device clear message was sent to the local controller.
99  IOCompletion = VI_EVENT_IO_COMPLETION, // Notifies the application that an asynchronous operation has completed.
100  Exception = VI_EVENT_EXCEPTION, // Notifies the application that an error condition has occured during an operation invocation.
101  GPIB_CIC = VI_EVENT_GPIB_CIC, // Notifies the application that the GPIB controller has gained or lost CIC (controller-in-charge) status.
102  GPIB_TALK = VI_EVENT_GPIB_TALK, // Notifies the application that the GPIB controller was addressed to talk.
103  GPIB_LISTEN = VI_EVENT_GPIB_LISTEN, // Notifies the application that the GPIB controller has been addressed to listen.
104  VXI_VME_SYSFAIL = VI_EVENT_VXI_VME_SYSFAIL, // Notifies the application that the VXI/VME SYSFAIL* line was asserted.
105  VXI_VME_SYSRESET = VI_EVENT_VXI_VME_SYSRESET, // Notifies the application that the VXI/VME SYSRESET* line was asserted.
106  VXI_SIGP = VI_EVENT_VXI_SIGP, // Notifies the application that a VXIbus signal or VXIbus interrupt was received from the device associated with the given session.
107  VXI_VME_INTR = VI_EVENT_VXI_VME_INTR, // Notifies the application that a VXIbus interrupt was received from the device associated with the given session.
108  PXI_INTR = VI_EVENT_PXI_INTR, // Notifies the application that a PXI interrupt occurred.
109  TCPIP_CONNECT = VI_EVENT_TCPIP_CONNECT, // Notifies the application that ...? No documentation...
110  USB_INTR = VI_EVENT_USB_INTR, // Notifies the application that a USB interrupt has occurred.
111  ALL = VI_ALL_ENABLED_EVENTS
112  };
113 
114  enum class eTriggerProtocol {
115  Default = VI_TRIG_PROT_DEFAULT,
116  VXI_Default = VI_TRIG_PROT_DEFAULT,
117  VXI_On = VI_TRIG_PROT_ON,
118  VXI_Off = VI_TRIG_PROT_OFF,
119  VXI_Sync = VI_TRIG_PROT_SYNC,
120  PXI_Reserve = VI_TRIG_PROT_RESERVE,
121  PXI_Unreserve = VI_TRIG_PROT_UNRESERVE
122  };
123 
124  enum class eSerialBaudrate { // Serial baudrate
125  k110 = 110,
126  k300 = 300,
127  k600 = 600,
128  k1200 = 1200,
129  k2400 = 2400,
130  k4800 = 4800,
131  k9600 = 9600,
132  k14400 = 14400,
133  k19200 = 19200,
134  k28800 = 28800,
135  k38400 = 38400,
136  k57600 = 57600,
137  k115200 = 115200,
138  k230400 = 230400,
139  k460800 = 460800,
140  k921600 = 921600
141  };
142  enum class eSerialDataBits { // Number of data bits for the serial communication
143  k7 = 7,
144  k8 = 8
145  };
146  enum class eSerialParity { // Parity configuration for the serial communication
147  kNone = VI_ASRL_PAR_NONE, //set Parity to None
148  kOdd = VI_ASRL_PAR_ODD, //set Parity to Odd
149  kEven = VI_ASRL_PAR_EVEN, //set Parity to Even
150  kMark = VI_ASRL_PAR_MARK, //set Parity to Mark
151  kSpace = VI_ASRL_PAR_SPACE //set Parity to Space
152 
153  };
154  enum class eSerialStopBits { // Stop bit configuration for the serial communication
155  k1 = VI_ASRL_STOP_ONE, //set Stop bit to 1
156  k1_5 = VI_ASRL_STOP_ONE5, //set Stop bit to 1.5
157  k2 = VI_ASRL_STOP_TWO //set Stop bit to 2
158  };
159  enum class eSerialHandshake { // Handshake configuration for the serial communication
160  kNone = VI_ASRL_FLOW_NONE, //set None
161  kXonXoff = VI_ASRL_FLOW_XON_XOFF, //set Software Handshake Xon/Xoff
162  kHardware = VI_ASRL_FLOW_RTS_CTS, //set Hardware Handshake RTS/CTS
163  kHardAndSoft = (VI_ASRL_FLOW_XON_XOFF | VI_ASRL_FLOW_RTS_CTS) //set Hardware & Software Handshake (Xon/Xoff & RTS/CTS)
164  };
165 
166  enum class eSerialTermMode { //Serial termination mode
167  kEndNone = VI_ASRL_END_NONE, //set termination character to None
168  kEndLast = VI_ASRL_END_LAST_BIT, //set termination character to Last bit
169  kEndTermChar = VI_ASRL_END_TERMCHAR, //set termination character to the one specified by VI_ATTR_TERMCHAR()
170  kEndBreak = VI_ASRL_END_BREAK //set termination character to Break (Only available in Write termination)
171  };
172 
173  struct sSerialPortSettings { // Sets serial port settings
174  eSerialBaudrate Baudrate; // [bd] Speed of the serial communication
175  eSerialDataBits DataBits; // [-] Number of transmitted bits per packet
176  eSerialParity Parity; // [-] Parity configuration of the serial communication
177  eSerialStopBits StopBits; // [-] Stop bit configuration of the serial communication
178  eSerialHandshake Handshake; // [-] Handshake configuration of the serial communication
179  eSerialTermMode ReadTermMode; // [-] Termination Read mode of the serial communication
180  char ReadTermChar; // [-] Specific termination character when readTermMode = kEndTermChar
182  : Baudrate(eSerialBaudrate::k9600),
184  Parity(eSerialParity::kNone),
186  Handshake(eSerialHandshake::kNone),
188  ReadTermChar('\n')
189  {}
190  };
191 
192  // For future use
194  {
195  public:
196  typedef std::string tClass; // INSTR / RAW / ...
197  typedef std::string tExpandedName;
198  typedef std::string tAlias; // If any
199 
200  private:
201  eInterfaceType m_Type;
202  tInterfaceNumber m_Number;
203  tClass m_Class;
204  tExpandedName m_ExpName;
205  tAlias m_Alias;
206  public:
208  {}
210  : m_Type(Type), m_Number(Number), m_Class(Class), m_ExpName(Expname), m_Alias(Alias)
211  {}
212  const eInterfaceType & Type() const
213  {
214  return m_Type;
215  }
216  const tInterfaceNumber & Number() const
217  {
218  return m_Number;
219  }
220  const tClass & Class() const
221  {
222  return m_Class;
223  }
224  const tExpandedName & ExpName() const
225  {
226  return m_ExpName;
227  }
228  const tAlias & Alias() const
229  {
230  return m_Alias;
231  }
232  };
233 
235  {
238 
240  : Name(rName), Info(rInfo)
241  {}
242 
243  bool operator==(sParsedResource const & other) const
244  {
245  return (Name == other.Name);
246  }
247  bool operator!=(sParsedResource const & other) const
248 
249  {
250  return !(*this == other);
251  }
252  };
253  class CParsedResourceList : public std::vector<sParsedResource>
254  {
255  public:
256  bool operator==(CParsedResourceList const & other)
257  {
258  if (other.size() != size())
259  return false;
260  for (CParsedResourceList::const_iterator thisit = begin(), otherit = other.begin(); thisit != end(); thisit++, otherit++)
261  {
262  if (*thisit != *otherit)
263  return false;
264  }
265  return true;
266  }
267  bool operator!=(CParsedResourceList const & other)
268  {
269  if (other.size() != size())
270  return true;
271  for (CParsedResourceList::const_iterator thisit = begin(), otherit = other.begin(); thisit != end(); thisit++, otherit++)
272  {
273  if (*thisit != *otherit)
274  return true;
275  }
276  return false;
277  }
278  };
279 
280 }} // namespace MTL::Instrument
MTL::Instrument::VISAResourceInfo::Number
const tInterfaceNumber & Number() const
Definition: VISAInstrumentTypes.h:216
MTL::Instrument::eSerialBaudrate::k600
@ k600
MTL::Instrument::eEventType::IOCompletion
@ IOCompletion
MTL::Instrument::CResourceList::operator==
bool operator==(CResourceList const &other)
Definition: VISAInstrumentTypes.h:33
MTL::Instrument::eSerialBaudrate::k2400
@ k2400
MTL::Instrument::eEventMechanism::All
@ All
MTL::Instrument::VISAResourceInfo::Type
const eInterfaceType & Type() const
Definition: VISAInstrumentTypes.h:212
MTL::Instrument::eSerialParity::kOdd
@ kOdd
MTL::Instrument::eResourceClass::RAW
@ RAW
MTL::Instrument::CResourceList
Definition: VISAInstrumentTypes.h:23
MTL::Instrument::eEventType::Clear
@ Clear
MTL::Instrument::eEventType::ServiceRequest
@ ServiceRequest
MTL::Instrument::eResourceClass
eResourceClass
Definition: VISAInstrumentTypes.h:69
MTL::Instrument::eSerialDataBits
eSerialDataBits
Definition: VISAInstrumentTypes.h:142
MTL::Instrument::CResourceList::operator!=
bool operator!=(CResourceList const &other)
Definition: VISAInstrumentTypes.h:44
MTL::Instrument::sSerialPortSettings::Handshake
eSerialHandshake Handshake
Definition: VISAInstrumentTypes.h:178
MTL::Instrument::eSerialBaudrate::k230400
@ k230400
MTL::Instrument::eInterfaceType::VXI
@ VXI
MTL::Instrument::sSerialPortSettings::ReadTermMode
eSerialTermMode ReadTermMode
Definition: VISAInstrumentTypes.h:179
MTL::Instrument::eSerialDataBits::k8
@ k8
MTL::Instrument::sSerialPortSettings::Baudrate
eSerialBaudrate Baudrate
Definition: VISAInstrumentTypes.h:174
MTL::Instrument::eSerialParity::kEven
@ kEven
MTL::Instrument::VISAResourceInfo::VISAResourceInfo
VISAResourceInfo(eInterfaceType Type, tInterfaceNumber Number, tClass Class, tExpandedName Expname, tAlias Alias)
Definition: VISAInstrumentTypes.h:209
MTL::Instrument::eTriggerProtocol::PXI_Unreserve
@ PXI_Unreserve
MTL::Instrument::eSerialHandshake::kHardware
@ kHardware
MTL::Instrument::eSerialBaudrate::k14400
@ k14400
MTL::Instrument::eResourceClass::INSTR
@ INSTR
MTL::Instrument::eEventMechanism
eEventMechanism
Definition: VISAInstrumentTypes.h:88
MTL::Instrument::eEventType::VXI_SIGP
@ VXI_SIGP
MTL::Instrument::eEventMechanism::Handle
@ Handle
MTL::Instrument::eTriggerProtocol::VXI_Default
@ VXI_Default
MTL::Instrument::eEventType::VXI_VME_INTR
@ VXI_VME_INTR
MTL::Instrument::VISAResourceInfo
Definition: VISAInstrumentTypes.h:193
MTL::Instrument::eInterfaceType::USB
@ USB
MTL::Instrument::eInterfaceType::TCPIP
@ TCPIP
MTL::Instrument::eEventType::GPIB_CIC
@ GPIB_CIC
MTL::Instrument::sSerialPortSettings
Definition: VISAInstrumentTypes.h:173
MTL::Instrument::eSerialTermMode::kEndNone
@ kEndNone
MTL::Instrument::eEventType::USB_INTR
@ USB_INTR
MTL::Instrument::eSerialTermMode::kEndBreak
@ kEndBreak
MTL::Instrument::sParsedResource::Info
VISAResourceInfo Info
Definition: VISAInstrumentTypes.h:237
MTL::Instrument::eTriggerProtocol::PXI_Reserve
@ PXI_Reserve
MTL::Instrument::eEventType
eEventType
Definition: VISAInstrumentTypes.h:95
MTL::Instrument::eTriggerProtocol::VXI_Off
@ VXI_Off
MTL::Instrument::eEventType::ALL
@ ALL
MTL::Instrument::VISAResourceInfo::Class
const tClass & Class() const
Definition: VISAInstrumentTypes.h:220
MTL::Instrument::CParsedResourceList::operator==
bool operator==(CParsedResourceList const &other)
Definition: VISAInstrumentTypes.h:256
MTL::Instrument::eInterfaceType
eInterfaceType
Definition: VISAInstrumentTypes.h:57
MTL::Instrument::eSerialBaudrate::k1200
@ k1200
MTL::Instrument::eInterfaceType::GPIB_VXI
@ GPIB_VXI
MTL::Instrument::eOpenAccessMode::NoLock
@ NoLock
MTL::Instrument::eResourceClass::MEMACC
@ MEMACC
MTL::Instrument::eResourceClass::SOCKET
@ SOCKET
MTL::Instrument::eSerialStopBits::k1_5
@ k1_5
MTL::Instrument::eEventType::GPIB_TALK
@ GPIB_TALK
MTL::Instrument::eInterfaceType::PXI
@ PXI
MTL::Instrument::eEventMechanism::Queue
@ Queue
MTL::Instrument::eInterfaceType::GPIB
@ GPIB
MTL
Definition: CPT2026PeripheralROM.h:19
MTL::Instrument::VISAResourceInfo::VISAResourceInfo
VISAResourceInfo()
Definition: VISAInstrumentTypes.h:207
MTL::Instrument::eSerialDataBits::k7
@ k7
MTL::Instrument::eEventType::TCPIP_CONNECT
@ TCPIP_CONNECT
MTL::Instrument::sParsedResource
Definition: VISAInstrumentTypes.h:234
MTL::Instrument::eSerialParity::kNone
@ kNone
MTL::Instrument::eSerialTermMode::kEndTermChar
@ kEndTermChar
MTL::Instrument::eEventType::VXI_VME_SYSFAIL
@ VXI_VME_SYSFAIL
MTL::Instrument::eSerialBaudrate::k28800
@ k28800
MTL::Instrument::sSerialPortSettings::DataBits
eSerialDataBits DataBits
Definition: VISAInstrumentTypes.h:175
MTL::Instrument::eSerialTermMode
eSerialTermMode
Definition: VISAInstrumentTypes.h:166
MTL::Instrument::eTriggerProtocol::VXI_On
@ VXI_On
MTL::Instrument::eSerialTermMode::kEndLast
@ kEndLast
MTL::Instrument::CParsedResourceList::operator!=
bool operator!=(CParsedResourceList const &other)
Definition: VISAInstrumentTypes.h:267
MTL::Instrument::eEventMechanism::Suspendedhandler
@ Suspendedhandler
MTL::Instrument::eTriggerProtocol
eTriggerProtocol
Definition: VISAInstrumentTypes.h:114
MTL::Instrument::eInterfaceType::ASRL
@ ASRL
MTL::Instrument::sSerialPortSettings::Parity
eSerialParity Parity
Definition: VISAInstrumentTypes.h:176
MTL::Instrument::eSerialParity
eSerialParity
Definition: VISAInstrumentTypes.h:146
MTL::Instrument::tInterfaceNumber
ViUInt16 tInterfaceNumber
Definition: VISAInstrumentTypes.h:67
MTL::Instrument::eSerialHandshake::kHardAndSoft
@ kHardAndSoft
MTL::Instrument::eEventType::Exception
@ Exception
MTL::Instrument::eSerialBaudrate::k57600
@ k57600
MTL::Instrument::eSerialBaudrate::k4800
@ k4800
MTL::Instrument::eEventType::GPIB_LISTEN
@ GPIB_LISTEN
MTL::Instrument::eSerialHandshake::kNone
@ kNone
MTL::Instrument::tResourceName
std::string tResourceName
Definition: VISAInstrumentTypes.h:21
MTL::Instrument::CResourceList::Dump
std::string Dump() const
Definition: VISAInstrumentTypes.h:26
MTL::Instrument::eSerialBaudrate::k38400
@ k38400
MTL::Instrument::eSerialHandshake::kXonXoff
@ kXonXoff
MTL::Instrument::eSerialStopBits
eSerialStopBits
Definition: VISAInstrumentTypes.h:154
MTL::Instrument::eResourceClass::BACKPLANE
@ BACKPLANE
MTL::Instrument::VISAResourceInfo::tAlias
std::string tAlias
Definition: VISAInstrumentTypes.h:198
MTL::Instrument::eSerialParity::kSpace
@ kSpace
MTL::Instrument::sParsedResource::sParsedResource
sParsedResource(tResourceName &rName, VISAResourceInfo &rInfo)
Definition: VISAInstrumentTypes.h:239
MTL::Instrument::eSerialBaudrate::k115200
@ k115200
MTL::Instrument::sSerialPortSettings::ReadTermChar
char ReadTermChar
Definition: VISAInstrumentTypes.h:180
MTL::Instrument::eSerialBaudrate::k9600
@ k9600
MTL::Instrument::eTriggerProtocol::VXI_Sync
@ VXI_Sync
MTL::Instrument::eSerialBaudrate::k460800
@ k460800
MTL::Instrument::VISAResourceInfo::ExpName
const tExpandedName & ExpName() const
Definition: VISAInstrumentTypes.h:224
MTL::Instrument::eSerialStopBits::k2
@ k2
MTL::Instrument::eOpenAccessMode
eOpenAccessMode
Definition: VISAInstrumentTypes.h:79
MTL::Instrument::eResourceClass::SERVANT
@ SERVANT
MTL::Instrument::eSerialBaudrate::k19200
@ k19200
MTL::Instrument::sParsedResource::operator==
bool operator==(sParsedResource const &other) const
Definition: VISAInstrumentTypes.h:243
MTL::Instrument::eSerialStopBits::k1
@ k1
MTL::Instrument::sSerialPortSettings::sSerialPortSettings
sSerialPortSettings()
Definition: VISAInstrumentTypes.h:181
MTL::Instrument::sSerialPortSettings::StopBits
eSerialStopBits StopBits
Definition: VISAInstrumentTypes.h:177
MTL::Instrument::eSerialBaudrate::k300
@ k300
MTL::Instrument::eEventType::PXI_INTR
@ PXI_INTR
MTL::Instrument::sParsedResource::operator!=
bool operator!=(sParsedResource const &other) const
Definition: VISAInstrumentTypes.h:247
MTL::Instrument::eTriggerProtocol::Default
@ Default
MTL::Instrument::VISAResourceInfo::tExpandedName
std::string tExpandedName
Definition: VISAInstrumentTypes.h:197
MTL::Instrument::eSerialBaudrate::k921600
@ k921600
MTL::Instrument::sParsedResource::Name
tResourceName Name
Definition: VISAInstrumentTypes.h:236
MTL::Instrument::eEventType::VXI_VME_SYSRESET
@ VXI_VME_SYSRESET
MTL::Instrument::VISAResourceInfo::tClass
std::string tClass
Definition: VISAInstrumentTypes.h:196
MTL::Instrument::eEventType::Trig
@ Trig
MTL::Instrument::CParsedResourceList
Definition: VISAInstrumentTypes.h:253
MTL::Instrument::eOpenAccessMode::LoadConfig
@ LoadConfig
MTL::Instrument::eResourceClass::INTFC
@ INTFC
MTL::Instrument::eSerialBaudrate::k110
@ k110
MTL::Instrument::eOpenAccessMode::ExclusiveLock
@ ExclusiveLock
MTL::Instrument::VISAResourceInfo::Alias
const tAlias & Alias() const
Definition: VISAInstrumentTypes.h:228
MTL::Instrument::eSerialBaudrate
eSerialBaudrate
Definition: VISAInstrumentTypes.h:124
MTL::Instrument::eSerialHandshake
eSerialHandshake
Definition: VISAInstrumentTypes.h:159
MTL::Instrument::eSerialParity::kMark
@ kMark