diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-18 16:33:39 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-18 16:33:39 -0500 |
commit | 23eadbf9246280ce6473a4fe4d3605cd730eb8c8 (patch) | |
tree | 99a742ea61a71eb7e65ad881acfa652b3030d096 /servers/gpib_server_lin | |
parent | 3ce46cc90fa5c488f1c41cd4cace0b2a98f3d143 (diff) | |
download | ulab-23eadbf9246280ce6473a4fe4d3605cd730eb8c8.tar.gz ulab-23eadbf9246280ce6473a4fe4d3605cd730eb8c8.zip |
Add channel controls to scope
Diffstat (limited to 'servers/gpib_server_lin')
-rw-r--r-- | servers/gpib_server_lin/src/gpib_conn.cpp | 30 | ||||
-rw-r--r-- | servers/gpib_server_lin/src/scope_functions.cpp | 86 | ||||
-rw-r--r-- | servers/gpib_server_lin/src/scope_functions.h | 6 |
3 files changed, 116 insertions, 6 deletions
diff --git a/servers/gpib_server_lin/src/gpib_conn.cpp b/servers/gpib_server_lin/src/gpib_conn.cpp index b46f469..dc081a3 100644 --- a/servers/gpib_server_lin/src/gpib_conn.cpp +++ b/servers/gpib_server_lin/src/gpib_conn.cpp @@ -313,7 +313,7 @@ void GPIBSocket::commandLoop() { else if (m_instrumentCommand == "SETVOLTSDIV") { // Want to change volts per division TQ_INT32 value1; ds >> value1; - float value2; + double value2; ds >> value2; if (scope_set_volts_div(value1, value2, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { ds << TQString("ACK"); @@ -507,6 +507,34 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } + else if (m_instrumentCommand == "GETPERMITTEDVDIVS") { // Want to get permitted volts/div settings + double attenuation_mult; + double* permitted_array; + int permitted_count; + TQ_INT32 value; + ds >> value; + if (scope_get_probe_attenuation_multiplier(&attenuation_mult, value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + if (scope_get_permitted_volts_div_settings_at_1x(&permitted_count, &permitted_array, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + long i; + TQDoubleList permittedValues; + for (i=0; i<permitted_count; i++) { + permittedValues.append(permitted_array[i]/attenuation_mult); + } + free(permitted_array); + ds << TQString("ACK"); + ds << permittedValues; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } else { printf("[WARNING] Received unknown command %s from host %s\n\r", m_instrumentCommand.ascii(), m_remoteHost.ascii()); fflush(stdout); } diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp index ce5adcd..0ba0bc1 100644 --- a/servers/gpib_server_lin/src/scope_functions.cpp +++ b/servers/gpib_server_lin/src/scope_functions.cpp @@ -273,9 +273,9 @@ int scope_set_timebase(float desired_timebase,const char * scopeType, int gpibDe } } -int scope_set_volts_div(int desired_channel, float desired_volts,const char * scopeType, int gpibDevice) { +int scope_set_volts_div(int desired_channel, double desired_volts, const char * scopeType, int gpibDevice) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { - printf("[INFO] Setting scope volts/div on channel %d to %f\n\r", desired_channel, desired_volts/8); + printf("[INFO] Setting scope volts/div on channel %d to %E\n\r", desired_channel, desired_volts); if (strcmp("HP54600OS", scopeType) == 0) { sprintf(falpha, "CHAN%d:RANG %E", desired_channel, desired_volts); #ifdef ENABLE_EXTRA_DEBUGGING @@ -289,7 +289,7 @@ int scope_set_volts_div(int desired_channel, float desired_volts,const char * sc } } else if (strcmp("TDS744AOS", scopeType) == 0) { - sprintf(falpha, "CH%d:SCALE %f", desired_channel, desired_volts/8); + sprintf(falpha, "CH%d:SCALE %E", desired_channel, desired_volts); #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Writing: %s\n\r", falpha); #endif @@ -387,6 +387,7 @@ int scope_set_channel_state(int desired_channel, int status,const char * scopeTy printf("[DEBG] Writing: %s\n\r", falpha); #endif if (gpib_write(gpibDevice, falpha) == 0) { + usleep(2*1000000); // The scope is slow to respond, and also blind to commands during the update window! [RAJA TESTME] return 0; } else { @@ -1118,4 +1119,83 @@ int scope_get_channel_sample_count(unsigned long * retval, int desired_channel, else { return -1; } +} + +int scope_get_probe_attenuation_multiplier(double * retval, int desired_channel, const char * scopeType, int gpibDevice) { + char floatstring[1024]; + long ai; + int max_num_bytes = 0; + + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + // Send request + printf("[INFO] Getting trigger level for channel %d\n\r", desired_channel); + sprintf(falpha,"CH%d:PROBE?", desired_channel); + #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 + + ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring); + if (ai == -1) { + return 1; + } + else { + floatstring[ai]=0; + *retval = atof(floatstring); + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + +int scope_get_permitted_volts_div_settings_at_1x(int * number_of_values, double ** retarray, const char * scopeType, int gpibDevice) { + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + *number_of_values = 13; + double* values = (double*)malloc(sizeof(double)*(*number_of_values)); + values[0] = 1e-3; + values[1] = 2e-3; + values[2] = 5e-3; + values[3] = 1e-2; + values[4] = 2e-2; + values[5] = 5e-2; + values[6] = 1e-1; + values[7] = 2e-1; + values[8] = 5e-1; + values[9] = 1e0; + values[10] = 2e0; + values[11] = 5e0; + values[12] = 1e1; + *retarray = values; + return 0; + } + else { + return -1; + } }
\ No newline at end of file diff --git a/servers/gpib_server_lin/src/scope_functions.h b/servers/gpib_server_lin/src/scope_functions.h index b38f821..a83ab9a 100644 --- a/servers/gpib_server_lin/src/scope_functions.h +++ b/servers/gpib_server_lin/src/scope_functions.h @@ -33,7 +33,7 @@ int scope_get_screenshot(const char * scopeType, int gpibDevice); int scope_get_screenshot_stage2(const char * scopeType, int gpibDevice); int scope_perform_initial_setup(const char * scopeType, int gpibDevice); int scope_set_timebase(float desired_timebase,const char * scopeType, int gpibDevice); -int scope_set_volts_div(int desired_channel, float desired_volts,const char * scopeType, int gpibDevice); +int scope_set_volts_div(int desired_channel, double desired_volts, const char * scopeType, int gpibDevice); int scope_set_acquisition(int status,const char * scopeType, int gpibDevice); int scope_set_channel_state(int desired_channel, int status,const char * scopeType, int gpibDevice); int scope_get_channel_state(int * retval, int desired_channel, const char * scopeType, int gpibDevice); @@ -48,4 +48,6 @@ int scope_get_trigger_channel(int * retval, const char * scopeType, int gpibDevi int scope_get_trigger_level(double * retval, const char * scopeType, int gpibDevice); int scope_get_channel_volts_div(double * retval, int desired_channel, const char * scopeType, int gpibDevice); int scope_get_channel_seconds_div(double * retval, int desired_channel, const char * scopeType, int gpibDevice); -int scope_get_channel_sample_count(unsigned long * retval, int desired_channel, const char * scopeType, int gpibDevice);
\ No newline at end of file +int scope_get_channel_sample_count(unsigned long * retval, int desired_channel, const char * scopeType, int gpibDevice); +int scope_get_probe_attenuation_multiplier(double * retval, int desired_channel, const char * scopeType, int gpibDevice); +int scope_get_permitted_volts_div_settings_at_1x(int * number_of_values, double ** retarray, const char * scopeType, int gpibDevice);
\ No newline at end of file |