summaryrefslogtreecommitdiffstats
path: root/servers/gpib_server_lin/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-10 15:18:59 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-10 15:18:59 -0500
commit8d3c1358eeaefec559c4a09995ff5b26393a9620 (patch)
treeab62cda8a3ddb0f77608625a52525726a7989665 /servers/gpib_server_lin/src
parentcb05310c2faa576313ebb0a637b09588a3a588a1 (diff)
downloadulab-8d3c1358eeaefec559c4a09995ff5b26393a9620.tar.gz
ulab-8d3c1358eeaefec559c4a09995ff5b26393a9620.zip
Add untested support for scope trace grabbing
Diffstat (limited to 'servers/gpib_server_lin/src')
-rw-r--r--servers/gpib_server_lin/src/gpib_conn.cpp23
-rw-r--r--servers/gpib_server_lin/src/scope_functions.cpp164
-rw-r--r--servers/gpib_server_lin/src/scope_functions.h4
3 files changed, 189 insertions, 2 deletions
diff --git a/servers/gpib_server_lin/src/gpib_conn.cpp b/servers/gpib_server_lin/src/gpib_conn.cpp
index cf19cee..a17ee1f 100644
--- a/servers/gpib_server_lin/src/gpib_conn.cpp
+++ b/servers/gpib_server_lin/src/gpib_conn.cpp
@@ -267,6 +267,27 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame();
}
}
+ else if ((m_instrumentCommand == "GETCHANNELTRACE")) { // Want channel trace
+ TQ_INT32 value;
+ ds >> value;
+ TQ_INT32 traceLength;
+ traceLength = scope_get_channel_trace(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket);
+ if (traceLength > 0) {
+ int i;
+ TQFloatArray traceData;
+ traceData.resize(traceLength);
+ for (i=0; i<traceLength; i++) {
+ traceData[i] = scope_raw_trace_data[i];
+ }
+ ds << TQString("ACK");
+ ds << traceData;
+ writeEndOfFrame();
+ }
+ else {
+ ds << TQString("NCK");
+ writeEndOfFrame();
+ }
+ }
else if (m_instrumentCommand == "SETVOLTSDIV") { // Want to change volts per division
TQ_INT32 value1;
ds >> value1;
@@ -461,7 +482,6 @@ void GPIBSocket::commandLoop() {
}
}
else if ((m_instrumentCommand == "GETSPECTRUMTRACE")) { // Want SA trace
- ds << TQString("ACK");
if (commanalyzer_get_spectrum_analyzer_trace(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket) == 0) {
int i;
int tracelen = commanalyzerTraceLength(m_serverParent->m_commanalyzerType.ascii());
@@ -470,6 +490,7 @@ void GPIBSocket::commandLoop() {
for (i=0; i<tracelen; i++) {
traceData[i] = commanalyzer_raw_trace_data[i];
}
+ ds << TQString("ACK");
ds << traceData;
writeEndOfFrame();
}
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
diff --git a/servers/gpib_server_lin/src/scope_functions.h b/servers/gpib_server_lin/src/scope_functions.h
index 8b0a215..fbab514 100644
--- a/servers/gpib_server_lin/src/scope_functions.h
+++ b/servers/gpib_server_lin/src/scope_functions.h
@@ -21,6 +21,7 @@
*/
extern unsigned char scope_raw_screenshot_data[4194304];
+extern double scope_raw_trace_data[65535];
unsigned long scopeScreenSize (const char * scopeType);
unsigned long scopeScreenWidth (const char * scopeType);
@@ -34,4 +35,5 @@ 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_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); \ No newline at end of file
+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