From d19a946c759740a84766fe90c47420690e4cc7e4 Mon Sep 17 00:00:00 2001 From: Teuniz Date: Sun, 7 Jun 2015 21:34:20 +0200 Subject: [PATCH] Work in progress. --- interface.cpp | 264 +++++++++++++++++++++++++++++++++++++++++- mainwindow.cpp | 6 + mainwindow.h | 26 +++++ mainwindow_constr.cpp | 4 +- notes.txt | 12 +- save_data.cpp | 240 ++++++++++++++++++++++++++++---------- 6 files changed, 476 insertions(+), 76 deletions(-) diff --git a/interface.cpp b/interface.cpp index bc3bb53..fa2b013 100644 --- a/interface.cpp +++ b/interface.cpp @@ -181,18 +181,272 @@ void UI_Mainwindow::navDialReleased() void UI_Mainwindow::acqButtonClicked() { - QMenu menu, - submenuacquisition; + int chn, + chns_on=0; - submenuacquisition.setTitle("Acquisition"); + QMenu menu, + submenuacquisition, + submenumemdepth; + + for(chn=0; chnmapToGlobal(QPoint(0,0))); } +void UI_Mainwindow::set_memdepth_auto() +{ + statusLabel->setText("Memory depth: auto"); + + tmcdev_write(device, ":ACQ:MDEP AUTO"); +} + + +void UI_Mainwindow::set_memdepth_12k() +{ + statusLabel->setText("Memory depth: 12k"); + + tmcdev_write(device, ":ACQ:MDEP 12000"); +} + + +void UI_Mainwindow::set_memdepth_120k() +{ + statusLabel->setText("Memory depth: 120k"); + + tmcdev_write(device, ":ACQ:MDEP 120000"); +} + + +void UI_Mainwindow::set_memdepth_1200k() +{ + statusLabel->setText("Memory depth: 1.2M"); + + tmcdev_write(device, ":ACQ:MDEP 1200000"); +} + + +void UI_Mainwindow::set_memdepth_12m() +{ + statusLabel->setText("Memory depth: 12M"); + + tmcdev_write(device, ":ACQ:MDEP 12000000"); +} + + +void UI_Mainwindow::set_memdepth_24m() +{ + statusLabel->setText("Memory depth: 24M"); + + tmcdev_write(device, ":ACQ:MDEP 24000000"); +} + + +void UI_Mainwindow::set_memdepth_3k() +{ + statusLabel->setText("Memory depth: 3K"); + + tmcdev_write(device, ":ACQ:MDEP 3000"); +} + + +void UI_Mainwindow::set_memdepth_30k() +{ + statusLabel->setText("Memory depth: 30K"); + + tmcdev_write(device, ":ACQ:MDEP 30000"); +} + + +void UI_Mainwindow::set_memdepth_300k() +{ + statusLabel->setText("Memory depth: 300K"); + + tmcdev_write(device, ":ACQ:MDEP 300000"); +} + + +void UI_Mainwindow::set_memdepth_3m() +{ + statusLabel->setText("Memory depth: 3M"); + + tmcdev_write(device, ":ACQ:MDEP 3000000"); +} + + +void UI_Mainwindow::set_memdepth_6m() +{ + statusLabel->setText("Memory depth: 6M"); + + tmcdev_write(device, ":ACQ:MDEP 6000000"); +} + + +void UI_Mainwindow::set_memdepth_6k() +{ + statusLabel->setText("Memory depth: 6K"); + + tmcdev_write(device, ":ACQ:MDEP 6000"); +} + + +void UI_Mainwindow::set_memdepth_60k() +{ + statusLabel->setText("Memory depth: 60K"); + + tmcdev_write(device, ":ACQ:MDEP 60000"); +} + + +void UI_Mainwindow::set_memdepth_600k() +{ + statusLabel->setText("Memory depth: 600K"); + + tmcdev_write(device, ":ACQ:MDEP 600000"); +} + + +void UI_Mainwindow::set_memdepth_7k() +{ + statusLabel->setText("Memory depth: 7k"); + + tmcdev_write(device, ":ACQ:MDEP 7000"); +} + + +void UI_Mainwindow::set_memdepth_70k() +{ + statusLabel->setText("Memory depth: 70k"); + + tmcdev_write(device, ":ACQ:MDEP 70000"); +} + + +void UI_Mainwindow::set_memdepth_700k() +{ + statusLabel->setText("Memory depth: 700K"); + + tmcdev_write(device, ":ACQ:MDEP 700000"); +} + + +void UI_Mainwindow::set_memdepth_7m() +{ + statusLabel->setText("Memory depth: 7M"); + + tmcdev_write(device, ":ACQ:MDEP 7000000"); +} + + +void UI_Mainwindow::set_memdepth_70m() +{ + statusLabel->setText("Memory depth: 70M"); + + tmcdev_write(device, ":ACQ:MDEP 70000000"); +} + + +void UI_Mainwindow::set_memdepth_14k() +{ + statusLabel->setText("Memory depth: 14k"); + + tmcdev_write(device, ":ACQ:MDEP 14000"); +} + + +void UI_Mainwindow::set_memdepth_140k() +{ + statusLabel->setText("Memory depth: 140k"); + + tmcdev_write(device, ":ACQ:MDEP 140000"); +} + + +void UI_Mainwindow::set_memdepth_1400k() +{ + statusLabel->setText("Memory depth: 1.4M"); + + tmcdev_write(device, ":ACQ:MDEP 1400000"); +} + + +void UI_Mainwindow::set_memdepth_14m() +{ + statusLabel->setText("Memory depth: 14M"); + + tmcdev_write(device, ":ACQ:MDEP 14000000"); +} + + +void UI_Mainwindow::set_memdepth_140m() +{ + statusLabel->setText("Memory depth: 140M"); + + tmcdev_write(device, ":ACQ:MDEP 140000000"); +} + + void UI_Mainwindow::set_acq_normal() { if(devparms.acquiretype == 0) @@ -241,7 +495,7 @@ void UI_Mainwindow::saveButtonClicked() QMenu menu; menu.addAction("Save screen waveform", this, SLOT(save_screen_waveform())); -// menu.addAction("Save memory waveform", this, SLOT(save_memory_waveform())); + menu.addAction("Save memory waveform", this, SLOT(save_memory_waveform())); menu.addAction("Save screenshot", this, SLOT(save_screenshot())); menu.exec(saveButton->mapToGlobal(QPoint(0,0))); @@ -308,7 +562,7 @@ void UI_Mainwindow::set_grid_type_dots() devparms.displaytype = 1; - statusLabel->setText("Display type: dotss"); + statusLabel->setText("Display type: dots"); tmcdev_write(device, ":DISP:TYPE DOTS"); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 2bfd487..2b02e89 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -214,6 +214,12 @@ void UI_Mainwindow::open_connection() devparms.screen_timer_ival = 50; } + else + { + devparms.status_timer_ival = 500; + + devparms.screen_timer_ival = 2000; + } connect(adjDial, SIGNAL(valueChanged(int)), this, SLOT(adjDialChanged(int))); connect(trigAdjustDial, SIGNAL(valueChanged(int)), this, SLOT(trigAdjustDialChanged(int))); diff --git a/mainwindow.h b/mainwindow.h index d3893e8..629b7e3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -313,6 +314,31 @@ private slots: void set_acq_normal(); void set_acq_average(); + void set_memdepth_auto(); + void set_memdepth_12k(); + void set_memdepth_120k(); + void set_memdepth_1200k(); + void set_memdepth_12m(); + void set_memdepth_24m(); + void set_memdepth_6k(); + void set_memdepth_60k(); + void set_memdepth_600k(); + void set_memdepth_6m(); + void set_memdepth_3k(); + void set_memdepth_30k(); + void set_memdepth_300k(); + void set_memdepth_3m(); + void set_memdepth_7k(); + void set_memdepth_70k(); + void set_memdepth_700k(); + void set_memdepth_7m(); + void set_memdepth_70m(); + void set_memdepth_14k(); + void set_memdepth_140k(); + void set_memdepth_1400k(); + void set_memdepth_14m(); + void set_memdepth_140m(); + protected: void closeEvent(QCloseEvent *); diff --git a/mainwindow_constr.cpp b/mainwindow_constr.cpp index 49f0dd6..229759b 100644 --- a/mainwindow_constr.cpp +++ b/mainwindow_constr.cpp @@ -73,9 +73,9 @@ UI_Mainwindow::UI_Mainwindow() devparms.hordivisions = 14; - devparms.status_timer_ival = 200; + devparms.status_timer_ival = 500; - devparms.screen_timer_ival = 500; + devparms.screen_timer_ival = 2000; menubar = menuBar(); diff --git a/notes.txt b/notes.txt index a97942c..0a29403 100644 --- a/notes.txt +++ b/notes.txt @@ -19,7 +19,7 @@ There are some peculiarities when testing with the DS6104 and the DS1054Z: DS6104: ====== -Full-speed USB (12MBit) +USB connection: full speed (12MBit) Reading screen data is pretty fast, 20 waveforms per second is easily possible. Reading a screenshot in BMP format is slow, approx. 3 seconds. Needs a usbtmc driver patch, needs to add an udev rule. @@ -27,8 +27,9 @@ Needs a usbtmc driver patch, needs to add an udev rule. DS1054Z: (softversion 00.04.02.SP4, boardversion 0.1.1) ======= -High-speed USB (480 Mbit) -Reading screen data is slow, maximum 7 waveforms per second. +USB connection: high speed (480 Mbit) +Reading screen data is slow, maximum 7 waveforms per second with one channel. +With all channels switched on, screen updates are very slow. Reading a screenshot in BMP format is faster, less than one second. No need to patch the usbtmc driver, no need to add an udev rule. It's plug and play. @@ -82,11 +83,12 @@ What's implemented so far: - acquire normal - acquire average +- acquire memory depth - save screenshot -- save display data (raw waveform, the part that is visible on the screen) - saving deep memory is not yet implemented +- save display data +- save memory data fileformat for waveform data is EDF, these files can be read by lots of viewers and analyzing software like EDFbrowser, Scilab, Octave, Matlab, Labview, etc. diff --git a/save_data.cpp b/save_data.cpp index 516413c..a3f47c1 100644 --- a/save_data.cpp +++ b/save_data.cpp @@ -26,6 +26,8 @@ */ +#define SAV_MEM_BSZ (250000) + void UI_Mainwindow::save_screenshot() @@ -157,14 +159,25 @@ OUT_ERROR: void UI_Mainwindow::save_memory_waveform() { - int i, j, k, n=0, chns=0, hdl=-1, yoffset[MAX_CHNS], bytes_rcvd, blocksz; + int i, j, k, + n=0, + chn, + chns=0, + hdl=-1, + bytes_rcvd, + mempnts, + yref[MAX_CHNS], + yor[MAX_CHNS], + smps_per_record, + datrecs=1; char str[128], opath[MAX_PATHLEN]; short *wavbuf[4]; - double rec_len = 0; + double rec_len = 0, + yinc[MAX_CHNS]; if(device == NULL) { @@ -176,11 +189,46 @@ void UI_Mainwindow::save_memory_waveform() wavbuf[2] = NULL; wavbuf[3] = NULL; - rec_len = devparms.memdepth / devparms.samplerate; + mempnts = devparms.memdepth; - QApplication::setOverrideCursor(Qt::WaitCursor); + smps_per_record = mempnts; - qApp->processEvents(); + QProgressDialog progress("Downloading data...", "Abort", 0, mempnts, this); + progress.setWindowModality(Qt::WindowModal); + progress.setMinimumDuration(100); + + statusLabel->setText("Downloading data..."); + + for(i=0; i= (5000000 / chns)) + { + smps_per_record /= 2; + + datrecs *= 2; + } + + if(mempnts < 1) + { + strcpy(str, "Can not save waveform when memory depth is set to \"Auto\"."); + goto OUT_ERROR; + } + + rec_len = mempnts / devparms.samplerate; if(rec_len < 1e-6) { @@ -195,20 +243,12 @@ void UI_Mainwindow::save_memory_waveform() continue; } - wavbuf[i] = (short *)malloc(devparms.memdepth * sizeof(short)); + wavbuf[i] = (short *)malloc(mempnts * sizeof(short)); if(wavbuf[i] == NULL) { strcpy(str, "Malloc error."); goto OUT_ERROR; } - - chns++; - } - - if(!chns) - { - strcpy(str, "No active channels."); - goto OUT_ERROR; } scrn_timer->stop(); @@ -217,16 +257,14 @@ void UI_Mainwindow::save_memory_waveform() tmcdev_write(device, ":STOP"); - blocksz = 1000000; - - for(i=0; ibuf); + + if(yinc[chn] < 1e-6) + { + strcpy(str, "Error, parameter \"YINC\" out of range."); + goto OUT_ERROR; + } + + tmcdev_write(device, ":WAV:YREF?"); + + tmcdev_read(device); + + yref[chn] = atoi(device->buf); + + if((yref[chn] < 1) || (yref[chn] > 255)) + { + strcpy(str, "Error, parameter \"YREF\" out of range."); + goto OUT_ERROR; + } + + tmcdev_write(device, ":WAV:YOR?"); + + tmcdev_read(device); + + yor[chn] = atoi(device->buf); + + if((yor[chn] < -255) || (yor[chn] > 255)) + { + strcpy(str, "Error, parameter \"YOR\" out of range."); + goto OUT_ERROR; + } + bytes_rcvd = 0; for(j=0; ; j++) { - sprintf(str, ":WAV:STAR %i", (j * blocksz) + 1); + progress.setValue(bytes_rcvd); + + qApp->processEvents(); + + if(progress.wasCanceled()) + { + strcpy(str, "Canceled"); + goto OUT_ERROR; + } + + sprintf(str, ":WAV:STAR %i", (j * SAV_MEM_BSZ) + 1); tmcdev_write(device, str); - if(((j + 1) * blocksz) > devparms.memdepth) + if(((j + 1) * SAV_MEM_BSZ) > mempnts) { - sprintf(str, ":WAV:STOP %i", devparms.memdepth); + sprintf(str, ":WAV:STOP %i", mempnts); } else { - sprintf(str, ":WAV:STOP %i", (j + 1) * blocksz); + sprintf(str, ":WAV:STOP %i", (j + 1) * SAV_MEM_BSZ); } tmcdev_write(device, str); @@ -265,7 +349,7 @@ void UI_Mainwindow::save_memory_waveform() printf("received %i bytes\n", n); - if(n > blocksz) + if(n > SAV_MEM_BSZ) { strcpy(str, "Datablock too big for buffer."); goto OUT_ERROR; @@ -278,33 +362,38 @@ void UI_Mainwindow::save_memory_waveform() bytes_rcvd += n; - if(bytes_rcvd >= devparms.memdepth) + for(k=0; kbuf)[k]) - yref[chn]; + } + + if(bytes_rcvd >= mempnts) { break; } - -// yoffset[i] = ((devparms.chanoffset[i] / devparms.chanscale[i]) * 25.0); - - for(k=0; kbuf)[k]) - 127; - -// wavbuf[i][k] -= yoffset[k]; - } } } + progress.reset(); + tmcdev_write(device, ":WAV:MODE NORM"); tmcdev_write(device, ":WAV:STAR 1"); - tmcdev_write(device, ":WAV:STOP 1200"); + if(devparms.modelserie == 1) + { + tmcdev_write(device, ":WAV:STOP 1200"); + } + else + { + tmcdev_write(device, ":WAV:STOP 1400"); + } stat_timer->start(devparms.status_timer_ival); scrn_timer->start(devparms.screen_timer_ival); - QApplication::restoreOverrideCursor(); + statusLabel->setText("Downloading finished"); opath[0] = 0; if(recent_savedir[0]!=0) @@ -330,7 +419,7 @@ void UI_Mainwindow::save_memory_waveform() goto OUT_ERROR; } - if(edf_set_double_datarecord_duration(hdl, rec_len)) + if(edf_set_double_datarecord_duration(hdl, rec_len / datrecs)) { strcpy(str, "Can not set datarecord duration of EDF file."); goto OUT_ERROR; @@ -338,29 +427,29 @@ void UI_Mainwindow::save_memory_waveform() j = 0; - for(i=0; i 2) + if(devparms.chanscale[chn] > 2) { - edf_set_physical_maximum(hdl, j, (devparms.chanscale[i] / 25) * 32767); - edf_set_physical_minimum(hdl, j, (devparms.chanscale[i] / 25) * 32767); + edf_set_physical_maximum(hdl, j, yinc[chn] * 32767); + edf_set_physical_minimum(hdl, j, yinc[chn] * 32767); edf_set_physical_dimension(hdl, j, "V"); } else { - edf_set_physical_maximum(hdl, j, 1000 * (devparms.chanscale[i] / 25) * 32767); - edf_set_physical_minimum(hdl, j, 1000 * (devparms.chanscale[i] / 25) * -32768); + edf_set_physical_maximum(hdl, j, 1000 * yinc[chn] * 32767); + edf_set_physical_minimum(hdl, j, 1000 * yinc[chn] * -32768); edf_set_physical_dimension(hdl, j, "mV"); } - sprintf(str, "CHAN%i", i + 1); + sprintf(str, "CHAN%i", chn + 1); edf_set_label(hdl, j, str); j++; @@ -368,17 +457,20 @@ void UI_Mainwindow::save_memory_waveform() edf_set_equipment(hdl, devparms.modelname); - for(i=0; isetText("Downloading aborted"); + + if(progress.wasCanceled() == false) + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText(str); + msgBox.exec(); + } if(hdl >= 0) { edfclose_file(hdl); } - for(i=0; istart(devparms.status_timer_ival); scrn_timer->start(devparms.screen_timer_ival); @@ -556,6 +666,8 @@ void UI_Mainwindow::save_screen_waveform() QApplication::setOverrideCursor(Qt::WaitCursor); + qApp->processEvents(); + n = tmcdev_read(device); QApplication::restoreOverrideCursor();