23#define DEBUG_MTL_USBTMC_INSTRUMENT 0
24#define DEBUG_MTL_USBTMC_INSTRUMENT_ERRORS_ONLY 0
25#if (defined(_DEBUG) && defined(DEBUG_MTL_USBTMC_INSTRUMENT) && DEBUG_MTL_USBTMC_INSTRUMENT)
26 #if (defined(DEBUG_MTL_USBTMC_INSTRUMENT_ERRORS_ONLY) && DEBUG_MTL_USBTMC_INSTRUMENT_ERRORS_ONLY)
27 #define MTL_USBTMC_INSTRUMENT_DEBUG_COUT(__X__)
29 #define MTL_USBTMC_INSTRUMENT_DEBUG_COUT(__X__) COUT(__X__)
31 #define MTL_USBTMC_INSTRUMENT_DEBUG_CERR(__X__) CERR(__X__)
33 #define MTL_USBTMC_INSTRUMENT_DEBUG_COUT(__X__)
34 #define MTL_USBTMC_INSTRUMENT_DEBUG_CERR(__X__)
36#define MTL_USBTMC_PAUSE_BETWEEN_READS 2
54 for (
auto l_pDeviceListEntry = m_DeviceList.begin(); l_pDeviceListEntry != m_DeviceList.end(); l_pDeviceListEntry++)
56 if (l_pDeviceListEntry->pDevice !=
nullptr)
57 libusb_unref_device(l_pDeviceListEntry->pDevice);
62 if (m_pContext !=
nullptr)
63 libusb_exit(m_pContext);
77 m_Status = libusb_init (&m_pContext);
82 m_Status = libusb_set_option (m_pContext, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_WARNING);
92 if (m_pContext !=
nullptr)
93 libusb_exit (m_pContext);
108 libusb_device ** l_USBDeviceList =
nullptr;
109 libusb_device_handle * l_hDevice =
nullptr;
110 tUSBTMCDeviceListEntry l_NewDeviceListEntry;
111 l_NewDeviceListEntry.clear();
117 for (
auto l_pDeviceListEntry = m_DeviceList.begin(); l_pDeviceListEntry != m_DeviceList.end(); l_pDeviceListEntry++)
118 l_pDeviceListEntry->PluggedIn =
false;
121 const std::regex l_RegexVID_PID(
"([0-9]+):([0-9]+)");
122 std::smatch l_MatchVID_PID;
123 if (!std::regex_match(Filter, l_MatchVID_PID, l_RegexVID_PID) ||
124 l_MatchVID_PID.size() != 3)
127 U16 l_VID =
static_cast<U16>(stoi(l_MatchVID_PID[1].str()));
128 U16 l_PID =
static_cast<U16>(stoi(l_MatchVID_PID[2].str()));
131 ssize_t l_DeviceCount = libusb_get_device_list(
nullptr, &l_USBDeviceList);
132 if (l_DeviceCount < 0)
136 for (ssize_t i = 0; i < l_DeviceCount; i++)
139 l_NewDeviceListEntry.clear();
142 libusb_device * l_pUSBDevice = l_USBDeviceList[i];
143 struct libusb_device_descriptor l_USBDeviceDescriptor;
144 m_Status = libusb_get_device_descriptor(l_pUSBDevice, &l_USBDeviceDescriptor);
149 if (l_USBDeviceDescriptor.idVendor != l_VID ||
150 l_USBDeviceDescriptor.idProduct != l_PID)
156 if (l_PathLength < 0)
158 std::vector<U8> l_PortPath;
159 for (
I32 i = 0; i < l_PathLength; i++)
160 l_PortPath.push_back(l_PortNumbers[i]);
164 auto l_pDeviceListEntry = m_DeviceList.begin();
165 for (; l_pDeviceListEntry != m_DeviceList.end(); l_pDeviceListEntry++)
166 if (l_PortPath == l_pDeviceListEntry->PortPath)
break;
167 if (l_pDeviceListEntry != m_DeviceList.end())
169 rList.push_back(l_pDeviceListEntry->ResourceName);
170 l_pDeviceListEntry->PluggedIn =
true;
176 m_Status = libusb_open(l_pUSBDevice, &l_hDevice);
181 libusb_ref_device(l_pUSBDevice);
182 l_NewDeviceListEntry.pDevice = l_pUSBDevice;
183 l_NewDeviceListEntry.PortPath = l_PortPath;
184 l_NewDeviceListEntry.PluggedIn =
true;
189 l_StringLength = libusb_get_string_descriptor_ascii (l_hDevice, l_USBDeviceDescriptor.iManufacturer, l_String,
USB_DESCRIPTOR_STRING_LENGTH);
190 if (l_StringLength < 0)
192 std::string l_Manufacturer = std::string(
reinterpret_cast<char *
>(l_String),
static_cast<size_t>(l_StringLength));
194 l_StringLength = libusb_get_string_descriptor_ascii (l_hDevice, l_USBDeviceDescriptor.iProduct, l_String,
USB_DESCRIPTOR_STRING_LENGTH);
195 if (l_StringLength < 0)
197 std::string l_Product = std::string(
reinterpret_cast<char *
>(l_String),
static_cast<size_t>(l_StringLength));
199 l_StringLength = libusb_get_string_descriptor_ascii (l_hDevice, l_USBDeviceDescriptor.iSerialNumber, l_String,
USB_DESCRIPTOR_STRING_LENGTH);
200 if (l_StringLength < 0)
202 std::string l_SerialNumber = std::string(
reinterpret_cast<char *
>(l_String),
static_cast<size_t>(l_StringLength));
204 l_NewDeviceListEntry.ResourceName = l_Manufacturer +
" " + l_Product +
" " + l_SerialNumber;
207 libusb_close(l_hDevice);
211 m_DeviceList.push_back(l_NewDeviceListEntry);
212 rList.push_back(l_NewDeviceListEntry.ResourceName);
217 libusb_free_device_list(l_USBDeviceList, 1);
220 for (
auto l_pDeviceListEntry = m_DeviceList.begin(); l_pDeviceListEntry != m_DeviceList.end();)
222 if (!l_pDeviceListEntry->PluggedIn)
224 libusb_unref_device(l_pDeviceListEntry->pDevice);
225 l_pDeviceListEntry = m_DeviceList.erase(l_pDeviceListEntry);
229 ++l_pDeviceListEntry;
234 if (rList.size() == 0)
245 if (l_USBDeviceList !=
nullptr)
246 libusb_free_device_list(l_USBDeviceList, 1);
247 if (l_hDevice !=
nullptr)
248 libusb_close(l_hDevice);
249 if (l_NewDeviceListEntry.pDevice !=
nullptr)
250 libusb_unref_device(l_NewDeviceListEntry.pDevice);
252 for (
auto l_pDeviceListEntry = m_DeviceList.begin(); l_pDeviceListEntry != m_DeviceList.end(); l_pDeviceListEntry++)
254 libusb_unref_device(l_pDeviceListEntry->pDevice);
256 m_DeviceList.clear();
266bool CUSBTMCResourceManager::GetDeviceListEntry(
const tResourceName ResourceName, libusb_device * & pDevice)
272 tUSBTMCDeviceListEntry * l_pDeviceListEntry =
nullptr;
273 for (
auto l_pDeviceList = m_DeviceList.begin(); l_pDeviceList != m_DeviceList.end(); l_pDeviceList++)
275 if (l_pDeviceList->ResourceName == ResourceName)
277 l_pDeviceListEntry = &(*l_pDeviceList);
283 if (l_pDeviceListEntry ==
nullptr)
292 pDevice = l_pDeviceListEntry->pDevice;
293 libusb_ref_device(pDevice);
306 return libusb_error_name(
Status);
317 return (
m_Status == LIBUSB_ERROR_TIMEOUT);
338 return (
R8(pResponse + 0) == USBTMC_status &&
339 R8(pResponse + 1) == bTag &&
340 R8(pResponse + 2) == StatusByte);
347 U8 bmTransferAttributes,
350 W8 (pHeader + 0, MsgID);
351 W8 (pHeader + 1, bTag);
352 W8 (pHeader + 2, ~bTag);
354 WL32(pHeader + 4, TransferSize);
355 W8 (pHeader + 8, bmTransferAttributes);
356 W8 (pHeader + 9, TermChar);
357 WL16(pHeader + 10, 0);
364 U8 & bmTransferAttributes)
366 if (
R8(pHeader + 0) != MsgID ||
367 R8(pHeader + 1) != bTag ||
368 R8(pHeader + 2) != (
unsigned char)~bTag)
370 TransferSize =
RL32(pHeader + 4);
371 bmTransferAttributes =
R8(pHeader + 8);
389static class:
public std::map<libusb_device *, tControlRecord *>
397 auto l_pClaimCheck = find(pDevice);
398 if (l_pClaimCheck != end())
400 l_pClaimCheck->second->UseCount++;
405 emplace(pDevice, l_pNewControlRecord);
406 libusb_ref_device(pDevice);
412 auto l_pClaimCheck = find(pDevice);
413 if (l_pClaimCheck != end())
415 l_pClaimCheck->second->UseCount--;
416 if (0 == l_pClaimCheck->second->UseCount)
418 delete l_pClaimCheck->second;
419 erase(l_pClaimCheck);
420 libusb_unref_device(pDevice);
429 bool Claim(libusb_device * pDevice,
U32 Timeout = 0)
432 auto l_pClaimCheck = find(pDevice);
433 if (l_pClaimCheck == end())
436 return l_pClaimCheck->second->Mutex.try_lock_for(std::chrono::milliseconds(Timeout));
441 auto l_pClaimCheck = find(pDevice);
442 if (l_pClaimCheck != end())
444 l_pClaimCheck->second->Mutex.unlock();
459 m_ConfigurationNo(0), m_InterfaceNo(0), m_InterruptEndpoint(0), m_BulkInEndpoint(0), m_BulkOutEndpoint(0),
460 m_BulkInMaxPacketSize(0), m_bTag(0), m_ExclusiveLock(false), m_SRQEnable(false)
482 struct libusb_config_descriptor * l_pConfig =
nullptr;
487 if (
IsOpen())
return true;
494 struct libusb_device_descriptor l_USBDeviceDescriptor;
495 m_Status = libusb_get_device_descriptor(m_pDevice, &l_USBDeviceDescriptor);
500 bool l_FoundInterface =
false;
501 for (
U8 l_iConf = 0; l_iConf < l_USBDeviceDescriptor.bNumConfigurations; l_iConf++)
503 int l_ReturnValue = libusb_get_config_descriptor(m_pDevice, l_iConf, &l_pConfig);
504 if (l_ReturnValue < 0 && l_ReturnValue != LIBUSB_ERROR_NOT_FOUND)
508 for (
int l_iIntfc = 0; l_iIntfc < l_pConfig->bNumInterfaces; l_iIntfc++)
510 const struct libusb_interface_descriptor * l_pIntfc = l_pConfig->interface[l_iIntfc].altsetting;
511 if (l_pIntfc->bInterfaceClass != LIBUSB_CLASS_APPLICATION ||
515 m_ConfigurationNo = l_pConfig->bConfigurationValue;
516 m_InterfaceNo = l_pIntfc->bInterfaceNumber;
519 for (
int l_iEP = 0; l_iEP < l_pIntfc->bNumEndpoints; l_iEP++)
521 const struct libusb_endpoint_descriptor * l_pEndpoint = &l_pIntfc->endpoint[l_iEP];
522 if (l_pEndpoint->bmAttributes == LIBUSB_TRANSFER_TYPE_BULK &&
523 !(l_pEndpoint->bEndpointAddress & (LIBUSB_ENDPOINT_DIR_MASK)))
525 m_BulkOutEndpoint = l_pEndpoint->bEndpointAddress;
527 if (l_pEndpoint->bmAttributes == LIBUSB_TRANSFER_TYPE_BULK &&
528 l_pEndpoint->bEndpointAddress & (LIBUSB_ENDPOINT_DIR_MASK))
530 m_BulkInEndpoint = l_pEndpoint->bEndpointAddress;
532 if (l_pEndpoint->bmAttributes == LIBUSB_TRANSFER_TYPE_INTERRUPT &&
533 l_pEndpoint->bEndpointAddress & (LIBUSB_ENDPOINT_DIR_MASK))
535 m_InterruptEndpoint = l_pEndpoint->bEndpointAddress;
540 m_BulkInMaxPacketSize = libusb_get_max_packet_size(m_pDevice, m_BulkInEndpoint);
543 l_FoundInterface =
true;
548 libusb_free_config_descriptor(l_pConfig);
550 if (l_FoundInterface)
break;
555 if (!l_FoundInterface)
559 m_Status = libusb_open(m_pDevice, &m_hDevice);
565 libusb_set_auto_detach_kernel_driver (m_hDevice, 1);
569 m_Status = libusb_get_configuration(m_hDevice, &l_CurrentConfig);
572 if (l_CurrentConfig != m_ConfigurationNo)
574 m_Status =libusb_set_configuration(m_hDevice, m_ConfigurationNo);
589 if (l_pConfig !=
nullptr)
590 libusb_free_config_descriptor(l_pConfig);
592 if (m_hDevice !=
nullptr)
594 libusb_close(m_hDevice);
598 if (m_pDevice !=
nullptr)
600 libusb_unref_device(m_pDevice);
603 m_ConfigurationNo = 0;
605 m_InterruptEndpoint = 0;
606 m_BulkInEndpoint = 0;
607 m_BulkOutEndpoint = 0;
608 m_BulkInMaxPacketSize = 0;
632 if (m_hDevice !=
nullptr)
634 libusb_close(m_hDevice);
639 if (m_pDevice !=
nullptr)
641 libusb_unref_device(m_pDevice);
649 m_ConfigurationNo = 0;
651 m_InterruptEndpoint = 0;
652 m_BulkInEndpoint = 0;
653 m_BulkOutEndpoint = 0;
654 m_BulkInMaxPacketSize = 0;
664 return (m_pDevice !=
nullptr && m_hDevice !=
nullptr);
676 return libusb_error_name(
Status);
687 return (
m_Status == LIBUSB_ERROR_TIMEOUT);
694bool CUSBTMCInstrument::USBTMCWrite(
U8 MessageID,
const char * pData,
const size_t Size,
U8 TransferAttributes)
699 bool l_InitialLockState = m_ExclusiveLock;
700 U8 * l_pBuffer =
nullptr;
712 I32 l_Size = pData ?
static_cast<I32>(Size) : 0;
714 l_pBuffer =
new U8[
static_cast<size_t>(l_PaddedSize)];
719 if (++m_bTag < 2 || m_bTag > 127)
729 m_Status = libusb_bulk_transfer(m_hDevice,
737 USBTMCClearBulkOut(m_bTag);
741 if (l_Transferred != l_PaddedSize)
752 if (!l_InitialLockState)
Unlock();
758 if (!l_InitialLockState)
Unlock();
761 if (l_pBuffer)
delete l_pBuffer;
801 bool l_InitialLockState = m_ExclusiveLock;
813 if (!Append) rBuf.
clear();
825 I32 l_BufferLength = m_BulkInMaxPacketSize;
828 I32 l_Transferred = 0;
831 m_Status = libusb_bulk_transfer(m_hDevice,
839 USBTMCClearBulkIn(m_bTag);
842 }
while (l_Transferred == 0);
848 U8 l_TransferAttributes;
850 !(l_TransferAttributes &
EOM))
854 size_t l_BufSize = rBuf.
size();
855 size_t l_BufCapacity = rBuf.
capacity();
856 if (l_MessageSize >
static_cast<I32>(l_BufCapacity - l_BufSize))
857 rBuf.
reserve(l_BufSize +
static_cast<size_t>(l_MessageSize));
861 if (l_MessageReceived > 0)
865 size_t l_MessagePending =
static_cast<size_t>(l_MessageSize) - l_MessageReceived;
866 if (l_MessagePending > 0)
871 U8 * l_pData =
reinterpret_cast<U8 *
>(rBuf.
data() + l_BufSize + l_MessageReceived);
872 m_Status = libusb_bulk_transfer(m_hDevice,
875 static_cast<I32>(l_MessagePending),
880 USBTMCClearBulkIn(m_bTag);
883 if (l_Transferred !=
static_cast<I32>(l_MessagePending))
888 rBuf.
resize(l_BufSize +
static_cast<size_t>(l_MessageSize));
898 if (!l_InitialLockState)
Unlock();
904 if (!l_InitialLockState)
Unlock();
912bool CUSBTMCInstrument::USBTMCClearBulkIn(
U8 bTag)
920 I32 l_ReturnValue = libusb_clear_halt(m_hDevice, m_BulkInEndpoint);
921 if (l_ReturnValue < 0)
930 l_ReturnValue = libusb_control_transfer(
934 static_cast<U16>(bTag),
941 if (l_ReturnValue < 0)
949 I32 l_BufferLength = m_BulkInMaxPacketSize;
953 l_ReturnValue = libusb_bulk_transfer(
960 if (l_ReturnValue < 0)
962 }
while (l_Transferred >= l_BufferLength);
969 l_ReturnValue = libusb_control_transfer(
979 if (l_ReturnValue < 0)
983 l_ReadBuffer[1] != 0 ||
984 l_ReadBuffer[2] != 0 ||
985 l_ReadBuffer[3] != 0)
994 catch (MTL::CException<CUSBTMCInstrument> & rE)
1005bool CUSBTMCInstrument::USBTMCClearBulkOut(
U8 bTag)
1008 CLockGuard<CRecursiveMutex> l_LockGuard(
m_Lock);
1013 I32 l_ReturnValue = libusb_clear_halt(m_hDevice, m_BulkOutEndpoint);
1014 if (l_ReturnValue < 0)
1022 l_ReturnValue = libusb_control_transfer(
1026 static_cast<U16>(bTag),
1033 if (l_ReturnValue < 0)
1044 l_ReturnValue = libusb_control_transfer(
1054 if (l_ReturnValue < 0)
1058 l_ReadBuffer[1] != 0 ||
1059 l_ReadBuffer[2] != 0 ||
1060 l_ReadBuffer[3] != 0)
1070 catch (MTL::CException<CUSBTMCInstrument> & rE)
1086 bool l_InitialLockState = m_ExclusiveLock;
1102 I32 l_ReturnValue = libusb_control_transfer(
1113 if (l_ReturnValue < 0)
1121 U8 l_Status, l_Clear;
1124 l_ReturnValue = libusb_control_transfer(
1134 if (l_ReturnValue < 0)
1146 l_ReturnValue = libusb_clear_halt(m_hDevice, m_BulkOutEndpoint);
1147 if (l_ReturnValue < 0)
1152 USBTMCClearBulkIn(m_bTag);
1162 if (!l_InitialLockState)
Unlock();
1168 if (!l_InitialLockState)
Unlock();
1179 bool l_InitialLockState = m_ExclusiveLock;
1195 bool l_GotSTB =
false;
1196 bool l_WriteCommand =
true;
1197 bool l_Success =
false;
1198 bool l_InterruptInBusy =
false;
1199 t_InterruptInData l_InterruptInPacket;
1206 if (++m_bTag < 2 || m_bTag > 127)
1211 I32 l_ReturnValue = libusb_control_transfer(
1222 if (l_ReturnValue < 0)
1227 !(l_Success || l_InterruptInBusy))
1231 l_WriteCommand =
false;
1236 I32 l_ReturnValue = libusb_interrupt_transfer(
1238 m_InterruptEndpoint,
1239 reinterpret_cast<U8 *
>(&l_InterruptInPacket),
1246 if (l_InterruptInBusy && l_ReturnValue == LIBUSB_ERROR_TIMEOUT)
1248 l_WriteCommand =
true;
1253 if (l_ReturnValue < 0)
1259 if (l_InterruptInPacket.bNotify1 == 0x81)
1261 if (m_SRQEnable) m_SRQQueue.push(l_InterruptInPacket);
1266 if (l_InterruptInPacket.bNotify1 != (0x80 | m_bTag))
1270 rSTB = l_InterruptInPacket.bNotify2;
1272 }
while (!l_GotSTB);
1283 if (!l_InitialLockState)
Unlock();
1289 if (!l_InitialLockState)
Unlock();
1300 bool l_InitialLockState = m_ExclusiveLock;
1312 if (++m_bTag < 2 || m_bTag > 127)
1321 m_Status = libusb_bulk_transfer(m_hDevice,
1329 USBTMCClearBulkOut(m_bTag);
1344 if (!l_InitialLockState)
Unlock();
1350 if (!l_InitialLockState)
Unlock();
1364 if (m_ExclusiveLock)
return true;
1374 I32 l_ReturnCode = libusb_claim_interface(m_hDevice, m_InterfaceNo);
1375 if (l_ReturnCode != LIBUSB_SUCCESS)
1383 m_ExclusiveLock =
true;
1394 if (!m_ExclusiveLock)
return true;
1397 I32 l_ReturnCode = libusb_release_interface(m_hDevice, m_InterfaceNo);
1398 if (l_ReturnCode != LIBUSB_SUCCESS)
1407 m_ExclusiveLock =
false;
1414 return m_ExclusiveLock;
1444 m_SRQEnable =
false;
1454 bool l_InitialLockState = m_ExclusiveLock;
1466 if (m_SRQQueue.size() > 0)
1479 t_InterruptInData l_InterruptInPacket;
1481 I32 l_ReturnValue = libusb_interrupt_transfer(
1483 m_InterruptEndpoint,
1484 reinterpret_cast<U8 *
>(&l_InterruptInPacket),
1487 static_cast<unsigned int>(
Timeout));
1490 if (l_ReturnValue < 0)
1493 l_InterruptInPacket.bNotify1 != 0x81)
1505 if (!l_InitialLockState)
Unlock();
1511 if (!l_InitialLockState)
Unlock();
1522 bool l_InitialLockState = m_ExclusiveLock;
1538 while (m_SRQQueue.size() > 0)
1545 t_InterruptInData l_InterruptInPacket;
1547 I32 l_ReturnValue = libusb_interrupt_transfer(
1549 m_InterruptEndpoint,
1550 reinterpret_cast<U8 *
>(&l_InterruptInPacket),
1556 if (l_ReturnValue == LIBUSB_ERROR_TIMEOUT)
1560 if (l_ReturnValue < 0)
1563 l_InterruptInPacket.bNotify1 != 0x81)
1575 if (!l_InitialLockState)
Unlock();
1581 if (!l_InitialLockState)
Unlock();
Collection of utility macros for error messages.
Platform Dependent Definitions.
unsigned char U8
Unsigned byte.
int I32
32-bit signed integer.
unsigned int U32
32-bit unsigned integer.
unsigned short U16
16-bit unsigned integer.
bool Register(libusb_device *pDevice)
static void USBTMCBulkOutHeaderWrite(U8 *pHeader, U8 MsgID, U8 bTag, U32 TransferSize, U8 bmTransferAttributes, char TermChar)
static bool USBTMCBulkInHeaderRead(U8 *pHeader, U8 MsgID, U8 bTag, I32 &TransferSize, U8 &bmTransferAttributes)
#define MTL_USBTMC_PAUSE_BETWEEN_READS
#define MTL_USBTMC_INSTRUMENT_DEBUG_COUT(__X__)
bool Release(libusb_device *pDevice)
bool Claim(libusb_device *pDevice, U32 Timeout=0)
#define MTL_USBTMC_INSTRUMENT_DEBUG_CERR(__X__)
static bool USBTMCReadSTBResponse(U8 *pResponse, U8 USBTMC_status, U8 bTag, U8 StatusByte)
bool Unregister(libusb_device *pDevice)
USBTMC driver based on libusb: interface definition.
static const U8 BULKIN_FIFO_BYTES
static const U16 USBTMC_READSTB_CTRL_RESP_LENGTH
static const U8 DEV_DEP_MSG_IN
static const U8 DEV_DEP_MSG_OUT
static const I32 USBTMC_BULK_TRIGGER_MSG_SIZE
static const U16 USB_CONTROL_ENDPOINT_NUMBER
static const U16 USBTMC_INITIATE_ABORT_BULKIN_RESP_LENGTH
static const U8 REQUEST_DEV_DEP_MSG_IN
static const U16 USBTMC_READSTB_INTR_RESP_LENGTH
static const I32 USB_MAX_PORT_DEPTH
#define R8(x)
Memory access macros.
static const U8 SUBCLASS_USBTMC
Constants for USBTMC and USB488.
static const U32 USB_DESCRIPTOR_STRING_LENGTH
@ USBTMC_STATUS_INTERRUPT_IN_BUSY
static const U16 USBTMC_INITIATE_CLEAR_RESP_LENGTH
static const U16 USBTMC_READ_BUFFER_SIZE
static const U16 USBTMC_CHECK_ABORT_BULKIN_STATUS_RESP_LENGTH
static const U16 USBTMC_CHECK_ABORT_BULKOUT_STATUS_RESP_LENGTH
static const U16 USBTMC_CHECK_CLEAR_STATUS_RESP_LENGTH
static const U8 USBTMC_USB488
static const U8 USBTMC_BM_REQUEST_TYPE_IN_CLS_IF
static const char * USBTMC_ERROR_EXPLANATION[]
Error explanations.
@ USBTMC_ERROR_CLEAR_BULKOUT_RESPONSE_ERROR
@ USBTMC_ERROR_GET_RESRC_NOT_FOUND
@ USBTMC_ERROR_WRITE_INVALID_TRANSFER_COUNT
@ USBTMC_ERROR_READSTB_INTERRUPT_RESPONSE_ERROR
@ USBTMC_ERROR_READSTB_CONTROL_RESPONSE_ERROR
@ USBTMC_ERROR_READ_INVALID_HEADER
@ USBTMC_ERROR_CLEAR_RESPONSE_ERROR
@ USBTMC_ERROR_READ_WRONG_MSG_SIZE
@ USBTMC_ERROR_CLEAR_BULKIN_RESPONSE_ERROR
@ USBTMC_ERROR_FIND_RESRC_BAD_FILTER
@ USBTMC_ERROR_DEVICE_NOT_OPEN
@ USBTMC_ERROR_SRQ_NOT_ENABLED
@ USBTMC_ERROR_INSTRUMENT_LOCKED
@ USBTMC_ERROR_FIND_RESRC_NO_USBTMC_USB488
static const U8 USBTMC_BM_REQUEST_TYPE_IN_CLS_EP
static const I32 USBTMC_BULK_HEADER_SIZE
static const U32 USBTMC_CHECK_CLEAR_STATUS_INTERVAL
static const U16 USBTMC_INITIATE_ABORT_BULKOUT_RESP_LENGTH
@ INITIATE_ABORT_BULK_OUT
@ CHECK_ABORT_BULK_IN_STATUS
@ CHECK_ABORT_BULK_OUT_STATUS
virtual const char * what() const noexcept
Return string describing what happened.
CRecursiveMutex m_Lock
Lock onto the class interface.
tResourceName m_Rsrc
Resource name of the instrument.
U32 m_Timeout
Timeout for operations.
CIEEE488ResourceManager & m_rRrsrcMan
Reference to the associated resource manager.
CIEEE488Instrument(CIEEE488ResourceManager &rRM, tResourceName Rsrc)
Constructor.
static const I32 IEEE488_DEFAULT_TIMEOUT
Default timeout (ms)
I32 m_Status
Status of last operation.
CMutex m_Lock
Lock onto the resource manager.
I32 m_Status
Status of last operation.
List of VISA resource names.
void resize(size_t size)
Resize the buffer.
MTL_INSTRUMENT_BUFFER_TYPE * data() noexcept
Return a pointer to the data.
void reserve(size_t capacity)
Allocate at least a given amount of space.
void clear()
Clear by setting the buffer size to zero.
size_t capacity() const
Return the buffer capacity (allocated size).
size_t size() const
Return the buffer size.
CUSBTMCInstrument(CUSBTMCResourceManager &rRM, tResourceName Rsrc)
Constructor.
virtual bool Timeout(void)
Last operation timed out.
virtual bool Read(CSCPIBuffer &rBuf, bool Append=false)
Read from a USBTMC instrument: SCPI buffer class variant.
virtual bool DiscardEvents(void)
Discard service requests.
virtual bool IsOpen(void)
Check whether a session to this instrument is open.
virtual bool LockedExclusive(void)
Check whether session is locked exclusively.
virtual void Close(void)
Close this VXI-11 instrument.
virtual ~CUSBTMCInstrument(void)
Destructor.
virtual bool WaitOnEvent(U32 Timeout)
Wait for a service request.
virtual bool LockExclusive(U32 Timeout)
Obtain an exclusive lock for this session.
virtual bool Unlock(void)
Unlock the session.
virtual bool DisableEvent(void)
Disable service requests.
virtual bool AssertTrigger(void)
Assert a trigger.
virtual bool Clear(void)
Clear the instrument.
virtual bool ReadSTB(U16 &rSTB)
Read status byte.
virtual bool Write(const char *Str)
Write to a USBTMC instrument: C string variant.
virtual std::string StatusDescription(I32 Status)
Return description of status word.
virtual bool EnableEvent(void)
Enable service requests.
virtual bool Open(void)
Open this USBTMC instrument.
USBTMC Resource Manager class.
virtual bool Timeout(void)
Last operation timed out.
virtual std::string StatusDescription(I32 Status)
Return description of status word.
CUSBTMCResourceManager(void)
Constructor.
virtual ~CUSBTMCResourceManager(void)
Destructor.
virtual bool FindResources(CResourceList &rList, std::string Filter="?*")
Find USBTMC resources.
virtual bool Initialize(void)
Initialize the Resource Manager.
std::string tResourceName
IEEE488 resource name.
@ Exception
Error condition has occured during an operation.