summaryrefslogtreecommitdiffstats
path: root/servers/gpib_server_lin/src/commanalyzer_functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'servers/gpib_server_lin/src/commanalyzer_functions.c')
-rw-r--r--servers/gpib_server_lin/src/commanalyzer_functions.c306
1 files changed, 306 insertions, 0 deletions
diff --git a/servers/gpib_server_lin/src/commanalyzer_functions.c b/servers/gpib_server_lin/src/commanalyzer_functions.c
index 0a91731..207a4d5 100644
--- a/servers/gpib_server_lin/src/commanalyzer_functions.c
+++ b/servers/gpib_server_lin/src/commanalyzer_functions.c
@@ -653,4 +653,310 @@ int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * comm
else {
return -1;
}
+}
+
+int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice) {
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ return 10;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer reference power level\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:RLEV?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ segarray[ai] = 0;
+ *retval = atof(segarray);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer scale\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:DISP:SCAL?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+int commanalyzer_set_display_brightness(float percent, char * commanalyzerType, int gpibDevice) {
+ int instrument_scale;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ instrument_scale = ((percent/100.0)*7.0)+1;
+ }
+ printf("[INFO] Setting display brightness to %d\n\r", instrument_scale);
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"CONF:INT %d", instrument_scale);
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ return 0;
+ }
+ else {
+ return 2;
+ }
+ }
+ }
+ else {
+ return 1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer center frequency\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:CFR?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_span(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer frequency span\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:SPAN?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
} \ No newline at end of file