OpenHantek
Public Slots | Signals | Public Member Functions
HantekDsoControl Class Reference

The DsoControl abstraction layer for Hantek USB DSOs. TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!). More...

#include <hantekdsocontrol.h>

Inheritance diagram for HantekDsoControl:

Public Slots

void enableSampling (bool enabled)
 If sampling is disabled, no samplesAvailable() signals are send anymore, no samples are fetched from the device and no processing takes place. More...
 
Dso::ErrorCode setRecordLength (unsigned size)
 Sets the size of the oscilloscopes sample buffer. More...
 
Dso::ErrorCode setSamplerate (double samplerate=0.0)
 Sets the samplerate of the oscilloscope. More...
 
Dso::ErrorCode setRecordTime (double duration=0.0)
 Sets the time duration of one aquisition by adapting the samplerate. More...
 
Dso::ErrorCode setChannelUsed (ChannelID channel, bool used)
 Enables/disables filtering of the given channel. More...
 
Dso::ErrorCode setCoupling (ChannelID channel, Dso::Coupling coupling)
 Set the coupling for the given channel. More...
 
Dso::ErrorCode setGain (ChannelID channel, double gain)
 Sets the gain for the given channel. Get the actual gain by specification.gainSteps[gainId]. More...
 
Dso::ErrorCode setOffset (ChannelID channel, const double offset)
 Set the offset for the given channel. Get the actual offset for the channel from controlsettings.voltage[channel].offsetReal. More...
 
Dso::ErrorCode setTriggerMode (Dso::TriggerMode mode)
 Set the trigger mode. More...
 
Dso::ErrorCode setTriggerSource (bool special, unsigned id)
 Set the trigger source. More...
 
Dso::ErrorCode setTriggerLevel (ChannelID channel, double level)
 Set the trigger level. More...
 
Dso::ErrorCode setTriggerSlope (Dso::Slope slope)
 Set the trigger slope. More...
 
Dso::ErrorCode setPretriggerPosition (double position)
 Set the trigger position. More...
 
void forceTrigger ()
 

Signals

void samplingStatusChanged (bool enabled)
 The oscilloscope started/stopped sampling/waiting for trigger.
 
void statusMessage (const QString &message, int timeout)
 Status message about the oscilloscope.
 
void samplesAvailable (const DSOsamples *samples)
 New sample data is available.
 
void availableRecordLengthsChanged (const std::vector< unsigned > &recordLengths)
 
void samplerateLimitsChanged (double minimum, double maximum)
 The available samplerate range has changed.
 
void samplerateSet (int mode, QList< double > sampleSteps)
 The available samplerate for fixed samplerate devices has changed.
 
void recordLengthChanged (unsigned long duration)
 The record length has changed.
 
void recordTimeChanged (double duration)
 The record time duration has changed.
 
void samplerateChanged (double samplerate)
 The samplerate has changed.
 
void communicationError () const
 

Public Member Functions

 HantekDsoControl (USBDevice *device)
 
 ~HantekDsoControl ()
 Cleans up.
 
void run ()
 
unsigned getChannelCount () const
 Gets the physical channel count for this oscilloscope. More...
 
const Dso::ControlSettingsgetDeviceSettings () const
 
const std::vector< unsigned > & getAvailableRecordLengths () const
 Get available record lengths for this oscilloscope. More...
 
double getMinSamplerate () const
 Get minimum samplerate for this oscilloscope. More...
 
double getMaxSamplerate () const
 Get maximum samplerate for this oscilloscope. More...
 
bool isSampling () const
 
const USBDevicegetDevice () const
 Return the associated usb device.
 
int getConnectionSpeed () const
 Gets the speed of the connection. More...
 
int getPacketSize () const
 Gets the maximum size of one packet transmitted via bulk transfer. More...
 
const DSOsamplesgetLastSamples ()
 Return the last sample set.
 
Dso::ErrorCode stringCommand (const QString &commandString)
 Sends bulk/control commands directly. More...
 
void addCommand (BulkCommand *newCommand, bool pending=true)
 
template<class T >
T * modifyCommand (Hantek::BulkCode code)
 
const BulkCommandgetCommand (Hantek::BulkCode code) const
 
void addCommand (ControlCommand *newCommand, bool pending=true)
 
template<class T >
T * modifyCommand (Hantek::ControlCode code)
 
const ControlCommandgetCommand (Hantek::ControlCode code) const
 

Detailed Description

The DsoControl abstraction layer for Hantek USB DSOs. TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!).

Constructor & Destructor Documentation

◆ HantekDsoControl()

HantekDsoControl::HantekDsoControl ( USBDevice device)

Creates a dsoControl object. The actual event loop / timer is not started. You can optionally create a thread and move the created object to the thread. You need to call updateInterval() to start the timer. This is done implicitly if run() is called.

Parameters
deviceThe usb device. This object does not take ownership.

Member Function Documentation

◆ availableRecordLengthsChanged

void HantekDsoControl::availableRecordLengthsChanged ( const std::vector< unsigned > &  recordLengths)
signal

The available record lengths, empty list for

◆ enableSampling

void HantekDsoControl::enableSampling ( bool  enabled)
slot

If sampling is disabled, no samplesAvailable() signals are send anymore, no samples are fetched from the device and no processing takes place.

Start sampling process.

Parameters
enabledEnables/Disables sampling

◆ getAvailableRecordLengths()

const std::vector< unsigned > & HantekDsoControl::getAvailableRecordLengths ( ) const

Get available record lengths for this oscilloscope.

Returns
The number of physical channels, empty list for continuous.

◆ getChannelCount()

unsigned HantekDsoControl::getChannelCount ( ) const

Gets the physical channel count for this oscilloscope.

Returns
The number of physical channels.

◆ getConnectionSpeed()

int HantekDsoControl::getConnectionSpeed ( ) const

Gets the speed of the connection.

Returns
The ::ConnectionSpeed of the USB connection.

◆ getDeviceSettings()

const ControlSettings * HantekDsoControl::getDeviceSettings ( ) const

Return the read-only device control settings. Use the set- Methods to change device settings.

◆ getMaxSamplerate()

double HantekDsoControl::getMaxSamplerate ( ) const

Get maximum samplerate for this oscilloscope.

Returns
The maximum samplerate for the current configuration in S/s.

◆ getMinSamplerate()

double HantekDsoControl::getMinSamplerate ( ) const

Get minimum samplerate for this oscilloscope.

Returns
The minimum samplerate for the current configuration in S/s.

◆ getPacketSize()

int HantekDsoControl::getPacketSize ( ) const

Gets the maximum size of one packet transmitted via bulk transfer.

Returns
The maximum packet size in bytes, negative libusb error code on error.

◆ run()

void HantekDsoControl::run ( )

Call this to start the processing. This method will call itself periodically from there on. It is wise to move this class object to an own thread and call run from there.

◆ setChannelUsed

Dso::ErrorCode HantekDsoControl::setChannelUsed ( ChannelID  channel,
bool  used 
)
slot

Enables/disables filtering of the given channel.

Parameters
channelThe channel that should be set.
usedtrue if the channel should be sampled.
Returns
See ::Dso::ErrorCode.

◆ setCoupling

Dso::ErrorCode HantekDsoControl::setCoupling ( ChannelID  channel,
Dso::Coupling  coupling 
)
slot

Set the coupling for the given channel.

Parameters
channelThe channel that should be set.
couplingThe new coupling for the channel.
Returns
See ::Dso::ErrorCode.

◆ setGain

Dso::ErrorCode HantekDsoControl::setGain ( ChannelID  channel,
double  gain 
)
slot

Sets the gain for the given channel. Get the actual gain by specification.gainSteps[gainId].

Parameters
channelThe channel that should be set.
gainThe gain that should be met (V/div).
Returns
The gain that has been set, ::Dso::ErrorCode on error.

◆ setOffset

Dso::ErrorCode HantekDsoControl::setOffset ( ChannelID  channel,
const double  offset 
)
slot

Set the offset for the given channel. Get the actual offset for the channel from controlsettings.voltage[channel].offsetReal.

Parameters
channelThe channel that should be set.
offsetThe new offset value (0.0 - 1.0).

◆ setPretriggerPosition

Dso::ErrorCode HantekDsoControl::setPretriggerPosition ( double  position)
slot

Set the trigger position.

Parameters
positionThe new trigger position (in s).
Returns
The trigger position that has been set.

◆ setRecordLength

Dso::ErrorCode HantekDsoControl::setRecordLength ( unsigned  size)
slot

Sets the size of the oscilloscopes sample buffer.

Parameters
indexThe record length index that should be set.
Returns
The record length that has been set, 0 on error.

◆ setRecordTime

Dso::ErrorCode HantekDsoControl::setRecordTime ( double  duration = 0.0)
slot

Sets the time duration of one aquisition by adapting the samplerate.

Parameters
durationThe record time duration that should be met (s), 0.0 to restore current record time.
Returns
The record time duration that has been set, 0.0 on error.

◆ setSamplerate

Dso::ErrorCode HantekDsoControl::setSamplerate ( double  samplerate = 0.0)
slot

Sets the samplerate of the oscilloscope.

Parameters
samplerateThe samplerate that should be met (S/s), 0.0 to restore current samplerate.
Returns
The samplerate that has been set, 0.0 on error.

◆ setTriggerLevel

Dso::ErrorCode HantekDsoControl::setTriggerLevel ( ChannelID  channel,
double  level 
)
slot

Set the trigger level.

Parameters
channelThe channel that should be set.
levelThe new trigger level (V).
Returns
The trigger level that has been set, ::Dso::ErrorCode on error.
Todo:
Get alternating trigger in here

◆ setTriggerMode

Dso::ErrorCode HantekDsoControl::setTriggerMode ( Dso::TriggerMode  mode)
slot

Set the trigger mode.

Returns
See ::Dso::ErrorCode.

◆ setTriggerSlope

Dso::ErrorCode HantekDsoControl::setTriggerSlope ( Dso::Slope  slope)
slot

Set the trigger slope.

Parameters
slopeThe Slope that should cause a trigger.
Returns
See ::Dso::ErrorCode.

◆ setTriggerSource

Dso::ErrorCode HantekDsoControl::setTriggerSource ( bool  special,
unsigned  id 
)
slot

Set the trigger source.

Parameters
specialtrue for a special channel (EXT, ...) as trigger source.
idThe number of the channel, that should be used as trigger.
Returns
See ::Dso::ErrorCode.

◆ stringCommand()

Dso::ErrorCode HantekDsoControl::stringCommand ( const QString &  commandString)

Sends bulk/control commands directly.

Syntax:

Bulk command:

send bulk [hex data]

Control command:

send control [hex code] [hex data]
Parameters
commandThe command as string (Has to be parsed).
Returns
See ::Dso::ErrorCode.

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