C++ Instrument Catalog
USBRemoteBox.cpp
Go to the documentation of this file.
1 // Personal includes
2 #include "USBRemoteBox.h"
3 #include "Helpers.h"
4 
5 //----------------------------------------------------------------------//
6 // Definitions //
7 //----------------------------------------------------------------------//
8 #define DEBUG_MTL_INSTRUMENT_USBREMOTEBOX 1
9 #define DEBUG_MTL_INSTRUMENT_USBREMOTEBOX_ERRORS_ONLY 1
10 #if (defined(_DEBUG) && defined(DEBUG_MTL_INSTRUMENT_USBREMOTEBOX) && DEBUG_MTL_INSTRUMENT_USBREMOTEBOX)
11 #if (defined(DEBUG_MTL_INSTRUMENT_USBREMOTEBOX_ERRORS_ONLY) && DEBUG_MTL_INSTRUMENT_USBREMOTEBOX_ERRORS_ONLY)
12 #define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(__X__)
13 #else
14 #define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(__X__) COUT(__X__)
15 #endif
16 #define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_CERR(__X__) CERR(__X__)
17 #else
18 #define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(__X__)
19 #define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_CERR(__X__)
20 #endif
21 
22 // Utilities
23 #define UNUSED_VAR(x) (void)x; // Prevents from unereferenced variable when compiling in release
24 
25 using namespace MTL::Instrument;
26 
27 const std::string CUSBRemoteBox::RSRC_FILTER = "USB[0-9]*::0x1BFA::0x1F6D::[0-9]+::RAW";
28 
30  : CVISAInstrument(rRM, Rsrc)
31 {
32 
33 }
34 
36 {
37  Disconnect();
38 }
39 
41 {
42  MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
44 
45  try
46  {
48  throw false;
49  if (!CVISAInstrument::SetTimeout(m_Timeout_ms))
50  throw false;
51 
52  ViByte l_BufIn[1];
53  ViUInt16 l_RetCount;
54  if (!CVISAInstrument::UsbControlIn(USB_ENDPOINT_IN | USB_REQUEST_TYPE_VENDOR | USB_RECIPIENT_DEVICE, 255, 0x370B, 0, sizeof(l_BufIn), (ViPBuf)l_BufIn, l_RetCount))
55  throw false;
56  if (!CVISAInstrument::UsbControlOut(USB_ENDPOINT_OUT | USB_REQUEST_TYPE_VENDOR | USB_RECIPIENT_INTERFACE, 2, 0x0002, 0, 0, NULL))
57  throw false;
58  }
59  catch (bool & rE)
60  {
61  UNUSED_VAR(rE);
62  Disconnect();
63  return false;
64  }
65  return true;
66 }
67 
69 {
70  MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
72 
74 }
75 
76 bool CUSBRemoteBox::Update(const uLEDs LEDs, uButtons & rButtons)
77 {
78  MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
80 
81  try
82  {
83  if (!CVISAInstrument::Write((ViPBuf)&LEDs.Buf, sizeof(LEDs.Buf)))
84  throw false;
85  ViUInt32 l_RetLen;
86  if (!CVISAInstrument::Read((ViPBuf)&rButtons.Buf, (ViUInt32)sizeof(rButtons.Buf), l_RetLen))
87  throw false;
88  }
89  catch (bool & rE)
90  {
91  UNUSED_VAR(rE);
92  return false;
93  }
94  return true;
95 }
MTL::Instrument::CVISAInstrument::UsbControlOut
bool UsbControlOut(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf)
Definition: VISAInstrument.cpp:739
MTL::Instrument::CVISAInstrument::UsbControlIn
bool UsbControlIn(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViUInt16 &rretCnt)
Definition: VISAInstrument.cpp:715
MTL::Instrument::CVISAInstrument::Read
bool Read(CVISABuffer &rBuf, bool Append=false)
Definition: VISAInstrument.cpp:430
MTL::Instrument::CUSBRemoteBox::uLEDs
Definition: USBRemoteBox.h:19
USBRemoteBox.h
MTL::Instrument::CUSBRemoteBox::uLEDs::Buf
uint32_t Buf
Definition: USBRemoteBox.h:25
MTL::Instrument::CUSBRemoteBox::uButtons
Definition: USBRemoteBox.h:27
MTL::Instrument::CVISAInstrument::SetTimeout
bool SetTimeout(ViUInt32 Timeout)
Definition: VISAInstrument.cpp:468
UNUSED_VAR
#define UNUSED_VAR(x)
Definition: USBRemoteBox.cpp:23
MTL::Instrument::CVISAInstrument::m_Lock
CRecursiveMutex m_Lock
Definition: VISAInstrument.h:63
Helpers.h
Collection of utility macros for error messages.
MTL::Instrument::CVISAInstrument::Write
bool Write(const char *Str)
Definition: VISAInstrument.cpp:393
MTL::Instrument
Definition: MFC3045.h:25
MTL::Instrument::CVISAInstrument::Close
void Close()
Definition: VISAInstrument.cpp:356
MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT
#define MTL_INSTRUMENT_USBREMOTEBOX_DEBUG_COUT(__X__)
Definition: USBRemoteBox.cpp:18
MTL::Instrument::CUSBRemoteBox::~CUSBRemoteBox
virtual ~CUSBRemoteBox()
Definition: USBRemoteBox.cpp:35
MTL::Instrument::CVISAInstrument::Open
bool Open(eOpenAccessMode AccessMode=eOpenAccessMode::NoLock, ViUInt32 Timeout_ms=0)
Definition: VISAInstrument.cpp:335
MTL::Instrument::CUSBRemoteBox::Disconnect
void Disconnect()
Definition: USBRemoteBox.cpp:68
MTL::Instrument::CUSBRemoteBox::uButtons::Buf
uint32_t Buf
Definition: USBRemoteBox.h:36
MTL::Instrument::CUSBRemoteBox::CUSBRemoteBox
CUSBRemoteBox(CVISAResourceManager &rRM, tResourceName Rsrc)
Definition: USBRemoteBox.cpp:29
MTL::Instrument::tResourceName
std::string tResourceName
Definition: VISAInstrumentTypes.h:21
MTL::Instrument::CUSBRemoteBox::RSRC_FILTER
static const std::string RSRC_FILTER
Definition: USBRemoteBox.h:18
MTL::Synchronization::CLockGuard
Lock.
Definition: Synchronization.h:62
MTL::Instrument::CUSBRemoteBox::Connect
bool Connect()
Definition: USBRemoteBox.cpp:40
MTL::Instrument::CVISAInstrument
VISA instrument class.
Definition: VISAInstrument.h:60
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition: VISAInstrument.h:35
MTL::Instrument::CUSBRemoteBox::Update
bool Update(const uLEDs LEDs, uButtons &rButtons)
Definition: USBRemoteBox.cpp:76
MTL::Instrument::eOpenAccessMode::ExclusiveLock
@ ExclusiveLock