void UI_Mainwindow::save_screen_waveform() { int i, j, n=0, chn, chns=0, hdl=-1, yref[MAX_CHNS], yor[MAX_CHNS]; char str[128], opath[MAX_PATHLEN]; short *wavbuf[4]; long long rec_len=0LL; double yinc[MAX_CHNS]; if(device == NULL) { return; } wavbuf[0] = NULL; wavbuf[1] = NULL; wavbuf[2] = NULL; wavbuf[3] = NULL; scrn_timer->stop(); scrn_thread->wait(); if(devparms.timebasedelayenable) { rec_len = EDFLIB_TIME_DIMENSION * devparms.timebasedelayscale * devparms.hordivisions; } else { rec_len = EDFLIB_TIME_DIMENSION * devparms.timebasescale * devparms.hordivisions; } if(rec_len < 10LL) { strcpy(str, "Can not save waveforms when timebase < 1uSec."); goto OUT_ERROR; } for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) // Download data only when channel is switched on { continue; } wavbuf[chn] = (short *)malloc(WAVFRM_MAX_BUFSZ * sizeof(short)); if(wavbuf[chn] == NULL) { strcpy(str, "Malloc error."); goto OUT_ERROR; } chns++; } if(!chns) { strcpy(str, "No active channels."); goto OUT_ERROR; } for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) // Download data only when channel is switched on { continue; } usleep(20000); sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); tmc_write(str); usleep(20000); tmc_write(":WAV:FORM BYTE"); usleep(20000); tmc_write(":WAV:MODE NORM"); usleep(20000); tmc_write(":WAV:YINC?"); usleep(20000); tmc_read(); yinc[chn] = atof(device->buf); if(yinc[chn] < 1e-6) { sprintf(str, "Error, parameter \"YINC\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } usleep(20000); tmc_write(":WAV:YREF?"); usleep(20000); tmc_read(); yref[chn] = atoi(device->buf); if((yref[chn] < 1) || (yref[chn] > 255)) { sprintf(str, "Error, parameter \"YREF\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } usleep(20000); tmc_write(":WAV:YOR?"); usleep(20000); tmc_read(); yor[chn] = atoi(device->buf); if((yor[chn] < -255) || (yor[chn] > 255)) { sprintf(str, "Error, parameter \"YOR\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } usleep(20000); tmc_write(":WAV:DATA?"); QApplication::setOverrideCursor(Qt::WaitCursor); qApp->processEvents(); n = tmc_read(); QApplication::restoreOverrideCursor(); if(n < 0) { strcpy(str, "Can not read from device."); goto OUT_ERROR; } if(n > WAVFRM_MAX_BUFSZ) { strcpy(str, "Datablock too big for buffer."); goto OUT_ERROR; } if(n < 16) { strcpy(str, "Not enough data in buffer."); goto OUT_ERROR; } for(i=0; i<n; i++) { wavbuf[chn][i] = ((int)(((unsigned char *)device->buf)[i]) - yref[chn] - yor[chn]) << 5; } } opath[0] = 0; if(recent_savedir[0]!=0) { strcpy(opath, recent_savedir); strcat(opath, "/"); } strcat(opath, "waveform.edf"); strcpy(opath, QFileDialog::getSaveFileName(this, "Save file", opath, "EDF files (*.edf *.EDF)").toLocal8Bit().data()); if(!strcmp(opath, "")) { goto OUT_NORMAL; } get_directory_from_path(recent_savedir, opath, MAX_PATHLEN); hdl = edfopen_file_writeonly(opath, EDFLIB_FILETYPE_EDFPLUS, chns); if(hdl < 0) { strcpy(str, "Can not create EDF file."); goto OUT_ERROR; } if(edf_set_datarecord_duration(hdl, rec_len / 100LL)) { strcpy(str, "Can not set datarecord duration of EDF file."); goto OUT_ERROR; } j = 0; for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } edf_set_samplefrequency(hdl, j, n); edf_set_digital_maximum(hdl, j, 32767); edf_set_digital_minimum(hdl, j, -32768); if(devparms.chanscale[chn] > 2) { edf_set_physical_maximum(hdl, j, yinc[chn] * 32767.0 / 32.0); edf_set_physical_minimum(hdl, j, yinc[chn] * -32768.0 / 32.0); edf_set_physical_dimension(hdl, j, "V"); } else { edf_set_physical_maximum(hdl, j, 1000.0 * yinc[chn] * 32767.0 / 32.0); edf_set_physical_minimum(hdl, j, 1000.0 * yinc[chn] * -32768.0 / 32.0); edf_set_physical_dimension(hdl, j, "mV"); } sprintf(str, "CHAN%i", chn + 1); edf_set_label(hdl, j, str); j++; } edf_set_equipment(hdl, devparms.modelname); for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } if(edfwrite_digital_short_samples(hdl, wavbuf[chn])) { strcpy(str, "A write error occurred."); goto OUT_ERROR; } } OUT_NORMAL: if(hdl >= 0) { edfclose_file(hdl); } for(chn=0; chn<MAX_CHNS; chn++) { free(wavbuf[chn]); } scrn_timer->start(devparms.screentimerival); return; OUT_ERROR: QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); msgBox.setText(str); msgBox.exec(); if(hdl >= 0) { edfclose_file(hdl); } for(chn=0; chn<MAX_CHNS; chn++) { free(wavbuf[chn]); } scrn_timer->start(devparms.screentimerival); }
void UI_Mainwindow::save_screenshot() { int n; char str[128], opath[MAX_PATHLEN]; QPainter painter; #if QT_VERSION >= 0x050000 painter.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif QPainterPath path; if(device == NULL) { return; } scrn_timer->stop(); scrn_thread->wait(); tmc_write(":DISP:DATA?"); QApplication::setOverrideCursor(Qt::WaitCursor); qApp->processEvents(); n = tmc_read(); QApplication::restoreOverrideCursor(); if(n < 0) { strcpy(str, "Can not read from device."); goto OUT_ERROR; } if(device->sz != SCRN_SHOT_BMP_SZ) { strcpy(str, "Error, bitmap has wrong filesize\n"); goto OUT_ERROR; } if(strncmp(device->buf, "BM", 2)) { strcpy(str, "Error, file is not a bitmap\n"); goto OUT_ERROR; } memcpy(devparms.screenshot_buf, device->buf, SCRN_SHOT_BMP_SZ); screenXpm.loadFromData((uchar *)(devparms.screenshot_buf), SCRN_SHOT_BMP_SZ); if(devparms.modelserie == 1) { painter.begin(&screenXpm); painter.fillRect(0, 0, 80, 29, Qt::black); painter.setPen(Qt::white); painter.drawText(5, 8, 65, 20, Qt::AlignCenter, devparms.modelname); painter.end(); } else if(devparms.modelserie == 6) { painter.begin(&screenXpm); painter.fillRect(0, 0, 95, 29, QColor(48, 48, 48)); path.addRoundedRect(5, 5, 85, 20, 3, 3); painter.fillPath(path, Qt::black); painter.setPen(Qt::white); painter.drawText(5, 5, 85, 20, Qt::AlignCenter, devparms.modelname); painter.end(); } if(devparms.screenshot_inv) { screenXpm.invertPixels(QImage::InvertRgb); } opath[0] = 0; if(recent_savedir[0]!=0) { strcpy(opath, recent_savedir); strcat(opath, "/"); } strcat(opath, "screenshot.png"); strcpy(opath, QFileDialog::getSaveFileName(this, "Save file", opath, "PNG files (*.png *.PNG)").toLocal8Bit().data()); if(!strcmp(opath, "")) { scrn_timer->start(devparms.screentimerival); return; } get_directory_from_path(recent_savedir, opath, MAX_PATHLEN); if(screenXpm.save(QString::fromLocal8Bit(opath), "PNG", 50) == false) { strcpy(str, "Could not save file (unknown error)"); goto OUT_ERROR; } scrn_timer->start(devparms.screentimerival); return; OUT_ERROR: scrn_timer->start(devparms.screentimerival); QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); msgBox.setText(str); msgBox.exec(); }
void screen_thread::run() { int i, j, k, n=0, chns=0, line, cmd_sent=0; char str[128]; double y_incr, binsz; params.error_stat = 0; params.result = TMC_THRD_RESULT_NONE; params.job = TMC_THRD_JOB_NONE; params.wavebufsz = 0; if(device == NULL) { return; } if(h_busy) { return; } if(!params.connected) { h_busy = 0; return; } h_busy = 1; while(params.cmd_cue_idx_out != params.cmd_cue_idx_in) { usleep(TMC_GDS_DELAY); tmc_write(deviceparms->cmd_cue[params.cmd_cue_idx_out]); if(deviceparms->cmd_cue_resp[params.cmd_cue_idx_out] != NULL) { usleep(TMC_GDS_DELAY); if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } strncpy(deviceparms->cmd_cue_resp[params.cmd_cue_idx_out], device->buf, 128); deviceparms->cmd_cue_resp[params.cmd_cue_idx_out][127] = 0; } if((!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":TLHA", 5)) || ((!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":CHAN", 5)) && (!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out] + 6, ":SCAL ", 6)))) { usleep(TMC_GDS_DELAY); if(tmc_write(":TRIG:EDG:LEV?") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } params.triggeredgelevel = atof(device->buf); params.job = TMC_THRD_JOB_TRIGEDGELEV; } else if(!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":TIM:DEL:ENAB 1", 15)) { usleep(TMC_GDS_DELAY); if(tmc_write(":TIM:DEL:OFFS?") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } params.timebasedelayoffset = atof(device->buf); usleep(TMC_GDS_DELAY); if(tmc_write(":TIM:DEL:SCAL?") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } params.timebasedelayscale = atof(device->buf); params.job = TMC_THRD_JOB_TIMDELAY; } if(params.math_fft) { if((!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":TIM:SCAL ", 10)) || (!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":MATH:OPER FFT", 14)) || (!strncmp(deviceparms->cmd_cue[params.cmd_cue_idx_out], ":CALC:MODE FFT", 14))) { usleep(TMC_GDS_DELAY * 10); if(params.modelserie != 1) { if(tmc_write(":CALC:FFT:HSP?") != 14) { line = __LINE__; goto OUT_ERROR; } } else { if(tmc_write(":MATH:FFT:HSC?") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } } if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } params.math_fft_hscale = atof(device->buf); usleep(TMC_GDS_DELAY); if(params.modelserie != 1) { if(tmc_write(":CALC:FFT:HCEN?") != 15) { line = __LINE__; goto OUT_ERROR; } } else { if(tmc_write(":MATH:FFT:HCEN?") != 15) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } } if(tmc_read() < 1) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } params.math_fft_hcenter = atof(device->buf); params.job = TMC_THRD_JOB_FFTHZDIV; } } params.cmd_cue_idx_out++; params.cmd_cue_idx_out %= TMC_CMD_CUE_SZ; cmd_sent = 1; } if(cmd_sent) { h_busy = 0; params.result = TMC_THRD_RESULT_CMD; return; } params.error_stat = get_devicestatus(); if(params.error_stat) { h_busy = 0; return; } if(!params.connected) { h_busy = 0; return; } for(i=0; i<MAX_CHNS; i++) { if(!params.chandisplay[i]) // Download data only when channel is switched on { continue; } chns++; } if(!chns) { h_busy = 0; return; } params.result = TMC_THRD_RESULT_SCRN; //struct waveform_preamble wfp; // if(params.triggerstatus != 1) // Don't download waveform data when triggerstatus is "wait" if(1) { for(i=0; i<MAX_CHNS; i++) { if(!params.chandisplay[i]) // Download data only when channel is switched on { continue; } /////////////////////////////////////////////////////////// // tmc_write(":WAV:PRE?"); // // n = tmc_read(); // // if(n < 0) // { // strcpy(str, "Can not read from device."); // goto OUT_ERROR; // } // // printf("waveform preamble: %s\n", device->buf); // // if(parse_preamble(device->buf, device->sz, &wfp, i)) // { // strcpy(str, "Preamble parsing error."); // goto OUT_ERROR; // } // // printf("waveform preamble:\n" // "format: %i\n" // "type: %i\n" // "points: %i\n" // "count: %i\n" // "xincrement: %e\n" // "xorigin: %e\n" // "xreference: %e\n" // "yincrement: %e\n" // "yorigin: %e\n" // "yreference: %i\n", // wfp.format, wfp.type, wfp.points, wfp.count, // wfp.xincrement[i], wfp.xorigin[i], wfp.xreference[i], // wfp.yincrement[i], wfp.yorigin[i], wfp.yreference[i]); // // printf("chanoffset[] is %e\n", params.chanoffset[i]); // rec_len = wfp.xincrement[i] * wfp.points; /////////////////////////////////////////////////////////// sprintf(str, ":WAV:SOUR CHAN%i", i + 1); if(tmc_write(str) != 15) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_write(":WAV:FORM BYTE") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_write(":WAV:MODE NORM") != 14) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } if(tmc_write(":WAV:DATA?") != 10) { printf("Can not write to device.\n"); line = __LINE__; goto OUT_ERROR; } n = tmc_read(); if(n < 0) { printf("Can not read from device.\n"); line = __LINE__; goto OUT_ERROR; } if(n > WAVFRM_MAX_BUFSZ) { printf("Datablock too big for buffer.\n"); line = __LINE__; goto OUT_ERROR; } if(n < 32) { n = 0; } for(j=0; j<n; j++) { params.wavebuf[i][j] = (int)(((unsigned char *)device->buf)[j]) - 127; } if((n == (params.fftbufsz * 2)) && (params.math_fft == 1) && (i == params.math_fft_src)) { if(params.modelserie == 6) { y_incr = params.chanscale[i] / 32.0; } else { y_incr = params.chanscale[i] / 25.0; } binsz = (double)params.current_screen_sf / (params.fftbufsz * 2.0); for(j=0; j<n; j++) { params.fftbuf_in[j] = params.wavebuf[i][j] * y_incr; } kiss_fftr(params.k_cfg, params.fftbuf_in, params.kiss_fftbuf); for(k=0; k<params.fftbufsz; k++) { params.fftbuf_out[k] = (((params.kiss_fftbuf[k].r * params.kiss_fftbuf[k].r) + (params.kiss_fftbuf[k].i * params.kiss_fftbuf[k].i)) / params.fftbufsz); params.fftbuf_out[k] /= params.current_screen_sf; if(k==0) // DC! { params.fftbuf_out[k] /= 2.0; } params.fftbuf_out[k] *= binsz; if(params.math_fft_unit) // dBm { if(params.fftbuf_out[k] < SPECT_LOG_MINIMUM) { params.fftbuf_out[k] = SPECT_LOG_MINIMUM; } // convert to deciBel's, not to Bel's! params.fftbuf_out[k] = log10(params.fftbuf_out[k]) * 10.0; if(params.fftbuf_out[k] < SPECT_LOG_MINIMUM_LOG) { params.fftbuf_out[k] = SPECT_LOG_MINIMUM_LOG; } } else // Vrms { params.fftbuf_out[k] = sqrt(params.fftbuf_out[k]); } } } } params.wavebufsz = n; } else // triggerstatus is "wait" { params.wavebufsz = 0; } h_busy = 0; return; OUT_ERROR: params.result = TMC_THRD_RESULT_NONE; sprintf(str, "An error occurred while reading screen data from device.\n" "File %s line %i", __FILE__, line); h_busy = 0; params.error_line = line; params.error_stat = -1; return; }
void UI_Mainwindow::save_memory_waveform() { int i, j, k, n=0, chn, chns=0, hdl=-1, bytes_rcvd=0, mempnts, yref[MAX_CHNS], yor[MAX_CHNS], smps_per_record, datrecs=1, empty_buf; char str[128], opath[MAX_PATHLEN]; short *wavbuf[4]; long long rec_len=0LL; double yinc[MAX_CHNS]; if(device == NULL) { return; } scrn_timer->stop(); scrn_thread->wait(); wavbuf[0] = NULL; wavbuf[1] = NULL; wavbuf[2] = NULL; wavbuf[3] = NULL; mempnts = devparms.acquirememdepth; smps_per_record = mempnts; QProgressDialog progress("Downloading data...", "Abort", 0, mempnts, this); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(100); statusLabel->setText("Downloading data..."); for(i=0; i<MAX_CHNS; i++) { if(!devparms.chandisplay[i]) { continue; } chns++; } if(!chns) { strcpy(str, "No active channels."); goto OUT_ERROR; } while(smps_per_record >= (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 = (EDFLIB_TIME_DIMENSION * (long long)mempnts) / devparms.samplerate; if(rec_len < 100) { strcpy(str, "Can not save waveforms shorter than 10 uSec.\n" "Set the horizontal timebase to 1 uSec or higher."); goto OUT_ERROR; } for(i=0; i<MAX_CHNS; i++) { if(!devparms.chandisplay[i]) // Download data only when channel is switched on { continue; } wavbuf[i] = (short *)malloc(mempnts * sizeof(short)); if(wavbuf[i] == NULL) { sprintf(str, "Malloc error. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } } tmc_write(":STOP"); usleep(20000); for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) // Download data only when channel is switched on { continue; } sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); tmc_write(str); tmc_write(":WAV:FORM BYTE"); usleep(20000); tmc_write(":WAV:MODE RAW"); usleep(20000); tmc_write(":WAV:YINC?"); usleep(20000); tmc_read(); yinc[chn] = atof(device->buf); if(yinc[chn] < 1e-6) { sprintf(str, "Error, parameter \"YINC\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } usleep(20000); tmc_write(":WAV:YREF?"); usleep(20000); tmc_read(); yref[chn] = atoi(device->buf); if((yref[chn] < 1) || (yref[chn] > 255)) { sprintf(str, "Error, parameter \"YREF\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } usleep(20000); tmc_write(":WAV:YOR?"); usleep(20000); tmc_read(); yor[chn] = atoi(device->buf); if((yor[chn] < -255) || (yor[chn] > 255)) { sprintf(str, "Error, parameter \"YOR\" out of range. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } empty_buf = 0; for(bytes_rcvd=0; bytes_rcvd<mempnts ;) { progress.setValue(bytes_rcvd); qApp->processEvents(); if(progress.wasCanceled()) { strcpy(str, "Canceled"); goto OUT_ERROR; } sprintf(str, ":WAV:STAR %i", bytes_rcvd + 1); usleep(20000); tmc_write(str); if((bytes_rcvd + SAV_MEM_BSZ) > mempnts) { sprintf(str, ":WAV:STOP %i", mempnts); } else { sprintf(str, ":WAV:STOP %i", bytes_rcvd + SAV_MEM_BSZ); } usleep(20000); tmc_write(str); usleep(20000); tmc_write(":WAV:DATA?"); n = tmc_read(); if(n < 0) { sprintf(str, "Can not read from device. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } printf("received %i bytes, total %i bytes\n", n, n + bytes_rcvd); if(n > SAV_MEM_BSZ) { sprintf(str, "Datablock too big for buffer. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } if(n < 1) { if(empty_buf++ > 100) { break; } } else { empty_buf = 0; } for(k=0; k<n; k++) { if((bytes_rcvd + k) >= mempnts) { break; } wavbuf[chn][bytes_rcvd + k] = ((int)(((unsigned char *)device->buf)[k]) - yref[chn] - yor[chn]) << 5; } bytes_rcvd += n; if(bytes_rcvd >= mempnts) { break; } } if(bytes_rcvd < mempnts) { sprintf(str, "Download error. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } } progress.reset(); for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); usleep(20000); tmc_write(str); usleep(20000); tmc_write(":WAV:MODE NORM"); usleep(20000); tmc_write(":WAV:STAR 1"); if(devparms.modelserie == 1) { usleep(20000); tmc_write(":WAV:STOP 1200"); } else { usleep(20000); tmc_write(":WAV:STOP 1400"); usleep(20000); tmc_write(":WAV:POIN 1400"); } } if(bytes_rcvd < mempnts) { sprintf(str, "Download error. line %i file %s", __LINE__, __FILE__); goto OUT_ERROR; } else { statusLabel->setText("Downloading finished"); } opath[0] = 0; if(recent_savedir[0]!=0) { strcpy(opath, recent_savedir); strcat(opath, "/"); } strcat(opath, "waveform.edf"); strcpy(opath, QFileDialog::getSaveFileName(this, "Save file", opath, "EDF files (*.edf *.EDF)").toLocal8Bit().data()); if(!strcmp(opath, "")) { goto OUT_NORMAL; } get_directory_from_path(recent_savedir, opath, MAX_PATHLEN); hdl = edfopen_file_writeonly(opath, EDFLIB_FILETYPE_EDFPLUS, chns); if(hdl < 0) { strcpy(str, "Can not create EDF file."); goto OUT_ERROR; } if(edf_set_datarecord_duration(hdl, (rec_len / 100LL) / datrecs)) { strcpy(str, "Can not set datarecord duration of EDF file."); goto OUT_ERROR; } j = 0; for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } edf_set_samplefrequency(hdl, j, smps_per_record); edf_set_digital_maximum(hdl, j, 32767); edf_set_digital_minimum(hdl, j, -32768); if(devparms.chanscale[chn] > 2) { edf_set_physical_maximum(hdl, j, yinc[chn] * 32767.0 / 32.0); edf_set_physical_minimum(hdl, j, yinc[chn] * -32768.0 / 32.0); edf_set_physical_dimension(hdl, j, "V"); } else { edf_set_physical_maximum(hdl, j, 1000.0 * yinc[chn] * 32767.0 / 32.0); edf_set_physical_minimum(hdl, j, 1000.0 * yinc[chn] * -32768.0 / 32.0); edf_set_physical_dimension(hdl, j, "mV"); } sprintf(str, "CHAN%i", chn + 1); edf_set_label(hdl, j, str); j++; } edf_set_equipment(hdl, devparms.modelname); for(i=0; i<datrecs; i++) { for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } if(edfwrite_digital_short_samples(hdl, wavbuf[chn] + (i * smps_per_record))) { strcpy(str, "A write error occurred."); goto OUT_ERROR; } } } OUT_NORMAL: if(hdl >= 0) { edfclose_file(hdl); } for(chn=0; chn<MAX_CHNS; chn++) { free(wavbuf[chn]); } scrn_timer->start(devparms.screentimerival); return; OUT_ERROR: progress.reset(); statusLabel->setText("Downloading aborted"); if(hdl >= 0) { edfclose_file(hdl); } if(progress.wasCanceled() == false) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); msgBox.setText(str); msgBox.exec(); } for(chn=0; chn<MAX_CHNS; chn++) { if(!devparms.chandisplay[chn]) { continue; } sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); tmc_write(str); tmc_write(":WAV:MODE NORM"); tmc_write(":WAV:STAR 1"); if(devparms.modelserie == 1) { tmc_write(":WAV:STOP 1200"); } else { tmc_write(":WAV:STOP 1400"); tmc_write(":WAV:POIN 1400"); } } for(chn=0; chn<MAX_CHNS; chn++) { free(wavbuf[chn]); } scrn_timer->start(devparms.screentimerival); }
int screen_thread::get_devicestatus() { int line; usleep(TMC_GDS_DELAY); if(tmc_write(":TRIG:STAT?") != 11) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } if(!strcmp(device->buf, "TD")) { params.triggerstatus = 0; } else if(!strcmp(device->buf, "WAIT")) { params.triggerstatus = 1; } else if(!strcmp(device->buf, "RUN")) { params.triggerstatus = 2; } else if(!strcmp(device->buf, "AUTO")) { params.triggerstatus = 3; } else if(!strcmp(device->buf, "FIN")) { params.triggerstatus = 4; } else if(!strcmp(device->buf, "STOP")) { params.triggerstatus = 5; } else { line = __LINE__; goto OUT_ERROR; } usleep(TMC_GDS_DELAY); if(tmc_write(":TRIG:SWE?") != 10) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } if(!strcmp(device->buf, "AUTO")) { params.triggersweep = 0; } else if(!strcmp(device->buf, "NORM")) { params.triggersweep = 1; } else if(!strcmp(device->buf, "SING")) { params.triggersweep = 2; } else { line = __LINE__; goto OUT_ERROR; } usleep(TMC_GDS_DELAY); if(tmc_write(":ACQ:SRAT?") != 10) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.samplerate = atof(device->buf); usleep(TMC_GDS_DELAY); if(tmc_write(":ACQ:MDEP?") != 10) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.memdepth = atoi(device->buf); if(params.countersrc) { usleep(TMC_GDS_DELAY); if(tmc_write(":MEAS:COUN:VAL?") != 15) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.counterfreq = atof(device->buf); } if(params.func_wrec_enable) { usleep(TMC_GDS_DELAY); if(tmc_write(":FUNC:WREC:OPER?") != 16) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } if(params.modelserie == 6) { if(!strcmp(device->buf, "REC")) { params.func_wrec_operate = 1; } else if(!strcmp(device->buf, "STOP")) { params.func_wrec_operate = 0; } else { line = __LINE__; goto OUT_ERROR; } } else { if(!strcmp(device->buf, "RUN")) { params.func_wrec_operate = 1; } else if(!strcmp(device->buf, "STOP")) { params.func_wrec_operate = 0; } else { line = __LINE__; goto OUT_ERROR; } } usleep(TMC_GDS_DELAY); if(tmc_write(":FUNC:WREP:OPER?") != 16) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } if(!strcmp(device->buf, "PLAY")) { params.func_wplay_operate = 1; } else if(!strcmp(device->buf, "STOP")) { params.func_wplay_operate = 0; } else if(!strcmp(device->buf, "PAUS")) { params.func_wplay_operate = 2; } else { line = __LINE__; goto OUT_ERROR; } usleep(TMC_GDS_DELAY); if(tmc_write(":FUNC:WREP:FCUR?") != 16) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.func_wplay_fcur = atoi(device->buf); usleep(TMC_GDS_DELAY); if(tmc_write(":FUNC:WREC:FMAX?") != 16) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.func_wrec_fmax = atoi(device->buf); usleep(TMC_GDS_DELAY); if(tmc_write(":FUNC:WREP:FMAX?") != 16) { line = __LINE__; goto OUT_ERROR; } if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; } params.func_wrep_fmax = atoi(device->buf); } params.debug_str[0] = 0; return 0; OUT_ERROR: strncpy(params.debug_str, device->hdrbuf, 1024); params.debug_str[1023] = 0; params.error_line = line; return -1; }