Commit 104958b20f7e739f0950ea51f41dcea685428d15

Authored by oliverhaag
1 parent 299283a1

Added DSO-5200 support and some smaller improvements

openhantek/ChangeLog
... ... @@ -61,3 +61,10 @@
61 61 * Added the samplerate formula to the documentation
62 62 * Documentation updated with additional information from Oleg
63 63 * Removed Oleg from AUTHORS
  64 +
  65 +2010-08-29 Oliver Haag <oliver.haag@gmail.com>
  66 +* DSO details are known after Hantek::Control::connectDevice() is executed
  67 +* Removed useless initialization in Hantek::Control
  68 +* DSO is started after the settings have been transferred
  69 +* Added additional debug messages when building as debug binary
  70 +* Added support for DSO-5200
... ...
openhantek/Doxyfile
... ... @@ -611,7 +611,7 @@ EXCLUDE_SYMLINKS = NO
611 611 # against the file with absolute path, so to exclude all test directories
612 612 # for example use the pattern */test/*
613 613  
614   -EXCLUDE_PATTERNS =
  614 +EXCLUDE_PATTERNS = */.svn*
615 615  
616 616 # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
617 617 # (namespaces, classes, functions, etc.) that should be excluded from the
... ...
openhantek/OpenHantek.pro
... ... @@ -92,6 +92,10 @@ else {
92 92 }
93 93 DEFINES += LIBUSB_VERSION=$${LIBUSB_VERSION}
94 94  
  95 +# Debug output
  96 +CONFIG(debug, debug|release):
  97 + DEFINES += DEBUG
  98 +
95 99 # Settings for different operating systems
96 100 unix:!macx {
97 101 isEmpty(PREFIX):PREFIX = /usr/local
... ... @@ -131,13 +135,7 @@ DEFINES += VERSION=\\\&quot;$${VERSION}\\\&quot;
131 135  
132 136 # Custom target "doc" for Doxygen
133 137 doxygen.target = doc
134   -doxygen.commands = rm \
135   - -r \
136   - doc/; \
137   - env \
138   - DEFINES=\"$${DEFINES}\" \
139   - doxygen \
140   - Doxyfile
  138 +doxygen.commands = "rm -r doc/; env DEFINES=\"$${DEFINES}\" doxygen Doxyfile"
141 139 doxygen.depends = $${SOURCES} \
142 140 $${HEADERS} \
143 141 $${DOXYFILES}
... ...
openhantek/src/dsocontrol.cpp
... ... @@ -52,6 +52,7 @@ const QStringList *DsoControl::getSpecialTriggerSources() {
52 52  
53 53 /// \brief Try to connect to the oscilloscope.
54 54 void DsoControl::connectDevice() {
  55 + this->sampling = false;
55 56 this->terminate = false;
56 57 this->start();
57 58 }
... ...
openhantek/src/hantek/control.cpp
... ... @@ -58,6 +58,9 @@ namespace Hantek {
58 58 this->command[COMMAND_SETGAIN] = new CommandSetGain();
59 59 this->command[COMMAND_SETLOGICALDATA] = new CommandSetLogicalData();
60 60 this->command[COMMAND_GETLOGICALDATA] = new CommandGetLogicalData();
  61 + this->command[COMMAND_SETSAMPLERATE5200] = new CommandSetSamplerate5200();
  62 + this->command[COMMAND_SETBUFFER5200] = new CommandSetBuffer5200();
  63 + this->command[COMMAND_SETTRIGGER5200] = new CommandSetTrigger5200();
61 64  
62 65 // Transmission-ready control commands
63 66 this->control[CONTROLINDEX_SETOFFSET] = new ControlSetOffset();
... ... @@ -73,20 +76,8 @@ namespace Hantek {
73 76 }
74 77 }
75 78  
76   - // Cached variables
77   - for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++) {
78   - this->setChannelUsed(channel, channel == 0);
79   - this->setCoupling(channel, Dso::COUPLING_AC);
80   - this->setGain(channel, 8.0);
81   - this->setOffset(channel, 0.5);
82   - this->setTriggerLevel(channel, 0.0);
83   - }
84   - this->setBufferSize(BUFFER_SMALL);
85   - this->setSamplerate(1e6);
86   - this->setTriggerMode(Dso::TRIGGERMODE_NORMAL);
87   - this->setTriggerPosition(5e3 / (this->samplerateMax / this->samplerateDivider));
88   - this->setTriggerSlope(Dso::SLOPE_POSITIVE);
89   - this->setTriggerSource(false, 0);
  79 + // USB device
  80 + this->device = new Device(this);
90 81  
91 82 // Sample buffers
92 83 for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++) {
... ... @@ -94,9 +85,6 @@ namespace Hantek {
94 85 this->samplesSize.append(0);
95 86 }
96 87  
97   - // USB device
98   - this->device = new Device(this);
99   -
100 88 connect(this->device, SIGNAL(disconnected()), this, SLOT(disconnectDevice()));
101 89 }
102 90  
... ... @@ -115,57 +103,6 @@ namespace Hantek {
115 103 void Control::run() {
116 104 int errorCode;
117 105  
118   - emit statusMessage(this->device->search(), 0);
119   - if(!this->device->isConnected())
120   - return;
121   -
122   - // Set all configuration commands as pending
123   - this->commandPending[COMMAND_SETFILTER] = true;
124   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
125   - this->commandPending[COMMAND_FORCETRIGGER] = false;
126   - this->commandPending[COMMAND_STARTSAMPLING] = false;
127   - this->commandPending[COMMAND_ENABLETRIGGER] = false;
128   - this->commandPending[COMMAND_GETDATA] = false;
129   - this->commandPending[COMMAND_GETCAPTURESTATE] = false;
130   - this->commandPending[COMMAND_SETGAIN] = true;
131   - this->commandPending[COMMAND_SETLOGICALDATA] = true;
132   - this->commandPending[COMMAND_GETLOGICALDATA] = false;
133   - for(int control = 0; control < CONTROLINDEX_COUNT; control++)
134   - this->controlPending[control] = true;
135   -
136   - // Maximum possible samplerate for a single channel
137   - switch(this->device->getModel()) {
138   - case MODEL_DSO2090:
139   - case MODEL_DSO2100:
140   - this->samplerateChannelMax = 50e6;
141   - break;
142   - case MODEL_DSO2150:
143   - this->samplerateChannelMax = 75e6;
144   - break;
145   - case MODEL_DSO2250:
146   - case MODEL_DSO5200:
147   - case MODEL_DSO5200A:
148   - this->samplerateChannelMax = 125e6;
149   - break;
150   - default:
151   - this->samplerateChannelMax = 50e6;
152   - break;
153   - }
154   -
155   - // Get channel level data
156   - errorCode = this->device->controlRead(CONTROL_VALUE, (unsigned char*) &(this->channelLevels), sizeof(this->channelLevels), (int) VALUE_CHANNELLEVEL);
157   - if(errorCode < 0) {
158   - this->device->disconnect();
159   - emit statusMessage(tr("Couldn't get channel level data from oscilloscope"), 0);
160   - return;
161   - }
162   -
163   - // Adapt offsets
164   - for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++)
165   - this->setOffset(channel, this->offset[channel]);
166   - this->setSamplerate(this->samplerateMax / this->samplerateDivider);
167   - this->setTriggerPosition(this->triggerPosition);
168   -
169 106 // The control loop is running until the device is disconnected
170 107 int captureState = CAPTURE_WAITING;
171 108 bool samplingStarted = false;
... ... @@ -177,6 +114,13 @@ namespace Hantek {
177 114 if(!this->commandPending[command])
178 115 continue;
179 116  
  117 +#ifdef DEBUG
  118 + QString hexDump, hexByte;
  119 + for(unsigned int index = 0; index < this->command[command]->getSize(); index++)
  120 + hexDump.append(hexByte.sprintf(" %02x", this->command[command]->data()[index]));
  121 + qDebug("Sending bulk command:%s", hexDump.toLocal8Bit().data());
  122 +#endif
  123 +
180 124 errorCode = this->device->bulkCommand(this->command[command]);
181 125 if(errorCode < 0) {
182 126 qDebug("Sending bulk command 0x%02x failed: %s", command, Helper::libUsbErrorString(errorCode).toLocal8Bit().data());
... ... @@ -197,6 +141,13 @@ namespace Hantek {
197 141 if(!this->controlPending[control])
198 142 continue;
199 143  
  144 +#ifdef DEBUG
  145 + QString hexDump, hexByte;
  146 + for(unsigned int index = 0; index < this->control[control]->getSize(); index++)
  147 + hexDump.append(hexByte.sprintf(" %02x", this->control[control]->data()[index]));
  148 + qDebug("Sending control command 0x%02x:%s", control, hexDump.toLocal8Bit().data());
  149 +#endif
  150 +
200 151 errorCode = this->device->controlWrite(this->controlCode[control], this->control[control]->data(), this->control[control]->getSize());
201 152 if(errorCode < 0) {
202 153 qDebug("Sending control command 0x%2x failed: %s", control, Helper::libUsbErrorString(errorCode).toLocal8Bit().data());
... ... @@ -346,20 +297,34 @@ namespace Hantek {
346 297  
347 298 // Save raw data to temporary buffer
348 299 unsigned int dataCount = this->bufferSize * HANTEK_CHANNELS;
349   - unsigned char data[dataCount];
350   - errorCode = this->device->bulkReadMulti(data, dataCount);
  300 + unsigned int dataLength = dataCount;
  301 + bool using9Bits = false;
  302 + if(this->device->getModel() == MODEL_DSO5200 || this->device->getModel() == MODEL_DSO5200A) {
  303 + using9Bits = true;
  304 + dataLength *= 2;
  305 + }
  306 +
  307 + unsigned char data[dataLength];
  308 + errorCode = this->device->bulkReadMulti(data, dataLength);
351 309 if(errorCode < 0)
352 310 return errorCode;
353 311  
354 312 // Process the data only if we want it
355 313 if(process) {
  314 + // How much data did we really receive?
  315 + dataLength = errorCode;
  316 + if(using9Bits)
  317 + dataCount = dataLength / 2;
  318 + else
  319 + dataCount = dataLength;
  320 +
356 321 this->samplesMutex.lock();
357 322  
358 323 // Convert channel data
359 324 if(((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getFastRate()) {
360 325 // Fast rate mode, one channel is using all buffers
361 326 int channel;
362   - if(((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannel() == USED_CH1)
  327 + if(((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannels() == USED_CH1)
363 328 channel = 0;
364 329 else
365 330 channel = 1;
... ... @@ -384,34 +349,57 @@ namespace Hantek {
384 349  
385 350 // Convert data from the oscilloscope and write it into the sample buffer
386 351 unsigned int bufferPosition = this->triggerPoint;
387   - for(unsigned int realPosition = 0; realPosition < dataCount; realPosition++, bufferPosition++) {
388   - if(bufferPosition >= dataCount)
389   - bufferPosition %= dataCount;
390   -
391   - this->samples[channel][realPosition] = ((double) data[bufferPosition] / 0xff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  352 + if(using9Bits) {
  353 + // Additional MSBs after the normal data
  354 + for(unsigned int realPosition = 0; realPosition < dataCount; realPosition++, bufferPosition++) {
  355 + if(bufferPosition >= dataCount)
  356 + bufferPosition %= dataCount;
  357 +
  358 + this->samples[channel][realPosition] = ((double) (data[bufferPosition] + (data[dataCount + bufferPosition] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  359 + }
  360 + }
  361 + else {
  362 + for(unsigned int realPosition = 0; realPosition < dataCount; realPosition++, bufferPosition++) {
  363 + if(bufferPosition >= dataCount)
  364 + bufferPosition %= dataCount;
  365 +
  366 + this->samples[channel][realPosition] = ((double) data[bufferPosition] / 0xff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  367 + }
392 368 }
393 369 }
394 370 }
395 371 else {
396 372 // Normal mode, channel are using their separate buffers
397   - unsigned char usedChannels = ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannel();
  373 + unsigned int channelDataCount = dataCount / HANTEK_CHANNELS;
  374 + unsigned char usedChannels = ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannels();
398 375 for(int channel = 0; channel < HANTEK_CHANNELS; channel++) {
399 376 if(usedChannels == USED_CH1CH2 || channel == usedChannels) {
400 377 // Reallocate memory for samples if the sample count has changed
401   - if(!this->samples[channel] || this->samplesSize[channel] != this->bufferSize) {
  378 + if(!this->samples[channel] || this->samplesSize[channel] != channelDataCount) {
402 379 if(this->samples[channel])
403 380 delete this->samples[channel];
404   - this->samples[channel] = new double[this->bufferSize];
405   - this->samplesSize[channel] = this->bufferSize;
  381 + this->samples[channel] = new double[channelDataCount];
  382 + this->samplesSize[channel] = channelDataCount;
406 383 }
407 384  
408 385 // Convert data from the oscilloscope and write it into the sample buffer
409 386 unsigned int bufferPosition = this->triggerPoint * 2;
410   - for(unsigned int realPosition = 0; realPosition < this->bufferSize; realPosition++, bufferPosition += 2) {
411   - if(bufferPosition >= dataCount)
412   - bufferPosition %= dataCount;
413   -
414   - this->samples[channel][realPosition] = ((double) data[bufferPosition + HANTEK_CHANNELS - 1 - channel] / 256.0 - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  387 + if(using9Bits) {
  388 + // Additional MSBs after the normal data
  389 + for(unsigned int realPosition = 0; realPosition < channelDataCount; realPosition++, bufferPosition += 2) {
  390 + if(bufferPosition >= dataCount)
  391 + bufferPosition %= dataCount;
  392 +
  393 + this->samples[channel][realPosition] = ((double) (data[bufferPosition + HANTEK_CHANNELS - 1 - channel] + (data[dataCount + bufferPosition + HANTEK_CHANNELS - 1 - channel] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  394 + }
  395 + }
  396 + else {
  397 + for(unsigned int realPosition = 0; realPosition < channelDataCount; realPosition++, bufferPosition += 2) {
  398 + if(bufferPosition >= dataCount)
  399 + bufferPosition %= dataCount;
  400 +
  401 + this->samples[channel][realPosition] = ((double) data[bufferPosition + HANTEK_CHANNELS - 1 - channel] / 0xff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
  402 + }
415 403 }
416 404 }
417 405 else if(this->samples[channel]) {
... ... @@ -436,15 +424,113 @@ namespace Hantek {
436 424 unsigned long int Control::updateBufferSize(unsigned long int size) {
437 425 BufferSizeId sizeId = (size <= BUFFER_SMALL) ? BUFFERID_SMALL : BUFFERID_LARGE;
438 426  
439   - // SetTriggerAndSamplerate bulk command for samplerate
440   - ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setBufferSize(sizeId);
441   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
442   -
443   - this->bufferSize = (sizeId == BUFFERID_SMALL) ? BUFFER_SMALL : BUFFER_LARGE;
  427 + switch(this->commandVersion) {
  428 + case 0:
  429 + // SetTriggerAndSamplerate bulk command for buffer size
  430 + ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setBufferSize(sizeId);
  431 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  432 +
  433 + this->bufferSize = (sizeId == BUFFERID_SMALL) ? BUFFER_SMALL : BUFFER_LARGE;
  434 + break;
  435 +
  436 + case 1:
  437 + // SetBuffer5200 bulk command for buffer size
  438 + CommandSetBuffer5200 *commandSetBuffer5200 = (CommandSetBuffer5200 *) this->command[COMMAND_SETBUFFER5200];
  439 + commandSetBuffer5200->setUsedPre(DTRIGGERPOSITION_ON);
  440 + commandSetBuffer5200->setUsedPost(DTRIGGERPOSITION_ON);
  441 + commandSetBuffer5200->setBufferSize(sizeId);
  442 + this->commandPending[COMMAND_SETBUFFER5200] = true;
  443 +
  444 + this->bufferSize = (sizeId == BUFFERID_SMALL) ? BUFFER_SMALL : BUFFER_LARGE5200;
  445 + break;
  446 + }
444 447  
445 448 return this->bufferSize;
446 449 }
447 450  
  451 + /// \brief Try to connect to the oscilloscope.
  452 + void Control::connectDevice() {
  453 + int errorCode;
  454 +
  455 + emit statusMessage(this->device->search(), 0);
  456 + if(!this->device->isConnected())
  457 + return;
  458 +
  459 + // Set all necessary configuration commands as pending
  460 + this->commandPending[COMMAND_SETFILTER] = true;
  461 + this->commandPending[COMMAND_FORCETRIGGER] = false;
  462 + this->commandPending[COMMAND_STARTSAMPLING] = false;
  463 + this->commandPending[COMMAND_ENABLETRIGGER] = false;
  464 + this->commandPending[COMMAND_GETDATA] = false;
  465 + this->commandPending[COMMAND_GETCAPTURESTATE] = false;
  466 + this->commandPending[COMMAND_SETGAIN] = true;
  467 + this->commandPending[COMMAND_SETLOGICALDATA] = false;
  468 + this->commandPending[COMMAND_GETLOGICALDATA] = false;
  469 +
  470 + // Determine the command version we need for this model
  471 + bool unsupported = false;
  472 + switch(this->device->getModel()) {
  473 + case MODEL_DSO2100:
  474 + case MODEL_DSO2150:
  475 + unsupported = true;
  476 + case MODEL_DSO2090:
  477 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  478 + this->commandPending[COMMAND_SETSAMPLERATE5200] = false;
  479 + this->commandPending[COMMAND_SETBUFFER5200] = false;
  480 + this->commandPending[COMMAND_SETTRIGGER5200] = false;
  481 + this->commandVersion = 0;
  482 + break;
  483 +
  484 + case MODEL_DSO2250:
  485 + case MODEL_DSO5200A:
  486 + unsupported = true;
  487 + case MODEL_DSO5200:
  488 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = false;
  489 + this->commandPending[COMMAND_SETSAMPLERATE5200] = true;
  490 + this->commandPending[COMMAND_SETBUFFER5200] = true;
  491 + this->commandPending[COMMAND_SETTRIGGER5200] = true;
  492 + this->commandVersion = 1;
  493 + break;
  494 +
  495 + default:
  496 + this->device->disconnect();
  497 + emit statusMessage(tr("Unknown model"), 0);
  498 + return;
  499 + }
  500 +
  501 + if(unsupported)
  502 + qDebug("Warning: This Hantek DSO model isn't supported officially, so it may not be working as expected. Reports about your experiences are very welcome though (Please open a feature request in the tracker at https://sf.net/projects/openhantek/ or email me directly to oliver.haag@gmail.com). If it's working perfectly I can remove this warning, if not it should be possible to get it working with your help soon.");
  503 +
  504 + for(int control = 0; control < CONTROLINDEX_COUNT; control++)
  505 + this->controlPending[control] = true;
  506 +
  507 + // Maximum possible samplerate for a single channel
  508 + switch(this->device->getModel()) {
  509 + case MODEL_DSO2090:
  510 + case MODEL_DSO2100:
  511 + this->samplerateChannelMax = 50e6;
  512 + break;
  513 +
  514 + case MODEL_DSO2150:
  515 + this->samplerateChannelMax = 75e6;
  516 + break;
  517 +
  518 + default:
  519 + this->samplerateChannelMax = 125e6;
  520 + break;
  521 + }
  522 +
  523 + // Get channel level data
  524 + errorCode = this->device->controlRead(CONTROL_VALUE, (unsigned char*) &(this->channelLevels), sizeof(this->channelLevels), (int) VALUE_CHANNELLEVEL);
  525 + if(errorCode < 0) {
  526 + this->device->disconnect();
  527 + emit statusMessage(tr("Couldn't get channel level data from oscilloscope"), 0);
  528 + return;
  529 + }
  530 +
  531 + DsoControl::connectDevice();
  532 + }
  533 +
448 534 /// \brief Sets the size of the oscilloscopes sample buffer.
449 535 /// \param size The buffer size that should be met (S).
450 536 /// \return The buffer size that has been set.
... ... @@ -465,19 +551,22 @@ namespace Hantek {
465 551 if(samplerate == 0)
466 552 return 0;
467 553  
468   - // SetTriggerAndSamplerate bulk command for samplerate
  554 + // Pointers to needed commands
469 555 CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE];
  556 + CommandSetSamplerate5200 *commandSetSamplerate5200 = (CommandSetSamplerate5200 *) this->command[COMMAND_SETSAMPLERATE5200];
  557 + CommandSetBuffer5200 *commandSetBuffer5200 = (CommandSetBuffer5200 *) this->command[COMMAND_SETBUFFER5200];
  558 + CommandSetTrigger5200 *commandSetTrigger5200 = (CommandSetTrigger5200 *) this->command[COMMAND_SETTRIGGER5200];
470 559  
471 560 // Calculate with fast rate first if only one channel is used
472 561 bool fastRate = false;
473 562 this->samplerateMax = this->samplerateChannelMax;
474   - if(((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannel() != USED_CH1CH2) {
  563 + if((this->commandVersion == 0) ? (commandSetTriggerAndSamplerate->getUsedChannels() != USED_CH1CH2) : (commandSetTrigger5200->getUsedChannels() != EUSED_CH1CH2)) {
475 564 fastRate = true;
476 565 this->samplerateMax *= HANTEK_CHANNELS;
477 566 }
478 567  
479 568 // The maximum sample rate depends on the buffer size
480   - switch(commandSetTriggerAndSamplerate->getBufferSize()) {
  569 + switch((this->commandVersion == 0) ? commandSetTriggerAndSamplerate->getBufferSize() : commandSetBuffer5200->getBufferSize()) {
481 570 case BUFFERID_ROLL:
482 571 this->samplerateMax /= 1000;
483 572 break;
... ... @@ -503,14 +592,32 @@ namespace Hantek {
503 592 long int valueSlow = qMax(((long int) this->samplerateDivider - 3) / 2, (long int) 0);
504 593 unsigned char valueFast = this->samplerateDivider - valueSlow * 2;
505 594  
506   - // Store samplerate fast value
507   - commandSetTriggerAndSamplerate->setSamplerateFast(valueFast);
508   - // Store samplerate slow value (two's complement)
509   - commandSetTriggerAndSamplerate->setSamplerateSlow(valueSlow == 0 ? 0 : 0xffff - valueSlow);
510   - // Set fast rate when used
511   - commandSetTriggerAndSamplerate->setFastRate(fastRate);
512   -
513   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  595 + switch(this->commandVersion) {
  596 + case 0:
  597 + // Store samplerate fast value
  598 + commandSetTriggerAndSamplerate->setSamplerateFast(valueFast);
  599 + // Store samplerate slow value (two's complement)
  600 + commandSetTriggerAndSamplerate->setSamplerateSlow(valueSlow == 0 ? 0 : 0xffff - valueSlow);
  601 + // Set fast rate when used
  602 + commandSetTriggerAndSamplerate->setFastRate(fastRate);
  603 +
  604 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  605 +
  606 + break;
  607 +
  608 + default:
  609 + // Store samplerate fast value
  610 + commandSetSamplerate5200->setSamplerateFast(4 - valueFast);
  611 + // Store samplerate slow value (two's complement)
  612 + commandSetSamplerate5200->setSamplerateSlow(valueSlow == 0 ? 0 : 0xffff - valueSlow);
  613 + // Set fast rate when used
  614 + commandSetTrigger5200->setFastRate(fastRate);
  615 +
  616 + this->commandPending[COMMAND_SETSAMPLERATE5200] = true;
  617 + this->commandPending[COMMAND_SETTRIGGER5200] = true;
  618 +
  619 + break;
  620 + }
514 621  
515 622 this->updateBufferSize(this->bufferSize);
516 623 this->setTriggerSlope(this->triggerSlope);
... ... @@ -530,16 +637,33 @@ namespace Hantek {
530 637 commandSetFilter->setChannel(channel, !used);
531 638 this->commandPending[COMMAND_SETFILTER] = true;
532 639  
533   - // SetTriggerAndSamplerate bulk command for trigger source
534   - unsigned char usedChannel = USED_CH1;
535   - if(!commandSetFilter->getChannel(1)) {
536   - if(commandSetFilter->getChannel(0))
537   - usedChannel = USED_CH2;
538   - else
539   - usedChannel = USED_CH1CH2;
  640 + switch(this->commandVersion) {
  641 + case 0: {
  642 + // SetTriggerAndSamplerate bulk command for trigger source
  643 + unsigned char usedChannels = USED_CH1;
  644 + if(!commandSetFilter->getChannel(1)) {
  645 + if(commandSetFilter->getChannel(0))
  646 + usedChannels = USED_CH2;
  647 + else
  648 + usedChannels = USED_CH1CH2;
  649 + }
  650 + ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setUsedChannels(usedChannels);
  651 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  652 + break;
  653 + }
  654 + case 1: {
  655 + unsigned char usedChannels = EUSED_CH1;
  656 + if(!commandSetFilter->getChannel(1)) {
  657 + if(commandSetFilter->getChannel(0))
  658 + usedChannels = EUSED_CH2;
  659 + else
  660 + usedChannels = EUSED_CH1CH2;
  661 + }
  662 + ((CommandSetTrigger5200 *) this->command[COMMAND_SETTRIGGER5200])->setUsedChannels(usedChannels);
  663 + this->commandPending[COMMAND_SETTRIGGER5200] = true;
  664 + break;
  665 + }
540 666 }
541   - ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setUsedChannel(usedChannel);
542   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
543 667  
544 668 return 0;
545 669 }
... ... @@ -641,9 +765,19 @@ namespace Hantek {
641 765 else
642 766 sourceValue = TRIGGER_CH1 - id;
643 767  
644   - // SetTriggerAndSamplerate bulk command for trigger source
645   - ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerSource(sourceValue);
646   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  768 + switch(this->commandVersion) {
  769 + case 0:
  770 + // SetTriggerAndSamplerate bulk command for trigger source
  771 + ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerSource(sourceValue);
  772 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  773 + break;
  774 +
  775 + case 1:
  776 + // SetTrigger5200 bulk command for trigger source
  777 + ((CommandSetTrigger5200 *) this->command[COMMAND_SETTRIGGER5200])->setTriggerSource(sourceValue);
  778 + this->commandPending[COMMAND_SETTRIGGER5200] = true;
  779 + break;
  780 + }
647 781  
648 782 // SetRelays control command for external trigger relay
649 783 ((ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS])->setTrigger(special);
... ... @@ -694,30 +828,61 @@ namespace Hantek {
694 828 if(slope != Dso::SLOPE_NEGATIVE && slope != Dso::SLOPE_POSITIVE)
695 829 return -1;
696 830  
697   - // SetTriggerAndSamplerate bulk command for trigger position
698   - CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE];
699   -
700   - commandSetTriggerAndSamplerate->setTriggerSlope((/*this->bufferSize != BUFFER_SMALL ||*/ commandSetTriggerAndSamplerate->getSamplerateFast() % 2 == 0) ? slope : Dso::SLOPE_NEGATIVE - slope);
701   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  831 + switch(this->commandVersion) {
  832 + case 0: {
  833 + // SetTriggerAndSamplerate bulk command for trigger slope
  834 + CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE];
  835 +
  836 + commandSetTriggerAndSamplerate->setTriggerSlope((/*this->bufferSize != BUFFER_SMALL ||*/ commandSetTriggerAndSamplerate->getSamplerateFast() % 2 == 0) ? slope : Dso::SLOPE_NEGATIVE - slope);
  837 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  838 + break;
  839 + }
  840 + case 1: {
  841 + // SetTrigger5200 bulk command for trigger slope
  842 + ((CommandSetTrigger5200 *) this->command[COMMAND_SETTRIGGER5200])->setTriggerSlope(slope);
  843 + this->commandPending[COMMAND_SETTRIGGER5200] = true;
  844 + break;
  845 + }
  846 + }
702 847  
703 848 this->triggerSlope = slope;
704 849 return 0;
705 850 }
706 851  
707 852 /// \brief Set the trigger position.
708   - /// \param position The new trigger position (0.0 - 1.0).
  853 + /// \param position The new trigger position (in s).
709 854 /// \return The trigger position that has been set.
710 855 double Control::setTriggerPosition(double position) {
711   - // Calculate the position value (Varying start point, measured in samples)
712   - //unsigned long int positionRange = (this->bufferSize == BUFFER_SMALL) ? 10000 : 32768;
713   - unsigned long int positionStart = (this->bufferSize == BUFFER_SMALL) ? 0x77660 : 0x78000;
714   - unsigned long int positionValue = position * this->samplerateMax / this->samplerateDivider + positionStart;
  856 + // All trigger position are measured in samples
  857 + unsigned long int positionSamples = position * this->samplerateMax / this->samplerateDivider;
715 858  
716   - // SetTriggerAndSamplerate bulk command for trigger position
717   - ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(positionValue);
718   - this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  859 + switch(this->commandVersion) {
  860 + case 0: {
  861 + // Calculate the position value (Start point depending on buffer size)
  862 + unsigned long int positionStart = (this->bufferSize == BUFFER_SMALL) ? 0x77660 : 0x78000;
  863 +
  864 + // SetTriggerAndSamplerate bulk command for trigger position
  865 + ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(positionStart + positionSamples);
  866 + this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
  867 +
  868 + break;
  869 + }
  870 + case 1: {
  871 + // Calculate the position values (Inverse, maximum is 0xffff)
  872 + unsigned short int positionPre = 0xffff - this->bufferSize + positionSamples;
  873 + unsigned short int positionPost = 0xffff - positionSamples;
  874 +
  875 + // SetBuffer5200 bulk command for trigger position
  876 + CommandSetBuffer5200 *commandSetBuffer5200 = (CommandSetBuffer5200 *) this->command[COMMAND_SETBUFFER5200];
  877 + commandSetBuffer5200->setTriggerPositionPre(positionPre);
  878 + commandSetBuffer5200->setTriggerPositionPost(positionPost);
  879 + this->commandPending[COMMAND_SETBUFFER5200] = true;
  880 +
  881 + break;
  882 + }
  883 + }
719 884  
720 885 this->triggerPosition = position;
721   - return (double) (positionValue - positionStart) / this->samplerateMax * this->samplerateDivider;
  886 + return (double) positionSamples / this->samplerateMax * this->samplerateDivider;
722 887 }
723 888 }
... ...
openhantek/src/hantek/control.h
... ... @@ -80,6 +80,8 @@ namespace Hantek {
80 80 unsigned char controlCode[CONTROLINDEX_COUNT]; ///< Request codes for control commands
81 81 bool controlPending[CONTROLINDEX_COUNT]; ///< true, when the control command should be executed
82 82  
  83 + short int commandVersion; ///< The used version of the commands
  84 +
83 85 /// Calibration data for the channel offsets
84 86 unsigned short int channelLevels[HANTEK_CHANNELS][GAIN_COUNT][OFFSET_COUNT];
85 87  
... ... @@ -107,6 +109,8 @@ namespace Hantek {
107 109 QList<double> gainSteps; ///< Voltage steps in V/screenheight
108 110  
109 111 public slots:
  112 + virtual void connectDevice();
  113 +
110 114 unsigned long int setSamplerate(unsigned long int samplerate);
111 115 unsigned long int setBufferSize(unsigned long int size);
112 116  
... ...
openhantek/src/hantek/types.cpp
... ... @@ -31,7 +31,7 @@
31 31  
32 32  
33 33 namespace Hantek {
34   - ////////////////////////////////////////////////////////////////////////////////
  34 + //////////////////////////////////////////////////////////////////////////////
35 35 // class CommandSetFilter
36 36 /// \brief Sets the data array to the default values.
37 37 CommandSetFilter::CommandSetFilter() : Helper::DataArray<unsigned char>(8) {
... ... @@ -93,7 +93,7 @@ namespace Hantek {
93 93 }
94 94  
95 95  
96   - ////////////////////////////////////////////////////////////////////////////////
  96 + //////////////////////////////////////////////////////////////////////////////
97 97 // class CommandSetTriggerAndSamplerate
98 98 /// \brief Sets the data array to the default values.
99 99 CommandSetTriggerAndSamplerate::CommandSetTriggerAndSamplerate() : Helper::DataArray<unsigned char>(12) {
... ... @@ -101,24 +101,24 @@ namespace Hantek {
101 101 }
102 102  
103 103 /// \brief Sets the data bytes to the specified values.
104   - /// \param samplerate The samplerate value.
  104 + /// \param samplerateSlow The SamplerateSlow value.
105 105 /// \param triggerPosition The trigger position value.
106 106 /// \param triggerSource The trigger source id (Tsr1).
107   - /// \param sampleSize The buffer size id (Tsr1).
  107 + /// \param bufferSize The buffer size id (Tsr1).
108 108 /// \param samplerateFast The samplerateFast value (Tsr1).
109   - /// \param usedChannel The enabled channels (Tsr2).
  109 + /// \param usedChannels The enabled channels (Tsr2).
110 110 /// \param fastRate The fastRate state (Tsr2).
111 111 /// \param triggerSlope The triggerSlope value (Tsr2).
112   - CommandSetTriggerAndSamplerate::CommandSetTriggerAndSamplerate(unsigned short int samplerate, unsigned long int triggerPosition, unsigned char triggerSource, unsigned char sampleSize, unsigned char samplerateFast, unsigned char usedChannel, bool fastRate, unsigned char triggerSlope) : Helper::DataArray<unsigned char>(12) {
  112 + CommandSetTriggerAndSamplerate::CommandSetTriggerAndSamplerate(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<unsigned char>(12) {
113 113 this->init();
114 114  
115 115 this->setTriggerSource(triggerSource);
116   - this->setBufferSize(sampleSize);
  116 + this->setBufferSize(bufferSize);
117 117 this->setSamplerateFast(samplerateFast);
118   - this->setUsedChannel(usedChannel);
  118 + this->setUsedChannels(usedChannels);
119 119 this->setFastRate(fastRate);
120 120 this->setTriggerSlope(triggerSlope);
121   - this->setSamplerateSlow(samplerate);
  121 + this->setSamplerateSlow(samplerateSlow);
122 122 this->setTriggerPosition(triggerPosition);
123 123 }
124 124  
... ... @@ -134,16 +134,16 @@ namespace Hantek {
134 134 ((Tsr1Bits *) &(this->array[2]))->triggerSource = value;
135 135 }
136 136  
137   - /// \brief Get the sampleSize value in Tsr1Bits.
138   - /// \return The sampleSize value.
  137 + /// \brief Get the bufferSize value in Tsr1Bits.
  138 + /// \return The #BufferSizeId value.
139 139 unsigned char CommandSetTriggerAndSamplerate::getBufferSize() {
140   - return ((Tsr1Bits *) &(this->array[2]))->sampleSize;
  140 + return ((Tsr1Bits *) &(this->array[2]))->bufferSize;
141 141 }
142 142  
143   - /// \brief Set the sampleSize in Tsr1Bits to the given value.
144   - /// \param value The new sampleSize value.
  143 + /// \brief Set the bufferSize in Tsr1Bits to the given value.
  144 + /// \param value The new #BufferSizeId value.
145 145 void CommandSetTriggerAndSamplerate::setBufferSize(unsigned char value) {
146   - ((Tsr1Bits *) &(this->array[2]))->sampleSize = value;
  146 + ((Tsr1Bits *) &(this->array[2]))->bufferSize = value;
147 147 }
148 148  
149 149 /// \brief Get the samplerateFast value in Tsr1Bits.
... ... @@ -158,16 +158,16 @@ namespace Hantek {
158 158 ((Tsr1Bits *) &(this->array[2]))->samplerateFast = value;
159 159 }
160 160  
161   - /// \brief Get the usedChannel value in Tsr2Bits.
162   - /// \return The usedChannel value.
163   - unsigned char CommandSetTriggerAndSamplerate::getUsedChannel() {
164   - return ((Tsr2Bits *) &(this->array[3]))->usedChannel;
  161 + /// \brief Get the usedChannels value in Tsr2Bits.
  162 + /// \return The usedChannels value.
  163 + unsigned char CommandSetTriggerAndSamplerate::getUsedChannels() {
  164 + return ((Tsr2Bits *) &(this->array[3]))->usedChannels;
165 165 }
166 166  
167   - /// \brief Set the usedChannel in Tsr2Bits to the given value.
168   - /// \param value The new usedChannel value.
169   - void CommandSetTriggerAndSamplerate::setUsedChannel(unsigned char value) {
170   - ((Tsr2Bits *) &(this->array[3]))->usedChannel = value;
  167 + /// \brief Set the usedChannels in Tsr2Bits to the given value.
  168 + /// \param value The new usedChannels value.
  169 + void CommandSetTriggerAndSamplerate::setUsedChannels(unsigned char value) {
  170 + ((Tsr2Bits *) &(this->array[3]))->usedChannels = value;
171 171 }
172 172  
173 173 /// \brief Get the fastRate state in Tsr2Bits.
... ... @@ -194,14 +194,14 @@ namespace Hantek {
194 194 ((Tsr2Bits *) &(this->array[3]))->triggerSlope = slope;
195 195 }
196 196  
197   - /// \brief Get the Samplerate value.
198   - /// \return The samplerate value.
199   - unsigned short int CommandSetTriggerAndSamplerate::getSamplerate() {
  197 + /// \brief Get the SamplerateSlow value.
  198 + /// \return The SamplerateSlow value.
  199 + unsigned short int CommandSetTriggerAndSamplerate::getSamplerateSlow() {
200 200 return (unsigned short int) this->array[4] | ((unsigned short int) this->array[5] << 8);
201 201 }
202 202  
203   - /// \brief Set the Samplerate to the given value.
204   - /// \param samplerate The new samplerate value.
  203 + /// \brief Set the SamplerateSlow to the given value.
  204 + /// \param samplerate The new SamplerateSlow value.
205 205 void CommandSetTriggerAndSamplerate::setSamplerateSlow(unsigned short int samplerate) {
206 206 this->array[4] = (unsigned char) samplerate;
207 207 this->array[5] = (unsigned char) (samplerate >> 8);
... ... @@ -227,7 +227,7 @@ namespace Hantek {
227 227 }
228 228  
229 229  
230   - ////////////////////////////////////////////////////////////////////////////////
  230 + //////////////////////////////////////////////////////////////////////////////
231 231 // class CommandForceTrigger
232 232 /// \brief Sets the data array to needed values.
233 233 CommandForceTrigger::CommandForceTrigger() : Helper::DataArray<unsigned char>(2) {
... ... @@ -235,7 +235,7 @@ namespace Hantek {
235 235 }
236 236  
237 237  
238   - ////////////////////////////////////////////////////////////////////////////////
  238 + //////////////////////////////////////////////////////////////////////////////
239 239 // class CommandCaptureStart
240 240 /// \brief Sets the data array to needed values.
241 241 CommandCaptureStart::CommandCaptureStart() : Helper::DataArray<unsigned char>(2) {
... ... @@ -243,7 +243,7 @@ namespace Hantek {
243 243 }
244 244  
245 245  
246   - ////////////////////////////////////////////////////////////////////////////////
  246 + //////////////////////////////////////////////////////////////////////////////
247 247 // class CommandTriggerEnabled
248 248 /// \brief Sets the data array to needed values.
249 249 CommandTriggerEnabled::CommandTriggerEnabled() : Helper::DataArray<unsigned char>(2) {
... ... @@ -251,7 +251,7 @@ namespace Hantek {
251 251 }
252 252  
253 253  
254   - ////////////////////////////////////////////////////////////////////////////////
  254 + //////////////////////////////////////////////////////////////////////////////
255 255 // class CommandGetData
256 256 /// \brief Sets the data array to needed values.
257 257 CommandGetData::CommandGetData() : Helper::DataArray<unsigned char>(2) {
... ... @@ -259,7 +259,7 @@ namespace Hantek {
259 259 }
260 260  
261 261  
262   - ////////////////////////////////////////////////////////////////////////////////
  262 + //////////////////////////////////////////////////////////////////////////////
263 263 // class CommandGetCaptureState
264 264 /// \brief Sets the data array to needed values.
265 265 CommandGetCaptureState::CommandGetCaptureState() : Helper::DataArray<unsigned char>(2) {
... ... @@ -267,7 +267,7 @@ namespace Hantek {
267 267 }
268 268  
269 269  
270   - ////////////////////////////////////////////////////////////////////////////////
  270 + //////////////////////////////////////////////////////////////////////////////
271 271 // class ResponseGetCaptureState
272 272 /// \brief Initializes the array.
273 273 ResponseGetCaptureState::ResponseGetCaptureState() : Helper::DataArray<unsigned char>(512) {
... ... @@ -286,7 +286,7 @@ namespace Hantek {
286 286 }
287 287  
288 288  
289   - ////////////////////////////////////////////////////////////////////////////////
  289 + //////////////////////////////////////////////////////////////////////////////
290 290 // class CommandSetGain
291 291 /// \brief Sets the data array to needed values.
292 292 CommandSetGain::CommandSetGain() : Helper::DataArray<unsigned char>(8) {
... ... @@ -333,7 +333,7 @@ namespace Hantek {
333 333 }
334 334  
335 335  
336   - ////////////////////////////////////////////////////////////////////////////////
  336 + //////////////////////////////////////////////////////////////////////////////
337 337 // class CommandSetLogicalData
338 338 /// \brief Sets the data array to needed values.
339 339 CommandSetLogicalData::CommandSetLogicalData() : Helper::DataArray<unsigned char>(8) {
... ... @@ -367,7 +367,7 @@ namespace Hantek {
367 367 }
368 368  
369 369  
370   - ////////////////////////////////////////////////////////////////////////////////
  370 + //////////////////////////////////////////////////////////////////////////////
371 371 // class CommandGetLogicalData
372 372 /// \brief Sets the data array to needed values.
373 373 CommandGetLogicalData::CommandGetLogicalData() : Helper::DataArray<unsigned char>(2) {
... ... @@ -375,7 +375,7 @@ namespace Hantek {
375 375 }
376 376  
377 377  
378   - ////////////////////////////////////////////////////////////////////////////////
  378 + //////////////////////////////////////////////////////////////////////////////
379 379 // class ControlGetSpeed
380 380 /// \brief Initializes the array.
381 381 ControlGetSpeed::ControlGetSpeed() : Helper::DataArray<unsigned char>(10) {
... ... @@ -388,7 +388,7 @@ namespace Hantek {
388 388 }
389 389  
390 390  
391   - ////////////////////////////////////////////////////////////////////////////////
  391 + //////////////////////////////////////////////////////////////////////////////
392 392 // class ControlBeginCommand
393 393 /// \brief Sets the command index to the given value.
394 394 /// \param index The CommandIndex for the command.
... ... @@ -416,7 +416,7 @@ namespace Hantek {
416 416 }
417 417  
418 418  
419   - ////////////////////////////////////////////////////////////////////////////////
  419 + //////////////////////////////////////////////////////////////////////////////
420 420 // class ControlSetOffset
421 421 /// \brief Sets the data array to the default values.
422 422 ControlSetOffset::ControlSetOffset() : Helper::DataArray<unsigned char>(17) {
... ... @@ -470,7 +470,7 @@ namespace Hantek {
470 470 }
471 471  
472 472  
473   - ////////////////////////////////////////////////////////////////////////////////
  473 + //////////////////////////////////////////////////////////////////////////////
474 474 // class ControlSetRelays
475 475 /// \brief Sets all relay states.
476 476 /// \param ch1Below1V Sets the state of the Channel 1 below 1 V relay.
... ... @@ -561,4 +561,235 @@ namespace Hantek {
561 561 void ControlSetRelays::setTrigger(bool ext) {
562 562 this->array[7] = ext ? 0xfe : 0x01;
563 563 }
  564 +
  565 +
  566 + //////////////////////////////////////////////////////////////////////////////
  567 + // class CommandSetSamplerate5200
  568 + /// \brief Sets the data array to the default values.
  569 + CommandSetSamplerate5200::CommandSetSamplerate5200() : Helper::DataArray<unsigned char>(6) {
  570 + this->init();
  571 + }
  572 +
  573 + /// \brief Sets the data bytes to the specified values.
  574 + /// \param samplerateSlow The SamplerateSlow value.
  575 + /// \param samplerateFast The SamplerateFast value.
  576 + CommandSetSamplerate5200::CommandSetSamplerate5200(unsigned short int samplerateSlow, unsigned char samplerateFast) : Helper::DataArray<unsigned char>(6) {
  577 + this->init();
  578 +
  579 + this->setSamplerateFast(samplerateFast);
  580 + this->setSamplerateSlow(samplerateSlow);
  581 + }
  582 +
  583 + /// \brief Get the SamplerateFast value.
  584 + /// \return The SamplerateFast value.
  585 + unsigned char CommandSetSamplerate5200::getSamplerateFast() {
  586 + return this->array[4];
  587 + }
  588 +
  589 + /// \brief Set the SamplerateFast to the given value.
  590 + /// \param value The new SamplerateFast value.
  591 + void CommandSetSamplerate5200::setSamplerateFast(unsigned char value) {
  592 + this->array[4] = value;
  593 + }
  594 +
  595 + /// \brief Get the SamplerateSlow value.
  596 + /// \return The SamplerateSlow value.
  597 + unsigned short int CommandSetSamplerate5200::getSamplerateSlow() {
  598 + return (unsigned short int) this->array[2] | ((unsigned short int) this->array[3] << 8);
  599 + }
  600 +
  601 + /// \brief Set the SamplerateSlow to the given value.
  602 + /// \param samplerate The new SamplerateSlow value.
  603 + void CommandSetSamplerate5200::setSamplerateSlow(unsigned short int samplerate) {
  604 + this->array[2] = (unsigned char) samplerate;
  605 + this->array[3] = (unsigned char) (samplerate >> 8);
  606 + }
  607 +
  608 + /// \brief Initialize the array to the needed values.
  609 + void CommandSetSamplerate5200::init() {
  610 + this->array[0] = COMMAND_SETSAMPLERATE5200;
  611 + }
  612 +
  613 +
  614 + //////////////////////////////////////////////////////////////////////////////
  615 + // class CommandSetBuffer5200
  616 + /// \brief Sets the data array to the default values.
  617 + CommandSetBuffer5200::CommandSetBuffer5200() : Helper::DataArray<unsigned char>(10) {
  618 + this->init();
  619 + }
  620 +
  621 + /// \brief Sets the data bytes to the specified values.
  622 + /// \param triggerPositionPre The TriggerPositionPre value.
  623 + /// \param triggerPositionPost The TriggerPositionPost value.
  624 + /// \param usedPre The TriggerPositionUsedPre value.
  625 + /// \param usedPost The TriggerPositionUsedPost value.
  626 + /// \param bufferSize The #BufferSizeId value.
  627 + CommandSetBuffer5200::CommandSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre, unsigned char usedPost, unsigned char bufferSize) : Helper::DataArray<unsigned char>(10) {
  628 + this->init();
  629 +
  630 + this->setTriggerPositionPre(triggerPositionPre);
  631 + this->setTriggerPositionPost(triggerPositionPost);
  632 + this->setUsedPre(usedPre);
  633 + this->setUsedPost(usedPost);
  634 + this->setBufferSize(bufferSize);
  635 + }
  636 +
  637 + /// \brief Get the TriggerPositionPre value.
  638 + /// \return The TriggerPositionPre value.
  639 + unsigned short int CommandSetBuffer5200::getTriggerPositionPre() {
  640 + return (unsigned short int) this->array[2] | ((unsigned short int) this->array[3] << 8);
  641 + }
  642 +
  643 + /// \brief Set the TriggerPositionPre to the given value.
  644 + /// \param position The new TriggerPositionPre value.
  645 + void CommandSetBuffer5200::setTriggerPositionPre(unsigned short int position) {
  646 + this->array[2] = (unsigned char) position;
  647 + this->array[3] = (unsigned char) (position >> 8);
  648 + }
  649 +
  650 + /// \brief Get the TriggerPositionPost value.
  651 + /// \return The TriggerPositionPost value.
  652 + unsigned short int CommandSetBuffer5200::getTriggerPositionPost() {
  653 + return (unsigned short int) this->array[6] | ((unsigned short int) this->array[7] << 8);
  654 + }
  655 +
  656 + /// \brief Set the TriggerPositionPost to the given value.
  657 + /// \param position The new TriggerPositionPost value.
  658 + void CommandSetBuffer5200::setTriggerPositionPost(unsigned short int position) {
  659 + this->array[6] = (unsigned char) position;
  660 + this->array[7] = (unsigned char) (position >> 8);
  661 + }
  662 +
  663 + /// \brief Get the TriggerPositionUsedPre value.
  664 + /// \return The #DTriggerPositionUsed value for the pre position.
  665 + unsigned char CommandSetBuffer5200::getUsedPre() {
  666 + return this->array[4];
  667 + }
  668 +
  669 + /// \brief Set the TriggerPositionUsedPre to the given value.
  670 + /// \param value The new #DTriggerPositionUsed value for the pre position.
  671 + void CommandSetBuffer5200::setUsedPre(unsigned char value) {
  672 + this->array[4] = value;
  673 + }
  674 +
  675 + /// \brief Get the TriggerPositionUsedPost value.
  676 + /// \return The #DTriggerPositionUsed value for the post position.
  677 + unsigned char CommandSetBuffer5200::getUsedPost() {
  678 + return ((DBufferBits *) &(this->array[8]))->triggerPositionUsed;
  679 + }
  680 +
  681 + /// \brief Set the TriggerPositionUsedPost to the given value.
  682 + /// \param value The new #DTriggerPositionUsed value for the post position.
  683 + void CommandSetBuffer5200::setUsedPost(unsigned char value) {
  684 + ((DBufferBits *) &(this->array[8]))->triggerPositionUsed = value;
  685 + }
  686 +
  687 + /// \brief Get the bufferSize value in DBufferBits.
  688 + /// \return The #BufferSizeId value.
  689 + unsigned char CommandSetBuffer5200::getBufferSize() {
  690 + return ((DBufferBits *) &(this->array[8]))->bufferSize;
  691 + }
  692 +
  693 + /// \brief Set the bufferSize in DBufferBits to the given value.
  694 + /// \param value The new #BufferSizeId value.
  695 + void CommandSetBuffer5200::setBufferSize(unsigned char value) {
  696 + ((DBufferBits *) &(this->array[8]))->bufferSize = value;
  697 + }
  698 +
  699 + /// \brief Initialize the array to the needed values.
  700 + void CommandSetBuffer5200::init() {
  701 + this->array[0] = COMMAND_SETBUFFER5200;
  702 + this->array[5] = 0xff;
  703 + this->array[9] = 0xff;
  704 + }
  705 +
  706 +
  707 + //////////////////////////////////////////////////////////////////////////////
  708 + // class CommandSetTrigger5200
  709 + /// \brief Sets the data array to the default values.
  710 + CommandSetTrigger5200::CommandSetTrigger5200() : Helper::DataArray<unsigned char>(10) {
  711 + this->init();
  712 + }
  713 +
  714 + /// \brief Sets the data bytes to the specified values.
  715 + /// \param triggerSource The trigger source id.
  716 + /// \param usedChannels The enabled channels.
  717 + /// \param fastRate The fastRate state.
  718 + /// \param triggerSlope The triggerSlope value.
  719 + /// \param triggerPulse The triggerPulse value.
  720 + CommandSetTrigger5200::CommandSetTrigger5200(unsigned char triggerSource, unsigned char usedChannels, bool fastRate, unsigned char triggerSlope, unsigned char triggerPulse) : Helper::DataArray<unsigned char>(8) {
  721 + this->init();
  722 +
  723 + this->setTriggerSource(triggerSource);
  724 + this->setUsedChannels(usedChannels);
  725 + this->setFastRate(fastRate);
  726 + this->setTriggerSlope(triggerSlope);
  727 + this->setTriggerPulse(triggerPulse);
  728 + }
  729 +
  730 + /// \brief Get the triggerSource value in ETsrBits.
  731 + /// \return The #TriggerSource value.
  732 + unsigned char CommandSetTrigger5200::getTriggerSource() {
  733 + return ((ETsrBits *) &(this->array[2]))->triggerSource;
  734 + }
  735 +
  736 + /// \brief Set the triggerSource in ETsrBits to the given value.
  737 + /// \param value The new #TriggerSource value.
  738 + void CommandSetTrigger5200::setTriggerSource(unsigned char value) {
  739 + ((ETsrBits *) &(this->array[2]))->triggerSource = value;
  740 + }
  741 +
  742 + /// \brief Get the usedChannels value in ETsrBits.
  743 + /// \return The #EUsedChannels value.
  744 + unsigned char CommandSetTrigger5200::getUsedChannels() {
  745 + return ((ETsrBits *) &(this->array[2]))->usedChannels;
  746 + }
  747 +
  748 + /// \brief Set the usedChannels in ETsrBits to the given value.
  749 + /// \param value The new #EUsedChannels value.
  750 + void CommandSetTrigger5200::setUsedChannels(unsigned char value) {
  751 + ((ETsrBits *) &(this->array[2]))->usedChannels = value;
  752 + }
  753 +
  754 + /// \brief Get the fastRate state in ETsrBits.
  755 + /// \return The fastRate state (Already inverted).
  756 + bool CommandSetTrigger5200::getFastRate() {
  757 + return ((ETsrBits *) &(this->array[2]))->fastRate == 0;
  758 + }
  759 +
  760 + /// \brief Set the fastRate in ETsrBits to the given state.
  761 + /// \param fastRate The new fastRate state (Automatically inverted).
  762 + void CommandSetTrigger5200::setFastRate(bool fastRate) {
  763 + ((ETsrBits *) &(this->array[2]))->fastRate = fastRate ? 0 : 1;
  764 + }
  765 +
  766 + /// \brief Get the triggerSlope value in ETsrBits.
  767 + /// \return The triggerSlope value.
  768 + unsigned char CommandSetTrigger5200::getTriggerSlope() {
  769 + return ((ETsrBits *) &(this->array[2]))->triggerSlope;
  770 + }
  771 +
  772 + /// \brief Set the triggerSlope in ETsrBits to the given value.
  773 + /// \param slope The new triggerSlope value.
  774 + void CommandSetTrigger5200::setTriggerSlope(unsigned char slope) {
  775 + ((ETsrBits *) &(this->array[2]))->triggerSlope = slope;
  776 + }
  777 +
  778 + /// \brief Get the triggerPulse state in ETsrBits.
  779 + /// \return The triggerPulse state.
  780 + bool CommandSetTrigger5200::getTriggerPulse() {
  781 + return ((ETsrBits *) &(this->array[2]))->triggerPulse == 1;
  782 + }
  783 +
  784 + /// \brief Set the triggerPulse in ETsrBits to the given state.
  785 + /// \param pulse The new triggerPulse state.
  786 + void CommandSetTrigger5200::setTriggerPulse(bool pulse) {
  787 + ((ETsrBits *) &(this->array[2]))->triggerPulse = pulse ? 1 : 0;
  788 + }
  789 +
  790 + /// \brief Initialize the array to the needed values.
  791 + void CommandSetTrigger5200::init() {
  792 + this->array[0] = COMMAND_SETTRIGGER5200;
  793 + this->array[4] = 0x02;
  794 + }
564 795 }
... ...
openhantek/src/hantek/types.h
... ... @@ -51,234 +51,287 @@ namespace Hantek {
51 51 /// \brief All supported bulk commands.
52 52 /// Indicies given in square brackets specify byte numbers in little endian format.
53 53 enum CommandCode {
54   - /// This command sets channel and trigger filter:
55   - /// <table>
56   - /// <tr>
57   - /// <td>0x00</td>
58   - /// <td>0x0f</td>
59   - /// <td>FilterBits</td>
60   - /// <td>0x00</td>
61   - /// <td>0x00</td>
62   - /// <td>0x00</td>
63   - /// <td>0x00</td>
64   - /// <td>0x00</td>
65   - /// </tr>
66   - /// </table>
  54 + /// <p>
  55 + /// This command sets channel and trigger filter:
  56 + /// <table>
  57 + /// <tr>
  58 + /// <td>0x00</td>
  59 + /// <td>0x0f</td>
  60 + /// <td>FilterBits</td>
  61 + /// <td>0x00</td>
  62 + /// <td>0x00</td>
  63 + /// <td>0x00</td>
  64 + /// <td>0x00</td>
  65 + /// <td>0x00</td>
  66 + /// </tr>
  67 + /// </table>
  68 + /// </p>
67 69 COMMAND_SETFILTER,
68 70  
69   - /// This command sets trigger and timebase:
70   - /// <table>
71   - /// <tr>
72   - /// <td>0x01</td>
73   - /// <td>0x00</td>
74   - /// <td>Tsr1Bits</td>
75   - /// <td>Tsr2Bits</td>
76   - /// <td>SamplerateValue[0]</td>
77   - /// <td>SamplerateValue[1]</td>
78   - /// </tr>
79   - /// </table>
80   - /// <table>
81   - /// <tr>
82   - /// <td>TriggerPosition[0]</td>
83   - /// <td>TriggerPosition[1]</td>
84   - /// <td>0x00</td>
85   - /// <td>0x00</td>
86   - /// <td>TriggerPosition[2]</td>
87   - /// <td>0x00</td>
88   - /// </tr>
89   - /// </table>
90   - /// The samplerate is set relative to the maximum sample rate by a divider that is set in Tsr1Bits.samplerateFast and the 16-bit value in the two SamplerateValue bytes.<br />
91   - /// Without using fast rate mode, the samplerate is:<br />
92   - /// <i>Samplerate = SamplerateMax / (2comp(SamplerateValue) * 2 + Tsr1Bits.samplerateFast)</i><br />
93   - /// SamplerateMax is 50 MHz for the DSO-2090.<br />
94   - /// When using fast rate mode the resulting samplerate is twice as fast, when using the large buffer it is half as fast. When Tsr1Bits.sampleSize 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.
  71 + /// <p>
  72 + /// This command sets trigger and timebase:
  73 + /// <table>
  74 + /// <tr>
  75 + /// <td>0x01</td>
  76 + /// <td>0x00</td>
  77 + /// <td>Tsr1Bits</td>
  78 + /// <td>Tsr2Bits</td>
  79 + /// <td>SamplerateSlow[0]</td>
  80 + /// <td>SamplerateSlow[1]</td>
  81 + /// </tr>
  82 + /// </table>
  83 + /// <table>
  84 + /// <tr>
  85 + /// <td>TriggerPosition[0]</td>
  86 + /// <td>TriggerPosition[1]</td>
  87 + /// <td>0x00</td>
  88 + /// <td>0x00</td>
  89 + /// <td>TriggerPosition[2]</td>
  90 + /// <td>0x00</td>
  91 + /// </tr>
  92 + /// </table>
  93 + /// </p>
  94 + /// <p>
  95 + /// The samplerate is set relative to the maximum sample rate by a divider that is set in Tsr1Bits.samplerateFast and the 16-bit value in the two SamplerateSlow bytes.<br />
  96 + /// Without using fast rate mode, the samplerate is:<br />
  97 + /// <i>Samplerate = SamplerateMax / (1comp(SamplerateSlow) * 2 + Tsr1Bits.samplerateFast)</i><br />
  98 + /// SamplerateMax is 50 MHz for the DSO-2090.<br />
  99 + /// When using fast rate mode the resulting samplerate is twice 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.
  100 + /// </p>
  101 + /// <p>
  102 + /// 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.
  103 + /// </p>
95 104 COMMAND_SETTRIGGERANDSAMPLERATE,
96 105  
97   - /// This command forces triggering:
98   - /// <table>
99   - /// <tr>
100   - /// <td>0x02</td>
101   - /// <td>0x00</td>
102   - /// </tr>
103   - /// </table>
  106 + /// <p>
  107 + /// This command forces triggering:
  108 + /// <table>
  109 + /// <tr>
  110 + /// <td>0x02</td>
  111 + /// <td>0x00</td>
  112 + /// </tr>
  113 + /// </table>
  114 + /// </p>
104 115 COMMAND_FORCETRIGGER,
105 116  
106   - /// This command starts to capture data:
107   - /// <table>
108   - /// <tr>
109   - /// <td>0x03</td>
110   - /// <td>0x00</td>
111   - /// </tr>
112   - /// </table>
  117 + /// <p>
  118 + /// This command starts to capture data:
  119 + /// <table>
  120 + /// <tr>
  121 + /// <td>0x03</td>
  122 + /// <td>0x00</td>
  123 + /// </tr>
  124 + /// </table>
  125 + /// </p>
113 126 COMMAND_STARTSAMPLING,
114 127  
115   - /// This command sets the trigger:
116   - /// <table>
117   - /// <tr>
118   - /// <td>0x04</td>
119   - /// <td>0x00</td>
120   - /// </tr>
121   - /// </table>
  128 + /// <p>
  129 + /// This command sets the trigger:
  130 + /// <table>
  131 + /// <tr>
  132 + /// <td>0x04</td>
  133 + /// <td>0x00</td>
  134 + /// </tr>
  135 + /// </table>
  136 + /// </p>
122 137 COMMAND_ENABLETRIGGER,
123 138  
124   - /// This command reads data from the hardware:
125   - /// <table>
126   - /// <tr>
127   - /// <td>0x05</td>
128   - /// <td>0x00</td>
129   - /// </tr>
130   - /// </table>
131   - /// The oscilloscope returns the sample data, that will be split if it's larger than the IN endpoint packet length:
132   - /// <table>
133   - /// <tr>
134   - /// <td>Sample[0]</td>
135   - /// <td>...</td>
136   - /// <td>Sample[511]</td>
137   - /// </tr>
138   - /// <tr>
139   - /// <td>Sample[512]</td>
140   - /// <td>...</td>
141   - /// <td>Sample[1023]</td>
142   - /// </tr>
143   - /// <tr>
144   - /// <td>Sample[1024]</td>
145   - /// <td>...</td>
146   - /// <td>...</td>
147   - /// </tr>
148   - /// </table>
149   - /// Because of the 9 bit data model, the DSO-5200 transmits an additional MSB for each sample afterwards.
  139 + /// <p>
  140 + /// This command reads data from the hardware:
  141 + /// <table>
  142 + /// <tr>
  143 + /// <td>0x05</td>
  144 + /// <td>0x00</td>
  145 + /// </tr>
  146 + /// </table>
  147 + /// </p>
  148 + /// <p>
  149 + /// The oscilloscope returns the sample data, that will be split if it's larger than the IN endpoint packet length:
  150 + /// <table>
  151 + /// <tr>
  152 + /// <td>Sample[0]</td>
  153 + /// <td>...</td>
  154 + /// <td>Sample[511]</td>
  155 + /// </tr>
  156 + /// <tr>
  157 + /// <td>Sample[512]</td>
  158 + /// <td>...</td>
  159 + /// <td>Sample[1023]</td>
  160 + /// </tr>
  161 + /// <tr>
  162 + /// <td>Sample[1024]</td>
  163 + /// <td>...</td>
  164 + /// <td>...</td>
  165 + /// </tr>
  166 + /// </table>
  167 + /// Because of the 9 bit data model, the DSO-5200 transmits an additional MSB for each sample afterwards.
  168 + /// </p>
150 169 COMMAND_GETDATA,
151 170  
152   - /// This command checks the capture state:
153   - /// <table>
154   - /// <tr>
155   - /// <td>0x06</td>
156   - /// <td>0x00</td>
157   - /// </tr>
158   - /// </table>
159   - /// The oscilloscope returns it's capture state and the trigger point. Not sure about this, looks like 248 16-bit words with nearly constant values. These can be converted to the start address of the data in the buffer (See Hantek::Control::calculateTriggerPoint):
160   - /// <table>
161   - /// <tr>
162   - /// <td>#CaptureState</td>
163   - /// <td>0x00</td>
164   - /// <td>TriggerPoint[0]</td>
165   - /// <td>TriggerPoint[1]</td>
166   - /// <td>...</td>
167   - /// </tr>
168   - /// </table>
  171 + /// <p>
  172 + /// This command checks the capture state:
  173 + /// <table>
  174 + /// <tr>
  175 + /// <td>0x06</td>
  176 + /// <td>0x00</td>
  177 + /// </tr>
  178 + /// </table>
  179 + /// </p>
  180 + /// <p>
  181 + /// The oscilloscope returns it's capture state and the trigger point. Not sure about this, looks like 248 16-bit words with nearly constant values. These can be converted to the start address of the data in the buffer (See Hantek::Control::calculateTriggerPoint):
  182 + /// <table>
  183 + /// <tr>
  184 + /// <td>#CaptureState</td>
  185 + /// <td>0x00</td>
  186 + /// <td>TriggerPoint[0]</td>
  187 + /// <td>TriggerPoint[1]</td>
  188 + /// <td>...</td>
  189 + /// </tr>
  190 + /// </table>
  191 + /// </p>
169 192 COMMAND_GETCAPTURESTATE,
170 193  
171   - /// This command sets the gain:
172   - /// <table>
173   - /// <tr>
174   - /// <td>0x07</td>
175   - /// <td>0x0f</td>
176   - /// <td>GainBits</td>
177   - /// <td>0x00</td>
178   - /// <td>0x00</td>
179   - /// <td>0x00</td>
180   - /// <td>0x00</td>
181   - /// <td>0x00</td>
182   - /// </tr>
183   - /// </table>
184   - /// It is usually used in combination with #CONTROL_SETRELAYS.
  194 + /// <p>
  195 + /// This command sets the gain:
  196 + /// <table>
  197 + /// <tr>
  198 + /// <td>0x07</td>
  199 + /// <td>0x0f</td>
  200 + /// <td>GainBits</td>
  201 + /// <td>0x00</td>
  202 + /// <td>0x00</td>
  203 + /// <td>0x00</td>
  204 + /// <td>0x00</td>
  205 + /// <td>0x00</td>
  206 + /// </tr>
  207 + /// </table>
  208 + /// It is usually used in combination with #CONTROL_SETRELAYS.
  209 + /// </p>
185 210 COMMAND_SETGAIN,
186 211  
187   - /// This command sets the logical data (And what the hell is this?...):
188   - /// <table>
189   - /// <tr>
190   - /// <td>0x08</td>
191   - /// <td>0x0f</td>
192   - /// <td>Data | 0x01</td>
193   - /// <td>0x00</td>
194   - /// <td>0x00</td>
195   - /// <td>0x00</td>
196   - /// <td>0x00</td>
197   - /// <td>0x00</td>
198   - /// </tr>
199   - /// </table>
  212 + /// <p>
  213 + /// This command sets the logical data (And what the hell is this?...):
  214 + /// <table>
  215 + /// <tr>
  216 + /// <td>0x08</td>
  217 + /// <td>0x0f</td>
  218 + /// <td>Data | 0x01</td>
  219 + /// <td>0x00</td>
  220 + /// <td>0x00</td>
  221 + /// <td>0x00</td>
  222 + /// <td>0x00</td>
  223 + /// <td>0x00</td>
  224 + /// </tr>
  225 + /// </table>
  226 + /// </p>
200 227 COMMAND_SETLOGICALDATA,
201 228  
202   - /// This command reads the logical data (And what the hell is this?...):
203   - /// <table>
204   - /// <tr>
205   - /// <td>0x09</td>
206   - /// <td>0x00</td>
207   - /// </tr>
208   - /// </table>
209   - /// The oscilloscope returns the logical data, which is 64 or 512 bytes long:
210   - /// <table>
211   - /// <tr>
212   - /// <td>?</td>
213   - /// <td>?</td>
214   - /// <td>?</td>
215   - /// <td>...</td>
216   - /// </tr>
217   - /// </table>
  229 + /// <p>
  230 + /// This command reads the logical data (And what the hell is this?...):
  231 + /// <table>
  232 + /// <tr>
  233 + /// <td>0x09</td>
  234 + /// <td>0x00</td>
  235 + /// </tr>
  236 + /// </table>
  237 + /// </p>
  238 + /// <p>
  239 + /// The oscilloscope returns the logical data, which is 64 or 512 bytes long:
  240 + /// <table>
  241 + /// <tr>
  242 + /// <td>?</td>
  243 + /// <td>?</td>
  244 + /// <td>?</td>
  245 + /// <td>...</td>
  246 + /// </tr>
  247 + /// </table>
  248 + /// </p>
218 249 COMMAND_GETLOGICALDATA,
219 250  
220   - /// This command isn't used for the DSO-2090 and DSO-5200:
221   - /// <table>
222   - /// <tr>
223   - /// <td>0x0a</td>
224   - /// <td>...</td>
225   - /// </tr>
226   - /// </table>
  251 + /// <p>
  252 + /// This command isn't used for the DSO-2090 and DSO-5200:
  253 + /// <table>
  254 + /// <tr>
  255 + /// <td>0x0a</td>
  256 + /// <td>...</td>
  257 + /// </tr>
  258 + /// </table>
  259 + /// </p>
227 260 COMMAND_UNKNOWN_0A,
228 261  
229   - /// This command isn't used for the DSO-2090 and DSO-5200:
230   - /// <table>
231   - /// <tr>
232   - /// <td>0x0b</td>
233   - /// <td>...</td>
234   - /// </tr>
235   - /// </table>
  262 + /// <p>
  263 + /// This command isn't used for the DSO-2090 and DSO-5200:
  264 + /// <table>
  265 + /// <tr>
  266 + /// <td>0x0b</td>
  267 + /// <td>...</td>
  268 + /// </tr>
  269 + /// </table>
  270 + /// </p>
236 271 COMMAND_UNKNOWN_0B,
237 272  
238   - /// This command seems to set the sampling rate for the DSO-5200:
239   - /// <table>
240   - /// <tr>
241   - /// <td>0x0c</td>
242   - /// <td>0x00</td>
243   - /// <td>Samplerate[0] (?)</td>
244   - /// <td>Samplerate[1] (?)</td>
245   - /// <td>Tsr1.samplerateFast replacement (?)</td>
246   - /// <td>0x00</td>
247   - /// </tr>
248   - /// </table>
  273 + /// <p>
  274 + /// This command sets the sampling rate for the DSO-5200:
  275 + /// <table>
  276 + /// <tr>
  277 + /// <td>0x0c</td>
  278 + /// <td>0x00</td>
  279 + /// <td>SamplerateSlow[0]</td>
  280 + /// <td>SamplerateSlow[1]</td>
  281 + /// <td>SamplerateFast</td>
  282 + /// <td>0x00</td>
  283 + /// </tr>
  284 + /// </table>
  285 + /// </p>
  286 + /// <p>
  287 + /// The values are similar to the ones used on the DSO-2090. The formula is a bit different here:<br />
  288 + /// <i>Samplerate = SamplerateMax / (2comp(SamplerateSlow) * 2 + 4 - SamplerateFast)</i><br />
  289 + /// SamplerateMax is 125 MHz for the DSO-5200 in default configuration though, the modifications regarding fast rate and buffer size are the the same that apply for the DSO-2090.
  290 + /// </p>
249 291 COMMAND_SETSAMPLERATE5200,
250 292  
251   - /// This command seems to set trigger settings for the DSO-5200:
252   - /// <table>
253   - /// <tr>
254   - /// <td>0x0d</td>
255   - /// <td>0x00</td>
256   - /// <td>Unknown</td>
257   - /// <td>Unknown</td>
258   - /// <td>TriggerPoint (?)</td>
259   - /// <td>0xff</td>
260   - /// <td>TriggerPoint (?)</td>
261   - /// <td>0xff</td>
262   - /// <td>TriggerPoint (?)</td>
263   - /// <td>0xff</td>
264   - /// </tr>
265   - /// </table>
266   - COMMAND_DSO5200_0D,
  293 + /// <p>
  294 + /// This command sets the trigger position and buffer size for the DSO-5200:
  295 + /// <table>
  296 + /// <tr>
  297 + /// <td>0x0d</td>
  298 + /// <td>0x00</td>
  299 + /// <td>TriggerPositionPre[0]</td>
  300 + /// <td>TriggerPositionPre[1]</td>
  301 + /// <td>#DTriggerPositionUsed</td>
  302 + /// </tr>
  303 + /// </table>
  304 + /// <table>
  305 + /// <tr>
  306 + /// <td>0xff</td>
  307 + /// <td>TriggerPositionPost[0]</td>
  308 + /// <td>TriggerPositionPost[1]</td>
  309 + /// <td>DBufferBits</td>
  310 + /// <td>0xff</td>
  311 + /// </tr>
  312 + /// </table>
  313 + /// </p>
  314 + /// <p>
  315 + /// 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%.
  316 + /// </p>
  317 + COMMAND_SETBUFFER5200,
267 318  
268   - /// This command seems to set some additional settings for the DSO-5200:
269   - /// <table>
270   - /// <tr>
271   - /// <td>0x0e</td>
272   - /// <td>0x00</td>
273   - /// <td>Unknown</td>
274   - /// <td>0x00</td>
275   - /// <td>Unknown</td>
276   - /// <td>0x00</td>
277   - /// <td>0x00</td>
278   - /// <td>0x00</td>
279   - /// </tr>
280   - /// </table>
281   - COMMAND_DSO5200_0E,
  319 + /// <p>
  320 + /// This command sets the channel and trigger settings for the DSO-5200:
  321 + /// <table>
  322 + /// <tr>
  323 + /// <td>0x0e</td>
  324 + /// <td>0x00</td>
  325 + /// <td>ETsrBits</td>
  326 + /// <td>0x00</td>
  327 + /// <td>Unknown (0x02)</td>
  328 + /// <td>0x00</td>
  329 + /// <td>0x00</td>
  330 + /// <td>0x00</td>
  331 + /// </tr>
  332 + /// </table>
  333 + /// </p>
  334 + COMMAND_SETTRIGGER5200,
282 335  
283 336 COMMAND_COUNT ///< Total number of commands
284 337 };
... ... @@ -466,6 +519,7 @@ namespace Hantek {
466 519 /// \brief The size of the sample buffer.
467 520 enum BufferSize {
468 521 BUFFER_SMALL = 10240,
  522 + BUFFER_LARGE5200 = 14336,
469 523 BUFFER_LARGE = 32768
470 524 };
471 525  
... ... @@ -473,9 +527,9 @@ namespace Hantek {
473 527 /// \enum BufferSizeId hantek/types.h
474 528 /// \brief The size id for CommandSetTriggerAndSamplerate.
475 529 enum BufferSizeId {
476   - BUFFERID_ROLL = 0,
477   - BUFFERID_SMALL,
478   - BUFFERID_LARGE
  530 + BUFFERID_ROLL = 0, ///< Used for the roll mode
  531 + BUFFERID_SMALL, ///< The standard buffer with 10240 samples
  532 + BUFFERID_LARGE ///< The large buffer, 32768 samples (14336 for DSO-5200)
479 533 };
480 534  
481 535 //////////////////////////////////////////////////////////////////////////////
... ... @@ -510,6 +564,22 @@ namespace Hantek {
510 564 };
511 565  
512 566 //////////////////////////////////////////////////////////////////////////////
  567 + /// \enum DTriggerPositionUsed hantek/types.h
  568 + /// \brief The trigger position states for the 0x0d command.
  569 + enum DTriggerPositionUsed {
  570 + DTRIGGERPOSITION_OFF = 0, ///< Used for Roll mode
  571 + DTRIGGERPOSITION_ON = 7 ///< Used for normal operation
  572 + };
  573 +
  574 + //////////////////////////////////////////////////////////////////////////////
  575 + /// \enum EUsedChannels hantek/types.h
  576 + /// \brief The enabled channels in command 0x0e.
  577 + enum EUsedChannels {
  578 + EUSED_CH1 = 2, EUSED_CH2 = 3,
  579 + EUSED_CH1CH2 = 0
  580 + };
  581 +
  582 + //////////////////////////////////////////////////////////////////////////////
513 583 /// \struct FilterBits hantek/types.h
514 584 /// \brief The bits for COMMAND_SETFILTER.
515 585 struct FilterBits {
... ... @@ -520,14 +590,6 @@ namespace Hantek {
520 590 };
521 591  
522 592 //////////////////////////////////////////////////////////////////////////////
523   - /// \union FilterByte hantek/types.h
524   - /// \brief Allows to read the FilterBits as unsigned char.
525   - union FilterByte {
526   - FilterBits bits; ///< Bitfield representation
527   - unsigned char byte; ///< Full byte as unsigned char
528   - };
529   -
530   - //////////////////////////////////////////////////////////////////////////////
531 593 /// \struct GainBits hantek/types.h
532 594 /// \brief The gain bits for COMMAND_SETGAIN.
533 595 struct GainBits {
... ... @@ -537,46 +599,42 @@ namespace Hantek {
537 599 };
538 600  
539 601 //////////////////////////////////////////////////////////////////////////////
540   - /// \union GainByte hantek/types.h
541   - /// \brief Allows to read the GainBits as unsigned char.
542   - union GainByte {
543   - GainBits bits; ///< Bitfield representation
544   - unsigned char byte; ///< Full byte as unsigned char
545   - };
546   -
547   - //////////////////////////////////////////////////////////////////////////////
548 602 /// \struct Tsr1Bits hantek/types.h
549 603 /// \brief Trigger and samplerate bits (Byte 1).
550 604 struct Tsr1Bits {
551 605 unsigned char triggerSource:2; ///< The trigger source, see Hantek::TriggerSource
552   - unsigned char sampleSize:3; ///< Buffer size, 0 = Roll, 1 = 10240 S, 2 = 32768 S
  606 + unsigned char bufferSize:3; ///< See #BufferSizeId
553 607 unsigned char samplerateFast:3; ///< samplerate value for fast sampling rates
554 608 };
555 609  
556 610 //////////////////////////////////////////////////////////////////////////////
557   - /// \union Tsr1Byte hantek/types.h
558   - /// \brief Allows to read the Tsr1Bits as unsigned char.
559   - union Tsr1Byte {
560   - Tsr1Bits bits; ///< Bitfield representation.
561   - unsigned char byte; ///< Full byte as unsigned char.
562   - };
563   -
564   - //////////////////////////////////////////////////////////////////////////////
565 611 /// \struct Tsr2Bits hantek/types.h
566 612 /// \brief Trigger and samplerate bits (Byte 2).
567 613 struct Tsr2Bits {
568   - unsigned char usedChannel:2; ///< Used channels, see Hantek::UsedChannels
  614 + unsigned char usedChannels:2; ///< Used channels, see Hantek::UsedChannels
569 615 unsigned char fastRate:1; ///< true, if one channels uses all buffers
570 616 unsigned char triggerSlope:1; ///< The trigger slope, see Dso::Slope, inverted when Tsr1Bits.samplerateFast is uneven
571 617 unsigned char reserved:4; ///< Unused bits
572 618 };
573 619  
574 620 //////////////////////////////////////////////////////////////////////////////
575   - /// \union Tsr2Byte hantek/types.h
576   - /// \brief Allows to read the Tsr2Bits as unsigned char.
577   - union Tsr2Byte {
578   - Tsr2Bits bits; ///< Bitfield representation
579   - unsigned char byte; ///< Full byte as unsigned char
  621 + /// \struct DBufferBits hantek/types.h
  622 + /// \brief Buffer mode bits for 0x0d command.
  623 + struct DBufferBits {
  624 + unsigned char triggerPositionUsed:3; ///< See #DTriggerPositionUsed
  625 + unsigned char bufferSize:3; ///< See #BufferSizeId
  626 + unsigned char reserved:2; ///< Unused bits
  627 + };
  628 +
  629 + //////////////////////////////////////////////////////////////////////////////
  630 + /// \struct ETsrBits hantek/types.h
  631 + /// \brief Trigger and samplerate bits for 0x0e command.
  632 + struct ETsrBits {
  633 + unsigned char fastRate:1; ///< false, if one channels uses all buffers
  634 + unsigned char usedChannels:2; ///< Used channels, see Hantek::EUsedChannels
  635 + unsigned char triggerSource:2; ///< The trigger source, see Hantek::TriggerSource
  636 + unsigned char triggerSlope:2; ///< The trigger slope, see Dso::Slope
  637 + unsigned char triggerPulse:1; ///< Pulses are causing trigger events
580 638 };
581 639  
582 640 //////////////////////////////////////////////////////////////////////////////
... ... @@ -602,7 +660,7 @@ namespace Hantek {
602 660 class CommandSetTriggerAndSamplerate : public Helper::DataArray<unsigned char> {
603 661 public:
604 662 CommandSetTriggerAndSamplerate();
605   - CommandSetTriggerAndSamplerate(unsigned short int samplerate, unsigned long int triggerPosition, unsigned char triggerSource = 0, unsigned char sampleSize = 0, unsigned char timebaseFast = 0, unsigned char usedChannel = 0, bool fastRate = false, unsigned char triggerSlope = 0);
  663 + CommandSetTriggerAndSamplerate(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);
606 664  
607 665 unsigned char getTriggerSource();
608 666 void setTriggerSource(unsigned char value);
... ... @@ -610,13 +668,13 @@ namespace Hantek {
610 668 void setBufferSize(unsigned char value);
611 669 unsigned char getSamplerateFast();
612 670 void setSamplerateFast(unsigned char value);
613   - unsigned char getUsedChannel();
614   - void setUsedChannel(unsigned char value);
  671 + unsigned char getUsedChannels();
  672 + void setUsedChannels(unsigned char value);
615 673 bool getFastRate();
616 674 void setFastRate(bool fastRate);
617 675 unsigned char getTriggerSlope();
618 676 void setTriggerSlope(unsigned char slope);
619   - unsigned short int getSamplerate();
  677 + unsigned short int getSamplerateSlow();
620 678 void setSamplerateSlow(unsigned short int samplerate);
621 679 unsigned long int getTriggerPosition();
622 680 void setTriggerPosition(unsigned long int position);
... ... @@ -771,6 +829,69 @@ namespace Hantek {
771 829 bool getTrigger();
772 830 void setTrigger(bool ext);
773 831 };
  832 +
  833 + //////////////////////////////////////////////////////////////////////////////
  834 + /// \class CommandSetSamplerate5200 hantek/types.h
  835 + /// \brief The COMMAND_SETSAMPLERATE5200 builder.
  836 + class CommandSetSamplerate5200 : public Helper::DataArray<unsigned char> {
  837 + public:
  838 + CommandSetSamplerate5200();
  839 + CommandSetSamplerate5200(unsigned short int samplerateSlow, unsigned char samplerateFast);
  840 +
  841 + unsigned char getSamplerateFast();
  842 + void setSamplerateFast(unsigned char value);
  843 + unsigned short int getSamplerateSlow();
  844 + void setSamplerateSlow(unsigned short int samplerate);
  845 +
  846 + private:
  847 + void init();
  848 + };
  849 +
  850 + //////////////////////////////////////////////////////////////////////////////
  851 + /// \class CommandSetBuffer5200 hantek/types.h
  852 + /// \brief The COMMAND_SETBUFFER5200 builder.
  853 + class CommandSetBuffer5200 : public Helper::DataArray<unsigned char> {
  854 + public:
  855 + CommandSetBuffer5200();
  856 + CommandSetBuffer5200(unsigned short int triggerPositionPre, unsigned short int triggerPositionPost, unsigned char usedPre = 0, unsigned char usedPost = 0, unsigned char bufferSize = 0);
  857 +
  858 + unsigned short int getTriggerPositionPre();
  859 + void setTriggerPositionPre(unsigned short int value);
  860 + unsigned short int getTriggerPositionPost();
  861 + void setTriggerPositionPost(unsigned short int value);
  862 + unsigned char getUsedPre();
  863 + void setUsedPre(unsigned char value);
  864 + unsigned char getUsedPost();
  865 + void setUsedPost(unsigned char value);
  866 + unsigned char getBufferSize();
  867 + void setBufferSize(unsigned char value);
  868 +
  869 + private:
  870 + void init();
  871 + };
  872 +
  873 + //////////////////////////////////////////////////////////////////////////////
  874 + /// \class CommandSetTrigger5200 hantek/types.h
  875 + /// \brief The COMMAND_SETTRIGGER5200 builder.
  876 + class CommandSetTrigger5200 : public Helper::DataArray<unsigned char> {
  877 + public:
  878 + CommandSetTrigger5200();
  879 + CommandSetTrigger5200(unsigned char triggerSource, unsigned char usedChannels, bool fastRate = false, unsigned char triggerSlope = 0, unsigned char triggerPulse = 0);
  880 +
  881 + unsigned char getTriggerSource();
  882 + void setTriggerSource(unsigned char value);
  883 + unsigned char getUsedChannels();
  884 + void setUsedChannels(unsigned char value);
  885 + bool getFastRate();
  886 + void setFastRate(bool fastRate);
  887 + unsigned char getTriggerSlope();
  888 + void setTriggerSlope(unsigned char slope);
  889 + bool getTriggerPulse();
  890 + void setTriggerPulse(bool pulse);
  891 +
  892 + private:
  893 + void init();
  894 + };
774 895 }
775 896  
776 897  
... ...
openhantek/src/openhantek.cpp
... ... @@ -129,6 +129,8 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag
129 129 connect(this->dsoControl, SIGNAL(samplingStopped()), this, SLOT(stopped()));
130 130  
131 131 // Set up the oscilloscope
  132 + this->dsoControl->connectDevice();
  133 +
132 134 for(unsigned int channel = 0; channel < this->settings->scope.physicalChannels; channel++) {
133 135 this->dsoControl->setCoupling(channel, (Dso::Coupling) this->settings->scope.voltage[channel].misc);
134 136 this->updateVoltageGain(channel);
... ... @@ -143,7 +145,6 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag
143 145 this->dsoControl->setTriggerSlope(this->settings->scope.trigger.slope);
144 146 this->dsoControl->setTriggerSource(this->settings->scope.trigger.special, this->settings->scope.trigger.source);
145 147  
146   - this->dsoControl->connectDevice();
147 148 this->dsoControl->startSampling();
148 149 }
149 150  
... ...