OpenHantek
Loading...
Searching...
No Matches
ScopeDevice Class Reference

This class handles the USB communication with an usb device that has one in and one out endpoint. More...

#include <scopedevice.h>

Inheritance diagram for ScopeDevice:

Signals

void deviceDisconnected ()
 The device has been disconnected.

Public Member Functions

 ScopeDevice (DSOModel *model, libusb_device *device, unsigned findIteration=0)
 ScopeDevice ()
 ScopeDevice (const ScopeDevice &)=delete
 ~ScopeDevice () override
bool connectDevice (QString &errorMessage)
void disconnectFromDevice ()
bool isConnected ()
 Check if the oscilloscope is connected.
bool isRealHW () const
 Distinguish between real hw or demo device.
bool isDemoDevice () const
void stopSampling ()
 Stop a long running (interruptible) bulk transfer.
bool hasStopped ()
bool needsFirmware ()
unsigned int getFwVersion () const
const QString getSerialNumber () const
 getSerialNumber
QString readUSBdescriptor (libusb_device_handle *handle, uint8_t index)
 readUSBdescriptor
void setFindIteration (unsigned iteration)
unsigned getFindIteration () const
int bulkReadMulti (unsigned char *data, unsigned length, bool captureSmallBlocks, unsigned &received, int attempts=HANTEK_ATTEMPTS_MULTI)
 Multi packet bulk read from the oscilloscope.
int controlTransfer (unsigned char type, unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts=HANTEK_ATTEMPTS)
 Control transfer to the oscilloscope.
template<class T>
int controlWrite (const T *command)
 Control write to the oscilloscope.
template<class T>
int controlRead (const T *command)
 Control read to the oscilloscope.
libusb_device * getUSBDevice () const
UniqueUSBid getUniqueUSBDeviceID () const
const DSOModelgetModel () const
 Get the oscilloscope model.
void overwriteInPacketLength (unsigned len)

Static Public Member Functions

static UniqueUSBid computeUSBdeviceID (libusb_device *device)

Protected Member Functions

int claimInterface (const libusb_interface_descriptor *interfaceDescriptor)

Protected Attributes

DSOModelmodel
struct libusb_device_descriptor descriptor
libusb_device * device
 The USB handle for the oscilloscope.
libusb_device_handle * handle = nullptr
unsigned findIteration
const UniqueUSBid uniqueUSBdeviceID
int nInterface
unsigned outPacketLength
 Packet length for the OUT endpoint.
unsigned inPacketLength
 Packet length for the IN endpoint.

Private Member Functions

int bulkTransfer (unsigned char endpoint, const unsigned char *data, unsigned int length, int attempts=HANTEK_ATTEMPTS, unsigned int timeout=HANTEK_TIMEOUT)
 Bulk transfer to/from the oscilloscope.
int bulkWrite (const unsigned char *data, unsigned int length, int attempts=HANTEK_ATTEMPTS)
 Bulk write to the oscilloscope.
template<class T>
int bulkRead (const T *command, int attempts=HANTEK_ATTEMPTS)
 Bulk read from the oscilloscope.

Private Attributes

bool realHW = true
bool stopTransfer = false
bool disconnected = true
QString serialNumber = "0000"

Detailed Description

This class handles the USB communication with an usb device that has one in and one out endpoint.

Constructor & Destructor Documentation

◆ ScopeDevice() [1/3]

ScopeDevice::ScopeDevice ( DSOModel * model,
libusb_device * device,
unsigned findIteration = 0 )
explicit

◆ ScopeDevice() [2/3]

ScopeDevice::ScopeDevice ( )
explicit

◆ ScopeDevice() [3/3]

ScopeDevice::ScopeDevice ( const ScopeDevice & )
delete

◆ ~ScopeDevice()

ScopeDevice::~ScopeDevice ( )
override

Member Function Documentation

◆ bulkRead()

template<class T>
int ScopeDevice::bulkRead ( const T * command,
int attempts = HANTEK_ATTEMPTS )
inlineprivate

Bulk read from the oscilloscope.

Parameters
dataBuffer for the sent/received data.
lengthThe length of the packet.
attemptsThe number of attempts, that are done on timeouts.
Returns
Number of received bytes on success, libusb error code on error.

◆ bulkReadMulti()

int ScopeDevice::bulkReadMulti ( unsigned char * data,
unsigned length,
bool captureSmallBlocks,
unsigned & received,
int attempts = HANTEK_ATTEMPTS_MULTI )

Multi packet bulk read from the oscilloscope.

Parameters
dataBuffer for the sent/received data.
lengthThe length of data contained in the packets.
captureSmallBlocksCapture many small blocks instead of one big block (faster gui update)
receivedThe amount of already captured samples
attemptsThe number of attempts, that are done on timeouts.
Returns
Number of received bytes on success, libusb error code on error.

◆ bulkTransfer()

int ScopeDevice::bulkTransfer ( unsigned char endpoint,
const unsigned char * data,
unsigned int length,
int attempts = HANTEK_ATTEMPTS,
unsigned int timeout = HANTEK_TIMEOUT )
private

Bulk transfer to/from the oscilloscope.

Parameters
endpointEndpoint number, also sets the direction of the transfer.
dataBuffer for the sent/received data.
lengthThe length of the packet.
attemptsThe number of attempts, that are done on timeouts.
timeoutThe timeout in ms.
Returns
Number of transferred bytes on success, libusb error code on error.

◆ bulkWrite()

int ScopeDevice::bulkWrite ( const unsigned char * data,
unsigned int length,
int attempts = HANTEK_ATTEMPTS )
inlineprivate

Bulk write to the oscilloscope.

Parameters
dataBuffer for the sent/received data.
lengthThe length of the packet.
attemptsThe number of attempts, that are done on timeouts.
Returns
Number of sent bytes on success, libusb error code on error.

◆ claimInterface()

int ScopeDevice::claimInterface ( const libusb_interface_descriptor * interfaceDescriptor)
protected

◆ computeUSBdeviceID()

UniqueUSBid ScopeDevice::computeUSBdeviceID ( libusb_device * device)
static

ID built from bus, port, VID, PID and FW version

◆ connectDevice()

bool ScopeDevice::connectDevice ( QString & errorMessage)

◆ controlRead()

template<class T>
int ScopeDevice::controlRead ( const T * command)
inline

Control read to the oscilloscope.

Parameters
commandBuffer for the sent/received data.
Returns
Number of received bytes on success, libusb error code on error.

◆ controlTransfer()

int ScopeDevice::controlTransfer ( unsigned char type,
unsigned char request,
unsigned char * data,
unsigned int length,
int value,
int index,
int attempts = HANTEK_ATTEMPTS )

Control transfer to the oscilloscope.

Parameters
typeThe request type, also sets the direction of the transfer.
requestThe request field of the packet.
dataBuffer for the sent/received data.
lengthThe length field of the packet.
valueThe value field of the packet.
indexThe index field of the packet.
attemptsThe number of attempts, that are done on timeouts.
Returns
Number of transferred bytes on success, libusb error code on error.

◆ controlWrite()

template<class T>
int ScopeDevice::controlWrite ( const T * command)
inline

Control write to the oscilloscope.

Parameters
commandBuffer for the sent/received data.
Returns
Number of sent bytes on success, libusb error code on error.

◆ deviceDisconnected

void ScopeDevice::deviceDisconnected ( )
signal

The device has been disconnected.

◆ disconnectFromDevice()

void ScopeDevice::disconnectFromDevice ( )

◆ getFindIteration()

unsigned ScopeDevice::getFindIteration ( ) const
inline

◆ getFwVersion()

unsigned int ScopeDevice::getFwVersion ( ) const
inline
Returns
Return device version as unsigned int

◆ getModel()

const DSOModel * ScopeDevice::getModel ( ) const
inline

Get the oscilloscope model.

Returns
The ::Model of the connected Hantek DSO.

◆ getSerialNumber()

const QString ScopeDevice::getSerialNumber ( ) const
inline

getSerialNumber

Returns
Return serial number string of the device

◆ getUniqueUSBDeviceID()

UniqueUSBid ScopeDevice::getUniqueUSBDeviceID ( ) const
inline
Returns
Return the unique usb device id USBDevice::computeUSBdeviceID().

◆ getUSBDevice()

libusb_device * ScopeDevice::getUSBDevice ( ) const
inline
Returns
Returns the raw libusb device

◆ hasStopped()

bool ScopeDevice::hasStopped ( )
inline

◆ isConnected()

bool ScopeDevice::isConnected ( )

Check if the oscilloscope is connected.

Returns
true, if a connection is up.

◆ isDemoDevice()

bool ScopeDevice::isDemoDevice ( ) const
inline

◆ isRealHW()

bool ScopeDevice::isRealHW ( ) const
inline

Distinguish between real hw or demo device.

◆ needsFirmware()

bool ScopeDevice::needsFirmware ( )
Returns
Return true if this device needs a firmware first

◆ overwriteInPacketLength()

void ScopeDevice::overwriteInPacketLength ( unsigned len)
inline

Usually a maximum packet length for in and outgoing packets is determined by the underlying implementation and usb specification. E.g. the roll buffer mode uses the maximum in length for transfer. Some devices do not support that much data though and need an artification restriction.

◆ readUSBdescriptor()

QString ScopeDevice::readUSBdescriptor ( libusb_device_handle * handle,
uint8_t index )

readUSBdescriptor

Parameters
handleThe device handle
indexof requested string
Returns
serial number string

◆ setFindIteration()

void ScopeDevice::setFindIteration ( unsigned iteration)
inline

Keep track of the find iteration on which this device was found

Parameters
iterationThe new iteration value

◆ stopSampling()

void ScopeDevice::stopSampling ( )
inline

Stop a long running (interruptible) bulk transfer.

Field Documentation

◆ descriptor

struct libusb_device_descriptor ScopeDevice::descriptor
protected

◆ device

libusb_device* ScopeDevice::device
protected

The USB handle for the oscilloscope.

◆ disconnected

bool ScopeDevice::disconnected = true
private

◆ findIteration

unsigned ScopeDevice::findIteration
protected

◆ handle

libusb_device_handle* ScopeDevice::handle = nullptr
protected

◆ inPacketLength

unsigned ScopeDevice::inPacketLength
protected

Packet length for the IN endpoint.

◆ model

DSOModel* ScopeDevice::model
protected

◆ nInterface

int ScopeDevice::nInterface
protected

◆ outPacketLength

unsigned ScopeDevice::outPacketLength
protected

Packet length for the OUT endpoint.

◆ realHW

bool ScopeDevice::realHW = true
private

◆ serialNumber

QString ScopeDevice::serialNumber = "0000"
private

◆ stopTransfer

bool ScopeDevice::stopTransfer = false
private

◆ uniqueUSBdeviceID

const UniqueUSBid ScopeDevice::uniqueUSBdeviceID
protected

The documentation for this class was generated from the following files: