ICP  1
nivisa.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "nivisa.h"
3 #include "icputils.h"
4 
5 // default: only read/write at most 40Mb in one go; got system resouces problems on merlin when went higher
6 static int nitems_max_default = (getenv("ISISVME_NITEMS_MAX") != NULL ? atoi(getenv("ISISVME_NITEMS_MAX")) : 10*1024*1024);
7 
9 {
10  static Poco::RWLock m_interface_lock;
11  static const DWORD INVALID_THREAD_ID;
12  static DWORD m_locker_id;
13  static LONG m_count;
14 public:
16  {
17  if (GetCurrentThreadId() == INVALID_THREAD_ID)
18  {
19  throw std::runtime_error("VisaAccessLock: invalid thread id");
20  }
21  // in poco cannot take out a read lock if alread have a write lock, so need to protect these cases
22  if (GetCurrentThreadId() != m_locker_id) // skip read lock if we already have a write lock
23  {
24  m_interface_lock.readLock();
25  }
26  }
28  {
29  if (GetCurrentThreadId() != m_locker_id)
30  {
31  m_interface_lock.unlock();
32  }
33  }
34  static void lockExclusive()
35  {
36  if (GetCurrentThreadId() != m_locker_id)
37  {
38  m_interface_lock.writeLock();
39  m_locker_id = GetCurrentThreadId();
41  {
42  throw std::runtime_error("VisaAccessLock: invalid thread id");
43  }
44  }
45  else
46  {
47  InterlockedIncrement(&m_count);
48  }
49  }
50  static void unlockExclusive()
51  {
52  if (m_count > 0)
53  {
54  InterlockedDecrement(&m_count);
55  }
56  else
57  {
59  m_interface_lock.unlock();
60  }
61  }
62 };
63 
65 const DWORD VisaAccessLock::INVALID_THREAD_ID = 0;
68 
69 void NIVisa::lockInterface(int timeout, DAEstatus& dstatus)
70 {
72 }
73 
75 {
77 }
78 
79 NIVisa::NIVisa(DAEstatus& dstatus) : ISISVME(), m_init_done(false), m_default_rm(VI_NULL), m_block_transfers(false), m_instr_le(VI_NULL), m_instr_be(VI_NULL),
80  m_instr_le_bt(VI_NULL), m_instr_be_bt(VI_NULL), m_instr_backplane(VI_NULL), m_device(""), m_device_bp(""), m_trigger_func(NULL), m_trigger_func_arg(NULL)
81 {
82  InitializeCriticalSection(&m_job_critical);
83  InitializeCriticalSection(&m_visa_critical);
84  setLoggerName("NIVisa");
85  reinit(dstatus);
86 }
87 
89 {
90  return m_init_done;
91 }
92 
93 
95 {
96  ViStatus status;
97  VisaAccessLock visa_lock;
99  m_init_done = false;
100  LOGSTR_INFORMATION("Calling NIVisa::reinit()");
101  dstatus.addInfo(FAC_DAE, "Calling NIVisa::reinit()");
102  close(dstatus);
103  if (m_default_rm != VI_NULL)
104  {
105  status = viClose(m_default_rm);
106  m_default_rm = VI_NULL;
107  }
108  m_default_rm = VI_NULL;
109  status = viOpenDefaultRM(&m_default_rm);
110  if (status == VI_SUCCESS)
111  {
112  m_init_done = true;
113  }
114  else
115  {
116 // addError(VI_NULL, "viOpenDefaultRM", status, "Unable to open default VISA resouce manager", dstatus);
117  std::ostringstream message;
118  message << "viOpenDefaultRM(error code=" << status << ")";
119  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, message.str());
120  LOGSTR_ERROR(message);
121  return ISISVME::Error;
122  }
123 // status = viOpen(m_default_rm, "VXI0::BACKPLANE", VI_NULL,
124 // VI_NULL, &m_instr_backplane);
125 // if (status != VI_SUCCESS)
126 // {
127 // std::cerr << "viOpen (backplane)" << status << std::endl;
128 // }
129  if (m_device != "")
130  {
131  open(m_device.c_str(), dstatus);
132  }
133  if (m_device_bp != "")
134  {
135  openBackplane(m_device_bp.c_str(), dstatus);
136  }
137  return ISISVME::Success;
138 }
139 
140 int NIVisa::addJobid(ViJobId jobId, ViStatus vi_status)
141 {
143  m_jobid_map[jobId] = vi_status;
144  return 0;
145 }
146 
147 ViStatus _VI_FUNCH NIVisa::IOEventHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle)
148 {
149  VisaAccessLock visa_lock;
150  ViJobId jobId;
151  ViStatus vi_status;
152  viGetAttribute(context, VI_ATTR_JOB_ID, &jobId);
153  viGetAttribute(context, VI_ATTR_STATUS, &vi_status);
154  NIVisa* vme = (NIVisa*)userHandle;
155  vme->addJobid(jobId, vi_status);
156  return VI_SUCCESS;
157 }
158 
159 ViStatus _VI_FUNCH NIVisa::TriggerHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userHandle)
160 {
161  VisaAccessLock visa_lock;
162 // ViStatus vi_status;
163 // ViEventType event_type;
164  ViInt16 trig_id; // 0 to 7 is VI_TRIG_TTL0 to VI_TRIG_TTL7 8 is VI_TRIG_ECL0 9 is ECL1
165 // ViUInt16 intr_id;
166  struct timeb tb;
167  ftime(&tb);
168 // viGetAttribute(context, VI_ATTR_EVENT_TYPE, &event_type); // should be VI_EVENT_TRIG
169  NIVisa* vme = (NIVisa*)userHandle;
170  if (eventType == VI_EVENT_TRIG)
171  {
172  viGetAttribute(context, VI_ATTR_RECV_TRIG_ID, &trig_id);
173  vme->onTrigger(tb.time, tb.millitm, trig_id);
174  }
175 // if (eventType == VI_EVENT_VXI_SIGP)
176 // {
177 // status = viGetAttribute (context, VI_ATTR_SIGP_STATUS_ID, &intrID);
178 // }
179  return VI_SUCCESS;
180 }
181 
182 int NIVisa::onTrigger(time_t the_secs, unsigned short the_ms, ViInt16 trig_id)
183 {
184  if (m_trigger_func != NULL)
185  {
186  return (*m_trigger_func)(m_trigger_func_arg, the_secs, the_ms, trig_id);
187  }
188  else
189  {
190  return ISISVME::Success;
191  }
192 }
193 
194 int NIVisa::open(const char* device, DAEstatus& dstatus)
195 {
196  VisaAccessLock visa_lock;
198  std::ostringstream message;
199  ViStatus status;
200  m_device = device;
201 // std::cerr << "vi return add = " << (void*)&m_instr_le << std::endl;
202  m_instr_le = VI_NULL;
203  status = viOpen(m_default_rm, (char*)device, VI_NULL,
204  VI_NULL, &m_instr_le);
205  if (status != VI_SUCCESS)
206  {
207  message << "Error opening \"" << device << "\"" << std::endl;
208  addError(m_default_rm, "viOpen", status, message.str(), dstatus);
209  return ISISVME::Error;
210  }
211  if (lockDevice(1000, dstatus) == ISISVME::Error)
212  {
213  return ISISVME::Error;
214  }
215  m_instr_le_bt = VI_NULL;
216  status = viOpen(m_default_rm, (char*)device, VI_NULL,
217  VI_NULL, &m_instr_le_bt);
218  if (status != VI_SUCCESS)
219  {
220  message << "Error opening \"" << device << "\"" << std::endl;
221  addError(m_default_rm, "viOpen", status, message.str(), dstatus);
222  return ISISVME::Error;
223  }
224  m_device = device;
225  ViUInt16 interface_type;
227  {
228  m_block_transfers = true; // MXI2
229  }
230  else
231  {
232  m_block_transfers = false; // USB
233  }
234  dstatus.addInfoVa(FAC_DAE, "Endian workaround %s, blocks transfers %s",
235  (m_endian_workaround ? "ENABLED" : "DISABLED"),
236  (m_block_transfers ? "ENABLED" : "DISABLED"));
237  status = viGetAttribute(m_instr_le, VI_ATTR_INTF_TYPE, &interface_type);
238  if (status == VI_SUCCESS)
239  {
240  switch(interface_type)
241  {
242  case VI_INTF_USB:
243  dstatus.addInfo(FAC_DAE, "This is a USB DAE");
244 // m_endian_workaround = false;
245  break;
246 
247  case VI_INTF_VXI:
248  dstatus.addInfo(FAC_DAE, "This is a VXI DAE");
249 // m_endian_workaround = true;
250  break;
251 
252  default:
253  dstatus.addInfo(FAC_DAE, "This is an UNKNOWN DAE");
254  break;
255  }
256  }
257  else
258  {
259  dstatus.addInfo(FAC_DAE, "Cannot access VI_ATTR_INTF_TYPE");
260  }
261  m_instr_be = VI_NULL;
262  status = viOpen(m_default_rm, (char*)device, VI_NULL,
263  VI_NULL, &m_instr_be);
264  if (status != VI_SUCCESS)
265  {
266  addError(m_default_rm, "viOpen", status, "", dstatus);
267  return ISISVME::Error;
268  }
269  m_instr_be_bt = VI_NULL;
270  status = viOpen(m_default_rm, (char*)device, VI_NULL,
271  VI_NULL, &m_instr_be_bt);
272  if (status != VI_SUCCESS)
273  {
274  addError(m_default_rm, "viOpen", status, "", dstatus);
275  return ISISVME::Error;
276  }
277  if (getenv("ISISVME_USE_PIO") != NULL)
278  {
279  if (status == VI_SUCCESS)
280  {
281  dstatus.addInfoVa(FAC_DAE, "Using PIO rather than DMA\n");
282  status = viSetAttribute(m_instr_be, VI_ATTR_DMA_ALLOW_EN, VI_FALSE);
283  status = viSetAttribute(m_instr_be_bt, VI_ATTR_DMA_ALLOW_EN, VI_FALSE);
284  }
285  if (status == VI_SUCCESS)
286  {
287  status = viSetAttribute(m_instr_le, VI_ATTR_DMA_ALLOW_EN, VI_FALSE);
288  status = viSetAttribute(m_instr_le_bt, VI_ATTR_DMA_ALLOW_EN, VI_FALSE);
289  }
290  }
291  if (getenv("ISISVME_TIMEOUT") != NULL)
292  {
293  ViUInt32 time_out = atol(getenv("ISISVME_TIMEOUT"));
294  if (status == VI_SUCCESS)
295  {
296  dstatus.addInfoVa(FAC_DAE, "Setting timeout to %u ms\n", time_out);
297  status = viSetAttribute(m_instr_be, VI_ATTR_TMO_VALUE, time_out);
298  status = viSetAttribute(m_instr_be_bt, VI_ATTR_TMO_VALUE, time_out);
299  }
300  if (status == VI_SUCCESS)
301  {
302  status = viSetAttribute(m_instr_le, VI_ATTR_TMO_VALUE, time_out);
303  status = viSetAttribute(m_instr_le_bt, VI_ATTR_TMO_VALUE, time_out);
304  }
305  }
306  // disable SyncMXI protocol - see http://digital.ni.com/public.nsf/allkb/3688705B6D2A405486256E9F005953F6
307  if (false)
308  {
309  if (status == VI_SUCCESS)
310  {
311  dstatus.addInfoVa(FAC_DAE, "Disabling SyncMXI protocol\n");
312  status = viSetAttribute (m_instr_le, 0x3FFF0161, 0x0);
313  status = viSetAttribute (m_instr_le_bt, 0x3FFF0161, 0x0);
314  }
315  if (status == VI_SUCCESS)
316  {
317  status = viSetAttribute (m_instr_be, 0x3FFF0161, 0x0);
318  status = viSetAttribute (m_instr_be_bt, 0x3FFF0161, 0x0);
319  }
320  }
321  if (status != VI_SUCCESS)
322  {
323  addError(m_default_rm, "viSetAttribute", status, "", dstatus);
324  return ISISVME::Error;
325  }
326 #if DO_MOVE_ASYNC
327  viInstallHandler(m_instr_le, VI_EVENT_IO_COMPLETION, IOEventHandler, this);
328  viInstallHandler(m_instr_be, VI_EVENT_IO_COMPLETION, IOEventHandler, this);
329  viInstallHandler(m_instr_le_bt, VI_EVENT_IO_COMPLETION, IOEventHandler, this);
330  viInstallHandler(m_instr_be_bt, VI_EVENT_IO_COMPLETION, IOEventHandler, this);
331 
332  if (viEnableEvent(m_instr_le, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL) != VI_SUCCESS)
333  {
334  addError(m_default_rm, "viEnableEvent", status, "", dstatus);
335  }
336  if (viEnableEvent(m_instr_be, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL) != VI_SUCCESS)
337  {
338  addError(m_default_rm, "viEnableEvent", status, "", dstatus);
339  }
340  if (viEnableEvent(m_instr_le_bt, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL) != VI_SUCCESS)
341  {
342  addError(m_default_rm, "viEnableEvent", status, "", dstatus);
343  }
344  if (viEnableEvent(m_instr_be_bt, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL) != VI_SUCCESS)
345  {
346  addError(m_default_rm, "viEnableEvent", status, "", dstatus);
347  }
348 #endif
351  setEndian(m_instr_le, true, dstatus);
352  return setEndian(m_instr_le_bt, true, dstatus);
353 }
354 
355 int NIVisa::openBackplane(const char* device_bp, DAEstatus& dstatus)
356 {
357  VisaAccessLock visa_lock;
359  std::ostringstream message;
360  ViStatus status;
361  m_device_bp = device_bp;
362  m_instr_backplane = VI_NULL;
363  status = viOpen(m_default_rm, (char*)device_bp, VI_NULL,
364  VI_NULL, &m_instr_backplane);
365  if (status != VI_SUCCESS)
366  {
367  message << "Error opening \"" << device_bp << "\"" << std::endl;
368  addError(m_default_rm, "viOpen", status, message.str(), dstatus);
369  return ISISVME::Error;
370  }
371  status = viInstallHandler(m_instr_backplane, VI_EVENT_TRIG, TriggerHandler, this);
372  if (status != VI_SUCCESS)
373  {
374  addError(m_default_rm, "viInstallHandler", status, "", dstatus);
375  return ISISVME::Error;
376  }
377 // status = viInstallHandler(m_instr_backplane, VI_EVENT_VXI_SIGP, TriggerHandler, this);
378 // if (status != VI_SUCCESS)
379 // {
380 // addError(m_default_rm, "viInstallHandler", status, "", dstatus);
381 // return ISISVME::Error;
382 // }
383  status = viSetAttribute(m_instr_backplane, VI_ATTR_TRIG_ID, VI_TRIG_ECL0); // frame sync
384  if (status != VI_SUCCESS)
385  {
386  addError(m_default_rm, "viSetAttribute", status, "", dstatus);
387  return ISISVME::Error;
388  }
389  status = viEnableEvent(m_instr_backplane, VI_EVENT_TRIG, VI_HNDLR, VI_NULL);
390  if (status != VI_SUCCESS)
391  {
392  addError(m_default_rm, "viEnableEvent", status, "", dstatus);
393  return ISISVME::Error;
394  }
395 // status = viEnableEvent(m_instr_backplane, VI_EVENT_VXI_SIGP, VI_HNDLR, VI_NULL);
396 // if (status != VI_SUCCESS)
397 // {
398 // addError(m_default_rm, "viEnableEvent", status, "", dstatus);
399 // return ISISVME::Error;
400 // }
401  ViUInt32 my_uint32;
402  status = viGetAttribute(m_instr_backplane, VI_ATTR_VXI_TRIG_SUPPORT, &my_uint32);
403  if (status != VI_SUCCESS)
404  {
405  addError(m_default_rm, "viGetAttribute", status, "", dstatus);
406  return ISISVME::Error;
407  }
408  if ( (my_uint32 & (1 << VI_TRIG_ECL0)) == 0)
409  {
410  dstatus.addInfo(FAC_DAE, "VI_TRIG_ECL0 not supported");
411  }
412  status = viGetAttribute(m_instr_backplane, VI_ATTR_VXI_TRIG_STATUS, &my_uint32);
413  if (status != VI_SUCCESS)
414  {
415  addError(m_default_rm, "viGetAttribute", status, "", dstatus);
416  return ISISVME::Error;
417  }
418 // if ( (my_uint32 & (1 << VI_TRIG_ECL0)) == 0)
419 // {
420 // dstatus.addInfo(FAC_DAE, "VI_TRIG_ECL0 not enabled");
421 // }
422  return ISISVME::Success;
423 }
424 
425 int NIVisa::lockDevice(int timeout, DAEstatus& dstatus)
426 {
427  VisaAccessLock visa_lock;
428 #if 0
429  ViStatus status;
430  ICPCritical cs(&m_critical);
431  if (m_visa_lock_name == NULL)
432  {
433  m_visa_lock_name = new char[256];
434  status = viLock(m_instr_le, VI_SHARED_LOCK, 1000 * timeout,
435  VI_NULL, m_visa_lock_name);
436  }
437  else
438  {
439  status = viLock(m_instr_le, VI_SHARED_LOCK, 1000 * timeout,
441  }
442  if (status == VI_SUCCESS)
443  {
444  return ISISVME::Success;
445  }
446  else
447  {
448  addError(m_instr_le, "viLock", status, "", dstatus);
449  return ISISVME::Error;
450  }
451 #endif
452  return ISISVME::Success;
453 }
454 
456 {
457  VisaAccessLock visa_lock;
458 #if 0
459  ViStatus status;
460  ICPCritical cs(&m_critical);
461  if (m_instr_le == VI_NULL)
462  {
463  return ISISVME::Success;
464  }
465  status = viUnlock(m_instr_le);
466  if (status == VI_SUCCESS)
467  {
468  return ISISVME::Success;
469  }
470  else
471  {
472  addError(m_instr_le, "viUnlock", status, "", dstatus);
473  return ISISVME::Error;
474  }
475 #endif
476  return ISISVME::Success;
477 }
478 
479 template <typename F, typename T>
480 int NIVisa::retrySingle(F pFunc, unsigned long address, T data, TransferProps props, DAEstatus& dstatus)
481 {
482  int current_sev = dstatus.severity();
483  int i, stat = ISISVME::Error;
484  for(i=0; i<m_tries; i++)
485  {
486  if (i > 0)
487  {
488  Sleep(m_retry_time);
490  if (i > 2)
491  {
492  LOGSTR_WARNING("retrySingle: address 0x" << std::hex << address << std::dec);
493  reinit(dstatus);
494  }
495  }
496  stat = (this->*pFunc)(address, data, props, dstatus);
497  if (stat == ISISVME::Success)
498  break;
499  }
500  if ( !(dstatus >= current_sev) )
501  {
502  dstatus.resetSeverityToAtLeast(current_sev);
503  }
504  return stat;
505 }
506 
507 template <typename F, typename T>
508 int NIVisa::retryBlock(F pFunc, unsigned long address, T data, long nitems, TransferProps props, DAEstatus& dstatus)
509 {
510  int i, stat = ISISVME::Error;
511  int current_sev = dstatus.severity();
512  for(i=0; i<m_tries; i++)
513  {
514  if (i > 0)
515  {
516  Sleep(m_retry_time);
518  if (i > 2)
519  {
520  LOGSTR_WARNING("retryBlock: " << nitems << " items from address 0x" << std::hex << address << std::dec);
521  reinit(dstatus);
522  }
523  }
524  stat = (this->*pFunc)(address, data, nitems, props, dstatus);
525  if (stat == ISISVME::Success)
526  break;
527  }
528  if ( !(dstatus >= current_sev) )
529  {
530  dstatus.resetSeverityToAtLeast(current_sev);
531  }
532  return stat;
533 }
534 
535 int NIVisa::readU16(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus)
536 {
537  return retrySingle(&NIVisa::readU16impl, address, data16, props, dstatus);
538 }
539 
540 int NIVisa::readU16noRetry(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus)
541 {
542  return readU16impl(address, data16, props, dstatus);
543 }
544 
545 
546 int NIVisa::readU16impl(unsigned long address, isisU16_t* data16, TransferProps props, DAEstatus& dstatus)
547 {
548  VisaAccessLock visa_lock;
549  ViStatus status;
550  ViSession session;
551  session = getSession(props);
552  status = viIn16(session, VI_A32_SPACE, address, data16);
553  if (status == VI_SUCCESS)
554  {
555  return ISISVME::Success;
556  }
557  else
558  {
559  addError(session, "viIn16", status, address, 1, "", dstatus);
560  return ISISVME::Error;
561  }
562 }
563 
564 int NIVisa::readU32(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus)
565 {
566  return retrySingle(&NIVisa::readU32impl, address, data32, props, dstatus);
567 }
568 
569 int NIVisa::readU32noRetry(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus)
570 {
571  return readU32impl(address, data32, props, dstatus);
572 }
573 
574 int NIVisa::readU32impl(unsigned long address, isisU32_t* data32, TransferProps props, DAEstatus& dstatus)
575 {
576  VisaAccessLock visa_lock;
577  ViStatus status;
578  ViSession session;
579  ICPCritical cs(&m_visa_critical); // just for safety - visa should be threadsafe
580  session = getSession(props);
581  status = viIn32(session, VI_A32_SPACE, address, data32);
582  if (status == VI_SUCCESS)
583  {
584  return ISISVME::Success;
585  }
586  else
587  {
588  addError(session, "viIn32", status, address, 1, "", dstatus);
589  return ISISVME::Error;
590  }
591 }
592 
593 int NIVisa::readBlockU16(unsigned long address, isisU16_t* data16,
594  long nitems, TransferProps props, DAEstatus& dstatus)
595 {
596  return retryBlock(&NIVisa::readBlockU16impl, address, data16, nitems, props, dstatus);
597 }
598 
599 // nove nitems of 2 bytes
600 // need to check the use of nitems_max in particular is address increment 2*n or 4*n?
601 int NIVisa::readBlockU16impl(unsigned long address, isisU16_t* data16,
602  long nitems, TransferProps props, DAEstatus& dstatus)
603 {
604  VisaAccessLock visa_lock;
605  int nitems_max;
606  ViStatus status;
607  ViSession session;
608  session = getSession(props);
609  if (nitems_max_default > 0)
610  {
611  nitems_max = nitems_max_default;
612  }
613  else
614  {
615  nitems_max = nitems;
616  }
617  int nitems_left = nitems;
618  int n;
619  bool error_signalled = false;
620  while(nitems_left > 0)
621  {
622  n = (nitems_left > nitems_max ? nitems_max : nitems_left);
623  status = viMoveIn16(session, VI_A32_SPACE, address, n, data16);
624  if (status != VI_SUCCESS)
625  {
626  addError(session, "viMoveIn16", status, address, n, "", dstatus);
627  error_signalled = true;
628  }
629  nitems_left -= n;
630  data16 += n;
631  address += (4*n);
632  }
633  if (error_signalled)
634  {
635  return ISISVME::Error;
636  }
637  else
638  {
639  return ISISVME::Success;
640  }
641 }
642 
643 int NIVisa::readBlockU32(unsigned long address, isisU32_t* data32,
644  long nitems, TransferProps props, DAEstatus& dstatus)
645 {
646  return retryBlock(&NIVisa::readBlockU32impl, address, data32, nitems, props, dstatus);
647 }
648 
649 int NIVisa::readBlockU64(unsigned long address, uint64_t* data64,
650  long nitems, TransferProps props, DAEstatus& dstatus)
651 {
652  return retryBlock(&NIVisa::readBlockU64impl, address, data64, nitems, props, dstatus);
653 }
654 
656 {
657  bool little_endian = (props & ISISVME::TransferLittleEndian ? true : false);
658  bool block_transfer = (props & ISISVME::TransferBlock ? true : false);
659  ICPCritical cs(&m_visa_critical); // so we wait for any reinit() that may be in progress
660  if (little_endian)
661  {
662  if (block_transfer)
663  {
664  return m_instr_le_bt;
665  }
666  else
667  {
668  return m_instr_le;
669  }
670  }
671  else
672  {
673  if (block_transfer)
674  {
675  return m_instr_be_bt;
676  }
677  else
678  {
679  return m_instr_be;
680  }
681  }
682 }
683 
684 int NIVisa::readBlockU64impl(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus)
685 {
686  return readBlockU32impl(address, reinterpret_cast<isisU32_t*>(data64), 2 * nitems, props, dstatus);
687 }
688 
689 // nove nitems of 4 bytes
690 int NIVisa::readBlockU32impl(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus)
691 {
692  VisaAccessLock visa_lock;
693  bool little_endian = (props & ISISVME::TransferLittleEndian ? true : false);
694  int i, nitems_max;
695 // cout << "NIVisa::readBlockU32 0x" << hex << address << dec << " " << nitems << std::endl;
696  ViStatus status;
697  ViSession session;
698  unsigned long k = address;
699  isisU32_t* d32 = data32;
700  ICPCritical cs(&m_visa_critical); // just for safety - visa should be threadsafe
701  session = getSession(props);
702  if (nitems_max_default > 0)
703  {
704  nitems_max = nitems_max_default;
705  }
706  else
707  {
708  nitems_max = nitems;
709  }
710  int nitems_left = nitems;
711  int n;
712  bool error_signalled = false;
713 // SYSTEMTIME s1, s2;
714  double d, mb;
715  while(!error_signalled && (nitems_left > 0))
716  {
717  n = (nitems_left > nitems_max ? nitems_max : nitems_left);
718  mb = (double)((n * 4) / (1024 * 1024));
719 // GetSystemTime(&s1);
720  if (false /* n == 1 */)
721  {
722  status = viIn32(session, VI_A32_SPACE, address, data32);
723  }
724  else
725  {
726  if (false)
727  {
728  ViJobId jobid;
729  status = viMoveAsyncEx(session, VI_A32_SPACE, address, VI_WIDTH_32, VI_LOCAL_SPACE,
730  (ViBusAddress64)data32, VI_WIDTH_32, n, &jobid);
731  if (status == VI_SUCCESS_SYNC)
732  {
733  status = VI_SUCCESS;
734  }
735  else if (status == VI_SUCCESS)
736  {
737  jobid_map_t::iterator it;
738  bool done = false;
739  while(!done)
740  {
741  EnterCriticalSection(&m_job_critical);
742  if ( (it = m_jobid_map.find(jobid)) != m_jobid_map.end() )
743  {
744  done = true;
745  }
746  else
747  {
748  LeaveCriticalSection(&m_job_critical);
749  Sleep(300);
750  }
751  }
752  status = it->second;
753  m_jobid_map.erase(it);
754  LeaveCriticalSection(&m_job_critical);
755  }
756  }
757  else
758  {
759  status = viMoveIn32(session, VI_A32_SPACE, address, n, data32);
760  }
761  }
762 // GetSystemTime(&s2);
763  if (status != VI_SUCCESS)
764  {
765  addError(session, "viMoveIn32", status, address, n, "", dstatus);
766  error_signalled = true;
767  }
768 // if (n > 100)
769 // {
770 // d = 60.0 * (double)(s2.wMinute - s1.wMinute) +
771 // (double)(s2.wSecond - s1.wSecond) +
772 // (double)(s2.wMilliseconds - s1.wMilliseconds) / 1000.0;
773 // cout << "Transfer rate / Mb/s = " << mb / d << std::endl;
774 // }
775  nitems_left -= n;
776  data32 += n;
777  address += (4*n);
778  }
779  if (m_endian_workaround && little_endian)
780  {
781  for(i=0; i<nitems; i++)
782  {
783  d32[i] = (((d32[i]) << 24) & 0xff000000) |
784  (((d32[i]) << 8) & 0x00ff0000) |
785  (((d32[i]) >> 8) & 0x0000ff00) |
786  (((d32[i]) >> 24) & 0x000000ff);
787  }
788  }
789 // for(i=0; i<30; i++)
790 // {
791 // std::cerr << hex << k + 4*i << " = " << d32[i] << dec << std::endl;
792 // }
793  if (error_signalled)
794  {
795  return ISISVME::Error;
796  }
797  else
798  {
799  return ISISVME::Success;
800  }
801 }
802 
803 int NIVisa::writeU16(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus& dstatus)
804 {
805  return retrySingle(&NIVisa::writeU16impl, address, data16, props, dstatus);
806 }
807 
808 int NIVisa::writeU16impl(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus& dstatus)
809 {
810  VisaAccessLock visa_lock;
811  ViStatus status;
812  ViSession session;
813  session = getSession(props);
814  status = viOut16(session, VI_A32_SPACE, address, data16);
815  if (status == VI_SUCCESS)
816  {
817  return ISISVME::Success;
818  }
819  else
820  {
821  addError(session, "viOut16", status, address, 1, "", dstatus);
822  return ISISVME::Error;
823  }
824 }
825 
826 int NIVisa::writeU32(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus& dstatus)
827 {
828  return retrySingle(&NIVisa::writeU32impl, address, data32, props, dstatus);
829 }
830 
831 int NIVisa::writeU32impl(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus& dstatus)
832 {
833  VisaAccessLock visa_lock;
834  ViStatus status;
835  ViSession session;
836  session = getSession(props);
837  status = viOut32(session, VI_A32_SPACE, address, data32);
838  if (status == VI_SUCCESS)
839  {
840  return ISISVME::Success;
841  }
842  else
843  {
844  addError(session, "viOut32", status, address, 1, "", dstatus);
845  return ISISVME::Error;
846  }
847 }
848 
849 
850 int NIVisa::writeBlockU16(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus)
851 {
852  return retryBlock(&NIVisa::writeBlockU16impl, address, data16, nitems, props, dstatus);
853 }
854 
855 
856 // nove nitems of 2 bytes
857 // need to check the use of nitems_max in particular is address increment 2*n or 4*n?
858 int NIVisa::writeBlockU16impl(unsigned long address, isisU16_t* data16, long nitems, TransferProps props, DAEstatus& dstatus)
859 {
860  VisaAccessLock visa_lock;
861  int nitems_max;
862  ViStatus status;
863  ViSession session;
864  session = getSession(props);
865  if (nitems_max_default > 0)
866  {
867  nitems_max = nitems_max_default;
868  }
869  else
870  {
871  nitems_max = nitems;
872  }
873  int nitems_left = nitems;
874  int n;
875  bool error_signalled = false;
876  while(nitems_left > 0)
877  {
878  n = (nitems_left > nitems_max ? nitems_max : nitems_left);
879  status = viMoveOut16(session, VI_A32_SPACE, address, n, data16);
880  if (status != VI_SUCCESS)
881  {
882  addError(session, "viMoveOut16", status, address, n, "", dstatus);
883  error_signalled = true;
884  }
885  nitems_left -= n;
886  data16 += n;
887  address += (4*n);
888  }
889  if (error_signalled)
890  {
891  return ISISVME::Error;
892  }
893  else
894  {
895  return ISISVME::Success;
896  }
897 }
898 
899 
900 int NIVisa::writeBlockU32(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus)
901 {
902  return retryBlock(&NIVisa::writeBlockU32impl, address, data32, nitems, props, dstatus);
903 }
904 
905 int NIVisa::writeBlockU64(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus)
906 {
907  return retryBlock(&NIVisa::writeBlockU64impl, address, data64, nitems, props, dstatus);
908 }
909 
910 int NIVisa::writeBlockU64impl(unsigned long address, uint64_t* data64, long nitems, TransferProps props, DAEstatus& dstatus)
911 {
912  return writeBlockU32impl(address, reinterpret_cast<isisU32_t*>(data64), 2 * nitems, props, dstatus);
913 }
914 
915 // nove nitems of 4 bytes
916 int NIVisa::writeBlockU32impl(unsigned long address, isisU32_t* data32, long nitems, TransferProps props, DAEstatus& dstatus)
917 {
918  VisaAccessLock visa_lock;
919  bool little_endian = (props & ISISVME::TransferLittleEndian ? true : false);
920  int i, nitems_max;
921  ViStatus status;
922  ViSession session;
923  unsigned long k = address;
924  if (nitems_max_default > 0)
925  {
926  nitems_max = nitems_max_default;
927  }
928  else
929  {
930  nitems_max = nitems;
931  }
932  int nitems_left = nitems;
933  int n;
934  bool error_signalled = false;
935  session = getSession(props);
936  isisU32_t *data32_tmp = NULL;
937  if (m_endian_workaround && little_endian)
938  {
939  data32_tmp = new isisU32_t[nitems];
940  for(i=0; i<nitems; i++)
941  {
942  data32_tmp[i] = (((data32[i]) << 24) & 0xff000000) |
943  (((data32[i]) << 8) & 0x00ff0000) |
944  (((data32[i]) >> 8) & 0x0000ff00) |
945  (((data32[i]) >> 24) & 0x000000ff);
946  }
947  data32 = data32_tmp;
948  }
949  while(!error_signalled && (nitems_left > 0))
950  {
951  n = (nitems_left > nitems_max ? nitems_max : nitems_left);
952  if (false /* n == 1 */ )
953  {
954  status = viOut32(session, VI_A32_SPACE, address, *data32);
955  }
956  else
957  {
958  status = viMoveOut32(session, VI_A32_SPACE, address, n, data32);
959  }
960  if (status != VI_SUCCESS)
961  {
962  addError(session, "viMoveOut32", status, address, n, "", dstatus);
963  error_signalled = true;
964  }
965  nitems_left -= n;
966  data32 += n;
967  address += (4*n);
968  }
969  if (data32_tmp != NULL)
970  {
971  delete[] data32_tmp;
972  data32_tmp = NULL;
973  }
974  if (error_signalled)
975  {
976  return ISISVME::Error;
977  }
978  else
979  {
980  return ISISVME::Success;
981  }
982 }
983 
984 int NIVisa::setEndian(ViSession session, bool little_endian, DAEstatus& dstatus)
985 {
986  VisaAccessLock visa_lock;
987  ViStatus status;
988  ViUInt16 order;
989  if (little_endian)
990  {
991  order = VI_LITTLE_ENDIAN;
992  }
993  else
994  {
995  order = VI_BIG_ENDIAN;
996  }
997  status = viSetAttribute(session, VI_ATTR_DEST_BYTE_ORDER, order);
998  if (status == VI_SUCCESS)
999  {
1000  status = viSetAttribute(session, VI_ATTR_SRC_BYTE_ORDER, order);
1001  }
1002 // we do not use viPeek() and viPoke() and so shoul dnot need to set this
1003 // if (status == VI_SUCCESS)
1004 // {
1005 // status = viSetAttribute(session, VI_ATTR_WIN_BYTE_ORDER, order);
1006 // }
1007  if (status == VI_SUCCESS)
1008  {
1009  return ISISVME::Success;
1010  }
1011  else
1012  {
1013  addError(session, "viSetAttribute(ENDIAN)", status, "", dstatus);
1014  return ISISVME::Error;
1015  }
1016 }
1017 
1018 int NIVisa::enableBlockTransfers(ViSession session, DAEstatus& dstatus)
1019 {
1020  VisaAccessLock visa_lock;
1021  ViStatus status;
1022  ViUInt16 priv = VI_BLCK_PRIV;
1023  if (m_block_transfers)
1024  {
1025  status = viSetAttribute(session, VI_ATTR_DEST_ACCESS_PRIV, priv);
1026  if (status == VI_SUCCESS)
1027  {
1028  status = viSetAttribute(session, VI_ATTR_SRC_ACCESS_PRIV, priv);
1029  }
1030  if (status == VI_SUCCESS)
1031  {
1032  return ISISVME::Success;
1033  }
1034  else
1035  {
1036  addError(session, "viSetAttribute(BLCK_PRIV)", status, "", dstatus);
1037  return ISISVME::Error;
1038  }
1039  }
1040  return ISISVME::Success;
1041 }
1042 
1043 int NIVisa::disableBlockTransfers(ViSession session, DAEstatus& dstatus)
1044 {
1045  VisaAccessLock visa_lock;
1046  ViStatus status;
1047  ViUInt16 priv = VI_DATA_PRIV;
1048 // if (m_block_transfers)
1049 // {
1050  status = viSetAttribute(session, VI_ATTR_DEST_ACCESS_PRIV, priv);
1051  if (status == VI_SUCCESS)
1052  {
1053  status = viSetAttribute(session, VI_ATTR_SRC_ACCESS_PRIV, priv);
1054  }
1055  if (status == VI_SUCCESS)
1056  {
1057  return ISISVME::Success;
1058  }
1059  else
1060  {
1061  addError(session, "viSetAttribute(DATA_PRIV)", status, "", dstatus);
1062  return ISISVME::Error;
1063  }
1064 // }
1065  return ISISVME::Success;
1066 }
1067 
1068 int NIVisa::restoreTransferMode(ViSession session, int mode, DAEstatus& dstatus)
1069 {
1070  VisaAccessLock visa_lock;
1071  ViStatus status;
1072  ViUInt16 priv = mode;
1073  status = viSetAttribute(session, VI_ATTR_DEST_ACCESS_PRIV, priv);
1074  if (status == VI_SUCCESS)
1075  {
1076  status = viSetAttribute(session, VI_ATTR_SRC_ACCESS_PRIV, priv);
1077  }
1078  if (status == VI_SUCCESS)
1079  {
1080  return ISISVME::Success;
1081  }
1082  else
1083  {
1084  addError(session, "restoreTransferMode", status, "", dstatus);
1085  return ISISVME::Error;
1086  }
1087 }
1088 
1090 {
1091  VisaAccessLock visa_lock;
1093  unlockDevice(dstatus);
1094  ViStatus status;
1095  if (m_instr_le != VI_NULL)
1096  {
1097  status = viClose(m_instr_le);
1098  m_instr_le = VI_NULL;
1099  }
1100  if (m_instr_be != VI_NULL)
1101  {
1102  status = viClose(m_instr_be);
1103  m_instr_be = VI_NULL;
1104  }
1105  if (m_instr_le_bt != VI_NULL)
1106  {
1107  status = viClose(m_instr_le_bt);
1108  m_instr_le_bt = VI_NULL;
1109  }
1110  if (m_instr_be_bt != VI_NULL)
1111  {
1112  status = viClose(m_instr_be_bt);
1113  m_instr_be_bt = VI_NULL;
1114  }
1115  if (m_instr_backplane != VI_NULL)
1116  {
1117  status = viDisableEvent(m_instr_backplane, VI_EVENT_TRIG, VI_ALL_MECH);
1118  status = viUninstallHandler(m_instr_backplane, VI_EVENT_TRIG, TriggerHandler, this);
1119  status = viClose(m_instr_backplane);
1120  m_instr_backplane = VI_NULL;
1121  }
1122  m_init_done = false;
1123  return ISISVME::Success;
1124 }
1125 
1127 {
1128  VisaAccessLock visa_lock;
1130  std::ostringstream message;
1131  ViStatus status;
1132  ViChar descr[VI_FIND_BUFLEN];
1133  ViUInt32 i, numInstrs;
1134  ViFindList fList;
1135  status = viFindRsrc(m_default_rm, "?*VXI[0-9]*::?*INSTR?*",
1136  &fList, &numInstrs, descr);
1137  if (status != VI_SUCCESS)
1138  {
1139  addError(m_default_rm, "viFindRsc ( ?*VXI[0-9]*::?*INSTR?* )", status, "", dstatus);
1140  }
1141  if (numInstrs == 0)
1142  {
1143  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, "No VME devices found");
1144  }
1145  i = numInstrs;
1146  while(i--)
1147  {
1148  message << descr << '\n';
1149  viFindNext(fList, descr);
1150  }
1151  dstatus.addInfo(FAC_NIVISA, message.str());
1152  viClose(fList);
1153  return numInstrs;
1154 }
1155 
1157 {
1158 // resetBusDevice("VXI0::1::INSTR");
1159  VisaAccessLock visa_lock;
1161  ViStatus status;
1162  ViInt16 state;
1163  status = viAssertUtilSignal(m_instr_backplane, VI_UTIL_ASSERT_SYSRESET);
1164  if (status != VI_SUCCESS)
1165  {
1166  addError(m_instr_backplane, "viAssertUtilSignal(ASSERT_SYSRESET)", status, "", dstatus);
1167  return false;
1168  }
1169 // During a SYSRESET devices assert SYSFAIL while their power up
1170 // tests are being done. SYSFAIL must be asserted within 50ms of the
1171 // start of the SYSRESET and remains asserted until reset is complete
1172  Sleep(200);
1173  bool reset_done = false;
1174  while(!reset_done)
1175  {
1176  status = viGetAttribute(m_instr_backplane, VI_ATTR_VXI_VME_SYSFAIL_STATE, &state);
1177  if (status != VI_SUCCESS)
1178  {
1179  addError(m_instr_backplane, "viGetAttribute(SYSFAIL_STATE)", status, "", dstatus);
1180  return false;
1181  }
1182  if (state == 0 /*VI_STATE_DEASSERTED*/ )
1183  {
1184  reset_done = true;
1185  }
1186  else
1187  {
1188  dstatus.addInfo(FAC_NIVISA, "VISA: Waiting for SYSFAIL to be removed from backplane");
1189  Sleep(1000);
1190  }
1191  }
1192  return true;
1193 }
1194 
1195 bool NIVisa::resetBusDevice(const char* name, DAEstatus& dstatus)
1196 {
1197  VisaAccessLock visa_lock;
1198  std::ostringstream message;
1199  ViStatus status;
1200  ViSession instr;
1201  ViUInt16 data16;
1202  unsigned enableA32;
1204  status = viOpen(m_default_rm, (char*)name, VI_NULL,
1205  VI_NULL, &instr);
1206  if (status != VI_SUCCESS)
1207  {
1208  message << "viOpen " << name << " " << status << std::endl;
1209  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, message.str());
1210  return false;
1211  }
1212 // read VME status/control register
1213  status = viIn16(instr, VI_A16_SPACE, 0x4, &data16);
1214  if (status != VI_SUCCESS)
1215  {
1216  message << "viOIn16 " << name << " " << status << std::endl;
1217  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, message.str());
1218  return false;
1219  }
1220  enableA32 = data16 & (1 << 15);
1221 // std::cerr << "VMEreset: a32 is " << enableA32 << std::endl;
1222 // start board reset
1223  viOut16(instr, VI_A16_SPACE, 0x4, 0xffff);
1224 // wait at least 100 usec
1225  Sleep(1);
1226 // end board reset
1227  viOut16(instr, VI_A16_SPACE, 0x4, 0xfffe);
1228 // check bits 2 and 3 set
1229  viIn16(instr, VI_A16_SPACE, 0x4, &data16);
1230  if ((data16 & 0xc) != 0xc)
1231  {
1232  message << "VME reset failed 0x" << std::hex << data16 << std::dec << std::endl;
1233  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, message.str());
1234  }
1235 // reset A32 mode
1236  viOut16(instr, VI_A16_SPACE, 0x4, 0x7ffc | enableA32);
1237  viClose(instr);
1238  return true;
1239 }
1240 
1242 {
1243  ViStatus status;
1244  DAEstatus dstatus;
1245  close(dstatus);
1246  if (m_default_rm != VI_NULL)
1247  {
1248  status = viClose(m_default_rm);
1249  m_default_rm = VI_NULL;
1250  }
1251  DeleteCriticalSection(&m_job_critical);
1252  DeleteCriticalSection(&m_visa_critical);
1253 }
1254 
1255 int NIVisa::addError(ViSession session, const char* func, ViStatus status, const std::string& message, DAEstatus& dstatus)
1256 {
1257  std::ostringstream oss;
1258  oss << message << '\n';
1259  printError(session, func, status, oss);
1260  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, oss.str());
1261  return 0;
1262 }
1263 
1264 int NIVisa::addError(ViSession session, const char * func, ViStatus status,
1265  unsigned long address, long nitems, const std::string& message, DAEstatus& dstatus)
1266 {
1267  std::ostringstream oss;
1268  oss << message << '\n';
1269  printError(session, func, status, address, nitems, oss);
1270  dstatus.add(FAC_NIVISA, SEV_ERROR, ERRTYPE_NIVISA, oss.str());
1271  return 0;
1272 }
1273 
1274 int NIVisa::printError(ViSession session, const char * func, ViStatus status, std::ostream& os)
1275 {
1276  ViChar desc[512];
1277  if (viStatusDesc(session, status, desc) == VI_SUCCESS)
1278  {
1279  os << "NIVISA: Error \"" << desc << "\" returned from \"" << func << "\"";
1280  }
1281  else
1282  {
1283  os << "NIVISA: Unknown Error code " << status << " returned from \"" << func << "\"";
1284  }
1285  return 0;
1286 }
1287 
1288 int NIVisa::printError(ViSession session, const char * func, ViStatus status,
1289  unsigned long address, long nitems, std::ostream& os)
1290 {
1291  ViChar desc[512]; // needs to be at least 256 bytes according to NI manual
1292  desc[0] = '\0';
1293  if (viStatusDesc(session, status, desc) == VI_SUCCESS)
1294  {
1295  os << "NIVISA: Error \"" << desc << "\" (code 0x" << std::hex << status << std::dec << ") returned from \"" << func << "\" "
1296  << " while transferring " << nitems << " items at VME address 0x"
1297  << std::hex << address << std::dec;
1298  }
1299  else
1300  {
1301  os << "NIVISA: Unknown Error code " << status << " returned from \"" << func << "\"";
1302  }
1303  return 0;
1304 }
1305 
1306 int NIVisa::writeBlock(unsigned long address, isisU32_t* data, long nitems, TransferProps props, DAEstatus& status)
1307 {
1308  return writeBlockU32(address, data, nitems, props, status);
1309 }
1310 
1311 int NIVisa::writeBlock(unsigned long address, uint64_t* data, long nitems, TransferProps props, DAEstatus& status)
1312 {
1313  return writeBlockU64(address, data, nitems, props, status);
1314 }
1315 
1316 int NIVisa::readBlock(unsigned long address, isisU32_t* data, long nitems, TransferProps props, DAEstatus& status)
1317 {
1318  return readBlockU32(address, data, nitems, props, status);
1319 }
1320 
1321 int NIVisa::readBlock(unsigned long address, uint64_t* data, long nitems, TransferProps props, DAEstatus& status)
1322 {
1323  return readBlockU64(address, data, nitems, props, status);
1324 }
1325 
1326 #if 0
1327 at startup
1328 status = ViLock(instr, VI_SHARED_LOCK, 15000, "DAE2VMELock", accessKey);
1329 // accessKey should now be "DAE2VMELock"
1330 // before write
1331 // not sure which pf these to use
1332 ViLock(instr, VI_LOCK_EXCLUSIVE, 5000, "DAE2VMELock", VI_NULL)
1333 ViLock(instr, VI_LOCK_EXCLUSIVE, 5000, VI_NULL, VI_NULL)
1334 #endif
1335 
1336 const int NIVisa::m_tries = 5;
1337 const int NIVisa::m_retry_time = 1000;
1338 bool NIVisa::m_endian_workaround = true;
1339 char* NIVisa::m_visa_lock_name = NULL;
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
#define FAC_DAE
#define SEV_WARNING
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
static DWORD m_locker_id
Definition: nivisa.cpp:12
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
unsigned long isisU32_t
Definition: isisvme_types.h:8
ViSession getSession(TransferProps props)
Definition: nivisa.cpp:655
int add(DAEstatus &dstatus, bool clear)
Definition: DAEstatus.cpp:131
trigger_func_t * m_trigger_func
Definition: nivisa.h:27
static int nitems_max_default
Definition: nivisa.cpp:6
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
#define LOGSTR_WARNING(__arg)
Definition: IsisBase.h:92
static const DWORD INVALID_THREAD_ID
Definition: nivisa.cpp:11
int reinit(DAEstatus &dstatus)
Definition: nivisa.cpp:94
int scanBus(DAEstatus &status)
Definition: nivisa.cpp:1126
int openBackplane(const char *device_bp, DAEstatus &dstatus)
Definition: nivisa.cpp:355
#define SEV_ERROR
void unlockInterface(DAEstatus &dstatus)
Definition: nivisa.cpp:74
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
static LONG m_count
Definition: nivisa.cpp:13
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
#define LOGSTR_INFORMATION(__arg)
Definition: IsisBase.h:78
static bool m_endian_workaround
Definition: nivisa.h:12
static void unlockExclusive()
Definition: nivisa.cpp:50
#define LOGSTR_ERROR(__arg)
Definition: IsisBase.h:99
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 resetSeverityToAtLeast(int severity)
Definition: DAEstatus.cpp:184
#define FAC_NIVISA
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
static Poco::RWLock m_interface_lock
Definition: nivisa.cpp:10
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 severity()
Definition: DAEstatus.h:142
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 lockDevice(int timeout, DAEstatus &dstatus)
Definition: nivisa.cpp:425
ViSession m_instr_be
Definition: nivisa.h:15
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
void setLoggerName(const std::string &logger_name)
Definition: IsisBase.h:17
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 addInfo(int facility, const std::string &text)
Definition: DAEstatus.cpp:86
#define ERRTYPE_NIVISA
int resetSeverityToAtMost(int severity)
Definition: DAEstatus.cpp:167
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 addInfoVa(int facility, const char *format,...)
Definition: DAEstatus.cpp:91
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
static void lockExclusive()
Definition: nivisa.cpp:34
int readBlockU64(unsigned long address, uint64_t *data64, long nitems, TransferProps props, DAEstatus &dstatus)
Definition: nivisa.cpp:649