a1de7e6e | 2015-09-09 21:33:05 | Timothy Pearson |
Add intial support for component analyzers |
||
A servers/gpib_server_lin/src/companalyzer_functions.cpp A servers/gpib_server_lin/src/companalyzer_functions.h M servers/gpib_server_lin/src/Makefile.am M servers/gpib_server_lin/src/gpib_conn.cpp M servers/gpib_server_lin/src/gpib_conn.h M servers/gpib_server_lin/src/gpib_functions.cpp M servers/gpib_server_lin/src/gpib_functions.h M servers/gpib_server_lin/src/main.cpp R servers/gpib_server_lin/src/main_server_lin.cpp |
||
diff --git a/servers/gpib_server_lin/src/Makefile.am b/servers/gpib_server_lin/src/Makefile.am index 2e4a862..1eb6963 100644 --- a/servers/gpib_server_lin/src/Makefile.am +++ b/servers/gpib_server_lin/src/Makefile.am @@ -3,7 +3,7 @@ bin_PROGRAMS = ulab_gpibserver -ulab_gpibserver_SOURCES = commanalyzer_functions.cpp gpib_functions.cpp scope_functions.cpp signal_functions.cpp main.cpp gpib_conn.cpp +ulab_gpibserver_SOURCES = commanalyzer_functions.cpp companalyzer_functions.cpp gpib_functions.cpp scope_functions.cpp signal_functions.cpp main.cpp gpib_conn.cpp ulab_gpibserver_METASOURCES = AUTO ulab_gpibserver_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor -ltdeldap -ltdekrbsocket -ltqtrla -lgpib diff --git a/servers/gpib_server_lin/src/companalyzer_functions.cpp b/servers/gpib_server_lin/src/companalyzer_functions.cpp new file mode 100644 index 0000000..4eda333 --- /dev/null +++ b/servers/gpib_server_lin/src/companalyzer_functions.cpp @@ -0,0 +1,423 @@ +/* + * Remote Laboratory Instrumentation Server + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2009 - 2015 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <ctype.h> +#include <ctime> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <getopt.h> +#include "parameters.h" +#include "gpib_functions.h" +#include "gpib/ib.h" + +#include "companalyzer_functions.h" + +extern char falpha[1024]; +double companalyzer_raw_trace_data[1024]; + +unsigned long companalyzerTraceLength (const char * companalyzerType) { + if (strcmp("HP4191A", companalyzerType) == 0) { + return 417; + } + else { + return 1; + } +} + +int companalyzer_set_date(struct tm * datetime, const char * companalyzerType, int gpibDevice) { + char datebuffer [80]; + strftime(datebuffer, 80, "CONF:DATE %m%d%y",datetime); + + if (strcmp("HP4191A", companalyzerType) == 0) { + printf("[INFO] Setting date on component analyzer\n\r"); + if (strcmp("HP4191A", companalyzerType) == 0) { + printf("[INFO] Instrument does not contain a clock, ignoring...\n\r"); + return 0; + } + else { + return 1; + } + } + else { + return 1; + } +} + +int companalyzer_set_time(struct tm * datetime, const char * companalyzerType, int gpibDevice) { + char timebuffer [80]; + strftime(timebuffer, 80, "CONF:TIME +%H.%M",datetime); // FIXME wrong format + + if (strcmp("HP4191A", companalyzerType) == 0) { + printf("[INFO] Setting time on component analyzer\n\r"); + if (strcmp("HP4191A", companalyzerType) == 0) { + printf("[INFO] Instrument does not contain a clock, ignoring...\n\r"); + // Since this function is used to detect instrument presence, reset the instrument displays here... + snprintf(timebuffer, 80, "A1B1"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", timebuffer); + #endif + if (gpib_write(gpibDevice, timebuffer) == 0) { + return 0; + } + else { + return 2; + } + return 0; + } + else { + return 1; + } + } + else { + return 1; + } +} + +int companalyzer_lock_local_controls (const char * companalyzerType, int gpibDevice) { + if (strcmp("HP4191A", companalyzerType) == 0) { + printf("[INFO] Locking component analyzer local controls\n\r"); + if (strcmp("HP4191A", companalyzerType) == 0) { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Setting REN\n\r"); + #endif + if (ibsre(gpibDevice, 1) == 0) { + return 0; + } + else { + return 2; + } + } + else { + return 1; + } + } + else { + return 1; + } +} + +int companalyzer_set_measurement_parameters(companalyzer_measurement::companalyzer_measurement_t parameter_a, companalyzer_measurement::companalyzer_measurement_t parameter_b, const char * companalyzerType, int gpibDevice, char * extendedError) { + char first_parameter[1024]; + + if ((strcmp("HP4191A", companalyzerType) == 0)) { + printf("[INFO] Setting component analyzer measurement parameters to types %d:%d\n\r", parameter_a, parameter_b); + if (strcmp("HP4191A", companalyzerType) == 0) { + falpha[0] = 0; + first_parameter[0] = 0; + if (parameter_a == companalyzer_measurement::resistance) { + sprintf(first_parameter, "A4"); + } + else if (parameter_a == companalyzer_measurement::conductance) { + sprintf(first_parameter, "A5"); + } + else if (parameter_a == companalyzer_measurement::inductance) { + sprintf(first_parameter, "A7"); + } + else if (parameter_a == companalyzer_measurement::capacitance) { + sprintf(first_parameter, "A8"); + } + else if (parameter_a == companalyzer_measurement::impedance) { + sprintf(first_parameter, "A1"); + } + else if (parameter_a == companalyzer_measurement::admittance) { + sprintf(first_parameter, "A2"); + } + else if (parameter_a == companalyzer_measurement::reflection_absolute) { + sprintf(first_parameter, "A3"); + } + else if (parameter_a == companalyzer_measurement::reflection_x) { + sprintf(first_parameter, "A6"); + } + + if (first_parameter[0] != 0) { + if (parameter_b == companalyzer_measurement::resistance) { + sprintf(falpha, "%sB1", first_parameter); + } + else if (parameter_b == companalyzer_measurement::conductance) { + sprintf(falpha, "%sB2", first_parameter); + } + else if (parameter_b == companalyzer_measurement::dissipation_factor) { + sprintf(falpha, "%sB3", first_parameter); + } + else if (parameter_b == companalyzer_measurement::quality_factor) { + sprintf(falpha, "%sB4", first_parameter); + } + else if (parameter_b == companalyzer_measurement::phase_angle_deg) { + sprintf(falpha, "%sB1", first_parameter); + } + else if (parameter_b == companalyzer_measurement::phase_angle_rad) { + sprintf(falpha, "%sB2", first_parameter); + } + } + if (strlen(falpha) == 0) { + sprintf(extendedError, "EXTAn invalid parameter or combination of parameters was requested��"); + return 2; + } + else { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!��"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!��"); + return 1; + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!��"); + return 1; + } +} + +int companalyzer_set_measurement_frequency(double frequency, const char * companalyzerType, int gpibDevice, char * extendedError) { + if ((strcmp("HP4191A", companalyzerType) == 0)) { + printf("[INFO] Setting component analyzer measurement frequency to %eMHz\n\r", frequency); + if (strcmp("HP4191A", companalyzerType) == 0) { + falpha[0] = 0; + + if ((frequency >= 1.0) && (frequency <= 1000.0)) { + sprintf(falpha, "FR%04.04fEN", frequency); + } + if (strlen(falpha) == 0) { + sprintf(extendedError, "EXTAn invalid parameter or combination of parameters was requested��"); + return 2; + } + else { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + return 0; + } + else { + sprintf(extendedError, "EXTAn unknown communications error has occured!��"); + return 2; + } + } + } + else { + sprintf(extendedError, "EXTAn invalid device was selected!��"); + return 1; ** Diff limit reached (max: 250 lines) ** |