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/scope_functions.cpp | |
| 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/scope_functions.cpp')
| -rw-r--r-- | servers/gpib_server_lin/src/scope_functions.cpp | 519 | 
1 files changed, 409 insertions, 110 deletions
| 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 | 
