diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-14 16:05:39 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-14 16:05:39 -0500 |
commit | fe06492794c15013e4511d1fcd623b0234c21afe (patch) | |
tree | ef6cc5128d33feb3fc73c218607d509a4c2a26e8 /servers/gpib_server_lin/src | |
parent | e382ba1107906e9f6725fe7b4f15f62b5bb282c5 (diff) | |
download | ulab-fe06492794c15013e4511d1fcd623b0234c21afe.tar.gz ulab-fe06492794c15013e4511d1fcd623b0234c21afe.zip |
Can now grab initial scope traces
Diffstat (limited to 'servers/gpib_server_lin/src')
-rw-r--r-- | servers/gpib_server_lin/src/gpib_conn.cpp | 136 | ||||
-rw-r--r-- | servers/gpib_server_lin/src/scope_functions.cpp | 519 | ||||
-rw-r--r-- | servers/gpib_server_lin/src/scope_functions.h | 12 |
3 files changed, 547 insertions, 120 deletions
diff --git a/servers/gpib_server_lin/src/gpib_conn.cpp b/servers/gpib_server_lin/src/gpib_conn.cpp index c0d43ca..6837725 100644 --- a/servers/gpib_server_lin/src/gpib_conn.cpp +++ b/servers/gpib_server_lin/src/gpib_conn.cpp @@ -263,7 +263,17 @@ void GPIBSocket::commandLoop() { if (m_instrumentCommand != "") { if (m_activeDeviceType == 2) { // Oscilloscope - if (m_instrumentCommand == "SETHORIZTIMEBASE") { // Want to change horizontal timebase + if (m_instrumentCommand == "RESET") { // Want to reset scope + if (scope_reset(m_serverParent->m_funcgenType.ascii(), m_serverParent->m_funcgenDeviceSocket) == 0) { + ds << TQString("ACK"); + writeEndOfFrame(); + } + else { + ds << TQString("NCK");; + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "SETHORIZTIMEBASE") { // Want to change horizontal timebase double value; ds >> value; if (scope_set_timebase(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { @@ -282,13 +292,17 @@ void GPIBSocket::commandLoop() { traceLength = scope_get_channel_trace(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket); if (traceLength > 0) { int i; - TQFloatArray traceData; + TQDoubleArray traceData; + TQDoubleArray positionData; traceData.resize(traceLength); + positionData.resize(traceLength); for (i=0; i<traceLength; i++) { traceData[i] = scope_raw_trace_data[i]; + positionData[i] = scope_raw_position_data[i]; } ds << TQString("ACK"); ds << traceData; + ds << positionData; writeEndOfFrame(); } else { @@ -310,6 +324,49 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } + else if (m_instrumentCommand == "GETVOLTSDIV") { // Want to get volts per division + double voltsdiv; + TQ_INT32 value; + ds >> value; + if (scope_get_channel_volts_div(&voltsdiv, value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + ds << TQString("ACK"); + ds << voltsdiv; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "GETSECONDSSDIV") { // Want to get seconds per division + double secondsdiv; + TQ_INT32 value; + ds >> value; + if (scope_get_channel_seconds_div(&secondsdiv, value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + ds << TQString("ACK"); + ds << secondsdiv; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "GETTRACESAMPLECOUNT") { // Want to get number of samples in the trace + unsigned long samples; + TQ_INT32 value; + ds >> value; + if (scope_get_channel_sample_count(&samples, value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + ds << TQString("ACK"); + TQ_INT32 safeSamples = samples; + ds << safeSamples; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } else if (m_instrumentCommand == "SETRUNNING") { // Want to change run status TQ_INT32 value; ds >> value; @@ -325,7 +382,7 @@ void GPIBSocket::commandLoop() { else if (m_instrumentCommand == "SETCHANNELACTIVE") { // Want to change channel enable TQ_INT32 value1; ds >> value1; - TQ_INT32 value2; + TQ_INT16 value2; ds >> value2; if (scope_set_channel_state(value1, value2, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { ds << TQString("ACK"); @@ -374,6 +431,60 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } + else if (m_instrumentCommand == "GETHORIZONTALDIVCOUNT") { // Want the number of horizontal divisions available + TQ_INT16 divisions = scope_get_number_of_vertical_divisions(m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket); + if (divisions >= 0) { + ds << TQString("ACK"); + ds << divisions; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "GETVERTICALDIVCOUNT") { // Want the number of vertical divisions available + TQ_INT16 divisions = scope_get_number_of_horizontal_divisions(m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket); + if (divisions >= 0) { + ds << TQString("ACK"); + ds << divisions; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "GETNUMBEROFCHANNELS") { // Want the number of channels available + TQ_INT16 divisions = scope_get_number_of_channels(m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket); + if (divisions >= 0) { + ds << TQString("ACK"); + ds << divisions; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } + else if (m_instrumentCommand == "GETCHANNELACTIVE") { // Want to get channel activity + int state; + TQ_INT32 value; + ds >> value; + if (scope_get_channel_state(&state, value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + TQ_INT16 safeState = state; + ds << TQString("ACK"); + ds << safeState; + 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); + } } else if (m_activeDeviceType == 3) { // Function generator @@ -476,6 +587,9 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } + else { + printf("[WARNING] Received unknown command %s from host %s\n\r", m_instrumentCommand.ascii(), m_remoteHost.ascii()); fflush(stdout); + } } else if (m_activeDeviceType == 4) { // Communications analyzer @@ -714,8 +828,8 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } - else if (m_instrumentCommand == "GETVERTICALDIVCOUNT") { // Want the number of vertical divisions available - TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); + else if (m_instrumentCommand == "GETHORIZONTALDIVCOUNT") { // Want the number of horizontal divisions available + TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); if (divisions >= 0) { ds << TQString("ACK"); ds << divisions; @@ -726,8 +840,8 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } - else if (m_instrumentCommand == "GETTRACESAMPLECOUNT") { // Want the number of samples in a trace - TQ_INT16 divisions = commanalyzerTraceLength(m_serverParent->m_commanalyzerType.ascii()); + else if (m_instrumentCommand == "GETVERTICALDIVCOUNT") { // Want the number of vertical divisions available + TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); if (divisions >= 0) { ds << TQString("ACK"); ds << divisions; @@ -738,8 +852,8 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } - else if (m_instrumentCommand == "GETHORIZONTALDIVCOUNT") { // Want the number of horizontal divisions available - TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); + else if (m_instrumentCommand == "GETTRACESAMPLECOUNT") { // Want the number of samples in a trace + TQ_INT16 divisions = commanalyzerTraceLength(m_serverParent->m_commanalyzerType.ascii()); if (divisions >= 0) { ds << TQString("ACK"); ds << divisions; @@ -798,6 +912,9 @@ void GPIBSocket::commandLoop() { writeEndOfFrame(); } } + else { + printf("[WARNING] Received unknown command %s from host %s\n\r", m_instrumentCommand.ascii(), m_remoteHost.ascii()); fflush(stdout); + } } else { // Unknown @@ -970,6 +1087,7 @@ int GPIBServer::readConfig() { printf("[INFO] %s\n\r", timebuffer); if (gpib_write(m_scopeDeviceSocket, timebuffer) == 0) { gpib_write(m_scopeDeviceSocket, datebuffer); + scope_perform_initial_setup(m_scopeType.ascii(), m_scopeDeviceSocket); printf("[INFO] Communication verified\n\r"); } else { diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp index dc6bf5f..abfc9e4 100644 --- a/servers/gpib_server_lin/src/scope_functions.cpp +++ b/servers/gpib_server_lin/src/scope_functions.cpp @@ -37,6 +37,7 @@ extern char falpha[1024]; unsigned char scope_raw_screenshot_data[4194304]; double scope_raw_trace_data[65535]; +double scope_raw_position_data[65535]; unsigned long scopeScreenWidth (const char * scopeType) { if (strcmp("HP54600OS", scopeType) == 0) { @@ -175,6 +176,11 @@ int scope_get_screenshot_stage2(const char * scopeType, int gpibDevice) { return 1; } +int scope_reset(const char * funcgenType, int gpibDevice) { + // FIXME + // GNDN + return 0; +} int scope_get_screenshot(const char * scopeType, int gpibDevice) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { @@ -255,6 +261,9 @@ int scope_set_timebase(float desired_timebase,const char * scopeType, int gpibDe return 2; } } + else { + return -1; + } } else { return 1; @@ -288,6 +297,9 @@ int scope_set_volts_div(int desired_channel, float desired_volts,const char * sc return 2; } } + else { + return -1; + } } else { return 1; @@ -326,6 +338,9 @@ int scope_set_acquisition(int status,const char * scopeType, int gpibDevice) { return 2; } } + else { + return -1; + } } else { return 1; @@ -375,12 +390,63 @@ int scope_set_channel_state(int desired_channel, int status,const char * scopeTy return 2; } } + else { + return -1; + } } else { return 1; } } +int scope_get_channel_state(int * retval, int desired_channel, const char * scopeType, int gpibDevice) { + char floatstring[1024]; + long ai; + int max_num_bytes = 0; + + printf("[INFO] Getting channel %d state\n\r", desired_channel); + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha, "SELECT:CH%d?", 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 = atoi(floatstring); + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + int scope_set_trigger_channel(int desired_channel,const char * scopeType, int gpibDevice) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { printf("[INFO] Setting scope trigger channel to %d\n\r", desired_channel); @@ -408,6 +474,9 @@ int scope_set_trigger_channel(int desired_channel,const char * scopeType, int gp return 2; } } + else { + return -1; + } } else { return 1; @@ -441,6 +510,9 @@ int scope_set_trigger_level(float desired_level,const char * scopeType, int gpib return 2; } } + else { + return -1; + } } else { return 1; @@ -474,21 +546,66 @@ int scope_set_channel_position(int desired_channel, float desired_level,const ch return 2; } } + else { + return -1; + } } else { return 1; } } -int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) { - int max_num_bytes = 0; +int scope_perform_initial_setup(const char * scopeType, int gpibDevice) { + // Send request + printf("[INFO] Configuring oscilloscope\n\r"); + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha,"DATA:ENCDG RIBINARY"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"DATA:WIDTH 2"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"DATA:START 1"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"DATA:STOP 65535"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + return 0; + } + else { + return -2; + } + } + else { + return -2; + } + } + else { + return -2; + } + } + else { + return -1; + } +} +int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) { char segarray[4194304]; - char floatstring[1024]; long array_pointer; long ai; - long left_char; - long right_char; // Send request printf("[INFO] Getting oscilloscope trace for channel %d [Stage 1]\n\r", desired_channel); @@ -504,132 +621,77 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi printf("[DEBG] Writing: %s\n\r", falpha); #endif if (gpib_write(gpibDevice, falpha) == 0) { - sprintf(falpha,"DATA:ENCDG RIBINARY"); + sprintf(falpha,"WFMPRE?"); #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Writing: %s\n\r", falpha); #endif if (gpib_write(gpibDevice, falpha) == 0) { - sprintf(falpha,"DATA:WIDTH 2"); + // Read response #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Writing: %s\n\r", falpha); + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535); #endif - if (gpib_write(gpibDevice, falpha) == 0) { - sprintf(falpha,"DATA:START 1"); + ai = gpib_read_array(gpibDevice, 65535, segarray); + if (ai == -1) { + return -1; + } + else { + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + TQString preamble(segarray); + TQStringList resultPairs = TQStringList::split(";", preamble, FALSE); + // Find/initialize critical data values + double ymult; + double yoffset; + double yposition; + const char* yunits; + double xincr; + double xposition; + const char* xunits; + + ymult = resultPairs[13].toDouble(); + yoffset = resultPairs[14].toDouble()*ymult; + yposition = resultPairs[15].toDouble()*ymult; + yunits = strdup(resultPairs[12]); + xincr = resultPairs[9].toDouble(); + xposition = resultPairs[10].toDouble(); + xunits = strdup(resultPairs[8]); + + // Get the curve data now + sprintf(falpha,"CURVE?"); #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Writing: %s\n\r", falpha); #endif if (gpib_write(gpibDevice, falpha) == 0) { - sprintf(falpha,"DATA:STOP 65535"); #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Writing: %s\n\r", falpha); + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535*2); #endif - if (gpib_write(gpibDevice, falpha) == 0) { - sprintf(falpha,"WFMPRE?"); + ai = gpib_read_array(gpibDevice, 65535*2, segarray); + if (ai == -1) { + return -1; + } + else { #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Writing: %s\n\r", falpha); + printf("[DEBG] Read %li bytes from GPIB device\n", ai); #endif - if (gpib_write(gpibDevice, falpha) == 0) { - // Read response - #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535); - #endif - ai = gpib_read_array(gpibDevice, 65535, segarray); - if (ai == -1) { - return -1; - } - else { - #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Read %li bytes from GPIB device\n", ai); - #endif - TQString preamble(segarray); - TQStringList resultPairs = TQStringList::split(";", preamble, FALSE); - // Find/initialize critical data values - double ymult; - double yoffset; - double yposition; - const char* yunits; - double xincr; - double xposition; - const char* xunits; - for (TQStringList::Iterator it = resultPairs.begin(); it != resultPairs.end(); ++it) { - TQString curVal = *it; - if (curVal.startsWith("YMULT ")) { - curVal.replace("YMULT ", ""); - ymult = curVal.toDouble(); - } - else if (curVal.startsWith("YOFF ")) { - curVal.replace("YOFF ", ""); - yoffset = curVal.toDouble(); - } - else if (curVal.startsWith("YZERO ")) { - curVal.replace("YZERO ", ""); - yposition = curVal.toDouble(); - } - else if (curVal.startsWith("YUNIT ")) { - curVal.replace("YUNIT ", ""); - yunits = strdup(curVal.ascii()); - } - else if (curVal.startsWith("XINCR ")) { - curVal.replace("XINCR ", ""); - xincr = curVal.toDouble(); - } - else if (curVal.startsWith("XZERO ")) { - curVal.replace("XZERO ", ""); - xposition = curVal.toDouble(); - } - else if (curVal.startsWith("XUNIT ")) { - curVal.replace("XUNIT ", ""); - xunits = strdup(curVal.ascii()); - } - } - // Get the curve data now - sprintf(falpha,"CURVE?"); - #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Writing: %s\n\r", falpha); - #endif - if (gpib_write(gpibDevice, falpha) == 0) { - #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535*2); - #endif - ai = gpib_read_array(gpibDevice, 65535*2, segarray); - if (ai == -1) { - return -1; - } - else { - #ifdef ENABLE_EXTRA_DEBUGGING - printf("[DEBG] Read %li bytes from GPIB device\n", ai); - #endif - // Interpret the results - long pointCount = ai/2; - for (array_pointer=0; array_pointer<pointCount; array_pointer++) { - TQ_INT16 tempvalue; - tempvalue = segarray[(array_pointer*2)+1]; // LSB - tempvalue = tempvalue | (segarray[(array_pointer*2)+0] << 8); // MSB - scope_raw_trace_data[array_pointer] = tempvalue; - scope_raw_trace_data[array_pointer] = scope_raw_trace_data[array_pointer] * ymult; - } - } - } - else { - return -2; - } - } - } - else { - return -2; + // Interpret the results + long pointCount = ai/2; + double horizPos = 0.0; + for (array_pointer=0; array_pointer<pointCount; array_pointer++) { + TQ_INT16 tempvalue; + tempvalue = segarray[(array_pointer*2)+1]; // LSB + tempvalue = tempvalue | (segarray[(array_pointer*2)+0] << 8); // MSB + scope_raw_trace_data[array_pointer] = tempvalue; + scope_raw_trace_data[array_pointer] = (scope_raw_trace_data[array_pointer] * ymult)-yoffset; + scope_raw_position_data[array_pointer] = horizPos; + horizPos = horizPos + xincr; } } - else { - return -2; - } } else { return -2; } } - else { - return -2; - } } else { return -2; @@ -641,4 +703,241 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi return array_pointer; } + else { + return -1; + } +} + +int scope_get_number_of_horizontal_divisions(const char * scopeType, int gpibDevice) { + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return 8; + } + else { + return -1; + } +} + +int scope_get_number_of_vertical_divisions(const char * scopeType, int gpibDevice) { + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return 10; + } + else { + return -1; + } +} + +int scope_get_number_of_channels(const char * scopeType, int gpibDevice) { + if (strcmp("HP54600OS", scopeType) == 0) { + return 2; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + return 4; + } + else { + return -1; + } +} + +int scope_get_channel_volts_div(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 scope volts per division for channel %d\n\r", desired_channel); + sprintf(falpha,"CH%d:SCALE?", 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_channel_seconds_div(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) { + double xincr; + + // Send request + printf("[INFO] Getting scope seconds per division for channel %d\n\r", desired_channel); + sprintf(falpha,"DATA:SOURCE CH%d", desired_channel); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) != 0) { + return 2; + } + + sprintf(falpha,"WFMPRE:CH%d:XINCR?",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; + xincr = atof(floatstring); + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + sprintf(falpha,"WFMPRE:CH%d:NR_P?", 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)*xincr)/scope_get_number_of_vertical_divisions(scopeType, gpibDevice)); + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + +int scope_get_channel_sample_count(unsigned long * 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 number of samples in trace for channel %d\n\r", desired_channel); + sprintf(falpha,"DATA:SOURCE CH%d", desired_channel); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) != 0) { + return 2; + } + + sprintf(falpha,"WFMPRE:CH%d:NR_P?", 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; + } }
\ 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 fbab514..2c0bcd1 100644 --- a/servers/gpib_server_lin/src/scope_functions.h +++ b/servers/gpib_server_lin/src/scope_functions.h @@ -22,18 +22,28 @@ extern unsigned char scope_raw_screenshot_data[4194304]; extern double scope_raw_trace_data[65535]; +extern double scope_raw_position_data[65535]; unsigned long scopeScreenSize (const char * scopeType); unsigned long scopeScreenWidth (const char * scopeType); unsigned long scopeScreenHeight (const char * scopeType); int gpib_read_binary(int ud, int max_num_bytes); +int scope_reset(const char * funcgenType, int gpibDevice); 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_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); int scope_set_trigger_channel(int desired_channel,const char * scopeType, int gpibDevice); int scope_set_trigger_level(float desired_level,const char * scopeType, int gpibDevice); int scope_set_channel_position(int desired_channel, float desired_level,const char * scopeType, int gpibDevice); -int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice);
\ No newline at end of file +int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice); +int scope_get_number_of_horizontal_divisions(const char * scopeType, int gpibDevice); +int scope_get_number_of_vertical_divisions(const char * scopeType, int gpibDevice); +int scope_get_number_of_channels(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 |