diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog index 456be19..399e155 100644 --- a/openhantek/ChangeLog +++ b/openhantek/ChangeLog @@ -143,3 +143,7 @@ 2012-09-01 Oliver Haag * Updated documentation with first DSO-2250 details * General documentation improvements + +2012-09-01 Oliver Haag +* First attempt to add DSO-2250 support +* More documentation updates diff --git a/openhantek/src/dataanalyzer.cpp b/openhantek/src/dataanalyzer.cpp index 0bcb4c9..bfd6c48 100644 --- a/openhantek/src/dataanalyzer.cpp +++ b/openhantek/src/dataanalyzer.cpp @@ -45,7 +45,7 @@ DataAnalyzer::DataAnalyzer(DsoSettings *settings, QObject *parent) : QThread(parent) { this->settings = settings; - this->lastBufferSize = 0; + this->lastRecordLength = 0; this->lastWindow = (Dso::WindowFunction) -1; this->window = 0; @@ -189,33 +189,33 @@ void DataAnalyzer::run() { for(int channel = 0; channel < this->analyzedData.count(); channel++) { if(this->analyzedData[channel]->samples.voltage.sample) { // Calculate new window - if(this->lastWindow != this->settings->scope.spectrumWindow || this->lastBufferSize != this->analyzedData[channel]->samples.voltage.count) { - if(this->lastBufferSize != this->analyzedData[channel]->samples.voltage.count) { - this->lastBufferSize = this->analyzedData[channel]->samples.voltage.count; + if(this->lastWindow != this->settings->scope.spectrumWindow || this->lastRecordLength != this->analyzedData[channel]->samples.voltage.count) { + if(this->lastRecordLength != this->analyzedData[channel]->samples.voltage.count) { + this->lastRecordLength = this->analyzedData[channel]->samples.voltage.count; if(this->window) fftw_free(this->window); - this->window = (double *) fftw_malloc(sizeof(double) * this->lastBufferSize); + this->window = (double *) fftw_malloc(sizeof(double) * this->lastRecordLength); } - unsigned int windowEnd = this->lastBufferSize - 1; + unsigned int windowEnd = this->lastRecordLength - 1; this->lastWindow = this->settings->scope.spectrumWindow; switch(this->settings->scope.spectrumWindow) { case Dso::WINDOW_HAMMING: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.54 - 0.46 * cos(2.0 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_HANN: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.5 * (1.0 - cos(2.0 * M_PI * windowPosition / windowEnd)); break; case Dso::WINDOW_COSINE: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = sin(M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_LANCZOS: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) { + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) { double sincParameter = (2.0 * windowPosition / windowEnd - 1.0) * M_PI; if(sincParameter == 0) *(this->window + windowPosition) = 1; @@ -224,55 +224,55 @@ void DataAnalyzer::run() { } break; case Dso::WINDOW_BARTLETT: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 2.0 / windowEnd * (windowEnd / 2 - abs(windowPosition - windowEnd / 2)); break; case Dso::WINDOW_TRIANGULAR: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) - *(this->window + windowPosition) = 2.0 / this->lastBufferSize * (this->lastBufferSize / 2 - abs(windowPosition - windowEnd / 2)); + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + *(this->window + windowPosition) = 2.0 / this->lastRecordLength * (this->lastRecordLength / 2 - abs(windowPosition - windowEnd / 2)); break; case Dso::WINDOW_GAUSS: { double sigma = 0.4; - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = exp(-0.5 * pow(((windowPosition - windowEnd / 2) / (sigma * windowEnd / 2)), 2)); } break; case Dso::WINDOW_BARTLETTHANN: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.62 - 0.48 * abs(windowPosition / windowEnd - 0.5) - 0.38 * cos(2.0 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMAN: { double alpha = 0.16; - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = (1 - alpha) / 2 - 0.5 * cos(2.0 * M_PI * windowPosition / windowEnd) + alpha / 2 * cos(4.0 * M_PI * windowPosition / windowEnd); } break; //case WINDOW_KAISER: // TODO //double alpha = 3.0; - //for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + //for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) //*(this->window + windowPosition) = ; //break; case Dso::WINDOW_NUTTALL: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.355768 - 0.487396 * cos(2 * M_PI * windowPosition / windowEnd) + 0.144232 * cos(4 * M_PI * windowPosition / windowEnd) - 0.012604 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMANHARRIS: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.35875 - 0.48829 * cos(2 * M_PI * windowPosition / windowEnd) + 0.14128 * cos(4 * M_PI * windowPosition / windowEnd) - 0.01168 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMANNUTTALL: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 0.3635819 - 0.4891775 * cos(2 * M_PI * windowPosition / windowEnd) + 0.1365995 * cos(4 * M_PI * windowPosition / windowEnd) - 0.0106411 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_FLATTOP: - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 1.0 - 1.93 * cos(2 * M_PI * windowPosition / windowEnd) + 1.29 * cos(4 * M_PI * windowPosition / windowEnd) - 0.388 * cos(6 * M_PI * windowPosition / windowEnd) + 0.032 * cos(8 * M_PI * windowPosition / windowEnd); break; default: // Dso::WINDOW_RECTANGULAR - for(unsigned int windowPosition = 0; windowPosition < this->lastBufferSize; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) *(this->window + windowPosition) = 1.0; } } @@ -297,7 +297,7 @@ void DataAnalyzer::run() { windowedValues[position] = this->window[position] * this->analyzedData[channel]->samples.voltage.sample[position]; // Do discrete real to half-complex transformation - /// \todo Check if buffer size is multiple of 2 + /// \todo Check if record length is multiple of 2 /// \todo Reuse plan and use FFTW_MEASURE to get fastest algorithm fftw_plan fftPlan = fftw_plan_r2r_1d(this->analyzedData[channel]->samples.voltage.count, windowedValues, this->analyzedData[channel]->samples.spectrum.sample, FFTW_R2HC, FFTW_ESTIMATE); fftw_execute(fftPlan); diff --git a/openhantek/src/dataanalyzer.h b/openhantek/src/dataanalyzer.h index 0a08c2e..70eb83d 100644 --- a/openhantek/src/dataanalyzer.h +++ b/openhantek/src/dataanalyzer.h @@ -89,8 +89,8 @@ class DataAnalyzer : public QThread { QList analyzedData; ///< The analyzed data for each channel QMutex *analyzedDataMutex; ///< A mutex for the analyzed data of all channels - unsigned long int lastBufferSize; ///< The buffer size of the previously analyzed data - unsigned long int maxSamples; ///< The maximum buffer size of the analyzed data + unsigned long int lastRecordLength; ///< The record length of the previously analyzed data + unsigned long int maxSamples; ///< The maximum record length of the analyzed data Dso::WindowFunction lastWindow; ///< The previously used dft window function double *window; ///< The array for the dft window factors diff --git a/openhantek/src/dso.h b/openhantek/src/dso.h index 9b3b773..3de5bc5 100644 --- a/openhantek/src/dso.h +++ b/openhantek/src/dso.h @@ -38,6 +38,16 @@ /// \brief All DSO specific things for different modes and so on. namespace Dso { ////////////////////////////////////////////////////////////////////////////// + /// \enum ErrorCode hantek/control.h + /// \brief The return codes for device control methods. + enum ErrorCode { + ERROR_NONE = 0, ///< Successful operation + ERROR_CONNECTION = -1, ///< Device not connected or communication error + ERROR_UNSUPPORTED = -2, ///< Not supported by this device + ERROR_PARAMETER = -3 ///< Parameter out of range + }; + + ////////////////////////////////////////////////////////////////////////////// /// \enum ChannelMode dso.h /// \brief The channel display modes. enum ChannelMode { diff --git a/openhantek/src/dsocontrol.h b/openhantek/src/dsocontrol.h index aba5200..d6ba2b1 100644 --- a/openhantek/src/dsocontrol.h +++ b/openhantek/src/dsocontrol.h @@ -72,13 +72,13 @@ class DsoControl : public QThread { virtual void stopSampling(); virtual unsigned long int setSamplerate(unsigned long int samplerate) = 0; ///< Set the samplerate that should be met - virtual unsigned long int setBufferSize(unsigned long int size) = 0; ///< Set the needed buffer size + virtual unsigned long int setRecordLength(unsigned long int size) = 0; ///< Set the required record length virtual int setTriggerMode(Dso::TriggerMode mode) = 0; ///< Set the trigger mode virtual int setTriggerSource(bool special, unsigned int id) = 0; ///< Set the trigger source virtual double setTriggerLevel(unsigned int channel, double level) = 0; ///< Set the trigger level for a channel virtual int setTriggerSlope(Dso::Slope slope) = 0; ///< Set the slope that causes triggering - virtual double setTriggerPosition(double position) = 0; ///< Set the pretrigger position (0.0 = left, 1.0 = right side) + virtual double setPretriggerPosition(double position) = 0; ///< Set the pretrigger position (0.0 = left, 1.0 = right side) virtual int setChannelUsed(unsigned int channel, bool used) = 0; ///< Enable/disable a channel virtual int setCoupling(unsigned int channel, Dso::Coupling coupling) = 0; ///< Set the coupling for a channel diff --git a/openhantek/src/dsowidget.cpp b/openhantek/src/dsowidget.cpp index c89da54..7ab1b96 100644 --- a/openhantek/src/dsowidget.cpp +++ b/openhantek/src/dsowidget.cpp @@ -114,12 +114,12 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // The table for the settings this->settingsTriggerLabel = new QLabel(); this->settingsTriggerLabel->setMinimumWidth(160); - this->settingsBufferLabel = new QLabel(); - this->settingsBufferLabel->setAlignment(Qt::AlignRight); - this->settingsBufferLabel->setPalette(palette); - this->settingsRateLabel = new QLabel(); - this->settingsRateLabel->setAlignment(Qt::AlignRight); - this->settingsRateLabel->setPalette(palette); + this->settingsRecordLengthLabel = new QLabel(); + this->settingsRecordLengthLabel->setAlignment(Qt::AlignRight); + this->settingsRecordLengthLabel->setPalette(palette); + this->settingsSamplerateLabel = new QLabel(); + this->settingsSamplerateLabel->setAlignment(Qt::AlignRight); + this->settingsSamplerateLabel->setPalette(palette); this->settingsTimebaseLabel = new QLabel(); this->settingsTimebaseLabel->setAlignment(Qt::AlignRight); this->settingsTimebaseLabel->setPalette(palette); @@ -128,8 +128,8 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget this->settingsFrequencybaseLabel->setPalette(palette); this->settingsLayout = new QHBoxLayout(); this->settingsLayout->addWidget(this->settingsTriggerLabel); - this->settingsLayout->addWidget(this->settingsBufferLabel, 1); - this->settingsLayout->addWidget(this->settingsRateLabel, 1); + this->settingsLayout->addWidget(this->settingsRecordLengthLabel, 1); + this->settingsLayout->addWidget(this->settingsSamplerateLabel, 1); this->settingsLayout->addWidget(this->settingsTimebaseLabel, 1); this->settingsLayout->addWidget(this->settingsFrequencybaseLabel, 1); @@ -225,7 +225,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // Apply settings and update measured values this->updateTriggerDetails(); - this->updateBufferSize(this->settings->scope.horizontal.samples); + this->updateRecordLength(this->settings->scope.horizontal.samples); this->updateFrequencybase(); this->updateTimebase(); this->updateZoom(this->settings->view.zoom); @@ -246,7 +246,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // Connect other signals this->connect(this->dataAnalyzer, SIGNAL(analyzed(unsigned int)), this, SLOT(dataAnalyzed())); - this->connect(this->dataAnalyzer, SIGNAL(analyzed(unsigned int)), this, SLOT(updateBufferSize(unsigned int))); + this->connect(this->dataAnalyzer, SIGNAL(analyzed(unsigned int)), this, SLOT(updateRecordLength(unsigned int))); } /// \brief Stops the oscilloscope thread and the timer. @@ -332,7 +332,7 @@ void DsoWidget::updateFrequencybase() { /// \brief Updates the samplerate field after changing the samplerate. void DsoWidget::updateSamplerate() { - this->settingsRateLabel->setText(Helper::valueToString(this->settings->scope.horizontal.samplerate, Helper::UNIT_SAMPLES) + tr("/s")); + this->settingsSamplerateLabel->setText(Helper::valueToString(this->settings->scope.horizontal.samplerate, Helper::UNIT_SAMPLES) + tr("/s")); } /// \brief Handles timebaseChanged signal from the horizontal dock. @@ -424,9 +424,9 @@ void DsoWidget::updateVoltageUsed(unsigned int channel, bool used) { this->updateVoltageDetails(channel); } -/// \brief Change the buffer size. -void DsoWidget::updateBufferSize(unsigned int size) { - this->settingsBufferLabel->setText(tr("%1 S").arg(size)); +/// \brief Change the record length. +void DsoWidget::updateRecordLength(unsigned int size) { + this->settingsRecordLengthLabel->setText(tr("%1 S").arg(size)); } /// \brief Export the oscilloscope screen to a file. diff --git a/openhantek/src/dsowidget.h b/openhantek/src/dsowidget.h index 9dda4f5..97dfefc 100644 --- a/openhantek/src/dsowidget.h +++ b/openhantek/src/dsowidget.h @@ -69,8 +69,8 @@ class DsoWidget : public QWidget { QHBoxLayout *settingsLayout; ///< The table for the settings info QLabel *settingsTriggerLabel; ///< The trigger details - QLabel *settingsBufferLabel; ///< The buffer size - QLabel *settingsRateLabel; ///< The samplerate + QLabel *settingsRecordLengthLabel; ///< The record length + QLabel *settingsSamplerateLabel; ///< The samplerate QLabel *settingsTimebaseLabel; ///< The timebase of the main scope QLabel *settingsFrequencybaseLabel; ///< The frequencybase of the main scope @@ -116,7 +116,7 @@ class DsoWidget : public QWidget { void updateVoltageUsed(unsigned int channel, bool used); // Menus - void updateBufferSize(unsigned int size); + void updateRecordLength(unsigned int size); // Export bool exportAs(); diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp index 39bfb40..70bb394 100644 --- a/openhantek/src/hantek/control.cpp +++ b/openhantek/src/hantek/control.cpp @@ -42,11 +42,12 @@ namespace Hantek { /// \param parent The parent widget. Control::Control(QObject *parent) : DsoControl(parent) { // Use DSO-2090 specification as default - this->specification.command.bulk.setBuffer = BULK_SETTRIGGERANDSAMPLERATE; + this->specification.command.bulk.setRecordLength = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.bulk.setFilter = BULK_SETFILTER; this->specification.command.bulk.setGain = BULK_SETGAIN; this->specification.command.bulk.setSamplerate = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.bulk.setTrigger = BULK_SETTRIGGERANDSAMPLERATE; + this->specification.command.bulk.setPretrigger = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.control.setOffset = CONTROL_SETOFFSET; this->specification.command.control.setRelays = CONTROL_SETRELAYS; this->specification.command.values.offsetLimits = VALUE_OFFSETLIMITS; @@ -65,7 +66,7 @@ namespace Hantek { } // Set settings to default values - this->settings.bufferSizeId = 0; + this->settings.recordLengthId = 0; this->settings.samplerate.limits = &(this->specification.samplerate.single); this->settings.samplerate.downsampling = 1; this->settings.trigger.position = 0; @@ -76,23 +77,11 @@ namespace Hantek { // Special trigger sources this->specialTriggerSources << tr("EXT") << tr("EXT/10"); - // Transmission-ready bulk commands - this->command[BULK_SETFILTER] = new BulkSetFilter(); - this->command[BULK_SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); - this->command[BULK_FORCETRIGGER] = new BulkForceTrigger(); - this->command[BULK_STARTSAMPLING] = new BulkCaptureStart(); - this->command[BULK_ENABLETRIGGER] = new BulkTriggerEnabled(); - this->command[BULK_GETDATA] = new BulkGetData(); - this->command[BULK_GETCAPTURESTATE] = new BulkGetCaptureState(); - this->command[BULK_SETGAIN] = new BulkSetGain(); - this->command[BULK_SETLOGICALDATA] = new BulkSetLogicalData(); - this->command[BULK_GETLOGICALDATA] = new BulkGetLogicalData(); - this->command[BULK_SETSAMPLERATE5200] = new BulkSetSamplerate5200(); - this->command[BULK_SETBUFFER5200] = new BulkSetBuffer5200(); - this->command[BULK_SETTRIGGER5200] = new BulkSetTrigger5200(); - - for(int command = 0; command < BULK_COUNT; command++) + // Instantiate bulk command later, some are not the same for all models + for(int command = 0; command < BULK_COUNT; ++command) { + this->command[command] = 0; this->commandPending[command] = false; + } // Transmission-ready control commands this->control[CONTROLINDEX_SETOFFSET] = new ControlSetOffset(); @@ -118,6 +107,12 @@ namespace Hantek { /// \brief Disconnects the device. Control::~Control() { this->device->disconnect(); + + // Clean up commands + for(int command = 0; command < BULK_COUNT; ++command) { + if(this->command[command]) + delete this->command[command]; + } } /// \brief Gets the physical channel count for this oscilloscope. @@ -186,7 +181,7 @@ namespace Hantek { // Check the current oscilloscope state everytime 25% of the time the buffer should be refilled // Not more often than every 10 ms though - int cycleTime = qMax((unsigned long int) (this->specification.bufferSizes[this->settings.bufferSizeId] / this->settings.samplerate.current * 250), (long unsigned int) 10); + int cycleTime = qMax((unsigned long int) (this->specification.recordLengths[this->settings.recordLengthId] / this->settings.samplerate.current * 250), (long unsigned int) 10); this->msleep(cycleTime); if(!this->sampling) { @@ -296,7 +291,7 @@ namespace Hantek { } /// \brief Gets the current state. - /// \return The current CaptureState of the oscilloscope. + /// \return The current CaptureState of the oscilloscope, libusb error code on error. int Control::getCaptureState() { int errorCode; @@ -325,7 +320,7 @@ namespace Hantek { return errorCode; // Save raw data to temporary buffer - unsigned int dataCount = this->specification.bufferSizes[this->settings.bufferSizeId] * HANTEK_CHANNELS; + unsigned int dataCount = this->specification.recordLengths[this->settings.recordLengthId] * HANTEK_CHANNELS; unsigned int dataLength = dataCount; bool using10Bits = false; if(this->device->getModel() == MODEL_DSO5200 || this->device->getModel() == MODEL_DSO5200A) { @@ -350,16 +345,28 @@ namespace Hantek { this->samplesMutex.lock(); // Get oscilloscope settings - bool fastRate; - UsedChannels usedChannels; - if(this->specification.command.bulk.setTrigger == BULK_SETTRIGGERANDSAMPLERATE) { - fastRate = ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getFastRate(); - usedChannels = (UsedChannels) ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getUsedChannels(); - } - else { - fastRate = ((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->getFastRate(); - usedChannels = (UsedChannels) ((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->getUsedChannels(); + bool fastRate = false; + UsedChannels usedChannels = USED_NONE; + switch(this->specification.command.bulk.setTrigger) { + case BULK_SETTRIGGERANDSAMPLERATE: + fastRate = ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getFastRate(); + usedChannels = (UsedChannels) ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getUsedChannels(); + break; + + case BULK_CSETTRIGGERORSAMPLERATE: + fastRate = ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getFastRate(); + usedChannels = (UsedChannels) ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getUsedChannels(); + break; + + case BULK_ESETTRIGGERORSAMPLERATE: + fastRate = ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getFastRate(); + usedChannels = (UsedChannels) ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getUsedChannels(); + break; + + default: + break; } + // Convert channel data if(fastRate) { // Fast rate mode, one channel is using all buffers @@ -462,50 +469,64 @@ namespace Hantek { } /// \brief Sets the size of the sample buffer without updating dependencies. - /// \param size The buffer size that should be met (S). - /// \return The buffer size that has been set, 0 on error. - unsigned long int Control::updateBufferSize(unsigned long int size) { - // Get the buffer size supporting the highest samplerate while meeting the requirement + /// \param size The record length that should be met (S). + /// \return The record length that has been set, 0 on error. + unsigned long int Control::updateRecordLength(unsigned long int size) { + // Get the record length supporting the highest samplerate while meeting the requirement int bestSizeId = -1; - for(int sizeId = 0; sizeId < this->specification.bufferSizes.count(); sizeId++) { - if(this->specification.bufferSizes[sizeId] >= size) { + for(int sizeId = 0; sizeId < this->specification.recordLengths.count(); sizeId++) { + if(this->specification.recordLengths[sizeId] >= size) { // We meet the size-requirement, check if we provide the highest possible samplerate - if(bestSizeId == -1 || this->specification.bufferSizes[bestSizeId] < size || this->specification.bufferDividers[sizeId] < this->specification.bufferDividers[bestSizeId]) + if(bestSizeId == -1 || this->specification.recordLengths[bestSizeId] < size || this->specification.bufferDividers[sizeId] < this->specification.bufferDividers[bestSizeId]) bestSizeId = sizeId; } else { // We don't meet the size-requirement, but maybe we're still the one coming closest - if(bestSizeId == -1 || this->specification.bufferSizes[sizeId] > this->specification.bufferSizes[bestSizeId]) + if(bestSizeId == -1 || this->specification.recordLengths[sizeId] > this->specification.recordLengths[bestSizeId]) bestSizeId = sizeId; } } - switch(this->specification.command.bulk.setBuffer) { + switch(this->specification.command.bulk.setRecordLength) { case BULK_SETTRIGGERANDSAMPLERATE: - // SetTriggerAndSamplerate bulk command for buffer size - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setBufferSize(bestSizeId); + // SetTriggerAndSamplerate bulk command for record length + ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setRecordLength(bestSizeId); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; - case BULK_SETBUFFER5200: { - // SetBuffer5200 bulk command for buffer size - BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_SETBUFFER5200]; - commandSetBuffer5200->setUsedPre(DTRIGGERPOSITION_ON); - commandSetBuffer5200->setUsedPost(DTRIGGERPOSITION_ON); - commandSetBuffer5200->setBufferSize(bestSizeId); - this->commandPending[BULK_SETBUFFER5200] = true; - + case BULK_DSETBUFFER: + if(this->specification.command.bulk.setPretrigger == BULK_FSETBUFFER) { + // Pointers to needed commands + BulkSetRecordLength2250 *commandSetRecordLength2250 = (BulkSetRecordLength2250 *) this->command[BULK_DSETBUFFER]; + BulkSetBuffer2250 *commandSetBuffer2250 = (BulkSetBuffer2250 *) this->command[BULK_FSETBUFFER]; + + commandSetRecordLength2250->setRecordLength(bestSizeId); + commandSetBuffer2250->setUsedPre(FTRIGGERPOSITION_ON); + commandSetBuffer2250->setUsedPost(FTRIGGERPOSITION_ON); + commandSetBuffer2250->setLargeBuffer(bestSizeId == RECORDLENGTHID_LARGE); + commandSetBuffer2250->setSlowBuffer(bestSizeId != RECORDLENGTHID_SMALL); + + this->commandPending[BULK_DSETBUFFER] = true; + this->commandPending[BULK_FSETBUFFER] = true; + } + else { + // SetBuffer5200 bulk command for record length + BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_DSETBUFFER]; + commandSetBuffer5200->setUsedPre(DTRIGGERPOSITION_ON); + commandSetBuffer5200->setUsedPost(DTRIGGERPOSITION_ON); + commandSetBuffer5200->setRecordLength(bestSizeId); + this->commandPending[BULK_DSETBUFFER] = true; + } break; - } default: return 0; } - this->settings.bufferSizeId = bestSizeId; + this->settings.recordLengthId = bestSizeId; - return this->specification.bufferSizes[this->settings.bufferSizeId]; + return this->specification.recordLengths[this->settings.recordLengthId]; } /// \brief Try to connect to the oscilloscope. @@ -516,28 +537,26 @@ namespace Hantek { if(!this->device->isConnected()) return; - // Initialize the commands used on the DSO-2090 as pending - this->commandPending[BULK_SETFILTER] = true; - this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; - this->commandPending[BULK_FORCETRIGGER] = false; - this->commandPending[BULK_STARTSAMPLING] = false; - this->commandPending[BULK_ENABLETRIGGER] = false; - this->commandPending[BULK_GETDATA] = false; - this->commandPending[BULK_GETCAPTURESTATE] = false; - this->commandPending[BULK_SETGAIN] = true; - this->commandPending[BULK_SETLOGICALDATA] = false; - this->commandPending[BULK_GETLOGICALDATA] = false; - this->commandPending[BULK_UNKNOWN_0A] = false; - this->commandPending[BULK_UNKNOWN_0B] = false; - this->commandPending[BULK_SETSAMPLERATE5200] = false; - this->commandPending[BULK_SETBUFFER5200] = false; - this->commandPending[BULK_SETTRIGGER5200] = false; + // Clean up commands and their pending state + for(int command = 0; command < BULK_COUNT; ++command) { + if(this->command[command]) + delete this->command[command]; + this->commandPending[command] = false; + } + // Instantiate the commands needed for all models + this->command[BULK_FORCETRIGGER] = new BulkForceTrigger(); + this->command[BULK_STARTSAMPLING] = new BulkCaptureStart(); + this->command[BULK_ENABLETRIGGER] = new BulkTriggerEnabled(); + this->command[BULK_GETDATA] = new BulkGetData(); + this->command[BULK_GETCAPTURESTATE] = new BulkGetCaptureState(); + this->command[BULK_SETGAIN] = new BulkSetGain(); // Initialize the command versions to the ones used on the DSO-2090 - this->specification.command.bulk.setBuffer = BULK_SETTRIGGERANDSAMPLERATE; + this->specification.command.bulk.setRecordLength = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.bulk.setFilter = BULK_SETFILTER; this->specification.command.bulk.setGain = BULK_SETGAIN; this->specification.command.bulk.setSamplerate = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.bulk.setTrigger = BULK_SETTRIGGERANDSAMPLERATE; + this->specification.command.bulk.setPretrigger = BULK_SETTRIGGERANDSAMPLERATE; this->specification.command.control.setOffset = CONTROL_SETOFFSET; this->specification.command.control.setRelays = CONTROL_SETRELAYS; this->specification.command.values.offsetLimits = VALUE_OFFSETLIMITS; @@ -550,23 +569,50 @@ namespace Hantek { unsupported = true; case MODEL_DSO2090: - // Keep the defaults we've set before + // Instantiate additional commands for the DSO-2090 + this->command[BULK_SETFILTER] = new BulkSetFilter(); + this->command[BULK_SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); + // Initialize those as pending + this->commandPending[BULK_SETFILTER] = true; + this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; case MODEL_DSO2250: + // Instantiate additional commands for the DSO-2250 + this->command[BULK_BSETFILTER] = new BulkSetFilter2250(); + this->command[BULK_CSETTRIGGERORSAMPLERATE] = new BulkSetTrigger2250(); + this->command[BULK_DSETBUFFER] = new BulkSetRecordLength2250(); + this->command[BULK_ESETTRIGGERORSAMPLERATE] = new BulkSetSamplerate2250(); + this->specification.command.bulk.setRecordLength = BULK_DSETBUFFER; + this->specification.command.bulk.setFilter = BULK_BSETFILTER; + this->specification.command.bulk.setSamplerate = BULK_ESETTRIGGERORSAMPLERATE; + this->specification.command.bulk.setTrigger = BULK_CSETTRIGGERORSAMPLERATE; + this->specification.command.bulk.setPretrigger = BULK_FSETBUFFER; + + this->commandPending[BULK_BSETFILTER] = true; + this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + this->commandPending[BULK_DSETBUFFER] = true; + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + + break; + case MODEL_DSO5200A: unsupported = true; case MODEL_DSO5200: - this->specification.command.bulk.setBuffer = BULK_SETBUFFER5200; - this->specification.command.bulk.setSamplerate = BULK_SETSAMPLERATE5200; - this->specification.command.bulk.setTrigger = BULK_SETTRIGGER5200; - this->specification.command.values.voltageLimits = VALUE_VOLTAGELIMITS; + // Instantiate additional commands for the DSO-5200 + this->command[BULK_CSETTRIGGERORSAMPLERATE] = new BulkSetSamplerate5200(); + this->command[BULK_DSETBUFFER] = new BulkSetBuffer5200(); + this->command[BULK_ESETTRIGGERORSAMPLERATE] = new BulkSetTrigger5200(); + this->specification.command.bulk.setRecordLength = BULK_DSETBUFFER; + this->specification.command.bulk.setSamplerate = BULK_CSETTRIGGERORSAMPLERATE; + this->specification.command.bulk.setTrigger = BULK_ESETTRIGGERORSAMPLERATE; + this->specification.command.bulk.setPretrigger = BULK_ESETTRIGGERORSAMPLERATE; + //this->specification.command.values.voltageLimits = VALUE_ETSCORRECTION; - this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = false; - this->commandPending[BULK_SETSAMPLERATE5200] = true; - this->commandPending[BULK_SETBUFFER5200] = true; - this->commandPending[BULK_SETTRIGGER5200] = true; + this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + this->commandPending[BULK_DSETBUFFER] = true; + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; break; @@ -582,15 +628,14 @@ namespace Hantek { for(int control = 0; control < CONTROLINDEX_COUNT; control++) this->controlPending[control] = true; - // Maximum possible samplerate for a single channel and dividers for buffer sizes + // Maximum possible samplerate for a single channel and dividers for record lengths this->specification.bufferDividers.clear(); - this->specification.bufferSizes.clear(); + this->specification.recordLengths.clear(); this->specification.gainSteps.clear(); for(int channel = 0; channel < HANTEK_CHANNELS; channel++) this->specification.voltageLimit[channel].clear(); switch(this->device->getModel()) { - case MODEL_DSO2250: case MODEL_DSO5200: case MODEL_DSO5200A: this->specification.samplerate.single.base = 100e6; @@ -598,7 +643,7 @@ namespace Hantek { this->specification.samplerate.multi.base = 200e6; this->specification.samplerate.multi.max = 250e6; this->specification.bufferDividers << 1000 << 1 << 2; - this->specification.bufferSizes << ULONG_MAX << 10240 << 14336; + this->specification.recordLengths << ULONG_MAX << 10240 << 14336; this->specification.gainSteps << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0 << 80.0; /// \todo Use calibration data to get the DSO-5200(A) sample ranges @@ -609,13 +654,29 @@ namespace Hantek { << 1 << 0 << 0 << 1 << 0 << 0 << 1 << 0 << 0; break; + case MODEL_DSO2250: + this->specification.samplerate.single.base = 200e6; + this->specification.samplerate.single.max = 125e6; + this->specification.samplerate.multi.base = 200e6; + this->specification.samplerate.multi.max = 250e6; + this->specification.bufferDividers << 1000 << 1 << 2; + this->specification.recordLengths << ULONG_MAX << 10240 << 524288; + this->specification.gainSteps + << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; + for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + this->specification.voltageLimit[channel] + << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; + this->specification.gainIndex + << 0 << 1 << 2 << 0 << 1 << 2 << 0 << 1 << 2; + break; + case MODEL_DSO2150: this->specification.samplerate.single.base = 50e6; this->specification.samplerate.single.max = 75e6; this->specification.samplerate.multi.base = 100e6; this->specification.samplerate.multi.max = 150e6; this->specification.bufferDividers << 1000 << 1 << 2; - this->specification.bufferSizes << ULONG_MAX << 10240 << 32768; + this->specification.recordLengths << ULONG_MAX << 10240 << 32768; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; for(int channel = 0; channel < HANTEK_CHANNELS; channel++) @@ -631,7 +692,7 @@ namespace Hantek { this->specification.samplerate.multi.base = 100e6; this->specification.samplerate.multi.max = 100e6; this->specification.bufferDividers << 1000 << 1 << 2; - this->specification.bufferSizes << ULONG_MAX << 10240 << 32768; + this->specification.recordLengths << ULONG_MAX << 10240 << 32768; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; for(int channel = 0; channel < HANTEK_CHANNELS; channel++) @@ -656,23 +717,23 @@ namespace Hantek { } /// \brief Sets the size of the oscilloscopes sample buffer. - /// \param size The buffer size that should be met (S). - /// \return The buffer size that has been set. - unsigned long int Control::setBufferSize(unsigned long int size) { + /// \param size The record length that should be met (S). + /// \return The record length that has been set, 0 on error. + unsigned long int Control::setRecordLength(unsigned long int size) { if(!this->device->isConnected()) return 0; - this->updateBufferSize(size); + this->updateRecordLength(size); - this->setTriggerPosition(this->settings.trigger.position); + this->setPretriggerPosition(this->settings.trigger.position); this->setSamplerate(); - return this->specification.bufferSizes[this->settings.bufferSizeId]; + return this->specification.recordLengths[this->settings.recordLengthId]; } /// \brief Sets the samplerate of the oscilloscope. /// \param samplerate The samplerate that should be met (S/s). - /// \return The samplerate that has been set. + /// \return The samplerate that has been set, 0 on error. unsigned long int Control::setSamplerate(unsigned long int samplerate) { if(!this->device->isConnected()) return 0; @@ -693,24 +754,24 @@ namespace Hantek { } // Get downsampling factor that would provide the requested rate - this->settings.samplerate.downsampling = this->settings.samplerate.limits->base / this->specification.bufferDividers[this->settings.bufferSizeId] / samplerate; + this->settings.samplerate.downsampling = this->settings.samplerate.limits->base / this->specification.bufferDividers[this->settings.recordLengthId] / samplerate; // A downsampling factor of zero will result in the maximum rate if(this->settings.samplerate.downsampling) - this->settings.samplerate.current = this->settings.samplerate.limits->base / this->specification.bufferDividers[this->settings.bufferSizeId] / this->settings.samplerate.downsampling; + this->settings.samplerate.current = this->settings.samplerate.limits->base / this->specification.bufferDividers[this->settings.recordLengthId] / this->settings.samplerate.downsampling; else - this->settings.samplerate.current = this->settings.samplerate.limits->max / this->specification.bufferDividers[this->settings.bufferSizeId]; + this->settings.samplerate.current = this->settings.samplerate.limits->max / this->specification.bufferDividers[this->settings.recordLengthId]; // Maybe normal mode would be sufficient or even better than fast rate mode if(fastRate) { // Don't set the downsampling factor to zero (maximum rate) if we could use fast rate mode anyway - unsigned long int slowDownsampling = qMax(this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.bufferSizeId] / samplerate, (long unsigned int) 1); + unsigned long int slowDownsampling = qMax(this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.recordLengthId] / samplerate, (long unsigned int) 1); // Use normal mode if we need valueSlow or it would meet the rate at least as exactly as fast rate mode - if(this->settings.samplerate.downsampling > 4 || (qAbs((double) this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.bufferSizeId] / slowDownsampling - samplerate) <= qAbs(this->settings.samplerate.current - samplerate))) { + if(this->settings.samplerate.downsampling > 4 || (qAbs((double) this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.recordLengthId] / slowDownsampling - samplerate) <= qAbs(this->settings.samplerate.current - samplerate))) { fastRate = false; this->settings.samplerate.limits = &(this->specification.samplerate.single); this->settings.samplerate.downsampling = slowDownsampling; - this->settings.samplerate.current = this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.bufferSizeId] / this->settings.samplerate.downsampling; + this->settings.samplerate.current = this->specification.samplerate.single.base / this->specification.bufferDividers[this->settings.recordLengthId] / this->settings.samplerate.downsampling; } } @@ -735,10 +796,11 @@ namespace Hantek { break; } - case BULK_SETSAMPLERATE5200: { + case BULK_CSETTRIGGERORSAMPLERATE: { // Pointers to needed commands - BulkSetSamplerate5200 *commandSetSamplerate5200 = (BulkSetSamplerate5200 *) this->command[BULK_SETSAMPLERATE5200]; - BulkSetTrigger5200 *commandSetTrigger5200 = (BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200]; + BulkSetSamplerate5200 *commandSetSamplerate5200 = (BulkSetSamplerate5200 *) this->command[BULK_CSETTRIGGERORSAMPLERATE]; + BulkSetTrigger5200 *commandSetTrigger5200 = (BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE]; + // Store samplerate fast value commandSetSamplerate5200->setSamplerateFast(4 - valueFast); // Store samplerate slow value (two's complement) @@ -746,8 +808,23 @@ namespace Hantek { // Set fast rate when used commandSetTrigger5200->setFastRate(fastRate); - this->commandPending[BULK_SETSAMPLERATE5200] = true; - this->commandPending[BULK_SETTRIGGER5200] = true; + this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + + break; + } + case BULK_ESETTRIGGERORSAMPLERATE: { + // Pointers to needed commands + BulkSetSamplerate2250 *commandSetSamplerate2250 = (BulkSetSamplerate2250 *) this->command[BULK_ESETTRIGGERORSAMPLERATE]; + + // Store samplerate fast value + commandSetSamplerate2250->setSamplerateFast(4 - valueFast); + // Store samplerate slow value (two's complement) + commandSetSamplerate2250->setSamplerateSlow(valueSlow == 0 ? 0 : 0xffff - valueSlow); + // Set fast rate when used + commandSetSamplerate2250->setFastRate(fastRate); + + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; break; } @@ -755,81 +832,102 @@ namespace Hantek { return 0; } - this->updateBufferSize(this->specification.bufferSizes[this->settings.bufferSizeId]); - this->setTriggerPosition(this->settings.trigger.position); + this->updateRecordLength(this->specification.recordLengths[this->settings.recordLengthId]); + this->setPretriggerPosition(this->settings.trigger.position); return this->settings.samplerate.current; } /// \brief Enables/disables filtering of the given channel. /// \param channel The channel that should be set. /// \param used true if the channel should be sampled. - /// \return 0 on success, -1 on invalid channel. + /// \return See ::Dso::ErrorCode. int Control::setChannelUsed(unsigned int channel, bool used) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(channel >= HANTEK_CHANNELS) - return -1; - - // SetFilter bulk command for channel filter (used has to be inverted!) - BulkSetFilter *commandSetFilter = (BulkSetFilter *) this->command[BULK_SETFILTER]; - commandSetFilter->setChannel(channel, !used); - this->commandPending[BULK_SETFILTER] = true; + return Dso::ERROR_PARAMETER; unsigned char usedChannels = USED_CH1; - if(!commandSetFilter->getChannel(1)) { - if(commandSetFilter->getChannel(0)) - usedChannels = USED_CH2; - else - usedChannels = USED_CH1CH2; - } - switch(this->specification.command.bulk.setTrigger) { - case BULK_SETTRIGGER5200: { - // SetTrigger5200s bulk command for trigger source - ((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->setUsedChannels(usedChannels); - this->commandPending[BULK_SETTRIGGER5200] = true; + switch(this->specification.command.bulk.setFilter) { + case BULK_SETFILTER: { + // SetFilter bulk command for channel filter (used has to be inverted!) + BulkSetFilter *commandSetFilter = (BulkSetFilter *) this->command[BULK_SETFILTER]; + commandSetFilter->setChannel(channel, !used); + this->commandPending[BULK_SETFILTER] = true; + + if(!commandSetFilter->getChannel(1)) { + if(commandSetFilter->getChannel(0)) + usedChannels = USED_CH2; + else + usedChannels = USED_CH1CH2; + } + break; } - default: { - // SetTriggerAndSamplerate bulk command for trigger source - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setUsedChannels(usedChannels); - this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + case BULK_BSETFILTER: { + // SetFilter2250 bulk command for channel filter (used has to be inverted!) + BulkSetFilter2250 *commandSetFilter2250 = (BulkSetFilter2250 *) this->command[BULK_BSETFILTER]; + commandSetFilter2250->setChannel(channel, !used); + this->commandPending[BULK_BSETFILTER] = true; + break; } + default: + return Dso::ERROR_UNSUPPORTED; } - return 0; + if(this->specification.command.bulk.setTrigger == BULK_SETTRIGGERANDSAMPLERATE || this->specification.command.bulk.setTrigger == BULK_ESETTRIGGERORSAMPLERATE) { + switch(this->specification.command.bulk.setTrigger) { + case BULK_SETTRIGGERANDSAMPLERATE: { + // SetTriggerAndSamplerate bulk command for trigger source + ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setUsedChannels(usedChannels); + this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + break; + } + case BULK_ESETTRIGGERORSAMPLERATE: { + // SetTrigger5200s bulk command for trigger source + ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setUsedChannels(usedChannels); + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + break; + } + default: + break; + } + } + + return Dso::ERROR_NONE; } /// \brief Set the coupling for the given channel. /// \param channel The channel that should be set. /// \param coupling The new coupling for the channel. - /// \return 0 on success, -1 on invalid channel. + /// \return See ::Dso::ErrorCode. int Control::setCoupling(unsigned int channel, Dso::Coupling coupling) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(channel >= HANTEK_CHANNELS) - return -1; + return Dso::ERROR_PARAMETER; // SetRelays control command for coupling relays ((ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS])->setCoupling(channel, coupling != Dso::COUPLING_AC); this->controlPending[CONTROLINDEX_SETRELAYS] = true; - return 0; + return Dso::ERROR_NONE; } /// \brief Sets the gain for the given channel. /// \param channel The channel that should be set. /// \param gain The gain that should be met (V/div). - /// \return The gain that has been set, -1 on invalid channel. + /// \return The gain that has been set, ::Dso::ErrorCode on error. double Control::setGain(unsigned int channel, double gain) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(channel >= HANTEK_CHANNELS) - return -1; + return Dso::ERROR_PARAMETER; // Find lowest gain voltage thats at least as high as the requested int gainId; @@ -857,13 +955,13 @@ namespace Hantek { /// \brief Set the offset for the given channel. /// \param channel The channel that should be set. /// \param offset The new offset value (0.0 - 1.0). - /// \return The offset that has been set, -1.0 on invalid channel. + /// \return The offset that has been set, ::Dso::ErrorCode on error. double Control::setOffset(unsigned int channel, double offset) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(channel >= HANTEK_CHANNELS) - return -1; + return Dso::ERROR_PARAMETER; // Calculate the offset value // The range is given by the calibration data (convert from big endian) @@ -885,28 +983,28 @@ namespace Hantek { } /// \brief Set the trigger mode. - /// \return 0 on success, -1 on invalid mode. + /// \return See ::Dso::ErrorCode. int Control::setTriggerMode(Dso::TriggerMode mode) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(mode < Dso::TRIGGERMODE_AUTO || mode > Dso::TRIGGERMODE_SINGLE) - return -1; + return Dso::ERROR_PARAMETER; this->settings.trigger.mode = mode; - return 0; + return Dso::ERROR_NONE; } /// \brief Set the trigger source. /// \param special true for a special channel (EXT, ...) as trigger source. /// \param id The number of the channel, that should be used as trigger. - /// \return 0 on success, -1 on invalid channel. + /// \return See ::Dso::ErrorCode. int Control::setTriggerSource(bool special, unsigned int id) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if((!special && id >= HANTEK_CHANNELS) || (special && id >= HANTEK_SPECIAL_CHANNELS)) - return -1; + return Dso::ERROR_PARAMETER; // Generate trigger source value that will be transmitted int sourceValue; @@ -916,17 +1014,26 @@ namespace Hantek { sourceValue = TRIGGER_CH1 - id; switch(this->specification.command.bulk.setTrigger) { - case BULK_SETTRIGGER5200: - // SetTrigger5200 bulk command for trigger source - ((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->setTriggerSource(sourceValue); - this->commandPending[BULK_SETTRIGGER5200] = true; - break; - - default: + case BULK_SETTRIGGERANDSAMPLERATE: // SetTriggerAndSamplerate bulk command for trigger source ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSource(sourceValue); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; + + case BULK_CSETTRIGGERORSAMPLERATE: + // SetTrigger2250 bulk command for trigger source + ((BulkSetTrigger2250 *) this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); + this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + break; + + case BULK_ESETTRIGGERORSAMPLERATE: + // SetTrigger5200 bulk command for trigger source + ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + break; + + default: + return Dso::ERROR_UNSUPPORTED; } // SetRelays control command for external trigger relay @@ -945,19 +1052,19 @@ namespace Hantek { else this->setTriggerLevel(id, this->settings.trigger.level[id]); - return 0; + return Dso::ERROR_NONE; } /// \brief Set the trigger level. /// \param channel The channel that should be set. /// \param level The new trigger level (V). - /// \return The trigger level that has been set, -1.0 on invalid channel. + /// \return The trigger level that has been set, ::Dso::ErrorCode on error. double Control::setTriggerLevel(unsigned int channel, double level) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(channel >= HANTEK_CHANNELS) - return -1.0; + return Dso::ERROR_PARAMETER; // Calculate the trigger level value unsigned short int minimum, maximum; @@ -994,22 +1101,16 @@ namespace Hantek { /// \brief Set the trigger slope. /// \param slope The Slope that should cause a trigger. - /// \return 0 on success, -1 on invalid slope. + /// \return See ::Dso::ErrorCode. int Control::setTriggerSlope(Dso::Slope slope) { if(!this->device->isConnected()) - return -2; + return Dso::ERROR_CONNECTION; if(slope != Dso::SLOPE_NEGATIVE && slope != Dso::SLOPE_POSITIVE) - return -1; + return Dso::ERROR_PARAMETER; switch(this->specification.command.bulk.setTrigger) { - case BULK_SETTRIGGER5200: { - // SetTrigger5200 bulk command for trigger slope - ((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->setTriggerSlope(slope); - this->commandPending[BULK_SETTRIGGER5200] = true; - break; - } - default: { + case BULK_SETTRIGGERANDSAMPLERATE: { // SetTriggerAndSamplerate bulk command for trigger slope BulkSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE]; @@ -1017,54 +1118,87 @@ namespace Hantek { this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; } + case BULK_CSETTRIGGERORSAMPLERATE: { + // SetTrigger2250 bulk command for trigger slope + ((BulkSetTrigger2250 *) this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + break; + } + case BULK_ESETTRIGGERORSAMPLERATE: { + // SetTrigger5200 bulk command for trigger slope + ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + break; + } + default: + return Dso::ERROR_UNSUPPORTED; } this->settings.trigger.slope = slope; - return 0; + return Dso::ERROR_NONE; } /// \brief Set the trigger position. /// \param position The new trigger position (in s). /// \return The trigger position that has been set. - double Control::setTriggerPosition(double position) { + double Control::setPretriggerPosition(double position) { if(!this->device->isConnected()) return -2; // All trigger positions are measured in samples unsigned long int positionSamples = position * this->settings.samplerate.current; - switch(this->specification.command.bulk.setTrigger) { - case BULK_SETTRIGGER5200: { + switch(this->specification.command.bulk.setPretrigger) { + case BULK_SETTRIGGERANDSAMPLERATE: { // Fast rate mode uses both channels - if(((BulkSetTrigger5200 *) this->command[BULK_SETTRIGGER5200])->getFastRate()) + if(((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getFastRate()) + positionSamples /= HANTEK_CHANNELS; + + // Calculate the position value (Start point depending on record length) + unsigned long int position = 0x7ffff - this->specification.recordLengths[this->settings.recordLengthId] + positionSamples; + + // SetTriggerAndSamplerate bulk command for trigger position + ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); + this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + + break; + } + case BULK_FSETBUFFER: { + // Fast rate mode uses both channels + if(((BulkSetSamplerate2250 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getFastRate()) positionSamples /= HANTEK_CHANNELS; // Calculate the position values (Inverse, maximum is 0xffff) - unsigned short int positionPre = 0xffff - this->specification.bufferSizes[this->settings.bufferSizeId] + positionSamples; + unsigned short int positionPre = 0xffff - this->specification.recordLengths[this->settings.recordLengthId] + positionSamples; unsigned short int positionPost = 0xffff - positionSamples; - // SetBuffer5200 bulk command for trigger position - BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_SETBUFFER5200]; - commandSetBuffer5200->setTriggerPositionPre(positionPre); - commandSetBuffer5200->setTriggerPositionPost(positionPost); - this->commandPending[BULK_SETBUFFER5200] = true; + // SetBuffer2250 bulk command for trigger position + BulkSetBuffer2250 *commandSetBuffer2250 = (BulkSetBuffer2250 *) this->command[BULK_FSETBUFFER]; + commandSetBuffer2250->setTriggerPositionPre(positionPre); + commandSetBuffer2250->setTriggerPositionPost(positionPost); + this->commandPending[BULK_FSETBUFFER] = true; break; } - default: { + case BULK_ESETTRIGGERORSAMPLERATE: { // Fast rate mode uses both channels - if(((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->getFastRate()) + if(((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->getFastRate()) positionSamples /= HANTEK_CHANNELS; - // Calculate the position value (Start point depending on buffer size) - unsigned long int position = 0x7ffff - this->specification.bufferSizes[this->settings.bufferSizeId] + positionSamples; + // Calculate the position values (Inverse, maximum is 0xffff) + unsigned short int positionPre = 0xffff - this->specification.recordLengths[this->settings.recordLengthId] + positionSamples; + unsigned short int positionPost = 0xffff - positionSamples; - // SetTriggerAndSamplerate bulk command for trigger position - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); - this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + // SetBuffer5200 bulk command for trigger position + BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_DSETBUFFER]; + commandSetBuffer5200->setTriggerPositionPre(positionPre); + commandSetBuffer5200->setTriggerPositionPost(positionPost); + this->commandPending[BULK_DSETBUFFER] = true; break; } + default: + return Dso::ERROR_UNSUPPORTED; } this->settings.trigger.position = position; @@ -1073,11 +1207,19 @@ namespace Hantek { #ifdef DEBUG /// \brief Sends bulk/control commands directly. + ///

+ /// Syntax:
+ ///
+ /// Bulk command: + ///

send bulk [hex data]
+ /// %Control command: + ///
send control [hex code] [hex data]
+ ///

/// \param command The command as string (Has to be parsed). - /// \return 0 on success, -1 on unknown command, -2 on syntax error. + /// \return See ::Dso::ErrorCode. int Control::stringCommand(QString command) { if(!this->device->isConnected()) - return -3; + return Dso::ERROR_CONNECTION; QStringList commandParts = command.split(' ', QString::SkipEmptyParts); @@ -1091,17 +1233,14 @@ namespace Hantek { // Read command code (First byte) Helper::hexParse(data, &commandCode, 1); if(commandCode > BULK_COUNT) - return -2; + return Dso::ERROR_UNSUPPORTED; // Update bulk command and mark as pending Helper::hexParse(data, this->command[commandCode]->data(), this->command[commandCode]->getSize()); this->commandPending[commandCode] = true; - return 0; + return Dso::ERROR_NONE; } else if(commandParts[1] == "control") { - if(commandParts.count() <= 1) - return -2; - // Get control code from third part unsigned char controlCode = commandParts[2].toUShort(); int control; @@ -1110,20 +1249,26 @@ namespace Hantek { break; } if(control >= CONTROLINDEX_COUNT) - return -2; + return Dso::ERROR_UNSUPPORTED; QString data = command.section(' ', 3, -1, QString::SectionSkipEmpty); // Update control command and mark as pending Helper::hexParse(data, this->control[control]->data(), this->control[control]->getSize()); this->controlPending[control] = true; - return 0; + return Dso::ERROR_NONE; } } + else { + return Dso::ERROR_PARAMETER; + } } } + else { + return Dso::ERROR_PARAMETER; + } - return -1; + return Dso::ERROR_UNSUPPORTED; } #endif } diff --git a/openhantek/src/hantek/control.h b/openhantek/src/hantek/control.h index 6b06118..719ba39 100644 --- a/openhantek/src/hantek/control.h +++ b/openhantek/src/hantek/control.h @@ -59,8 +59,9 @@ namespace Hantek { BulkCode setFilter; ///< Command for setting used channels BulkCode setSamplerate; ///< Command for samplerate settings BulkCode setGain; ///< Command for gain settings (Usually in combination with CONTROL_SETRELAYS) - BulkCode setBuffer; ///< Command for buffer settings + BulkCode setRecordLength; ///< Command for buffer settings BulkCode setTrigger; ///< Command for trigger settings + BulkCode setPretrigger; ///< Command for pretrigger settings }; ////////////////////////////////////////////////////////////////////////////// @@ -113,8 +114,8 @@ namespace Hantek { // Limits ControlSpecificationSamplerate samplerate; ///< The samplerate specifications - QList bufferSizes; ///< Available buffer sizes, ULONG_MAX means rolling - QList bufferDividers; ///< Samplerate dividers for buffer sizes + QList recordLengths; ///< Available record lengths, ULONG_MAX means rolling + QList bufferDividers; ///< Samplerate dividers for record lengths QList gainSteps; ///< Available voltage steps in V/screenheight // Calibration @@ -166,7 +167,7 @@ namespace Hantek { ControlSettingsSamplerate samplerate; ///< The samplerate settings ControlSettingsVoltage voltage[HANTEK_CHANNELS]; ///< The amplification settings ControlSettingsTrigger trigger; ///< The trigger settings - unsigned int bufferSizeId; ///< The id in the buffer size array + unsigned int recordLengthId; ///< The id in the record length array unsigned short int usedChannels; ///< Number of activated channels }; @@ -188,7 +189,7 @@ namespace Hantek { unsigned short int calculateTriggerPoint(unsigned short int value); int getCaptureState(); int getSamples(bool process); - unsigned long int updateBufferSize(unsigned long int size); + unsigned long int updateRecordLength(unsigned long int size); // Communication with device Device *device; ///< The USB device for the oscilloscope @@ -212,7 +213,7 @@ namespace Hantek { virtual void connectDevice(); unsigned long int setSamplerate(unsigned long int samplerate = 0); - unsigned long int setBufferSize(unsigned long int size); + unsigned long int setRecordLength(unsigned long int size); int setChannelUsed(unsigned int channel, bool used); int setCoupling(unsigned int channel, Dso::Coupling coupling); @@ -223,7 +224,7 @@ namespace Hantek { int setTriggerSource(bool special, unsigned int id); double setTriggerLevel(unsigned int channel, double level); int setTriggerSlope(Dso::Slope slope); - double setTriggerPosition(double position); + double setPretriggerPosition(double position); #ifdef DEBUG int stringCommand(QString command); diff --git a/openhantek/src/hantek/types.cpp b/openhantek/src/hantek/types.cpp index 94d3999..852527c 100644 --- a/openhantek/src/hantek/types.cpp +++ b/openhantek/src/hantek/types.cpp @@ -104,16 +104,16 @@ namespace Hantek { /// \param samplerateSlow The SamplerateSlow value. /// \param triggerPosition The trigger position value. /// \param triggerSource The trigger source id (Tsr1). - /// \param bufferSize The buffer size id (Tsr1). + /// \param recordLength The record length id (Tsr1). /// \param samplerateFast The samplerateFast value (Tsr1). /// \param usedChannels The enabled channels (Tsr2). /// \param fastRate The fastRate state (Tsr2). /// \param triggerSlope The triggerSlope value (Tsr2). - BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate(unsigned short int samplerateSlow, unsigned long int triggerPosition, unsigned char triggerSource, unsigned char bufferSize, unsigned char samplerateFast, unsigned char usedChannels, bool fastRate, unsigned char triggerSlope) : Helper::DataArray(12) { + BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate(unsigned short int samplerateSlow, unsigned long int triggerPosition, unsigned char triggerSource, unsigned char recordLength, unsigned char samplerateFast, unsigned char usedChannels, bool fastRate, unsigned char triggerSlope) : Helper::DataArray(12) { this->init(); this->setTriggerSource(triggerSource); - this->setBufferSize(bufferSize); + this->setRecordLength(recordLength); this->setSamplerateFast(samplerateFast); this->setUsedChannels(usedChannels); this->setFastRate(fastRate); @@ -134,16 +134,16 @@ namespace Hantek { ((Tsr1Bits *) &(this->array[2]))->triggerSource = value; } - /// \brief Get the bufferSize value in Tsr1Bits. - /// \return The ::BufferSizeId value. - unsigned char BulkSetTriggerAndSamplerate::getBufferSize() { - return ((Tsr1Bits *) &(this->array[2]))->bufferSize; + /// \brief Get the recordLength value in Tsr1Bits. + /// \return The ::RecordLengthId value. + unsigned char BulkSetTriggerAndSamplerate::getRecordLength() { + return ((Tsr1Bits *) &(this->array[2]))->recordLength; } - /// \brief Set the bufferSize in Tsr1Bits to the given value. - /// \param value The new ::BufferSizeId value. - void BulkSetTriggerAndSamplerate::setBufferSize(unsigned char value) { - ((Tsr1Bits *) &(this->array[2]))->bufferSize = value; + /// \brief Set the recordLength in Tsr1Bits to the given value. + /// \param value The new ::RecordLengthId value. + void BulkSetTriggerAndSamplerate::setRecordLength(unsigned char value) { + ((Tsr1Bits *) &(this->array[2]))->recordLength = value; } /// \brief Get the samplerateFast value in Tsr1Bits. @@ -376,190 +376,94 @@ namespace Hantek { ////////////////////////////////////////////////////////////////////////////// - // class BulkGetSpeed - /// \brief Initializes the array. - ControlGetSpeed::ControlGetSpeed() : Helper::DataArray(10) { - } - - /// \brief Gets the speed of the connection. - /// \return The speed level of the USB connection. - ConnectionSpeed ControlGetSpeed::getSpeed() { - return (ConnectionSpeed) this->array[0]; + // class BulkSetFilter2250 + /// \brief Sets the data array to needed values. + BulkSetFilter2250::BulkSetFilter2250() : Helper::DataArray(4) { + this->init(); } - - ////////////////////////////////////////////////////////////////////////////// - // class BulkBeginCommand - /// \brief Sets the command index to the given value. - /// \param index The CommandIndex for the command. - ControlBeginCommand::ControlBeginCommand(BulkIndex index) : Helper::DataArray(10) { + /// \brief Sets the used channels. + /// \param channel1 true if channel 1 is filtered. + /// \param channel2 true if channel 2 is filtered. + BulkSetFilter2250::BulkSetFilter2250(bool channel1, bool channel2) : Helper::DataArray(4) { this->init(); - this->setIndex(index); - } - - /// \brief Gets the command index. - /// \return The CommandIndex for the command. - BulkIndex ControlBeginCommand::getIndex() { - return (BulkIndex) this->array[1]; - } - - /// \brief Sets the command index to the given value. - /// \param index The new CommandIndex for the command. - void ControlBeginCommand::setIndex(BulkIndex index) { - memset(&(this->array[1]), (unsigned char) index, 3); - } - - /// \brief Initialize the array to the needed values. - void ControlBeginCommand::init() { - this->array[0] = 0x0f; - } - - - ////////////////////////////////////////////////////////////////////////////// - // class BulkSetOffset - /// \brief Sets the data array to the default values. - ControlSetOffset::ControlSetOffset() : Helper::DataArray(17) { - } - - /// \brief Sets the offsets to the given values. - /// \param channel1 The offset for channel 1. - /// \param channel2 The offset for channel 2. - /// \param trigger The offset for ext. trigger. - ControlSetOffset::ControlSetOffset(unsigned short int channel1, unsigned short int channel2, unsigned short int trigger) : Helper::DataArray(17) { this->setChannel(0, channel1); this->setChannel(1, channel2); - this->setTrigger(trigger); } - /// \brief Get the offset for the given channel. - /// \param channel The channel whose offset should be returned. - /// \return The channel offset value. - unsigned short int ControlSetOffset::getChannel(unsigned int channel) { + /// \brief Gets the filtering state of one channel. + /// \param channel The channel whose filtering state should be returned. + /// \return The filtering state of the channel. + bool BulkSetFilter2250::getChannel(unsigned int channel) { + FilterBits *filterBits = (FilterBits *) &(this->array[2]); if(channel == 0) - return ((this->array[0] & 0x0f) << 8) | this->array[1]; + return filterBits->channel1 == 1; else - return ((this->array[2] & 0x0f) << 8) | this->array[3]; + return filterBits->channel2 == 1; } - /// \brief Set the offset for the given channel. + /// \brief Enables/disables filtering of one channel. /// \param channel The channel that should be set. - /// \param offset The new channel offset value. - void ControlSetOffset::setChannel(unsigned int channel, unsigned short int offset) { - if(channel == 0) { - this->array[0] = (unsigned char) (offset >> 8); - this->array[1] = (unsigned char) offset; - } - else { - this->array[2] = (unsigned char) (offset >> 8); - this->array[3] = (unsigned char) offset; - } - } - - /// \brief Get the trigger level. - /// \return The trigger level value. - unsigned short int ControlSetOffset::getTrigger() { - return ((this->array[4] & 0x0f) << 8) | this->array[5]; + /// \param filtered true if the channel should be filtered. + void BulkSetFilter2250::setChannel(unsigned int channel, bool filtered) { + FilterBits *filterBits = (FilterBits *) &(this->array[2]); + if(channel == 0) + filterBits->channel1 = filtered ? 1 : 0; + else + filterBits->channel2 = filtered ? 1 : 0; } - /// \brief Set the trigger level. - /// \param level The new trigger level value. - void ControlSetOffset::setTrigger(unsigned short int level) { - this->array[4] = (unsigned char) (level >> 8); - this->array[5] = (unsigned char) level; + /// \brief Initialize the array to the needed values. + void BulkSetFilter2250::init() { + this->array[0] = BULK_BSETFILTER; } ////////////////////////////////////////////////////////////////////////////// - // class BulkSetRelays - /// \brief Sets all relay states. - /// \param ch1Below1V Sets the state of the Channel 1 below 1 V relay. - /// \param ch1Below100mV Sets the state of the Channel 1 below 100 mV relay. - /// \param ch1CouplingDC Sets the state of the Channel 1 coupling relay. - /// \param ch2Below1V Sets the state of the Channel 2 below 1 V relay. - /// \param ch2Below100mV Sets the state of the Channel 2 below 100 mV relay. - /// \param ch2CouplingDC Sets the state of the Channel 2 coupling relay. - /// \param triggerExt Sets the state of the external trigger relay. - ControlSetRelays::ControlSetRelays(bool ch1Below1V, bool ch1Below100mV, bool ch1CouplingDC, bool ch2Below1V, bool ch2Below100mV, bool ch2CouplingDC, bool triggerExt) : Helper::DataArray(17) { - this->setBelow1V(0, ch1Below1V); - this->setBelow100mV(0, ch1Below100mV); - this->setCoupling(0, ch1CouplingDC); - this->setBelow1V(1, ch2Below1V); - this->setBelow100mV(1, ch2Below100mV); - this->setCoupling(1, ch2CouplingDC); - this->setTrigger(triggerExt); - } - - /// \brief Get the below 1 V relay state for the given channel. - /// \param channel The channel whose relay state should be returned. - /// \return true, if the gain of the channel is below 1 V. - bool ControlSetRelays::getBelow1V(unsigned int channel) { - if(channel == 0) - return (this->array[1] & 0x04) == 0x00; - else - return (this->array[4] & 0x20) == 0x00; - } - - /// \brief Set the below 1 V relay for the given channel. - /// \param channel The channel that should be set. - /// \param below true, if the gain of the channel should be below 1 V. - void ControlSetRelays::setBelow1V(unsigned int channel, bool below) { - if(channel == 0) - this->array[1] = below ? 0xfb : 0x04; - else - this->array[4] = below ? 0xdf : 0x20; + // class BulkSetTrigger2250 + /// \brief Sets the data array to needed values. + BulkSetTrigger2250::BulkSetTrigger2250() : Helper::DataArray(8) { + this->init(); } - /// \brief Get the below 1 V relay state for the given channel. - /// \param channel The channel whose relay state should be returned. - /// \return true, if the gain of the channel is below 1 V. - bool ControlSetRelays::getBelow100mV(unsigned int channel) { - if(channel == 0) - return (this->array[2] & 0x08) == 0x00; - else - return (this->array[5] & 0x40) == 0x00; + /// \brief Sets the used channels. + /// \param triggerSource The trigger source id (CTriggerBits). + /// \param triggerSlope The triggerSlope value (CTriggerBits). + BulkSetTrigger2250::BulkSetTrigger2250(unsigned char triggerSource, unsigned char triggerSlope) : Helper::DataArray(8) { + this->init(); + + this->setTriggerSource(triggerSource); + this->setTriggerSlope(triggerSlope); } - - /// \brief Set the below 100 mV relay for the given channel. - /// \param channel The channel that should be set. - /// \param below true, if the gain of the channel should be below 100 mV. - void ControlSetRelays::setBelow100mV(unsigned int channel, bool below) { - if(channel == 0) - this->array[2] = below ? 0xf7 : 0x08; - else - this->array[5] = below ? 0xbf : 0x40; + + /// \brief Get the triggerSource value in CTriggerBits. + /// \return The triggerSource value. + unsigned char BulkSetTrigger2250::getTriggerSource() { + return ((CTriggerBits *) &(this->array[2]))->triggerSource; } - /// \brief Get the coupling relay state for the given channel. - /// \param channel The channel whose relay state should be returned. - /// \return true, if the coupling of the channel is DC. - bool ControlSetRelays::getCoupling(unsigned int channel) { - if(channel == 0) - return (this->array[3] & 0x02) == 0x00; - else - return (this->array[6] & 0x10) == 0x00; + /// \brief Set the triggerSource in CTriggerBits to the given value. + /// \param value The new triggerSource value. + void BulkSetTrigger2250::setTriggerSource(unsigned char value) { + ((CTriggerBits *) &(this->array[2]))->triggerSource = value; } - /// \brief Set the coupling relay for the given channel. - /// \param channel The channel that should be set. - /// \param dc true, if the coupling of the channel should be DC. - void ControlSetRelays::setCoupling(unsigned int channel, bool dc) { - if(channel == 0) - this->array[3] = dc ? 0xfd : 0x02; - else - this->array[6] = dc ? 0xef : 0x10; + /// \brief Get the triggerSlope value in CTriggerBits. + /// \return The triggerSlope value. + unsigned char BulkSetTrigger2250::getTriggerSlope() { + return ((CTriggerBits *) &(this->array[2]))->triggerSlope; } - /// \brief Get the external trigger relay state. - /// \return true, if the trigger is external (EXT-Connector). - bool ControlSetRelays::getTrigger() { - return (this->array[7] & 0x01) == 0x00; + /// \brief Set the triggerSlope in CTriggerBits to the given value. + /// \param slope The new triggerSlope value. + void BulkSetTrigger2250::setTriggerSlope(unsigned char slope) { + ((CTriggerBits *) &(this->array[2]))->triggerSlope = slope; } - - /// \brief Set the external trigger relay. - /// \param ext true, if the trigger should be external (EXT-Connector). - void ControlSetRelays::setTrigger(bool ext) { - this->array[7] = ext ? 0xfe : 0x01; + + /// \brief Initialize the array to the needed values. + void BulkSetTrigger2250::init() { + this->array[0] = BULK_CSETTRIGGERORSAMPLERATE; } @@ -607,7 +511,40 @@ namespace Hantek { /// \brief Initialize the array to the needed values. void BulkSetSamplerate5200::init() { - this->array[0] = BULK_SETSAMPLERATE5200; + this->array[0] = BULK_CSETTRIGGERORSAMPLERATE; + } + + + ////////////////////////////////////////////////////////////////////////////// + // class BulkSetBuffer2250 + /// \brief Sets the data array to the default values. + BulkSetRecordLength2250::BulkSetRecordLength2250() : Helper::DataArray(4) { + this->init(); + } + + /// \brief Sets the data bytes to the specified values. + /// \param recordLength The ::RecordLengthId value. + BulkSetRecordLength2250::BulkSetRecordLength2250(unsigned char recordLength) : Helper::DataArray(4) { + this->init(); + + this->setRecordLength(recordLength); + } + + /// \brief Get the ::RecordLengthId value. + /// \return The ::RecordLengthId value. + unsigned char BulkSetRecordLength2250::getRecordLength() { + return this->array[2]; + } + + /// \brief Set the ::RecordLengthId to the given value. + /// \param value The new ::RecordLengthId value. + void BulkSetRecordLength2250::setRecordLength(unsigned char value) { + this->array[2] = value; + } + + /// \brief Initialize the array to the needed values. + void BulkSetRecordLength2250::init() { + this->array[0] = BULK_DSETBUFFER; } @@ -623,15 +560,15 @@ namespace Hantek { /// \param triggerPositionPost The TriggerPositionPost value. /// \param usedPre The TriggerPositionUsedPre value. /// \param usedPost The TriggerPositionUsedPost value. - /// \param bufferSize The ::BufferSizeId value. - BulkSetBuffer5200::BulkSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre, unsigned char usedPost, unsigned char bufferSize) : Helper::DataArray(10) { + /// \param recordLength The ::RecordLengthId value. + BulkSetBuffer5200::BulkSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre, unsigned char usedPost, unsigned char recordLength) : Helper::DataArray(10) { this->init(); this->setTriggerPositionPre(triggerPositionPre); this->setTriggerPositionPost(triggerPositionPost); this->setUsedPre(usedPre); this->setUsedPost(usedPost); - this->setBufferSize(bufferSize); + this->setRecordLength(recordLength); } /// \brief Get the TriggerPositionPre value. @@ -684,27 +621,89 @@ namespace Hantek { ((DBufferBits *) &(this->array[8]))->triggerPositionUsed = value; } - /// \brief Get the bufferSize value in DBufferBits. - /// \return The ::BufferSizeId value. - unsigned char BulkSetBuffer5200::getBufferSize() { - return ((DBufferBits *) &(this->array[8]))->bufferSize; + /// \brief Get the recordLength value in DBufferBits. + /// \return The ::RecordLengthId value. + unsigned char BulkSetBuffer5200::getRecordLength() { + return ((DBufferBits *) &(this->array[8]))->recordLength; } - /// \brief Set the bufferSize in DBufferBits to the given value. - /// \param value The new ::BufferSizeId value. - void BulkSetBuffer5200::setBufferSize(unsigned char value) { - ((DBufferBits *) &(this->array[8]))->bufferSize = value; + /// \brief Set the recordLength in DBufferBits to the given value. + /// \param value The new ::RecordLengthId value. + void BulkSetBuffer5200::setRecordLength(unsigned char value) { + ((DBufferBits *) &(this->array[8]))->recordLength = value; } /// \brief Initialize the array to the needed values. void BulkSetBuffer5200::init() { - this->array[0] = BULK_SETBUFFER5200; + this->array[0] = BULK_DSETBUFFER; this->array[5] = 0xff; this->array[9] = 0xff; } ////////////////////////////////////////////////////////////////////////////// + // class BulkSetSamplerate2250 + /// \brief Sets the data array to the default values. + BulkSetSamplerate2250::BulkSetSamplerate2250() : Helper::DataArray(8) { + this->init(); + } + + /// \brief Sets the data bytes to the specified values. + /// \param fastRate The fastRate state (ESamplerateBits). + /// \param samplerateFast The SamplerateFast value (ESamplerateBits). + /// \param samplerateSlow The SamplerateSlow value. + BulkSetSamplerate2250::BulkSetSamplerate2250(bool fastRate, unsigned char samplerateFast, unsigned short int samplerateSlow) : Helper::DataArray(8) { + this->init(); + + this->setFastRate(fastRate); + this->setSamplerateFast(samplerateFast); + this->setSamplerateSlow(samplerateSlow); + } + + /// \brief Get the fastRate state in ESamplerateBits. + /// \return The fastRate state. + bool BulkSetSamplerate2250::getFastRate() { + return ((ESamplerateBits *) &(this->array[2]))->fastRate == 1; + } + + /// \brief Set the fastRate in ESamplerateBits to the given state. + /// \param fastRate The new fastRate state. + void BulkSetSamplerate2250::setFastRate(bool fastRate) { + ((ESamplerateBits *) &(this->array[2]))->fastRate = fastRate ? 1 : 0; + } + + /// \brief Get the samplerateFast value in ESamplerateBits. + /// \return The samplerateFast value in ESamplerateBits. + unsigned char BulkSetSamplerate2250::getSamplerateFast() { + return ((ESamplerateBits *) &(this->array[2]))->samplerateFast; + } + + /// \brief Set the samplerateFast in ESamplerateBits to the given value. + /// \param value The new samplerateFast value. + void BulkSetSamplerate2250::setSamplerateFast(unsigned char value) { + ((ESamplerateBits *) &(this->array[2]))->samplerateFast = value; + } + + /// \brief Get the SamplerateSlow value. + /// \return The SamplerateSlow value. + unsigned short int BulkSetSamplerate2250::getSamplerateSlow() { + return (unsigned short int) this->array[4] | ((unsigned short int) this->array[5] << 8); + } + + /// \brief Set the SamplerateSlow to the given value. + /// \param samplerate The new SamplerateSlow value. + void BulkSetSamplerate2250::setSamplerateSlow(unsigned short int samplerate) { + this->array[4] = (unsigned char) samplerate; + this->array[5] = (unsigned char) (samplerate >> 8); + } + + /// \brief Initialize the array to the needed values. + void BulkSetSamplerate2250::init() { + this->array[0] = BULK_ESETTRIGGERORSAMPLERATE; + } + + + ////////////////////////////////////////////////////////////////////////////// // class BulkSetTrigger5200 /// \brief Sets the data array to the default values. BulkSetTrigger5200::BulkSetTrigger5200() : Helper::DataArray(8) { @@ -789,7 +788,301 @@ namespace Hantek { /// \brief Initialize the array to the needed values. void BulkSetTrigger5200::init() { - this->array[0] = BULK_SETTRIGGER5200; + this->array[0] = BULK_ESETTRIGGERORSAMPLERATE; this->array[4] = 0x02; } + + + ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetBuffer2250 hantek/types.h + /// \brief The DSO-2250 BULK_FSETBUFFER builder. + /// \brief Sets the data array to the default values. + BulkSetBuffer2250::BulkSetBuffer2250() : Helper::DataArray(10) { + this->init(); + } + + /// \brief Sets the data bytes to the specified values. + /// \param triggerPositionPre The TriggerPositionPre value. + /// \param triggerPositionPost The TriggerPositionPost value. + /// \param usedPre The TriggerPositionUsedPre value. + /// \param usedPost The TriggerPositionUsedPost value. + /// \param largeBuffer The largeBuffer state. + /// \param slowBuffer The slowBuffer state. + BulkSetBuffer2250::BulkSetBuffer2250(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre, unsigned char usedPost, bool largeBuffer, bool slowBuffer) : Helper::DataArray(10) { + this->init(); + + this->setTriggerPositionPre(triggerPositionPre); + this->setTriggerPositionPost(triggerPositionPost); + this->setUsedPre(usedPre); + this->setUsedPost(usedPost); + this->setLargeBuffer(largeBuffer); + this->setSlowBuffer(slowBuffer); + } + + /// \brief Get the TriggerPositionPre value. + /// \return The TriggerPositionPre value. + unsigned short int BulkSetBuffer2250::getTriggerPositionPre() { + return (unsigned short int) this->array[2] | ((unsigned short int) this->array[3] << 8); + } + + /// \brief Set the TriggerPositionPre to the given value. + /// \param position The new TriggerPositionPre value. + void BulkSetBuffer2250::setTriggerPositionPre(unsigned short int position) { + this->array[2] = (unsigned char) position; + this->array[3] = (unsigned char) (position >> 8); + } + + /// \brief Get the TriggerPositionPost value. + /// \return The TriggerPositionPost value. + unsigned short int BulkSetBuffer2250::getTriggerPositionPost() { + return (unsigned short int) this->array[6] | ((unsigned short int) this->array[7] << 8); + } + + /// \brief Set the TriggerPositionPost to the given value. + /// \param position The new TriggerPositionPost value. + void BulkSetBuffer2250::setTriggerPositionPost(unsigned short int position) { + this->array[6] = (unsigned char) position; + this->array[7] = (unsigned char) (position >> 8); + } + + /// \brief Get the TriggerPositionUsedPre value. + /// \return The ::DTriggerPositionUsed value for the pre position. + unsigned char BulkSetBuffer2250::getUsedPre() { + return ((FBuffer1Bits *) &(this->array[4]))->triggerPositionUsed; + } + + /// \brief Set the TriggerPositionUsedPre to the given value. + /// \param value The new ::DTriggerPositionUsed value for the pre position. + void BulkSetBuffer2250::setUsedPre(unsigned char value) { + ((FBuffer1Bits *) &(this->array[4]))->triggerPositionUsed = value; + } + + /// \brief Get the TriggerPositionUsedPost value. + /// \return The ::DTriggerPositionUsed value for the post position. + unsigned char BulkSetBuffer2250::getUsedPost() { + return ((FBuffer1Bits *) &(this->array[8]))->triggerPositionUsed; + } + + /// \brief Set the TriggerPositionUsedPost to the given value. + /// \param value The new ::DTriggerPositionUsed value for the post position. + void BulkSetBuffer2250::setUsedPost(unsigned char value) { + ((FBuffer1Bits *) &(this->array[8]))->triggerPositionUsed = value; + } + + /// \brief Get the largeBuffer state in FBuffer1Bits. + /// \return The largeBuffer state. + bool BulkSetBuffer2250::getLargeBuffer() { + return ((FBuffer1Bits *) &(this->array[2]))->largeBuffer == 0; + } + + /// \brief Set the largeBuffer in FBuffer1Bits to the given state. + /// \param largeBuffer The new largeBuffer state. + void BulkSetBuffer2250::setLargeBuffer(bool largeBuffer) { + ((FBuffer1Bits *) &(this->array[2]))->largeBuffer = largeBuffer ? 0 : 1; + } + + /// \brief Get the slowBuffer state in FBuffer2Bits. + /// \return The slowBuffer state. + bool BulkSetBuffer2250::getSlowBuffer() { + return ((FBuffer2Bits *) &(this->array[2]))->slowBuffer == 1; + } + + /// \brief Set the slowBuffer in FBuffer2Bits to the given state. + /// \param slowBuffer The new slowBuffer state. + void BulkSetBuffer2250::setSlowBuffer(bool slowBuffer) { + ((FBuffer2Bits *) &(this->array[2]))->slowBuffer = slowBuffer ? 1 : 0; + } + + /// \brief Initialize the array to the needed values. + void BulkSetBuffer2250::init() { + this->array[0] = BULK_FSETBUFFER; + } + + + ////////////////////////////////////////////////////////////////////////////// + // class ControlGetSpeed + /// \brief Initializes the array. + ControlGetSpeed::ControlGetSpeed() : Helper::DataArray(10) { + } + + /// \brief Gets the speed of the connection. + /// \return The speed level of the USB connection. + ConnectionSpeed ControlGetSpeed::getSpeed() { + return (ConnectionSpeed) this->array[0]; + } + + + ////////////////////////////////////////////////////////////////////////////// + // class ControlBeginCommand + /// \brief Sets the command index to the given value. + /// \param index The CommandIndex for the command. + ControlBeginCommand::ControlBeginCommand(BulkIndex index) : Helper::DataArray(10) { + this->init(); + + this->setIndex(index); + } + + /// \brief Gets the command index. + /// \return The CommandIndex for the command. + BulkIndex ControlBeginCommand::getIndex() { + return (BulkIndex) this->array[1]; + } + + /// \brief Sets the command index to the given value. + /// \param index The new CommandIndex for the command. + void ControlBeginCommand::setIndex(BulkIndex index) { + memset(&(this->array[1]), (unsigned char) index, 3); + } + + /// \brief Initialize the array to the needed values. + void ControlBeginCommand::init() { + this->array[0] = 0x0f; + } + + + ////////////////////////////////////////////////////////////////////////////// + // class ControlSetOffset + /// \brief Sets the data array to the default values. + ControlSetOffset::ControlSetOffset() : Helper::DataArray(17) { + } + + /// \brief Sets the offsets to the given values. + /// \param channel1 The offset for channel 1. + /// \param channel2 The offset for channel 2. + /// \param trigger The offset for ext. trigger. + ControlSetOffset::ControlSetOffset(unsigned short int channel1, unsigned short int channel2, unsigned short int trigger) : Helper::DataArray(17) { + this->setChannel(0, channel1); + this->setChannel(1, channel2); + this->setTrigger(trigger); + } + + /// \brief Get the offset for the given channel. + /// \param channel The channel whose offset should be returned. + /// \return The channel offset value. + unsigned short int ControlSetOffset::getChannel(unsigned int channel) { + if(channel == 0) + return ((this->array[0] & 0x0f) << 8) | this->array[1]; + else + return ((this->array[2] & 0x0f) << 8) | this->array[3]; + } + + /// \brief Set the offset for the given channel. + /// \param channel The channel that should be set. + /// \param offset The new channel offset value. + void ControlSetOffset::setChannel(unsigned int channel, unsigned short int offset) { + if(channel == 0) { + this->array[0] = (unsigned char) (offset >> 8); + this->array[1] = (unsigned char) offset; + } + else { + this->array[2] = (unsigned char) (offset >> 8); + this->array[3] = (unsigned char) offset; + } + } + + /// \brief Get the trigger level. + /// \return The trigger level value. + unsigned short int ControlSetOffset::getTrigger() { + return ((this->array[4] & 0x0f) << 8) | this->array[5]; + } + + /// \brief Set the trigger level. + /// \param level The new trigger level value. + void ControlSetOffset::setTrigger(unsigned short int level) { + this->array[4] = (unsigned char) (level >> 8); + this->array[5] = (unsigned char) level; + } + + + ////////////////////////////////////////////////////////////////////////////// + // class ControlSetRelays + /// \brief Sets all relay states. + /// \param ch1Below1V Sets the state of the Channel 1 below 1 V relay. + /// \param ch1Below100mV Sets the state of the Channel 1 below 100 mV relay. + /// \param ch1CouplingDC Sets the state of the Channel 1 coupling relay. + /// \param ch2Below1V Sets the state of the Channel 2 below 1 V relay. + /// \param ch2Below100mV Sets the state of the Channel 2 below 100 mV relay. + /// \param ch2CouplingDC Sets the state of the Channel 2 coupling relay. + /// \param triggerExt Sets the state of the external trigger relay. + ControlSetRelays::ControlSetRelays(bool ch1Below1V, bool ch1Below100mV, bool ch1CouplingDC, bool ch2Below1V, bool ch2Below100mV, bool ch2CouplingDC, bool triggerExt) : Helper::DataArray(17) { + this->setBelow1V(0, ch1Below1V); + this->setBelow100mV(0, ch1Below100mV); + this->setCoupling(0, ch1CouplingDC); + this->setBelow1V(1, ch2Below1V); + this->setBelow100mV(1, ch2Below100mV); + this->setCoupling(1, ch2CouplingDC); + this->setTrigger(triggerExt); + } + + /// \brief Get the below 1 V relay state for the given channel. + /// \param channel The channel whose relay state should be returned. + /// \return true, if the gain of the channel is below 1 V. + bool ControlSetRelays::getBelow1V(unsigned int channel) { + if(channel == 0) + return (this->array[1] & 0x04) == 0x00; + else + return (this->array[4] & 0x20) == 0x00; + } + + /// \brief Set the below 1 V relay for the given channel. + /// \param channel The channel that should be set. + /// \param below true, if the gain of the channel should be below 1 V. + void ControlSetRelays::setBelow1V(unsigned int channel, bool below) { + if(channel == 0) + this->array[1] = below ? 0xfb : 0x04; + else + this->array[4] = below ? 0xdf : 0x20; + } + + /// \brief Get the below 1 V relay state for the given channel. + /// \param channel The channel whose relay state should be returned. + /// \return true, if the gain of the channel is below 1 V. + bool ControlSetRelays::getBelow100mV(unsigned int channel) { + if(channel == 0) + return (this->array[2] & 0x08) == 0x00; + else + return (this->array[5] & 0x40) == 0x00; + } + + /// \brief Set the below 100 mV relay for the given channel. + /// \param channel The channel that should be set. + /// \param below true, if the gain of the channel should be below 100 mV. + void ControlSetRelays::setBelow100mV(unsigned int channel, bool below) { + if(channel == 0) + this->array[2] = below ? 0xf7 : 0x08; + else + this->array[5] = below ? 0xbf : 0x40; + } + + /// \brief Get the coupling relay state for the given channel. + /// \param channel The channel whose relay state should be returned. + /// \return true, if the coupling of the channel is DC. + bool ControlSetRelays::getCoupling(unsigned int channel) { + if(channel == 0) + return (this->array[3] & 0x02) == 0x00; + else + return (this->array[6] & 0x10) == 0x00; + } + + /// \brief Set the coupling relay for the given channel. + /// \param channel The channel that should be set. + /// \param dc true, if the coupling of the channel should be DC. + void ControlSetRelays::setCoupling(unsigned int channel, bool dc) { + if(channel == 0) + this->array[3] = dc ? 0xfd : 0x02; + else + this->array[6] = dc ? 0xef : 0x10; + } + + /// \brief Get the external trigger relay state. + /// \return true, if the trigger is external (EXT-Connector). + bool ControlSetRelays::getTrigger() { + return (this->array[7] & 0x01) == 0x00; + } + + /// \brief Set the external trigger relay. + /// \param ext true, if the trigger should be external (EXT-Connector). + void ControlSetRelays::setTrigger(bool ext) { + this->array[7] = ext ? 0xfe : 0x01; + } } diff --git a/openhantek/src/hantek/types.h b/openhantek/src/hantek/types.h index 196b75c..dada574 100644 --- a/openhantek/src/hantek/types.h +++ b/openhantek/src/hantek/types.h @@ -51,7 +51,7 @@ namespace Hantek { /// \brief All supported bulk commands. /// Indicies given in square brackets specify byte numbers in little endian format. enum BulkCode { - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkSetFilter [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command sets channel and trigger filter: /// @@ -70,7 +70,7 @@ namespace Hantek { ///


BULK_SETFILTER, - /// [::MODEL_DSO2090, ::MODEL_DSO2150] + /// BulkSetTriggerAndSamplerate [::MODEL_DSO2090, ::MODEL_DSO2150] ///

/// This command sets trigger and timebase: ///

@@ -99,7 +99,7 @@ namespace Hantek { /// Without using fast rate mode, the samplerate is:
/// Samplerate = SamplerateMax / (1comp(SamplerateSlow) * 2 + Tsr1Bits.samplerateFast)
/// SamplerateMax is 50 MHz for the DSO-2090.
- /// When using fast rate mode the resulting samplerate is twice (For DSO-2150 three times) as fast, when using the large buffer it is half as fast. When Tsr1Bits.bufferSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. SamplerateSlow can't be used together with fast rate mode, the result is always the the same as SlowValue = 0. + /// When using fast rate mode the resulting samplerate is twice (For DSO-2150 three times) as fast, when using the large buffer it is half as fast. When Tsr1Bits.recordLength is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. SamplerateSlow can't be used together with fast rate mode, the result is always the the same as SlowValue = 0. ///

///

/// The TriggerPosition sets the position of the pretrigger in samples. The left side (0 %) is 0x77660 when using the small buffer and 0x78000 when using the large buffer. @@ -107,7 +107,7 @@ namespace Hantek { ///


BULK_SETTRIGGERANDSAMPLERATE, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkForceTrigger [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command forces triggering: ///

@@ -120,7 +120,7 @@ namespace Hantek { ///


BULK_FORCETRIGGER, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkCaptureStart [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command starts to capture data: ///

@@ -133,7 +133,7 @@ namespace Hantek { ///


BULK_STARTSAMPLING, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkTriggerEnabled [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command sets the trigger: ///

@@ -146,7 +146,7 @@ namespace Hantek { ///


BULK_ENABLETRIGGER, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkGetData [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command reads data from the hardware: ///

@@ -194,7 +194,7 @@ namespace Hantek { ///


BULK_GETDATA, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkGetCaptureState [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command checks the capture state: ///

@@ -219,7 +219,7 @@ namespace Hantek { ///


BULK_GETCAPTURESTATE, - /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkSetGain [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command sets the gain: ///

@@ -239,9 +239,9 @@ namespace Hantek { ///


BULK_SETGAIN, - /// [] + /// BulkSetLogicalData [] ///

- /// This command sets the logical data (Not used in official Hantek software): + /// This command sets the logical data (Not used in official %Hantek software): ///

/// /// @@ -258,9 +258,9 @@ namespace Hantek { ///


BULK_SETLOGICALDATA, - /// [::MODEL_DSO2250] + /// BulkGetLogicalData [] ///

- /// This command reads the logical data (Not used in official Hantek software): + /// This command reads the logical data (Not used in official %Hantek software): ///

0x08
/// /// @@ -280,7 +280,7 @@ namespace Hantek { ///


BULK_GETLOGICALDATA, - /// [] + /// [] ///

/// This command isn't used for any supported model: ///

0x09
@@ -291,24 +291,41 @@ namespace Hantek { ///
///

///


- BULK_UNKNOWN_0A, + BULK_AUNKNOWN, - /// [::MODEL_DSO2250] + /// BulkSetFilter2250 [::MODEL_DSO2250] ///

- /// This command is used for the DSO-2250: + /// This command sets the activated channels for the DSO-2250: /// /// /// /// - /// + /// /// /// ///
0x0b0x00(unknown)::UsedChannels0x00
///

///


- BULK_UNKNOWN_0B, + BULK_BSETFILTER, - /// [::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkSetTrigger2250 [::MODEL_DSO2250] + ///

+ /// This command sets the trigger source for the DSO-2250: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + ///
0x0c0x0fCTriggerBits0x000x020x000x000x00
+ ///

+ ///


+ /// BulkSetSamplerate5200 [::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// This command sets the sampling rate for the DSO-5200: /// @@ -325,14 +342,27 @@ namespace Hantek { ///

/// The values are similar to the ones used with ::BULK_SETTRIGGERANDSAMPLERATE. The formula is a bit different here:
/// Samplerate = SamplerateMax / (2comp(SamplerateSlow) * 2 + 4 - SamplerateFast)
- /// SamplerateMax is 100 MS/s for the DSO-5200 in default configuration and 250 MS/s in fast rate mode though, the modifications regarding buffer size are the the same that apply for the DSO-2090. + /// SamplerateMax is 100 MS/s for the DSO-5200 in default configuration and 250 MS/s in fast rate mode though, the modifications regarding record length are the the same that apply for the DSO-2090. ///

///


- BULK_SETSAMPLERATE5200, - - /// [::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + BULK_CSETTRIGGERORSAMPLERATE, + + /// BulkSetRecordLength2250 [::MODEL_DSO2250] + ///

+ /// This command sets the record length for the DSO-2250: + ///

+ /// + /// + /// + /// + /// + /// + ///
0x0d0x00::RecordLengthId0x00
+ ///

+ ///


+ /// BulkSetBuffer5200 [::MODEL_DSO5200, ::MODEL_DSO5200A] ///

- /// This command sets the trigger position and buffer size for the DSO-5200: + /// This command sets the trigger position and record length for the DSO-5200: /// /// /// @@ -356,18 +386,40 @@ namespace Hantek { /// The TriggerPositionPre and TriggerPositionPost values set the pretrigger position. Both values have a range from 0xd7ff (0xc7ff for 14 kiS buffer) to 0xfffe. On the left side (0 %) the TriggerPositionPre value is minimal, on the right side (100 %) it is maximal. The TriggerPositionPost value is maximal for 0 % and minimal for 100%. ///

///


- BULK_SETBUFFER5200, + BULK_DSETBUFFER, - /// [::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] + /// BulkSetSamplerate2250 [::MODEL_DSO2250] + ///

+ /// This command sets the samplerate: + ///

0x0d
+ /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + ///
0x0e0x00ESamplerateBits0x00SamplerateSlow[0]SamplerateSlow[1]0x000x00
+ ///

///

- /// This command sets the channel and trigger settings for the DSO-5200: + /// The values are similar to the ones used with ::BULK_SETTRIGGERANDSAMPLERATE. The formula is a bit different here:
+ /// Samplerate = SamplerateMax / (2comp(SamplerateSlow) * 2 + ESamplerateBits.samplerateFast)
+ /// SamplerateMax is 100 MS/s for the DSO-2250 in default configuration and 250 MS/s in fast rate mode though, the modifications regarding record length are the the same that apply for the DSO-2090. + ///

+ ///


+ /// BulkSetTrigger5200 [::MODEL_DSO5200, ::MODEL_DSO5200A] + ///

+ /// This command sets the channel and trigger settings: /// /// /// /// /// /// - /// + /// /// /// /// @@ -375,34 +427,37 @@ namespace Hantek { ///
0x0e0x00ETsrBits0x00Unknown (0x02)0x000x000x000x00
///

///


- BULK_SETTRIGGER5200, + BULK_ESETTRIGGERORSAMPLERATE, - /// [::MODEL_DSO2250] + /// BulkSetBuffer2250 [::MODEL_DSO2250] ///

- /// This command is used for the DSO-2250: + /// This command sets the trigger position and buffer configuration for the DSO-2250: /// /// /// /// - /// - /// - /// - /// + /// + /// + /// + /// /// ///
0x0f0x00(unknown)(unknown)(unknown)(unknown)TriggerPositionPre[0]TriggerPositionPre[1]FBuffer1Bits0x00
/// /// - /// - /// - /// - /// - /// - /// + /// + /// + /// + /// + /// + /// /// ///
(unknown)(unknown)(unknown)(unknown)(unknown)(unknown)TriggerPositionPost[0]TriggerPositionPost[1]FBuffer1Bits0x00FBuffer2Bits0x00
///

+ ///

+ /// The TriggerPositionPre and TriggerPositionPost values set the pretrigger position. Both values have a range from 0xd7ff (0xc7ff for 14 kiS buffer) to 0xfffe. On the left side (0 %) the TriggerPositionPre value is minimal, on the right side (100 %) it is maximal. The TriggerPositionPost value is maximal for 0 % and minimal for 100%. + ///

///


- BULK_UNKNOWN_0F, + BULK_FSETBUFFER, BULK_COUNT }; @@ -556,14 +611,14 @@ namespace Hantek { /// Value 0x60 is the calibration data for the fast rate mode on the DSO-2250, DSO-5200 and DSO-5200A. It's used to correct the level differences between the two merged channels to avoid deterministic noise. ///

///


- VALUE_CALIBRATIONDATA = 0x60, + VALUE_FASTRATECALIBRATION = 0x60, /// [::MODEL_DSO5200, ::MODEL_DSO5200A] ///

/// Value 0x70 contains correction values for the ETS functionality of the DSO-5200 and DSO-5200A. ///

///


- VALUE_VOLTAGELIMITS = 0x70 + VALUE_ETSCORRECTION = 0x70 }; ////////////////////////////////////////////////////////////////////////////// @@ -591,8 +646,10 @@ namespace Hantek { /// \enum UsedChannels hantek/types.h /// \brief The enabled channels. enum UsedChannels { - USED_CH1, USED_CH2, - USED_CH1CH2 + USED_CH1, ///< Only channel 1 is activated + USED_CH2, ///< Only channel 2 is activated + USED_CH1CH2, ///< Channel 1 and 2 are both activated + USED_NONE ///< No channels are activated }; ////////////////////////////////////////////////////////////////////////////// @@ -605,21 +662,12 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// - /// \enum BufferSize hantek/types.h - /// \brief The size of the sample buffer. - enum BufferSize { - BUFFER_SMALL = 10240, - BUFFER_LARGE5200 = 14336, - BUFFER_LARGE = 32768 - }; - - ////////////////////////////////////////////////////////////////////////////// - /// \enum BufferSizeId hantek/types.h + /// \enum RecordLengthId hantek/types.h /// \brief The size id for CommandSetTriggerAndSamplerate. - enum BufferSizeId { - BUFFERID_ROLL = 0, ///< Used for the roll mode - BUFFERID_SMALL, ///< The standard buffer with 10240 samples - BUFFERID_LARGE ///< The large buffer, 32768 samples (14336 for DSO-5200) + enum RecordLengthId { + RECORDLENGTHID_ROLL = 0, ///< Used for the roll mode + RECORDLENGTHID_SMALL, ///< The standard buffer with 10240 samples + RECORDLENGTHID_LARGE ///< The large buffer, 32768 samples (14336 for DSO-5200) }; ////////////////////////////////////////////////////////////////////////////// @@ -662,6 +710,14 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \enum FTriggerPositionUsed hantek/types.h + /// \brief The trigger position states for the 0x0f command. + enum FTriggerPositionUsed { + FTRIGGERPOSITION_OFF = 0, ///< Used for Roll mode + FTRIGGERPOSITION_ON = 3 ///< Used for normal operation + }; + + ////////////////////////////////////////////////////////////////////////////// /// \struct FilterBits hantek/types.h /// \brief The bits for BULK_SETFILTER. struct FilterBits { @@ -685,7 +741,7 @@ namespace Hantek { /// \brief Trigger and samplerate bits (Byte 1). struct Tsr1Bits { unsigned char triggerSource:2; ///< The trigger source, see Hantek::TriggerSource - unsigned char bufferSize:3; ///< See ::BufferSizeId + unsigned char recordLength:3; ///< See ::RecordLengthId unsigned char samplerateFast:3; ///< samplerate value for fast sampling rates }; @@ -700,17 +756,35 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \struct CTriggerBits hantek/types.h + /// \brief Trigger bits for 0x0c command. + struct CTriggerBits { + unsigned char triggerSource:2; ///< The trigger source, see Hantek::TriggerSource + unsigned char triggerSlope:1; ///< The trigger slope, see Dso::Slope + unsigned char reserved:5; ///< Unused bits + }; + + ////////////////////////////////////////////////////////////////////////////// /// \struct DBufferBits hantek/types.h /// \brief Buffer mode bits for 0x0d command. struct DBufferBits { unsigned char triggerPositionUsed:3; ///< See ::DTriggerPositionUsed - unsigned char bufferSize:3; ///< See ::BufferSizeId + unsigned char recordLength:3; ///< See ::RecordLengthId unsigned char reserved:2; ///< Unused bits }; ////////////////////////////////////////////////////////////////////////////// + /// \struct ESamplerateBits hantek/types.h + /// \brief Samplerate bits for DSO-2250 0x0e command. + struct ESamplerateBits { + unsigned char fastRate:1; ///< false, if one channels uses all buffers + unsigned char samplerateFast:3; ///< samplerate value for fast sampling rates + unsigned char reserved:4; ///< Unused bits + }; + + ////////////////////////////////////////////////////////////////////////////// /// \struct ETsrBits hantek/types.h - /// \brief Trigger and samplerate bits for 0x0e command. + /// \brief Trigger and samplerate bits for DSO-5200/DSO-5200A 0x0e command. struct ETsrBits { unsigned char fastRate:1; ///< false, if one channels uses all buffers unsigned char usedChannels:2; ///< Used channels, see Hantek::UsedChannels @@ -720,6 +794,23 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \struct FBuffer1Bits hantek/types.h + /// \brief Buffer mode bits for 0x0f command (Byte 1). + struct FBuffer1Bits { + unsigned char triggerPositionUsed:2; ///< See ::DTriggerPositionUsed + unsigned char largeBuffer:1; ///< false, if ::RecordLengthId is ::RECORDLENGTHID_LARGE + unsigned char reserved:5; ///< Unused bits + }; + + ////////////////////////////////////////////////////////////////////////////// + /// \struct FBuffer2Bits hantek/types.h + /// \brief Buffer mode bits for 0x0f command (Byte 2). + struct FBuffer2Bits { + unsigned char reserved:7; ///< Unused bits + unsigned char slowBuffer:1; ///< false, if ::RecordLengthId is ::RECORDLENGTHID_SMALL + }; + + ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetFilter hantek/types.h /// \brief The BULK_SETFILTER builder. class BulkSetFilter : public Helper::DataArray { @@ -742,12 +833,12 @@ namespace Hantek { class BulkSetTriggerAndSamplerate : public Helper::DataArray { public: BulkSetTriggerAndSamplerate(); - BulkSetTriggerAndSamplerate(unsigned short int samplerateSlow, unsigned long int triggerPosition, unsigned char triggerSource = 0, unsigned char bufferSize = 0, unsigned char samplerateFast = 0, unsigned char usedChannels = 0, bool fastRate = false, unsigned char triggerSlope = 0); + BulkSetTriggerAndSamplerate(unsigned short int samplerateSlow, unsigned long int triggerPosition, unsigned char triggerSource = 0, unsigned char recordLength = 0, unsigned char samplerateFast = 0, unsigned char usedChannels = 0, bool fastRate = false, unsigned char triggerSlope = 0); unsigned char getTriggerSource(); void setTriggerSource(unsigned char value); - unsigned char getBufferSize(); - void setBufferSize(unsigned char value); + unsigned char getRecordLength(); + void setRecordLength(unsigned char value); unsigned char getSamplerateFast(); void setSamplerateFast(unsigned char value); unsigned char getUsedChannels(); @@ -855,8 +946,40 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetFilter2250 hantek/types.h + /// \brief The DSO-5200/DSO-5200A BULK_BSETFILTER builder. + class BulkSetFilter2250 : public Helper::DataArray { + public: + BulkSetFilter2250(); + BulkSetFilter2250(bool channel1, bool channel2); + + bool getChannel(unsigned int channel); + void setChannel(unsigned int channel, bool filtered); + + private: + void init(); + }; + + ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetTrigger2250 hantek/types.h + /// \brief The DSO-2250 BULK_CSETTRIGGERORSAMPLERATE builder. + class BulkSetTrigger2250 : public Helper::DataArray { + public: + BulkSetTrigger2250(); + BulkSetTrigger2250(unsigned char triggerSource, unsigned char triggerSlope); + + unsigned char getTriggerSource(); + void setTriggerSource(unsigned char value); + unsigned char getTriggerSlope(); + void setTriggerSlope(unsigned char slope); + + private: + void init(); + }; + + ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetSamplerate5200 hantek/types.h - /// \brief The BULK_SETSAMPLERATE5200 builder. + /// \brief The DSO-5200/DSO-5200A BULK_CSETTRIGGERORSAMPLERATE builder. class BulkSetSamplerate5200 : public Helper::DataArray { public: BulkSetSamplerate5200(); @@ -872,12 +995,27 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetRecordLength2250 hantek/types.h + /// \brief The DSO-2250 BULK_DSETBUFFER builder. + class BulkSetRecordLength2250 : public Helper::DataArray { + public: + BulkSetRecordLength2250(); + BulkSetRecordLength2250(unsigned char recordLength); + + unsigned char getRecordLength(); + void setRecordLength(unsigned char value); + + private: + void init(); + }; + + ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetBuffer5200 hantek/types.h - /// \brief The BULK_SETBUFFER5200 builder. + /// \brief The DSO-5200/DSO-5200A BULK_DSETBUFFER builder. class BulkSetBuffer5200 : public Helper::DataArray { public: BulkSetBuffer5200(); - BulkSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre = 0, unsigned char usedPost = 0, unsigned char bufferSize = 0); + BulkSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre = 0, unsigned char usedPost = 0, unsigned char recordLength = 0); unsigned short int getTriggerPositionPre(); void setTriggerPositionPre(unsigned short int value); @@ -887,8 +1025,27 @@ namespace Hantek { void setUsedPre(unsigned char value); unsigned char getUsedPost(); void setUsedPost(unsigned char value); - unsigned char getBufferSize(); - void setBufferSize(unsigned char value); + unsigned char getRecordLength(); + void setRecordLength(unsigned char value); + + private: + void init(); + }; + + ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetSamplerate2250 hantek/types.h + /// \brief The DSO-2250 BULK_ESETTRIGGERORSAMPLERATE builder. + class BulkSetSamplerate2250 : public Helper::DataArray { + public: + BulkSetSamplerate2250(); + BulkSetSamplerate2250(bool fastRate, unsigned char samplerateFast = 0, unsigned short int samplerateSlow = 0); + + bool getFastRate(); + void setFastRate(bool fastRate); + unsigned char getSamplerateFast(); + void setSamplerateFast(unsigned char value); + unsigned short int getSamplerateSlow(); + void setSamplerateSlow(unsigned short int samplerate); private: void init(); @@ -896,7 +1053,7 @@ namespace Hantek { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetTrigger5200 hantek/types.h - /// \brief The BULK_SETTRIGGER5200 builder. + /// \brief The DSO-5200/DSO-5200A BULK_ESETTRIGGERORSAMPLERATE builder. class BulkSetTrigger5200 : public Helper::DataArray { public: BulkSetTrigger5200(); @@ -918,6 +1075,31 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \class BulkSetBuffer2250 hantek/types.h + /// \brief The DSO-2250 BULK_FSETBUFFER builder. + class BulkSetBuffer2250 : public Helper::DataArray { + public: + BulkSetBuffer2250(); + BulkSetBuffer2250(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre = 0, unsigned char usedPost = 0, bool largeBuffer = false, bool slowBuffer = false); + + unsigned short int getTriggerPositionPre(); + void setTriggerPositionPre(unsigned short int value); + unsigned short int getTriggerPositionPost(); + void setTriggerPositionPost(unsigned short int value); + unsigned char getUsedPre(); + void setUsedPre(unsigned char value); + unsigned char getUsedPost(); + void setUsedPost(unsigned char value); + bool getLargeBuffer(); + void setLargeBuffer(bool largeBuffer); + bool getSlowBuffer(); + void setSlowBuffer(bool slowBuffer); + + private: + void init(); + }; + + ////////////////////////////////////////////////////////////////////////////// /// \class ControlGetSpeed hantek/types.h /// \brief The CONTROL_GETSPEED parser. class ControlGetSpeed : public Helper::DataArray { diff --git a/openhantek/src/openhantek.cpp b/openhantek/src/openhantek.cpp index a6b0e3f..96b3e97 100644 --- a/openhantek/src/openhantek.cpp +++ b/openhantek/src/openhantek.cpp @@ -140,10 +140,10 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag this->dsoControl->setTriggerLevel(channel, this->settings->scope.voltage[channel].trigger); } this->updateUsed(this->settings->scope.physicalChannels); - this->dsoControl->setBufferSize(this->settings->scope.horizontal.samples); + this->dsoControl->setRecordLength(this->settings->scope.horizontal.samples); this->updateTimebase(); this->dsoControl->setTriggerMode(this->settings->scope.trigger.mode); - this->dsoControl->setTriggerPosition(this->settings->scope.trigger.position * this->settings->scope.horizontal.timebase * DIVS_TIME); + this->dsoControl->setPretriggerPosition(this->settings->scope.trigger.position * this->settings->scope.horizontal.timebase * DIVS_TIME); this->dsoControl->setTriggerSlope(this->settings->scope.trigger.slope); this->dsoControl->setTriggerSource(this->settings->scope.trigger.special, this->settings->scope.trigger.source); @@ -203,20 +203,20 @@ void OpenHantekMainWindow::createActions() { this->startStopAction->setShortcut(tr("Space")); this->stopped(); - this->bufferSizeActionGroup = new QActionGroup(this); - connect(this->bufferSizeActionGroup, SIGNAL(selected(QAction *)), this, SLOT(bufferSizeSelected(QAction *))); + this->recordLengthActionGroup = new QActionGroup(this); + connect(this->recordLengthActionGroup, SIGNAL(selected(QAction *)), this, SLOT(recordLengthSelected(QAction *))); - this->bufferSizeSmallAction = new QAction(tr("&Small"), this); - this->bufferSizeSmallAction->setActionGroup(this->bufferSizeActionGroup); - this->bufferSizeSmallAction->setCheckable(true); - this->bufferSizeSmallAction->setChecked(this->settings->scope.horizontal.samples == Hantek::BUFFER_SMALL); - this->bufferSizeSmallAction->setStatusTip(tr("10240 Samples")); + this->recordLengthSmallAction = new QAction(tr("&Small"), this); + this->recordLengthSmallAction->setActionGroup(this->recordLengthActionGroup); + this->recordLengthSmallAction->setCheckable(true); + this->recordLengthSmallAction->setChecked(this->settings->scope.horizontal.samples == 10240); + this->recordLengthSmallAction->setStatusTip(tr("10240 Samples")); - this->bufferSizeLargeAction = new QAction(tr("&Large"), this); - this->bufferSizeLargeAction->setActionGroup(this->bufferSizeActionGroup); - this->bufferSizeLargeAction->setCheckable(true); - this->bufferSizeLargeAction->setChecked(this->settings->scope.horizontal.samples == Hantek::BUFFER_LARGE); - this->bufferSizeLargeAction->setStatusTip(tr("32768 Samples")); + this->recordLengthLargeAction = new QAction(tr("&Large"), this); + this->recordLengthLargeAction->setActionGroup(this->recordLengthActionGroup); + this->recordLengthLargeAction->setCheckable(true); + this->recordLengthLargeAction->setChecked(this->settings->scope.horizontal.samples != 10240); + this->recordLengthLargeAction->setStatusTip(tr("32768 Samples")); this->digitalPhosphorAction = new QAction(QIcon(":actions/digitalphosphor.png"), tr("Digital &phosphor"), this); this->digitalPhosphorAction->setCheckable(true); @@ -279,9 +279,9 @@ void OpenHantekMainWindow::createMenus() { this->oscilloscopeMenu->addAction(this->commandAction); #endif this->oscilloscopeMenu->addSeparator(); - this->bufferSizeMenu = this->oscilloscopeMenu->addMenu(tr("&Buffer size")); - this->bufferSizeMenu->addAction(this->bufferSizeSmallAction); - this->bufferSizeMenu->addAction(this->bufferSizeLargeAction); + this->recordLengthMenu = this->oscilloscopeMenu->addMenu(tr("&Record length")); + this->recordLengthMenu->addAction(this->recordLengthSmallAction); + this->recordLengthMenu->addAction(this->recordLengthLargeAction); this->menuBar()->addSeparator(); @@ -598,11 +598,11 @@ void OpenHantekMainWindow::updateSettings() { } } -/// \brief Apply new buffer size to settings. -/// \param action The selected buffer size menu item. -void OpenHantekMainWindow::bufferSizeSelected(QAction *action) { - this->settings->scope.horizontal.samples = (action == this->bufferSizeSmallAction) ? Hantek::BUFFER_SMALL : Hantek::BUFFER_LARGE; - this->dsoControl->setBufferSize(this->settings->scope.horizontal.samples); +/// \brief Apply new record length to settings. +/// \param action The selected record length menu item. +void OpenHantekMainWindow::recordLengthSelected(QAction *action) { + this->settings->scope.horizontal.samples = (action == this->recordLengthSmallAction) ? 10240 : 32768; + this->dsoControl->setRecordLength(this->settings->scope.horizontal.samples); } /// \brief Sets the offset of the oscilloscope for the given channel. @@ -620,7 +620,7 @@ void OpenHantekMainWindow::updateTimebase() { this->dsoWidget->updateSamplerate(); // The trigger position should be kept at the same place but the timebase has changed - this->dsoControl->setTriggerPosition(this->settings->scope.trigger.position * this->settings->scope.horizontal.timebase * DIVS_TIME); + this->dsoControl->setPretriggerPosition(this->settings->scope.trigger.position * this->settings->scope.horizontal.timebase * DIVS_TIME); } /// \brief Sets the state of the given oscilloscope channel. diff --git a/openhantek/src/openhantek.h b/openhantek/src/openhantek.h index fb8eb65..cb9e4b2 100644 --- a/openhantek/src/openhantek.h +++ b/openhantek/src/openhantek.h @@ -81,8 +81,8 @@ class OpenHantekMainWindow : public QMainWindow { QAction *configAction; QAction *startStopAction; - QActionGroup *bufferSizeActionGroup; - QAction *bufferSizeSmallAction, *bufferSizeLargeAction; + QActionGroup *recordLengthActionGroup; + QAction *recordLengthSmallAction, *recordLengthLargeAction; QAction *digitalPhosphorAction, *zoomAction; QAction *aboutAction, *aboutQtAction; @@ -94,7 +94,7 @@ class OpenHantekMainWindow : public QMainWindow { // Menus QMenu *fileMenu; QMenu *viewMenu, *dockMenu, *toolbarMenu; - QMenu *oscilloscopeMenu, *bufferSizeMenu; + QMenu *oscilloscopeMenu, *recordLengthMenu; QMenu *helpMenu; // Toolbars @@ -143,7 +143,7 @@ class OpenHantekMainWindow : public QMainWindow { void applySettings(); void updateSettings(); - void bufferSizeSelected(QAction *action); + void recordLengthSelected(QAction *action); void updateOffset(unsigned int channel); void updateTimebase(); void updateUsed(unsigned int channel);