diff --git a/connection.cpp b/connection.cpp new file mode 100644 index 0000000..8cc1a7f --- /dev/null +++ b/connection.cpp @@ -0,0 +1,86 @@ +/* +*************************************************************************** +* +* Author: Teunis van Beelen +* +* Copyright (C) 2015 Teunis van Beelen +* +* Email: teuniz@gmail.com +* +*************************************************************************** +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +*************************************************************************** +*/ + + +#include "connection.h" + + +int tmc_connection_type; + +struct tmcdev *usb_tmcdev; + + + +struct tmcdev * tmc_open_usb(const char *device) +{ + tmc_connection_type = 0; + + usb_tmcdev = tmcdev_open(device); + + return usb_tmcdev; +} + + +void tmc_close(void) +{ + if(tmc_connection_type == 0) + { + tmcdev_close(usb_tmcdev); + + usb_tmcdev = NULL; + } +} + + +int tmc_write(const char *msg) +{ + if(tmc_connection_type == 0) + { + return tmcdev_write(usb_tmcdev, msg); + } + + return -1; +} + + +int tmc_read(void) +{ + if(tmc_connection_type == 0) + { + return tmcdev_read(usb_tmcdev); + } + + return -1; +} + + + + + + + + diff --git a/connection.h b/connection.h new file mode 100644 index 0000000..657bfd3 --- /dev/null +++ b/connection.h @@ -0,0 +1,46 @@ +/* +*************************************************************************** +* +* Author: Teunis van Beelen +* +* Copyright (C) 2015 Teunis van Beelen +* +* Email: teuniz@gmail.com +* +*************************************************************************** +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +*************************************************************************** +*/ + + +#ifndef DSR_CONNECTION_H +#define DSR_CONNECTION_H + + +#include "global.h" +#include "tmc_dev.h" +#include "utils.h" + + +struct tmcdev * tmc_open_usb(const char *device); +void tmc_close(void); +int tmc_write(const char *); +int tmc_read(void); + + + +#endif + diff --git a/dsremote.pro b/dsremote.pro index 09e4cc5..6ee0f23 100644 --- a/dsremote.pro +++ b/dsremote.pro @@ -21,6 +21,7 @@ HEADERS += global.h HEADERS += mainwindow.h HEADERS += about_dialog.h HEADERS += utils.h +HEADERS += connection.h HEADERS += tmc_dev.h HEADERS += tled.h HEADERS += edflib.h @@ -35,6 +36,7 @@ SOURCES += save_data.cpp SOURCES += interface.cpp SOURCES += about_dialog.cpp SOURCES += utils.c +SOURCES += connection.cpp SOURCES += tmc_dev.c SOURCES += tled.cpp SOURCES += edflib.c diff --git a/global.h b/global.h index b40c6ea..bad7b14 100644 --- a/global.h +++ b/global.h @@ -26,12 +26,12 @@ */ -#ifndef DEMO_GLOBAL_H -#define DEMO_GLOBAL_H +#ifndef DSR_GLOBAL_H +#define DSR_GLOBAL_H -#define PROGRAM_NAME "DSRemote" -#define PROGRAM_VERSION "0.11_1506220825" +#define PROGRAM_NAME "DSRemote" +#define PROGRAM_VERSION "0.11_1506271103" #define MAX_PATHLEN 4096 @@ -82,6 +82,7 @@ struct waveform_preamble struct device_settings { int connected; + int connectiontype; // 0=USB, 1=LAN char modelname[128]; char serialnr[128]; char softwvers[128]; diff --git a/interface.cpp b/interface.cpp index 85a4387..1d108ce 100644 --- a/interface.cpp +++ b/interface.cpp @@ -181,7 +181,7 @@ void UI_Mainwindow::navDialReleased() sprintf(str, ":TRIG:HOLD %e", devparms.triggerholdoff); - tmcdev_write(device, str); + tmc_write(str); } else if(devparms.timebasedelayenable) { @@ -195,7 +195,7 @@ void UI_Mainwindow::navDialReleased() sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } adjDialFunc = ADJ_DIAL_FUNC_NONE; @@ -416,7 +416,7 @@ void UI_Mainwindow::trigAdjustDialChanged(int new_pos) sprintf(str, ":TRIG:EDG:LEV %e", devparms.triggeredgelevel[chn]); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; @@ -548,7 +548,7 @@ void UI_Mainwindow::horScaleDialChanged(int new_pos) sprintf(str, ":TIM:DEL:SCAL %e", devparms.timebasedelayscale); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; } @@ -624,7 +624,7 @@ void UI_Mainwindow::horScaleDialChanged(int new_pos) sprintf(str, ":TIM:SCAL %e", devparms.timebasescale); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; } @@ -716,7 +716,7 @@ void UI_Mainwindow::horPosDialChanged(int new_pos) sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; } @@ -759,7 +759,7 @@ void UI_Mainwindow::horPosDialChanged(int new_pos) sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; } @@ -859,7 +859,7 @@ void UI_Mainwindow::vertOffsetDialChanged(int new_pos) sprintf(str, ":CHAN%i:OFFS %e", chn + 1, devparms.chanoffset[chn]); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; @@ -985,7 +985,7 @@ void UI_Mainwindow::vertScaleDialChanged(int new_pos) sprintf(str, ":CHAN%i:SCAL %e", chn + 1, devparms.chanscale[chn]); - tmcdev_write(device, str); + tmc_write(str); old_pos = new_pos; @@ -1118,13 +1118,13 @@ void UI_Mainwindow::set_memdepth(int mdepth) { statusLabel->setText("Memory depth: auto"); - tmcdev_write(device, ":ACQ:MDEP AUTO"); + tmc_write(":ACQ:MDEP AUTO"); devparms.timebaseoffset = 0; usleep(20000); - tmcdev_write(device, ":TIM:OFFS 0"); + tmc_write(":TIM:OFFS 0"); return; } @@ -1137,13 +1137,13 @@ void UI_Mainwindow::set_memdepth(int mdepth) sprintf(str, ":ACQ:MDEP %i", mdepth); - tmcdev_write(device, str); + tmc_write(str); devparms.timebaseoffset = 0; usleep(20000); - tmcdev_write(device, ":TIM:OFFS 0"); + tmc_write(":TIM:OFFS 0"); } @@ -1314,7 +1314,7 @@ void UI_Mainwindow::set_acq_normal() statusLabel->setText("Acquire: normal"); - tmcdev_write(device, ":ACQ:TYPE NORM"); + tmc_write(":ACQ:TYPE NORM"); } @@ -1329,7 +1329,7 @@ void UI_Mainwindow::set_acq_peak() statusLabel->setText("Acquire: peak"); - tmcdev_write(device, ":ACQ:TYPE PEAK"); + tmc_write(":ACQ:TYPE PEAK"); } @@ -1344,7 +1344,7 @@ void UI_Mainwindow::set_acq_hres() statusLabel->setText("Acquire: high resolution"); - tmcdev_write(device, ":ACQ:TYPE HRES"); + tmc_write(":ACQ:TYPE HRES"); } @@ -1367,7 +1367,7 @@ void UI_Mainwindow::set_acq_average() statusLabel->setText("Acquire: average"); - tmcdev_write(device, ":ACQ:TYPE AVER"); + tmc_write(":ACQ:TYPE AVER"); } @@ -1436,7 +1436,7 @@ void UI_Mainwindow::set_grid_type_vectors() statusLabel->setText("Display type: vectors"); - tmcdev_write(device, ":DISP:TYPE VECT"); + tmc_write(":DISP:TYPE VECT"); } @@ -1451,7 +1451,7 @@ void UI_Mainwindow::set_grid_type_dots() statusLabel->setText("Display type: dots"); - tmcdev_write(device, ":DISP:TYPE DOTS"); + tmc_write(":DISP:TYPE DOTS"); } @@ -1466,7 +1466,7 @@ void UI_Mainwindow::set_grid_full() statusLabel->setText("Display grid: full"); - tmcdev_write(device, ":DISP:GRID FULL"); + tmc_write(":DISP:GRID FULL"); } @@ -1481,7 +1481,7 @@ void UI_Mainwindow::set_grid_half() statusLabel->setText("Display grid: half"); - tmcdev_write(device, ":DISP:GRID HALF"); + tmc_write(":DISP:GRID HALF"); } @@ -1496,7 +1496,7 @@ void UI_Mainwindow::set_grid_none() statusLabel->setText("Display grid: none"); - tmcdev_write(device, ":DISP:GRID NONE"); + tmc_write(":DISP:GRID NONE"); } @@ -1504,7 +1504,7 @@ void UI_Mainwindow::set_grading_min() { statusLabel->setText("Display grading: Minimum"); - tmcdev_write(device, ":DISP:GRAD:TIME MIN"); + tmc_write(":DISP:GRAD:TIME MIN"); } @@ -1512,7 +1512,7 @@ void UI_Mainwindow::set_grading_005() { statusLabel->setText("Display grading: 0.05 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 0.05"); + tmc_write(":DISP:GRAD:TIME 0.05"); } @@ -1520,7 +1520,7 @@ void UI_Mainwindow::set_grading_01() { statusLabel->setText("Display grading: 0.1 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 0.1"); + tmc_write(":DISP:GRAD:TIME 0.1"); } @@ -1528,7 +1528,7 @@ void UI_Mainwindow::set_grading_02() { statusLabel->setText("Display grading: 0.2 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 0.2"); + tmc_write(":DISP:GRAD:TIME 0.2"); } @@ -1536,7 +1536,7 @@ void UI_Mainwindow::set_grading_05() { statusLabel->setText("Display grading: 0.5 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 0.5"); + tmc_write(":DISP:GRAD:TIME 0.5"); } @@ -1544,7 +1544,7 @@ void UI_Mainwindow::set_grading_1() { statusLabel->setText("Display grading: 1 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 1"); + tmc_write(":DISP:GRAD:TIME 1"); } @@ -1552,7 +1552,7 @@ void UI_Mainwindow::set_grading_2() { statusLabel->setText("Display grading: 2 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 2"); + tmc_write(":DISP:GRAD:TIME 2"); } @@ -1560,7 +1560,7 @@ void UI_Mainwindow::set_grading_5() { statusLabel->setText("Display grading: 5 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 5"); + tmc_write(":DISP:GRAD:TIME 5"); } @@ -1568,7 +1568,7 @@ void UI_Mainwindow::set_grading_10() { statusLabel->setText("Display grading: 10 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 10"); + tmc_write(":DISP:GRAD:TIME 10"); } @@ -1576,7 +1576,7 @@ void UI_Mainwindow::set_grading_20() { statusLabel->setText("Display grading: 20 Sec."); - tmcdev_write(device, ":DISP:GRAD:TIME 20"); + tmc_write(":DISP:GRAD:TIME 20"); } @@ -1584,7 +1584,7 @@ void UI_Mainwindow::set_grading_inf() { statusLabel->setText("Display grading: Infinite"); - tmcdev_write(device, ":DISP:GRAD:TIME INF"); + tmc_write(":DISP:GRAD:TIME INF"); } @@ -1654,7 +1654,7 @@ void UI_Mainwindow::vertScaleDialClicked(QPoint) sprintf(str, ":CHAN%i:VERN 0", chn + 1); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -1666,7 +1666,7 @@ void UI_Mainwindow::vertScaleDialClicked(QPoint) sprintf(str, ":CHAN%i:VERN 1", chn + 1); - tmcdev_write(device, str); + tmc_write(str); } } @@ -1681,7 +1681,7 @@ void UI_Mainwindow::ch1ButtonClicked() statusLabel->setText("Channel 1 off"); - tmcdev_write(device, ":CHAN1:DISP 0"); + tmc_write(":CHAN1:DISP 0"); ch1Button->setStyleSheet(def_stylesh); @@ -1708,7 +1708,7 @@ void UI_Mainwindow::ch1ButtonClicked() statusLabel->setText("Channel 1 on"); - tmcdev_write(device, ":CHAN1:DISP 1"); + tmc_write(":CHAN1:DISP 1"); ch1Button->setStyleSheet("background: #FFFF33;"); @@ -1727,7 +1727,7 @@ void UI_Mainwindow::ch2ButtonClicked() statusLabel->setText("Channel 2 off"); - tmcdev_write(device, ":CHAN2:DISP 0"); + tmc_write(":CHAN2:DISP 0"); ch2Button->setStyleSheet(def_stylesh); @@ -1754,7 +1754,7 @@ void UI_Mainwindow::ch2ButtonClicked() statusLabel->setText("Channel 2 on"); - tmcdev_write(device, ":CHAN2:DISP 1"); + tmc_write(":CHAN2:DISP 1"); ch2Button->setStyleSheet("background: #33FFFF;"); @@ -1773,7 +1773,7 @@ void UI_Mainwindow::ch3ButtonClicked() statusLabel->setText("Channel 3 off"); - tmcdev_write(device, ":CHAN3:DISP 0"); + tmc_write(":CHAN3:DISP 0"); ch3Button->setStyleSheet(def_stylesh); @@ -1800,7 +1800,7 @@ void UI_Mainwindow::ch3ButtonClicked() statusLabel->setText("Channel 3 on"); - tmcdev_write(device, ":CHAN3:DISP 1"); + tmc_write(":CHAN3:DISP 1"); ch3Button->setStyleSheet("background: #FF33FF;"); @@ -1819,7 +1819,7 @@ void UI_Mainwindow::ch4ButtonClicked() statusLabel->setText("Channel 4 off"); - tmcdev_write(device, ":CHAN4:DISP 0"); + tmc_write(":CHAN4:DISP 0"); ch4Button->setStyleSheet(def_stylesh); @@ -1846,7 +1846,7 @@ void UI_Mainwindow::ch4ButtonClicked() statusLabel->setText("Channel 4 on"); - tmcdev_write(device, ":CHAN4:DISP 1"); + tmc_write(":CHAN4:DISP 1"); ch4Button->setStyleSheet("background: #0066CC;"); @@ -1900,7 +1900,7 @@ void UI_Mainwindow::chan_coupling_ac() sprintf(str, ":CHAN%i:COUP AC", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -1916,7 +1916,7 @@ void UI_Mainwindow::chan_coupling_dc() sprintf(str, ":CHAN%i:COUP DC", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -1932,7 +1932,7 @@ void UI_Mainwindow::chan_coupling_gnd() sprintf(str, ":CHAN%i:COUP GND", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -1948,7 +1948,7 @@ void UI_Mainwindow::chan_bwl_off() sprintf(str, ":CHAN%i:BWL OFF", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -1964,7 +1964,7 @@ void UI_Mainwindow::chan_bwl_20() sprintf(str, ":CHAN%i:BWL 20M", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -1980,7 +1980,7 @@ void UI_Mainwindow::chan_bwl_250() sprintf(str, ":CHAN%i:BWL 250M", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -2001,7 +2001,7 @@ void UI_Mainwindow::chan_invert_on() sprintf(str, ":CHAN%i:INV 1", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -2022,7 +2022,7 @@ void UI_Mainwindow::chan_invert_off() sprintf(str, ":CHAN%i:INV 0", devparms.activechannel + 1); - tmcdev_write(device, str); + tmc_write(str); } @@ -2056,7 +2056,7 @@ void UI_Mainwindow::vertOffsetDialClicked(QPoint) sprintf(str, ":CHAN%i:OFFS %e", chn + 1, devparms.chanoffset[chn]); - tmcdev_write(device, str); + tmc_write(str); } @@ -2064,7 +2064,7 @@ void UI_Mainwindow::clearButtonClicked() { statusLabel->setText("Display cleared"); - tmcdev_write(device, ":DISP:CLE"); + tmc_write(":DISP:CLE"); } @@ -2079,7 +2079,7 @@ void UI_Mainwindow::autoButtonClicked() statusLabel->setText("Auto settings"); - tmcdev_write(device, ":AUT"); + tmc_write(":AUT"); qApp->processEvents(); @@ -2101,13 +2101,13 @@ void UI_Mainwindow::runButtonClicked() { statusLabel->setText("Trigger: run"); - tmcdev_write(device, ":RUN"); + tmc_write(":RUN"); } else { statusLabel->setText("Trigger: stop"); - tmcdev_write(device, ":STOP"); + tmc_write(":STOP"); } } @@ -2116,7 +2116,7 @@ void UI_Mainwindow::singleButtonClicked() { statusLabel->setText("Trigger: single"); - tmcdev_write(device, ":SING"); + tmc_write(":SING"); } @@ -2165,7 +2165,7 @@ void UI_Mainwindow::horizontal_delayed_on() statusLabel->setText("Delayed timebase enabled"); - tmcdev_write(device, ":TIM:DEL:ENAB 1"); + tmc_write(":TIM:DEL:ENAB 1"); devparms.timebasedelayoffset = devparms.timebaseoffset; } @@ -2182,7 +2182,7 @@ void UI_Mainwindow::horizontal_delayed_off() statusLabel->setText("Delayed timebase disabled"); - tmcdev_write(device, ":TIM:DEL:ENAB 0"); + tmc_write(":TIM:DEL:ENAB 0"); } @@ -2194,7 +2194,7 @@ void UI_Mainwindow::horizontal_delayed_toggle() statusLabel->setText("Delayed timebase disabled"); - tmcdev_write(device, ":TIM:DEL:ENAB 0"); + tmc_write(":TIM:DEL:ENAB 0"); } else { @@ -2204,17 +2204,17 @@ void UI_Mainwindow::horizontal_delayed_toggle() statusLabel->setText("Delayed timebase enabled"); - tmcdev_write(device, ":TIM:DEL:ENAB 1"); + tmc_write(":TIM:DEL:ENAB 1"); - tmcdev_write(device, ":TIM:DEL:OFFS?"); + tmc_write(":TIM:DEL:OFFS?"); - tmcdev_read(device); + tmc_read(); devparms.timebasedelayoffset = atof(device->buf); - tmcdev_write(device, ":TIM:DEL:SCAL?"); + tmc_write(":TIM:DEL:SCAL?"); - tmcdev_read(device); + tmc_read(); devparms.timebasedelayscale = atof(device->buf); @@ -2241,7 +2241,7 @@ void UI_Mainwindow::horPosDialClicked(QPoint) sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -2257,7 +2257,7 @@ void UI_Mainwindow::horPosDialClicked(QPoint) sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } } @@ -2301,7 +2301,7 @@ void UI_Mainwindow::counter_off() statusLabel->setText("Freq. counter off"); - tmcdev_write(device, ":MEAS:COUN:SOUR OFF"); + tmc_write(":MEAS:COUN:SOUR OFF"); } @@ -2311,7 +2311,7 @@ void UI_Mainwindow::counter_ch1() statusLabel->setText("Freq. counter channel 1"); - tmcdev_write(device, ":MEAS:COUN:SOUR CHAN1"); + tmc_write(":MEAS:COUN:SOUR CHAN1"); } @@ -2321,7 +2321,7 @@ void UI_Mainwindow::counter_ch2() statusLabel->setText("Freq. counter channel 2"); - tmcdev_write(device, ":MEAS:COUN:SOUR CHAN2"); + tmc_write(":MEAS:COUN:SOUR CHAN2"); } @@ -2331,7 +2331,7 @@ void UI_Mainwindow::counter_ch3() statusLabel->setText("Freq. counter channel 3"); - tmcdev_write(device, ":MEAS:COUN:SOUR CHAN3"); + tmc_write(":MEAS:COUN:SOUR CHAN3"); } @@ -2341,7 +2341,7 @@ void UI_Mainwindow::counter_ch4() statusLabel->setText("Freq. counter channel 4"); - tmcdev_write(device, ":MEAS:COUN:SOUR CHAN4"); + tmc_write(":MEAS:COUN:SOUR CHAN4"); } @@ -2356,17 +2356,17 @@ void UI_Mainwindow::trigModeButtonClicked() case 0: trigModeAutoLed->setValue(true); trigModeSingLed->setValue(false); statusLabel->setText("Trigger auto"); - tmcdev_write(device, ":TRIG:SWE AUTO"); + tmc_write(":TRIG:SWE AUTO"); break; case 1: trigModeNormLed->setValue(true); trigModeAutoLed->setValue(false); statusLabel->setText("Trigger norm"); - tmcdev_write(device, ":TRIG:SWE NORM"); + tmc_write(":TRIG:SWE NORM"); break; case 2: trigModeSingLed->setValue(true); trigModeNormLed->setValue(false); statusLabel->setText("Trigger single"); - tmcdev_write(device, ":TRIG:SWE SING"); + tmc_write(":TRIG:SWE SING"); break; } } @@ -2426,7 +2426,7 @@ void UI_Mainwindow::trigger_source_ch1() statusLabel->setText("Trigger source channel 1"); - tmcdev_write(device, ":TRIG:EDG:SOUR CHAN1"); + tmc_write(":TRIG:EDG:SOUR CHAN1"); } @@ -2436,7 +2436,7 @@ void UI_Mainwindow::trigger_source_ch2() statusLabel->setText("Trigger source channel 2"); - tmcdev_write(device, ":TRIG:EDG:SOUR CHAN2"); + tmc_write(":TRIG:EDG:SOUR CHAN2"); } @@ -2446,7 +2446,7 @@ void UI_Mainwindow::trigger_source_ch3() statusLabel->setText("Trigger source channel 3"); - tmcdev_write(device, ":TRIG:EDG:SOUR CHAN3"); + tmc_write(":TRIG:EDG:SOUR CHAN3"); } @@ -2456,7 +2456,7 @@ void UI_Mainwindow::trigger_source_ch4() statusLabel->setText("Trigger source channel 4"); - tmcdev_write(device, ":TRIG:EDG:SOUR CHAN4"); + tmc_write(":TRIG:EDG:SOUR CHAN4"); } @@ -2466,7 +2466,7 @@ void UI_Mainwindow::trigger_source_ext() statusLabel->setText("Trigger source extern"); - tmcdev_write(device, ":TRIG:EDG:SOUR EXT"); + tmc_write(":TRIG:EDG:SOUR EXT"); } @@ -2476,7 +2476,7 @@ void UI_Mainwindow::trigger_source_ext5() statusLabel->setText("Trigger source extern 5"); - tmcdev_write(device, ":TRIG:EDG:SOUR EXT5"); + tmc_write(":TRIG:EDG:SOUR EXT5"); } @@ -2486,7 +2486,7 @@ void UI_Mainwindow::trigger_source_acl() statusLabel->setText("Trigger source AC powerline"); - tmcdev_write(device, ":TRIG:EDG:SOUR ACL"); + tmc_write(":TRIG:EDG:SOUR ACL"); } @@ -2496,7 +2496,7 @@ void UI_Mainwindow::trigger_coupling_ac() statusLabel->setText("Trigger coupling AC"); - tmcdev_write(device, ":TRIG:COUP AC"); + tmc_write(":TRIG:COUP AC"); } @@ -2506,7 +2506,7 @@ void UI_Mainwindow::trigger_coupling_dc() statusLabel->setText("Trigger coupling DC"); - tmcdev_write(device, ":TRIG:COUP DC"); + tmc_write(":TRIG:COUP DC"); } @@ -2516,7 +2516,7 @@ void UI_Mainwindow::trigger_coupling_lfreject() statusLabel->setText("Trigger LF reject"); - tmcdev_write(device, ":TRIG:COUP LFR"); + tmc_write(":TRIG:COUP LFR"); } @@ -2526,7 +2526,7 @@ void UI_Mainwindow::trigger_coupling_hfreject() statusLabel->setText("Trigger HF reject"); - tmcdev_write(device, ":TRIG:COUP HFR"); + tmc_write(":TRIG:COUP HFR"); } @@ -2536,7 +2536,7 @@ void UI_Mainwindow::trigger_slope_pos() statusLabel->setText("Trigger edge positive"); - tmcdev_write(device, ":TRIG:EDG:SLOP POS"); + tmc_write(":TRIG:EDG:SLOP POS"); } @@ -2546,7 +2546,7 @@ void UI_Mainwindow::trigger_slope_neg() statusLabel->setText("Trigger edge negative"); - tmcdev_write(device, ":TRIG:EDG:SLOP NEG"); + tmc_write(":TRIG:EDG:SLOP NEG"); } @@ -2556,7 +2556,7 @@ void UI_Mainwindow::trigger_slope_rfal() statusLabel->setText("Trigger edge positive /negative"); - tmcdev_write(device, ":TRIG:EDG:SLOP RFAL"); + tmc_write(":TRIG:EDG:SLOP RFAL"); } @@ -2578,7 +2578,7 @@ void UI_Mainwindow::trigForceButtonClicked() { statusLabel->setText("Trigger force"); - tmcdev_write(device, ":TFOR"); + tmc_write(":TFOR"); } @@ -2586,13 +2586,13 @@ void UI_Mainwindow::trig50pctButtonClicked() { statusLabel->setText("Trigger 50%"); - tmcdev_write(device, ":TLHA"); + tmc_write(":TLHA"); usleep(30000); - tmcdev_write(device, ":TRIG:EDG:LEV?"); + tmc_write(":TRIG:EDG:LEV?"); - tmcdev_read(device); + tmc_read(); devparms.triggeredgelevel[devparms.triggeredgesource] = atof(device->buf); @@ -2616,7 +2616,7 @@ void UI_Mainwindow::trigAdjustDialClicked(QPoint) sprintf(str, ":TRIG:EDG:LEV %e", devparms.triggeredgelevel[devparms.triggeredgesource]); - tmcdev_write(device, str); + tmc_write(str); } diff --git a/mainwindow.cpp b/mainwindow.cpp index b5697e6..caa2bea 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,7 +36,7 @@ void UI_Mainwindow::open_settings_dialog() { - UI_select_device_window sel_device; + UI_settings_window settings(this); } @@ -56,29 +56,52 @@ void UI_Mainwindow::open_connection() return; } - strcpy(dev_str, settings.value("connection/device").toString().toLocal8Bit().data()); - - if(!strcmp(dev_str, "")) + if(devparms.connected) { - strcpy(dev_str, "/dev/usbtmc0"); - - settings.setValue("connection/device", dev_str); + return; } - device = tmcdev_open(dev_str); - if(device == NULL) + strcpy(str, settings.value("connection/type").toString().toLatin1().data()); + + if(!strcmp(str, "LAN")) { - sprintf(str, "Can not open device %s", dev_str); - goto OUT_ERROR; + devparms.connectiontype = 1; + } + else + { + devparms.connectiontype = 0; } - if(tmcdev_write(device, "*IDN?") != 5) + if(devparms.connectiontype == 0) // USB + { + strcpy(dev_str, settings.value("connection/device").toString().toLocal8Bit().data()); + + if(!strcmp(dev_str, "")) + { + strcpy(dev_str, "/dev/usbtmc0"); + + settings.setValue("connection/device", dev_str); + } + + device = tmc_open_usb(dev_str); + if(device == NULL) + { + sprintf(str, "Can not open device %s", dev_str); + goto OUT_ERROR; + } + } + + if(devparms.connectiontype == 1) // LAN + { + } + + if(tmc_write("*IDN?") != 5) { sprintf(str, "Can not write to device %s", dev_str); goto OUT_ERROR; } - n = tmcdev_read(device); + n = tmc_read(); if(n < 0) { @@ -155,7 +178,7 @@ void UI_Mainwindow::open_connection() msgBox.setIcon(QMessageBox::Warning); msgBox.setText("Unsupported device detected."); msgBox.setInformativeText("This software has not been tested with your device.\n" - "It has been tested with the DS6000 and DS1054 series only.\n" + "It has been tested with the DS6000 and DS1000Z series only.\n" "If you continue, it's likely that the program will not work correctly at some points.\n" "\nDo you want to continue?\n"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); @@ -342,7 +365,7 @@ void UI_Mainwindow::close_connection() waveForm->clear(); - tmcdev_close(device); + tmc_close(); device = NULL; @@ -360,7 +383,7 @@ void UI_Mainwindow::closeEvent(QCloseEvent *cl_event) adjdial_timer->stop(); - tmcdev_close(device); + tmc_close(); device = NULL; @@ -384,13 +407,13 @@ int UI_Mainwindow::get_device_settings() { sprintf(str, ":CHAN%i:BWL?", chn + 1); - if(tmcdev_write(device, str) != 11) + if(tmc_write(str) != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -416,13 +439,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:COUP?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -448,13 +471,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:DISP?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -507,13 +530,13 @@ int UI_Mainwindow::get_device_settings() { sprintf(str, ":CHAN%i:IMP?", chn + 1); - if(tmcdev_write(device, str) != 11) + if(tmc_write(str) != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -536,13 +559,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:INV?", chn + 1); - if(tmcdev_write(device, str) != 11) + if(tmc_write(str) != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -564,13 +587,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:OFFS?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -580,13 +603,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:PROB?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -596,13 +619,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:SCAL?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -612,13 +635,13 @@ int UI_Mainwindow::get_device_settings() sprintf(str, ":CHAN%i:VERN?", chn + 1); - if(tmcdev_write(device, str) != 12) + if(tmc_write(str) != 12) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -639,13 +662,13 @@ int UI_Mainwindow::get_device_settings() } } - if(tmcdev_write(device, ":TIM:OFFS?") != 10) + if(tmc_write(":TIM:OFFS?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -653,13 +676,13 @@ int UI_Mainwindow::get_device_settings() devparms.timebaseoffset = atof(device->buf); - if(tmcdev_write(device, ":TIM:SCAL?") != 10) + if(tmc_write(":TIM:SCAL?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -667,13 +690,13 @@ int UI_Mainwindow::get_device_settings() devparms.timebasescale = atof(device->buf); - if(tmcdev_write(device, ":TIM:DEL:ENAB?") != 14) + if(tmc_write(":TIM:DEL:ENAB?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -693,13 +716,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TIM:DEL:OFFS?") != 14) + if(tmc_write(":TIM:DEL:OFFS?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -707,13 +730,13 @@ int UI_Mainwindow::get_device_settings() devparms.timebasedelayoffset = atof(device->buf); - if(tmcdev_write(device, ":TIM:DEL:SCAL?") != 14) + if(tmc_write(":TIM:DEL:SCAL?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -723,13 +746,13 @@ int UI_Mainwindow::get_device_settings() if(devparms.modelserie != 1) { - if(tmcdev_write(device, ":TIM:HREF:MODE?") != 15) + if(tmc_write(":TIM:HREF:MODE?") != 15) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -753,13 +776,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TIM:HREF:POS?") != 14) + if(tmc_write(":TIM:HREF:POS?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -768,13 +791,13 @@ int UI_Mainwindow::get_device_settings() devparms.timebasehrefpos = atoi(device->buf); - if(tmcdev_write(device, ":TIM:MODE?") != 10) + if(tmc_write(":TIM:MODE?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -800,13 +823,13 @@ int UI_Mainwindow::get_device_settings() if(devparms.modelserie != 1) { - if(tmcdev_write(device, ":TIM:VERN?") != 10) + if(tmc_write(":TIM:VERN?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -829,13 +852,13 @@ int UI_Mainwindow::get_device_settings() if((devparms.modelserie != 1) && (devparms.modelserie != 2)) { - if(tmcdev_write(device, ":TIM:XY1:DISP?") != 14) + if(tmc_write(":TIM:XY1:DISP?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -855,13 +878,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TIM:XY2:DISP?") != 14) + if(tmc_write(":TIM:XY2:DISP?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -882,13 +905,13 @@ int UI_Mainwindow::get_device_settings() } } - if(tmcdev_write(device, ":TRIG:COUP?") != 11) + if(tmc_write(":TRIG:COUP?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -916,13 +939,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:SWE?") != 10) + if(tmc_write(":TRIG:SWE?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -958,13 +981,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:MODE?") != 11) + if(tmc_write(":TRIG:MODE?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1016,13 +1039,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:STAT?") != 11) + if(tmc_write(":TRIG:STAT?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1058,13 +1081,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:EDG:SLOP?") != 15) + if(tmc_write(":TRIG:EDG:SLOP?") != 15) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1088,13 +1111,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:EDG:SOUR?") != 15) + if(tmc_write(":TRIG:EDG:SOUR?") != 15) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1138,19 +1161,19 @@ int UI_Mainwindow::get_device_settings() { sprintf(str, ":TRIG:EDG:SOUR CHAN%i", chn + 1); - if(tmcdev_write(device, str) != 20) + if(tmc_write(str) != 20) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:EDG:LEV?") != 14) + if(tmc_write(":TRIG:EDG:LEV?") != 14) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1163,7 +1186,7 @@ int UI_Mainwindow::get_device_settings() { sprintf(str, ":TRIG:EDG:SOUR CHAN%i", devparms.triggeredgesource + 1); - if(tmcdev_write(device, str) != 20) + if(tmc_write(str) != 20) { line = __LINE__; goto OUT_ERROR; @@ -1172,7 +1195,7 @@ int UI_Mainwindow::get_device_settings() if(devparms.triggeredgesource== 4) { - if(tmcdev_write(device, ":TRIG:EDG:SOUR EXT") != 18) + if(tmc_write(":TRIG:EDG:SOUR EXT") != 18) { line = __LINE__; goto OUT_ERROR; @@ -1181,7 +1204,7 @@ int UI_Mainwindow::get_device_settings() if(devparms.triggeredgesource== 5) { - if(tmcdev_write(device, ":TRIG:EDG:SOUR EXT5") != 19) + if(tmc_write(":TRIG:EDG:SOUR EXT5") != 19) { line = __LINE__; goto OUT_ERROR; @@ -1190,20 +1213,20 @@ int UI_Mainwindow::get_device_settings() if(devparms.triggeredgesource== 6) { - if(tmcdev_write(device, ":TRIG:EDG:SOUR AC") != 17) + if(tmc_write(":TRIG:EDG:SOUR AC") != 17) { line = __LINE__; goto OUT_ERROR; } } - if(tmcdev_write(device, ":TRIG:HOLD?") != 11) + if(tmc_write(":TRIG:HOLD?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1243,13 +1266,13 @@ int UI_Mainwindow::get_device_settings() } } - if(tmcdev_write(device, ":ACQ:SRAT?") != 10) + if(tmc_write(":ACQ:SRAT?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1257,13 +1280,13 @@ int UI_Mainwindow::get_device_settings() devparms.samplerate = atof(device->buf); - if(tmcdev_write(device, ":DISP:GRID?") != 11) + if(tmc_write(":DISP:GRID?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1287,13 +1310,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":MEAS:COUN:SOUR?") != 16) + if(tmc_write(":MEAS:COUN:SOUR?") != 16) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1325,13 +1348,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":DISP:TYPE?") != 11) + if(tmc_write(":DISP:TYPE?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1351,13 +1374,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":ACQ:TYPE?") != 10) + if(tmc_write(":ACQ:TYPE?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1385,13 +1408,13 @@ int UI_Mainwindow::get_device_settings() goto OUT_ERROR; } - if(tmcdev_write(device, ":ACQ:AVER?") != 10) + if(tmc_write(":ACQ:AVER?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -1881,7 +1904,7 @@ void UI_Mainwindow::former_page() sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -1912,7 +1935,7 @@ void UI_Mainwindow::former_page() sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -1952,7 +1975,7 @@ void UI_Mainwindow::next_page() sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -1983,7 +2006,7 @@ void UI_Mainwindow::next_page() sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -2023,7 +2046,7 @@ void UI_Mainwindow::shift_page_left() sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -2054,7 +2077,7 @@ void UI_Mainwindow::shift_page_left() sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -2094,7 +2117,7 @@ void UI_Mainwindow::shift_page_right() sprintf(str, ":TIM:DEL:OFFS %e", devparms.timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -2125,7 +2148,7 @@ void UI_Mainwindow::shift_page_right() sprintf(str, ":TIM:OFFS %e", devparms.timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -2186,7 +2209,7 @@ void UI_Mainwindow::zoom_in() sprintf(str, ":TIM:DEL:SCAL %e", devparms.timebasedelayscale); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -2233,7 +2256,7 @@ void UI_Mainwindow::zoom_in() sprintf(str, ":TIM:SCAL %e", devparms.timebasescale); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -2277,7 +2300,7 @@ void UI_Mainwindow::zoom_out() sprintf(str, ":TIM:DEL:SCAL %e", devparms.timebasedelayscale); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -2300,7 +2323,7 @@ void UI_Mainwindow::zoom_out() sprintf(str, ":TIM:SCAL %e", devparms.timebasescale); - tmcdev_write(device, str); + tmc_write(str); } waveForm->update(); @@ -2358,7 +2381,7 @@ void UI_Mainwindow::chan_scale_plus() sprintf(str, ":CHAN%i:SCAL %e", chn + 1, devparms.chanscale[chn]); - tmcdev_write(device, str); + tmc_write(str); waveForm->update(); } @@ -2422,7 +2445,7 @@ void UI_Mainwindow::chan_scale_minus() sprintf(str, ":CHAN%i:SCAL %e", chn + 1, devparms.chanscale[chn]); - tmcdev_write(device, str); + tmc_write(str); waveForm->update(); } @@ -2436,7 +2459,7 @@ void UI_Mainwindow::set_to_factory() scrn_timer->stop(); - tmcdev_write(device, "*RST"); + tmc_write("*RST"); devparms.timebasescale = 1e-6; @@ -2514,7 +2537,7 @@ void UI_Mainwindow::set_to_factory() { sprintf(str, ":CHAN%i:SCAL 1", i + 1); - tmcdev_write(device, str); + tmc_write(str); usleep(20000); } diff --git a/mainwindow.h b/mainwindow.h index 2911ec6..bddb0fa 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -75,6 +75,7 @@ #include "global.h" #include "about_dialog.h" #include "utils.h" +#include "connection.h" #include "tmc_dev.h" #include "tled.h" #include "edflib.h" diff --git a/mainwindow_constr.cpp b/mainwindow_constr.cpp index df8bfc7..81af213 100644 --- a/mainwindow_constr.cpp +++ b/mainwindow_constr.cpp @@ -34,6 +34,8 @@ UI_Mainwindow::UI_Mainwindow() { int i; + char str[1024]; + setMinimumSize(1170, 630); setWindowTitle(PROGRAM_NAME " " PROGRAM_VERSION); setWindowIcon(QIcon(":/images/r.png")); @@ -380,6 +382,17 @@ UI_Mainwindow::UI_Mainwindow() strcpy(recent_savedir, settings.value("path/savedir").toString().toLocal8Bit().data()); + strcpy(str, settings.value("connection/type").toString().toLatin1().data()); + + if(!strcmp(str, "LAN")) + { + devparms.connectiontype = 1; + } + else + { + devparms.connectiontype = 0; + } + adjDialFunc = ADJ_DIAL_FUNC_NONE; navDialFunc = NAV_DIAL_FUNC_NONE; diff --git a/save_data.cpp b/save_data.cpp index 6ac467c..5b29a0f 100644 --- a/save_data.cpp +++ b/save_data.cpp @@ -48,13 +48,13 @@ void UI_Mainwindow::save_screenshot() scrn_timer->stop(); - tmcdev_write(device, ":DISP:DATA?"); + tmc_write(":DISP:DATA?"); QApplication::setOverrideCursor(Qt::WaitCursor); qApp->processEvents(); - n = tmcdev_read(device); + n = tmc_read(); QApplication::restoreOverrideCursor(); @@ -246,7 +246,7 @@ void UI_Mainwindow::save_memory_waveform() } } - tmcdev_write(device, ":STOP"); + tmc_write(":STOP"); usleep(20000); @@ -261,21 +261,21 @@ void UI_Mainwindow::save_memory_waveform() sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); - tmcdev_write(device, str); + tmc_write(str); - tmcdev_write(device, ":WAV:FORM BYTE"); + tmc_write(":WAV:FORM BYTE"); usleep(20000); - tmcdev_write(device, ":WAV:MODE RAW"); + tmc_write(":WAV:MODE RAW"); usleep(20000); - tmcdev_write(device, ":WAV:YINC?"); + tmc_write(":WAV:YINC?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yinc[chn] = atof(device->buf); @@ -287,11 +287,11 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, ":WAV:YREF?"); + tmc_write(":WAV:YREF?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yref[chn] = atoi(device->buf); @@ -303,11 +303,11 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, ":WAV:YOR?"); + tmc_write(":WAV:YOR?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yor[chn] = atoi(device->buf); @@ -323,15 +323,15 @@ void UI_Mainwindow::save_memory_waveform() // // usleep(20000); // -// tmcdev_write(device, str); +// tmc_write(str); // // usleep(20000); // -// tmcdev_write(device, ":WAV:RES"); +// tmc_write(":WAV:RES"); // // usleep(20000); // -// tmcdev_write(device, ":WAV:BEG"); +// tmc_write(":WAV:BEG"); // } empty_buf = 0; @@ -354,7 +354,7 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, str); + tmc_write(str); if((bytes_rcvd + SAV_MEM_BSZ) > mempnts) { @@ -367,7 +367,7 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -375,7 +375,7 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, str); + tmc_write(str); if((bytes_rcvd + SAV_MEM_BSZ) > mempnts) { @@ -388,38 +388,38 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, str); + tmc_write(str); usleep(20000); - tmcdev_write(device, ":WAV:RES"); + tmc_write(":WAV:RES"); usleep(20000); - tmcdev_write(device, ":WAV:BEG"); + tmc_write(":WAV:BEG"); usleep(20000); - tmcdev_write(device, ":WAV:STAT?"); + tmc_write(":WAV:STAT?"); usleep(20000); - tmcdev_read(device); + tmc_read(); printf(":WAV:STAT? %s\n", device->buf); } usleep(20000); - tmcdev_write(device, ":WAV:DATA?"); + tmc_write(":WAV:DATA?"); - n = tmcdev_read(device); + n = tmc_read(); if(devparms.modelserie != 1) { usleep(20000); - tmcdev_write(device, ":WAV:END"); + tmc_write(":WAV:END"); } if(n < 0) @@ -481,7 +481,7 @@ void UI_Mainwindow::save_memory_waveform() // { // usleep(20000); // -// tmcdev_write(device, ":WAV:END"); +// tmc_write(":WAV:END"); // } if(bytes_rcvd < mempnts) @@ -504,40 +504,40 @@ void UI_Mainwindow::save_memory_waveform() usleep(20000); - tmcdev_write(device, str); + tmc_write(str); usleep(20000); - tmcdev_write(device, ":WAV:MODE NORM"); + tmc_write(":WAV:MODE NORM"); if(devparms.modelserie == 6) { usleep(20000); - tmcdev_write(device, ":WAV:STAR 0"); + tmc_write(":WAV:STAR 0"); } else { usleep(20000); - tmcdev_write(device, ":WAV:STAR 1"); + tmc_write(":WAV:STAR 1"); } if(devparms.modelserie == 1) { usleep(20000); - tmcdev_write(device, ":WAV:STOP 1200"); + tmc_write(":WAV:STOP 1200"); } else { usleep(20000); - tmcdev_write(device, ":WAV:STOP 1400"); + tmc_write(":WAV:STOP 1400"); usleep(20000); - tmcdev_write(device, ":WAV:POIN 1400"); + tmc_write(":WAV:POIN 1400"); } } @@ -674,28 +674,28 @@ OUT_ERROR: sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); - tmcdev_write(device, str); + tmc_write(str); - tmcdev_write(device, ":WAV:MODE NORM"); + tmc_write(":WAV:MODE NORM"); if(devparms.modelserie == 6) { - tmcdev_write(device, ":WAV:STAR 0"); + tmc_write(":WAV:STAR 0"); } else { - tmcdev_write(device, ":WAV:STAR 1"); + tmc_write(":WAV:STAR 1"); } if(devparms.modelserie == 1) { - tmcdev_write(device, ":WAV:STOP 1200"); + tmc_write(":WAV:STOP 1200"); } else { - tmcdev_write(device, ":WAV:STOP 1400"); + tmc_write(":WAV:STOP 1400"); - tmcdev_write(device, ":WAV:POIN 1400"); + tmc_write(":WAV:POIN 1400"); } } @@ -708,9 +708,9 @@ OUT_ERROR: } -// tmcdev_write(device, ":WAV:PRE?"); +// tmc_write(":WAV:PRE?"); // -// n = tmcdev_read(device); +// n = tmc_read(); // // if(n < 0) // { @@ -826,23 +826,23 @@ void UI_Mainwindow::save_screen_waveform() sprintf(str, ":WAV:SOUR CHAN%i", chn + 1); - tmcdev_write(device, str); + tmc_write(str); usleep(20000); - tmcdev_write(device, ":WAV:FORM BYTE"); + tmc_write(":WAV:FORM BYTE"); usleep(20000); - tmcdev_write(device, ":WAV:MODE NORM"); + tmc_write(":WAV:MODE NORM"); usleep(20000); - tmcdev_write(device, ":WAV:YINC?"); + tmc_write(":WAV:YINC?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yinc[chn] = atof(device->buf); @@ -854,11 +854,11 @@ void UI_Mainwindow::save_screen_waveform() usleep(20000); - tmcdev_write(device, ":WAV:YREF?"); + tmc_write(":WAV:YREF?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yref[chn] = atoi(device->buf); @@ -870,11 +870,11 @@ void UI_Mainwindow::save_screen_waveform() usleep(20000); - tmcdev_write(device, ":WAV:YOR?"); + tmc_write(":WAV:YOR?"); usleep(20000); - tmcdev_read(device); + tmc_read(); yor[chn] = atoi(device->buf); @@ -886,13 +886,13 @@ void UI_Mainwindow::save_screen_waveform() usleep(20000); - tmcdev_write(device, ":WAV:DATA?"); + tmc_write(":WAV:DATA?"); QApplication::setOverrideCursor(Qt::WaitCursor); qApp->processEvents(); - n = tmcdev_read(device); + n = tmc_read(); QApplication::restoreOverrideCursor(); diff --git a/settings_dialog.cpp b/settings_dialog.cpp index 5e63b29..495b1ae 100644 --- a/settings_dialog.cpp +++ b/settings_dialog.cpp @@ -32,7 +32,7 @@ -UI_select_device_window::UI_select_device_window(QDialog *parnt) +UI_settings_window::UI_settings_window(QWidget *parnt) { QSettings settings; @@ -45,8 +45,24 @@ UI_select_device_window::UI_select_device_window(QDialog *parnt) setWindowTitle("Settings"); setModal(true); + usbRadioButton = new QRadioButton("USB", this); + usbRadioButton->setAutoExclusive(true); + usbRadioButton->setGeometry(40, 20, 110, 25); + if(mainwindow->devparms.connectiontype == 0) + { + usbRadioButton->setChecked(true); + } + + lanRadioButton = new QRadioButton("LAN", this); + lanRadioButton->setAutoExclusive(true); + lanRadioButton->setGeometry(260, 20, 110, 25); + if(mainwindow->devparms.connectiontype == 1) + { + lanRadioButton->setChecked(true); + } + comboBox1 = new QComboBox(this); - comboBox1->setGeometry(20, 20, 110, 26); + comboBox1->setGeometry(20, 65, 110, 25); comboBox1->addItem("/dev/usbtmc0"); comboBox1->addItem("/dev/usbtmc1"); comboBox1->addItem("/dev/usbtmc2"); @@ -58,12 +74,24 @@ UI_select_device_window::UI_select_device_window(QDialog *parnt) comboBox1->addItem("/dev/usbtmc8"); comboBox1->addItem("/dev/usbtmc9"); + ipLineEdit = new QLineEdit(this); + ipLineEdit->setGeometry(240, 65, 110, 25); + ipLineEdit->setInputMask("000.000.000.000;_"); + if(settings.contains("connection/ip")) + { + ipLineEdit->setText(settings.value("connection/ip").toString()); + } + else + { + ipLineEdit->setText("192.168.001.088"); + } + applyButton = new QPushButton(this); applyButton->setGeometry(20, 155, 100, 25); applyButton->setText("Apply"); cancelButton = new QPushButton(this); - cancelButton->setGeometry(280, 155, 100, 25); + cancelButton->setGeometry(240, 155, 100, 25); cancelButton->setText("Cancel"); strcpy(dev_str, settings.value("connection/device").toString().toLocal8Bit().data()); @@ -75,28 +103,52 @@ UI_select_device_window::UI_select_device_window(QDialog *parnt) comboBox1->setCurrentIndex(dev_str[11] - '0'); - QObject::connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked())); - QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close())); + QObject::connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked())); + QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close())); exec(); } - -void UI_select_device_window::applyButtonClicked() +void UI_settings_window::applyButtonClicked() { char dev_str[128]; QSettings settings; + if(mainwindow->devparms.connected) + { + close(); + } + strcpy(dev_str, "/dev/usbtmc0"); dev_str[11] = '0' + comboBox1->currentIndex(); + if(usbRadioButton->isChecked() == true) + { + settings.setValue("connection/type", "USB"); + + mainwindow->devparms.connectiontype = 0; + } + else + { + settings.setValue("connection/type", "LAN"); + + mainwindow->devparms.connectiontype = 1; + } + settings.setValue("connection/device", dev_str); + settings.setValue("connection/ip", ipLineEdit->text()); + close(); } + + + + + diff --git a/settings_dialog.h b/settings_dialog.h index 2379392..b091976 100644 --- a/settings_dialog.h +++ b/settings_dialog.h @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "mainwindow.h" #include "global.h" @@ -48,21 +50,26 @@ class UI_Mainwindow; -class UI_select_device_window : public QDialog +class UI_settings_window : public QDialog { Q_OBJECT public: - UI_select_device_window(QDialog *parent=0); + UI_settings_window(QWidget *parent=0); private: QPushButton *cancelButton, *applyButton; +QRadioButton *usbRadioButton, + *lanRadioButton; + QComboBox *comboBox1; +QLineEdit *ipLineEdit; + UI_Mainwindow *mainwindow; private slots: diff --git a/signalcurve.cpp b/signalcurve.cpp index e47cc30..8798c4d 100644 --- a/signalcurve.cpp +++ b/signalcurve.cpp @@ -1394,7 +1394,7 @@ void SignalCurve::mouseReleaseEvent(QMouseEvent *release_event) sprintf(str, ":TIM:DEL:OFFS %e", devparms->timebasedelayoffset); - tmcdev_write(device, str); + tmc_write(str); } else { @@ -1414,7 +1414,7 @@ void SignalCurve::mouseReleaseEvent(QMouseEvent *release_event) sprintf(str, ":TIM:OFFS %e", devparms->timebaseoffset); - tmcdev_write(device, str); + tmc_write(str); } } else if(trig_level_arrow_moving) @@ -1458,7 +1458,7 @@ void SignalCurve::mouseReleaseEvent(QMouseEvent *release_event) if(device != NULL) { - tmcdev_write(device, str); + tmc_write(str); } trig_line_timer->start(1000); @@ -1507,7 +1507,7 @@ void SignalCurve::mouseReleaseEvent(QMouseEvent *release_event) if(device != NULL) { - tmcdev_write(device, str); + tmc_write(str); } devparms->activechannel = chn; diff --git a/signalcurve.h b/signalcurve.h index 8c32158..64a7a5f 100644 --- a/signalcurve.h +++ b/signalcurve.h @@ -50,6 +50,7 @@ #include "mainwindow.h" #include "global.h" +#include "connection.h" #include "tmc_dev.h" #include "utils.h" diff --git a/timer_handlers.cpp b/timer_handlers.cpp index 05c5bf3..be86517 100644 --- a/timer_handlers.cpp +++ b/timer_handlers.cpp @@ -91,13 +91,13 @@ void UI_Mainwindow::adjdial_timer_handler() sprintf(str, ":TRIG:HOLD %e", devparms.triggerholdoff); - tmcdev_write(device, str); + tmc_write(str); if(devparms.modelserie == 6) { usleep(20000); - tmcdev_write(device, ":CLE"); + tmc_write(":CLE"); } } else if(adjDialFunc == ADJ_DIAL_FUNC_ACQ_AVG) @@ -108,7 +108,7 @@ void UI_Mainwindow::adjdial_timer_handler() sprintf(str, ":ACQ:AVER %i", devparms.acquireaverages); - tmcdev_write(device, str); + tmc_write(str); } adjDialFunc = ADJ_DIAL_FUNC_NONE; @@ -131,13 +131,13 @@ void UI_Mainwindow::stat_timer_handler() char str[512]; - if(tmcdev_write(device, ":TRIG:STAT?") != 11) + if(tmc_write(":TRIG:STAT?") != 11) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -189,13 +189,13 @@ void UI_Mainwindow::stat_timer_handler() goto OUT_ERROR; } - if(tmcdev_write(device, ":TRIG:SWE?") != 10) + if(tmc_write(":TRIG:SWE?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -231,13 +231,13 @@ void UI_Mainwindow::stat_timer_handler() goto OUT_ERROR; } - if(tmcdev_write(device, ":ACQ:SRAT?") != 10) + if(tmc_write(":ACQ:SRAT?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -245,13 +245,13 @@ void UI_Mainwindow::stat_timer_handler() devparms.samplerate = atof(device->buf); - if(tmcdev_write(device, ":ACQ:MDEP?") != 10) + if(tmc_write(":ACQ:MDEP?") != 10) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -261,13 +261,13 @@ void UI_Mainwindow::stat_timer_handler() if(devparms.countersrc) { - if(tmcdev_write(device, ":MEAS:COUN:VAL?") != 15) + if(tmc_write(":MEAS:COUN:VAL?") != 15) { line = __LINE__; goto OUT_ERROR; } - if(tmcdev_read(device) < 1) + if(tmc_read() < 1) { line = __LINE__; goto OUT_ERROR; @@ -335,9 +335,9 @@ void UI_Mainwindow::scrn_timer_handler() /////////////////////////////////////////////////////////// -// tmcdev_write(device, ":WAV:PRE?"); +// tmc_write(":WAV:PRE?"); // -// n = tmcdev_read(device); +// n = tmc_read(); // // if(n < 0) // { @@ -376,15 +376,15 @@ void UI_Mainwindow::scrn_timer_handler() sprintf(str, ":WAV:SOUR CHAN%i", i + 1); - tmcdev_write(device, str); + tmc_write(str); - tmcdev_write(device, ":WAV:FORM BYTE"); + tmc_write(":WAV:FORM BYTE"); - tmcdev_write(device, ":WAV:MODE NORM"); + tmc_write(":WAV:MODE NORM"); - tmcdev_write(device, ":WAV:DATA?"); + tmc_write(":WAV:DATA?"); - n = tmcdev_read(device); + n = tmc_read(); if(n < 0) {