diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-10 15:18:59 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-10 15:18:59 -0500 |
commit | 8d3c1358eeaefec559c4a09995ff5b26393a9620 (patch) | |
tree | ab62cda8a3ddb0f77608625a52525726a7989665 /servers/gpib_server_lin/src/scope_functions.cpp | |
parent | cb05310c2faa576313ebb0a637b09588a3a588a1 (diff) | |
download | ulab-8d3c1358eeaefec559c4a09995ff5b26393a9620.tar.gz ulab-8d3c1358eeaefec559c4a09995ff5b26393a9620.zip |
Add untested support for scope trace grabbing
Diffstat (limited to 'servers/gpib_server_lin/src/scope_functions.cpp')
-rw-r--r-- | servers/gpib_server_lin/src/scope_functions.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp index d05deb4..dc6bf5f 100644 --- a/servers/gpib_server_lin/src/scope_functions.cpp +++ b/servers/gpib_server_lin/src/scope_functions.cpp @@ -36,6 +36,7 @@ extern char falpha[1024]; unsigned char scope_raw_screenshot_data[4194304]; +double scope_raw_trace_data[65535]; unsigned long scopeScreenWidth (const char * scopeType) { if (strcmp("HP54600OS", scopeType) == 0) { @@ -478,3 +479,166 @@ int scope_set_channel_position(int desired_channel, float desired_level,const ch return 1; } } + +int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) { + int max_num_bytes = 0; + + 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); + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + // We need to get/parse the preamble, then obtain and adjust the trace data + 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) { + 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 + if (gpib_write(gpibDevice, falpha) == 0) { + sprintf(falpha,"WFMPRE?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #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; + } + } + else { + return -2; + } + } + else { + return -2; + } + } + else { + return -2; + } + } + else { + return -2; + } + } + else { + return -2; + } + + return array_pointer; + } +}
\ No newline at end of file |