ICP  1
nivisa.h
Go to the documentation of this file.
1 #ifndef NIVISA_H
2 #define NIVISA_H
3 
4 #include "isisvme.h"
5 #include "visa.h"
6 
7 class NIVisa : public ISISVME
8 {
9  protected: // variables
12  static bool m_endian_workaround; // workaround for MXI2 little endian bug
13  ViSession m_default_rm;
14  ViSession m_instr_le; // little endian session
15  ViSession m_instr_be; // big endian session
16  ViSession m_instr_le_bt; // little endian block transfer session
17  ViSession m_instr_be_bt; // big endian block transfer session
18  ViSession m_instr_backplane;
19  std::string m_device;
20  std::string m_device_bp;
21  static const int m_tries;
22  static const int m_retry_time;
23  typedef std::map<ViJobId, ViStatus> jobid_map_t;
25  CRITICAL_SECTION m_job_critical;
26  CRITICAL_SECTION m_visa_critical;
29 
30  protected: // functions
31  int printError(ViSession session, const char * func, ViStatus status, std::ostream& os);
32  int printError(ViSession session, const char * func, ViStatus status,
33  unsigned long address, long nitems, std::ostream& os);
34  int addError(ViSession session, const char * func, ViStatus status, const std::string& message, DAEstatus& dstatus);
35  int addError(ViSession session, const char * func, ViStatus status,
36  unsigned long address, long nitems, const std::string& message, DAEstatus& dstatus);
37  bool resetBusDevice(const char* name, DAEstatus& dstatus);
38  int setEndian(ViSession session, bool little_endian, DAEstatus& dstatus);
39  int enableBlockTransfers(ViSession session, DAEstatus& dstatus);
40  int disableBlockTransfers(ViSession session, DAEstatus& dstatus);
41  int restoreTransferMode(ViSession session, int mode, DAEstatus& dstatus);
42  int reinit(DAEstatus& dstatus);
43 
44  template <typename F, typename T>
45  int retrySingle(F pFunc, unsigned long address, T data, TransferProps props, DAEstatus& dstatus);
46  template <typename F, typename T>
47  int retryBlock(F pFunc, unsigned long address, T data, long nitems, TransferProps props, DAEstatus& dstatus);
48 
49  int readU16impl(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus);
50  int readU32impl(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus);
51  int readBlockU16impl(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus);
52  int readBlockU32impl(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus);
53  int readBlockU64impl(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus);
54  int writeU16impl(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus& dstatus);
55  int writeU32impl(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus& dstatus);
56  int writeBlockU16impl(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus);
57  int writeBlockU32impl(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus);
58  int writeBlockU64impl(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus);
59 
60  static ViStatus _VI_FUNCH IOEventHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle);
61  static ViStatus _VI_FUNCH TriggerHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle);
62  static char* m_visa_lock_name;
63  ViSession getSession(TransferProps props);
64  int onTrigger(time_t the_secs, unsigned short the_ms, ViInt16 trig_id);
65 
66  public: // functions
67  NIVisa(DAEstatus& dstatus);
68  virtual ~NIVisa();
69  int open(const char* device, DAEstatus& dstatus);
70  int openBackplane(const char* device_bp, DAEstatus& dstatus);
71  int lockDevice(int timeout, DAEstatus& dstatus);
72  int unlockDevice(DAEstatus& dstatus);
73  void lockInterface(int timeout, DAEstatus& dstatus);
74  void unlockInterface(DAEstatus& dstatus);
75  int readU16noRetry(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus);
76  int readU32noRetry(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus);
77  int readU16(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus);
78  int readU32(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus);
79  int readBlockU16(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus);
80  int readBlockU32(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus);
81  int readBlockU64(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus);
82  int writeU16(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus& dstatus);
83  int writeU32(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus& dstatus);
84  int writeBlockU16(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus);
85  int writeBlockU32(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus);
86  int writeBlockU64(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus);
87  int writeBlock(unsigned long address, isisU32_t* data, long nitems, TransferProps props, DAEstatus& status);
88  int writeBlock(unsigned long address, uint64_t* data, long nitems, TransferProps props, DAEstatus& status);
89  int readBlock(unsigned long address, isisU32_t* data, long nitems, TransferProps props, DAEstatus& status);
90  int readBlock(unsigned long address, uint64_t* data, long nitems, TransferProps props, DAEstatus& status);
91  int close(DAEstatus& status);
92  int scanBus(DAEstatus& status);
93  bool resetBus(DAEstatus& status);
94  bool initOK();
95  const char* device() { return m_device.c_str(); }
96  const char* deviceBackplane() { return m_device_bp.c_str(); }
97  int addJobid(ViJobId jobId, ViStatus vi_status);
98  void setTriggerFunc(trigger_func_t* func, void* arg) { m_trigger_func = func; m_trigger_func_arg = arg; }
99  static void setEndianWorkaround(bool endian_workaround) { m_endian_workaround = endian_workaround; }
100 };
101 
102 #endif /* NIVISA_H */
NIVisa(DAEstatus &dstatus)
Definition: nivisa.cpp:79
int readU32(unsigned long address, isisU32_t *data32, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:564
ViSession m_instr_be_bt
Definition: nivisa.h:17
uint32_t TransferProps
combination of TransferProp values
Definition: isisvme.h:16
std::string m_device_bp
Definition: nivisa.h:20
virtual ~NIVisa()
Definition: nivisa.cpp:1241
int printError(ViSession session, const char *func, ViStatus status, std::ostream &os)
Definition: nivisa.cpp:1274
int readBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)
Definition: nivisa.cpp:1316
int writeBlockU64impl(unsigned long address, uint64_t *data64, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:910
int readU16impl(unsigned long address, isisU16_t *data16, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:546
ViSession m_instr_le_bt
Definition: nivisa.h:16
static ViStatus _VI_FUNCH TriggerHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle)
Definition: nivisa.cpp:159
void lockInterface(int timeout, DAEstatus &dstatus)
Definition: nivisa.cpp:69
int addError(ViSession session, const char *func, ViStatus status, const std::string &message, DAEstatus &dstatus)
Definition: nivisa.cpp:1255
void * m_trigger_func_arg
Definition: nivisa.h:28
std::map< ViJobId, ViStatus > jobid_map_t
Definition: nivisa.h:23
unsigned long isisU32_t
Definition: isisvme_types.h:8
ViSession getSession(TransferProps props)
Definition: nivisa.cpp:655
trigger_func_t * m_trigger_func
Definition: nivisa.h:27
jobid_map_t m_jobid_map
Definition: nivisa.h:24
int addJobid(ViJobId jobId, ViStatus vi_status)
Definition: nivisa.cpp:140
bool resetBusDevice(const char *name, DAEstatus &dstatus)
Definition: nivisa.cpp:1195
int restoreTransferMode(ViSession session, int mode, DAEstatus &dstatus)
Definition: nivisa.cpp:1068
bool m_init_done
Definition: nivisa.h:10
CRITICAL_SECTION m_job_critical
Definition: nivisa.h:25
int readBlockU16impl(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:601
int reinit(DAEstatus &dstatus)
Definition: nivisa.cpp:94
int scanBus(DAEstatus &status)
Definition: nivisa.cpp:1126
static void setEndianWorkaround(bool endian_workaround)
Definition: nivisa.h:99
int openBackplane(const char *device_bp, DAEstatus &dstatus)
Definition: nivisa.cpp:355
void unlockInterface(DAEstatus &dstatus)
Definition: nivisa.cpp:74
const char * deviceBackplane()
Definition: nivisa.h:96
static const int m_retry_time
milliseconds between retries
Definition: nivisa.h:22
int writeBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)
Definition: nivisa.cpp:1306
int writeU32impl(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:831
int open(const char *device, DAEstatus &dstatus)
Definition: nivisa.cpp:194
bool initOK()
Definition: nivisa.cpp:88
int readBlockU64impl(unsigned long address, uint64_t *data64, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:684
static bool m_endian_workaround
Definition: nivisa.h:12
unsigned short isisU16_t
Definition: isisvme_types.h:7
int disableBlockTransfers(ViSession session, DAEstatus &dstatus)
Definition: nivisa.cpp:1043
int unlockDevice(DAEstatus &dstatus)
Definition: nivisa.cpp:455
CRITICAL_SECTION m_visa_critical
Definition: nivisa.h:26
int writeBlockU16(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:850
int writeBlockU64(unsigned long address, uint64_t *data64, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:905
int writeU16impl(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:808
int readU16noRetry(unsigned long address, isisU16_t *data16, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:540
int retrySingle(F pFunc, unsigned long address, T data, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:480
int retryBlock(F pFunc, unsigned long address, T data, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:508
Definition: nivisa.h:7
bool m_block_transfers
Definition: nivisa.h:11
static char * m_visa_lock_name
Definition: nivisa.h:62
int close(DAEstatus &status)
Definition: nivisa.cpp:1089
static const int m_tries
number of times to try a read/write
Definition: nivisa.h:21
ViSession m_instr_backplane
Definition: nivisa.h:18
int writeU32(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:826
int readBlockU16(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:593
ViSession m_default_rm
Definition: nivisa.h:13
int enableBlockTransfers(ViSession session, DAEstatus &dstatus)
Definition: nivisa.cpp:1018
std::string m_device
Definition: nivisa.h:19
int trigger_func_t(void *arg, time_t the_secs, unsigned short the_ms, int trig_id)
Definition: isisvme.h:8
int lockDevice(int timeout, DAEstatus &dstatus)
Definition: nivisa.cpp:425
ViSession m_instr_be
Definition: nivisa.h:15
void setTriggerFunc(trigger_func_t *func, void *arg)
Definition: nivisa.h:98
int readU16(unsigned long address, isisU16_t *data16, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:535
int readBlockU32impl(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:690
int writeBlockU32(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:900
ViSession m_instr_le
Definition: nivisa.h:14
const char * device()
Definition: nivisa.h:95
int writeBlockU32impl(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:916
int writeBlockU16impl(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:858
int setEndian(ViSession session, bool little_endian, DAEstatus &dstatus)
Definition: nivisa.cpp:984
int readBlockU32(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:643
int writeU16(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:803
static ViStatus _VI_FUNCH IOEventHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle)
Definition: nivisa.cpp:147
int onTrigger(time_t the_secs, unsigned short the_ms, ViInt16 trig_id)
Definition: nivisa.cpp:182
bool resetBus(DAEstatus &status)
Definition: nivisa.cpp:1156
int readU32noRetry(unsigned long address, isisU32_t *data32, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:569
int readU32impl(unsigned long address, isisU32_t *data32, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:574
int readBlockU64(unsigned long address, uint64_t *data64, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:649