-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVisaSession.h
102 lines (81 loc) · 2.5 KB
/
VisaSession.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
@file VisaSession.h
@copyright (c) Rohde & Schwarz GmbH & Co. KG, Munich
*/
#pragma once
#include <vector>
#include <string>
#include "visa.h"
#include "VisaException.h"
/**
@class VisaSession
@brief Provides some basic VISA function calls
If a function fails a VisaException is thrown
*/
class VisaSession
{
public:
enum class Events
{
IO_COMPLETION
, EVENT_TRIG
, SERVICE_REQ
, CLEAR
, EXCEPTION
, GPIB_CIC
, GPIB_TALK
, GPIB_LISTEN
, VXI_VME_SYSFAIL
, VXI_VME_SYSRESET
, VXI_SIGP
, VXI_VME_INTR
, PXI_INTR
, TCPIP_CONNECT
, USB_INTR
, ALL_EVENTS
};
enum EventMechanism
{
QUEUE = VI_QUEUE,
HNDLR = VI_HNDLR,
SUSPEND_HNDLR = VI_SUSPEND_HNDLR,
QUEUE_HNDLR = VI_QUEUE | VI_HNDLR,
QUEUE_SUSPEND_HNDLR = VI_QUEUE | SUSPEND_HNDLR
};
explicit VisaSession(ViSession vi);
virtual ~VisaSession();
/// writes the string to the connected device and returns the number of written bytes
ViUInt32 write(const std::string& msg);
/// reads from the device
std::string read(uint16_t num);
/// writes formatted output to the device
void Printf(const std::string writeFmt, ...);
/// reads formatted input from the device
void Scanf(const std::string readFmt, ...);
/// formatted in- and output
void Queryf(const std::string& writeFmt, const std::string readFmt, ...);
/// Enable events of the given type
void enableEvent(Events eventType, EventMechanism mechanism);
/// Disable events of the given type
void disableEvent(Events eventType, EventMechanism mechanism);
/// Discard events of the given type
void discardEvents(Events eventType, EventMechanism mechanism);
/// Installs an event handler
void installHandler(Events eventType, ViHndlr handler, ViAddr userHandle);
/// Uninstalls an event handler
void uninstallHandler(Events eventType, ViHndlr handler, ViAddr userHandle);
/// Read status byte
ViUInt16 readSTB();
/// Sets the value of an attribute
void setAttribute(ViAttr attrName, ViAttrState attrValue);
/// Gets the value of an attribute
ViAttrState getAttribute(ViAttr attrName);
/// Clears the session
void clear();
protected:
ViSession getVi() const { return m_vi; }
static void checkAndThrow(ViStatus status, const std::string& msg = "");
private:
const ViSession m_vi;
static ViEventType Event2EventType(Events eventType);
};