THM1176InstrumentManager 1.1
Qt Object abstraction for Metrolab THM1176
Loading...
Searching...
No Matches
USBTMCPrivate.h
Go to the documentation of this file.
1// Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
4#pragma once
5
7
8using namespace MTL::Instrument;
9
10//----------------------------------------------------------------------//
12// Some USBTMC-specific enums, as defined in the USBTMC standard.
13static const U8 SUBCLASS_USBTMC = 0x03;
14static const U8 USBTMC_USB488 = 0x01;
15
16// USBTMC control requests
17enum {
26
27 // USB488 control requests
32};
33
34// Constants for control endpoint transfers.
35static const I32 USB_MAX_PORT_DEPTH = 7;
40static const U16 USBTMC_READ_BUFFER_SIZE = 256;
50
51// USBTMC status codes
52enum
53{
61};
62
63// USBTMC capabilities
64static const U8 USBTMC_INT_CAP_LISTEN_ONLY = 0x01;
65static const U8 USBTMC_INT_CAP_TALK_ONLY = 0x02;
66static const U8 USBTMC_INT_CAP_INDICATOR = 0x04;
67
68static const U8 USBTMC_DEV_CAP_TERMCHAR = 0x01;
69
70static const U8 USB488_DEV_CAP_DT1 = 0x01;
71static const U8 USB488_DEV_CAP_RL1 = 0x02;
72static const U8 USB488_DEV_CAP_SR1 = 0x04;
73static const U8 USB488_DEV_CAP_SCPI = 0x08;
74
75// Bulk message constants
76static const I32 USBTMC_BULK_HEADER_SIZE = 12;
79
80// Bulk MsgID values
81static const U8 DEV_DEP_MSG_OUT = 1;
82static const U8 REQUEST_DEV_DEP_MSG_IN = 2;
83static const U8 DEV_DEP_MSG_IN = 2;
84static const U8 TRIGGER = 128;
85
86// bmTransferAttributes
87static const U8 EOM = 0x01;
88static const U8 TERM_CHAR_ENABLED = 0x02;
89
90// bmClear
91static const U8 BULKIN_FIFO_BYTES = 0x01;
92
93//----------------------------------------------------------------------//
113
115static const char * USBTMC_ERROR_EXPLANATION[] =
116{
117 "USBTMC: Success",
118 "USBTMC FindResources: Invalid filter",
119 "USBTMC FindResources: Failed to find USBTMC-USB488 interface",
120 "USBTMC GetDeviceListEntry: Resource not found",
121 "USBTMC Write: invalid transfer count",
122 "USBTMC Read: Buffer is invalid for append read (no room for read header)",
123 "USBTMC Read: Read header is invalid",
124 "USBTMC Read: Message size is wrong",
125 "USBTMC Clear: Response error",
126 "USBTMC Clear BulkIn: Response error",
127 "USBTMC Clear BulkOut: Response error",
128 "USBTMC ReadSTB: Control endpoint response error",
129 "USBTMC ReadSTB: Interrupt endpoint response error",
130 "USBTMC: Instrument is locked by someone else",
131 "USBTMC: Instrument is not open",
132 "USBTMC: Service Requests not enabled"
133};
134
135//----------------------------------------------------------------------//
137
142#define R8(x) ((unsigned)((const U8*)(x))[0])
143
149#define RB16(x) (((unsigned)((const U8*)(x))[0] << 8) | \
150(unsigned)((const U8*)(x))[1])
151
157#define RL16(x) (((unsigned)((const U8*)(x))[1] << 8) | \
158(unsigned)((const U8*)(x))[0])
159
165#define RB16S(x) ((int16_t) \
166(((unsigned)((const U8*)(x))[0] << 8) | \
167(unsigned)((const U8*)(x))[1]))
168
174#define RL16S(x) ((int16_t) \
175(((unsigned)((const U8*)(x))[1] << 8) | \
176(unsigned)((const U8*)(x))[0]))
177
183#define RB32(x) (((unsigned)((const U8*)(x))[0] << 24) | \
184((unsigned)((const U8*)(x))[1] << 16) | \
185((unsigned)((const U8*)(x))[2] << 8) | \
186(unsigned)((const U8*)(x))[3])
187
193#define RL32(x) (((unsigned)((const U8*)(x))[3] << 24) | \
194((unsigned)((const U8*)(x))[2] << 16) | \
195((unsigned)((const U8*)(x))[1] << 8) | \
196(unsigned)((const U8*)(x))[0])
197
203#define RB32S(x) ((int32_t) \
204(((unsigned)((const U8*)(x))[0] << 24) | \
205((unsigned)((const U8*)(x))[1] << 16) | \
206((unsigned)((const U8*)(x))[2] << 8) | \
207(unsigned)((const U8*)(x))[3]))
208
214#define RL32S(x) ((int32_t) \
215(((unsigned)((const U8*)(x))[3] << 24) | \
216((unsigned)((const U8*)(x))[2] << 16) | \
217((unsigned)((const U8*)(x))[1] << 8) | \
218(unsigned)((const U8*)(x))[0]))
219
225#define RB64(x) (((uint64_t)((const U8*)(x))[0] << 56) | \
226((uint64_t)((const U8*)(x))[1] << 48) | \
227((uint64_t)((const U8*)(x))[2] << 40) | \
228((uint64_t)((const U8*)(x))[3] << 32) | \
229((uint64_t)((const U8*)(x))[4] << 24) | \
230((uint64_t)((const U8*)(x))[5] << 16) | \
231((uint64_t)((const U8*)(x))[6] << 8) | \
232(uint64_t)((const U8*)(x))[7])
233
239#define RL64(x) (((uint64_t)((const U8*)(x))[7] << 56) | \
240((uint64_t)((const U8*)(x))[6] << 48) | \
241((uint64_t)((const U8*)(x))[5] << 40) | \
242((uint64_t)((const U8*)(x))[4] << 32) | \
243((uint64_t)((const U8*)(x))[3] << 24) | \
244((uint64_t)((const U8*)(x))[2] << 16) | \
245((uint64_t)((const U8*)(x))[1] << 8) | \
246(uint64_t)((const U8*)(x))[0])
247
253#define RL64S(x) ((int64_t) \
254(((uint64_t)((const U8*)(x))[7] << 56) | \
255((uint64_t)((const U8*)(x))[6] << 48) | \
256((uint64_t)((const U8*)(x))[5] << 40) | \
257((uint64_t)((const U8*)(x))[4] << 32) | \
258((uint64_t)((const U8*)(x))[3] << 24) | \
259((uint64_t)((const U8*)(x))[2] << 16) | \
260((uint64_t)((const U8*)(x))[1] << 8) | \
261(uint64_t)((const U8*)(x))[0]))
262
268#define RBFL(x) ((union { uint32_t u; float f; }) { .u = RB32(x) }.f)
269
275#define RLFL(x) ((union { uint32_t u; float f; }) { .u = RL32(x) }.f)
276
282#define W8(p, x) do { ((U8*)(p))[0] = (U8) (x); } while (0)
283
289#define WB16(p, x) do { ((U8*)(p))[1] = (U8) (x); \
290((U8*)(p))[0] = (U8)((x)>>8); } while (0)
291
297#define WL16(p, x) do { ((U8*)(p))[0] = (U8) (x); \
298((U8*)(p))[1] = (U8)((x)>>8); } while (0)
299
305#define WB32(p, x) do { ((U8*)(p))[3] = (U8) (x); \
306((U8*)(p))[2] = (U8)((x)>>8); \
307((U8*)(p))[1] = (U8)((x)>>16); \
308((U8*)(p))[0] = (U8)((x)>>24); } while (0)
309
315#define WL32(p, x) do { ((U8*)(p))[0] = (U8) (x); \
316((U8*)(p))[1] = (U8)((x)>>8); \
317((U8*)(p))[2] = (U8)((x)>>16); \
318((U8*)(p))[3] = (U8)((x)>>24); } while (0)
319
325#define WBFL(p, x) WB32(p, (union { uint32_t u; float f; }) { .f = x }.u)
326
332#define WLFL(p, x) WL32(p, (union { uint32_t u; float f; }) { .f = x }.u)
Abstract IEEE488 instrument class: type definitions.
unsigned char U8
Unsigned byte.
Definition OSDefines.h:29
int I32
32-bit signed integer.
Definition OSDefines.h:27
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
static const U8 USB488_DEV_CAP_DT1
static const U8 BULKIN_FIFO_BYTES
static const U8 USBTMC_INT_CAP_LISTEN_ONLY
static const U8 USB488_DEV_CAP_SCPI
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
static const U8 USB488_DEV_CAP_RL1
static const U8 EOM
static const U8 TRIGGER
static const U8 SUBCLASS_USBTMC
Constants for USBTMC and USB488.
static const U32 USB_DESCRIPTOR_STRING_LENGTH
@ USBTMC_STATUS_SPLIT_IN_PROGRESS
@ USBTMC_STATUS_SUCCESS
@ USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS
@ USBTMC_STATUS_INTERRUPT_IN_BUSY
@ USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS
@ USBTMC_STATUS_PENDING
@ USBTMC_STATUS_FAILED
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 I32 USBTMC_BULK_MIN_BUFFER_SIZE
static const U16 USBTMC_CHECK_CLEAR_STATUS_RESP_LENGTH
static const U8 TERM_CHAR_ENABLED
static const U8 USBTMC_USB488
static const U8 USB488_DEV_CAP_SR1
static const U8 USBTMC_BM_REQUEST_TYPE_IN_CLS_IF
static const char * USBTMC_ERROR_EXPLANATION[]
Error explanations.
static const U8 USBTMC_INT_CAP_TALK_ONLY
USBTMCError
Error codes. Complementary to libusb errors (0 to -99).
@ 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_READ_INVALID_BUFFER_FOR_APPEND
@ 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 U8 USBTMC_INT_CAP_INDICATOR
static const U32 USBTMC_CHECK_CLEAR_STATUS_INTERVAL
static const U16 USBTMC_INITIATE_ABORT_BULKOUT_RESP_LENGTH
static const U8 USBTMC_DEV_CAP_TERMCHAR
@ INDICATOR_PULSE
@ READ_STATUS_BYTE
@ GET_CAPABILITIES
@ INITIATE_CLEAR
@ LOCAL_LOCKOUT
@ INITIATE_ABORT_BULK_OUT
@ CHECK_ABORT_BULK_IN_STATUS
@ REN_CONTROL
@ CHECK_CLEAR_STATUS
@ CHECK_ABORT_BULK_OUT_STATUS
@ INITIATE_ABORT_BULK_IN
@ GO_TO_LOCAL