Can now grab initial scope traces

master
Timothy Pearson 13 years ago
parent e382ba1107
commit fe06492794

@ -572,7 +572,7 @@ void CommAnalyzerPart::mainEventLoop() {
if (result == "ACK") { if (result == "ACK") {
#if 1 #if 1
// Trace grap is slow on most instruments // Trace grab is slow on most instruments
// Put in the next trace request before processing the trace we just got so as to increase the overall update rate // Put in the next trace request before processing the trace we just got so as to increase the overall update rate
if (m_commHandlerMode == 0) { if (m_commHandlerMode == 0) {
// Get trace, step 1 // Get trace, step 1

@ -65,10 +65,6 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject *
m_base = new ScopeBase(widget()); m_base = new ScopeBase(widget());
m_traceWidget = m_base->traceWidget; m_traceWidget = m_base->traceWidget;
m_traceWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); m_traceWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
m_traceWidget->setTraceEnabled(0, true);
m_traceWidget->setTraceName(0, "Trace 1");
m_traceWidget->setTraceHorizontalUnits(0, "Hz");
m_traceWidget->setTraceVerticalUnits(0, "dBm");
m_traceWidget->setNumberOfCursors(4); m_traceWidget->setNumberOfCursors(4);
m_traceWidget->setCursorOrientation(0, TQt::Horizontal); m_traceWidget->setCursorOrientation(0, TQt::Horizontal);
m_traceWidget->setCursorOrientation(1, TQt::Horizontal); m_traceWidget->setCursorOrientation(1, TQt::Horizontal);
@ -89,10 +85,6 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject *
m_traceWidget->setZoomBoxEnabled(true); m_traceWidget->setZoomBoxEnabled(true);
m_base->traceZoomWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); m_base->traceZoomWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
m_base->traceZoomWidget->setTraceEnabled(0, true, false);
m_base->traceZoomWidget->setTraceName(0, "Trace 1");
m_base->traceZoomWidget->setTraceHorizontalUnits(0, "Hz");
m_base->traceZoomWidget->setTraceVerticalUnits(0, "dBm");
connect(m_traceWidget, SIGNAL(zoomBoxChanged(const TQRectF&)), this, SLOT(updateZoomWidgetLimits(const TQRectF&))); connect(m_traceWidget, SIGNAL(zoomBoxChanged(const TQRectF&)), this, SLOT(updateZoomWidgetLimits(const TQRectF&)));
connect(m_traceWidget, SIGNAL(offsetChanged(uint, double)), m_base->traceZoomWidget, SLOT(setTraceOffset(uint, double))); connect(m_traceWidget, SIGNAL(offsetChanged(uint, double)), m_base->traceZoomWidget, SLOT(setTraceOffset(uint, double)));
@ -219,10 +211,22 @@ void ScopePart::setTickerMessage(TQString message) {
} \ } \
else { \ else { \
m_commHandlerState = 255; \ m_commHandlerState = 255; \
} } \
printf("[RAJA DEBUG 640.0] Entering state %d\n\r", m_commHandlerState); fflush(stdout);
#define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE); #define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE);
int getNextActiveChannel(int current, bool* activity, int maxtracenumber) {
int ret = -1;
for (int i=current+1; i<=maxtracenumber; i++) {
if (activity[i]) {
ret = i;
break;
}
}
return ret;
}
void ScopePart::mainEventLoop() { void ScopePart::mainEventLoop() {
TQDataStream ds(m_socket); TQDataStream ds(m_socket);
ds.setPrintableData(true); ds.setPrintableData(true);
@ -267,8 +271,8 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 2) { else if (m_commHandlerState == 2) {
// Set spectrum analyzer mode // Reset scope
ds << TQString("SETMODESPECTRUMANALYZER"); ds << TQString("RESET");
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(3) SET_NEXT_STATE(3)
@ -299,8 +303,8 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 4) { else if (m_commHandlerState == 4) {
// Get number of samples in trace, step 1 // Get number of horizontal divisions, step 1
ds << TQString("GETTRACESAMPLECOUNT"); ds << TQString("GETHORIZONTALDIVCOUNT");
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(5) SET_NEXT_STATE(5)
@ -311,11 +315,11 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get number of samples in trace, step 2 // Get number of horizontal divisions, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_samplesInTrace; ds >> m_hdivs;
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
@ -334,8 +338,8 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 6) { else if (m_commHandlerState == 6) {
// Get number of horizontal divisions, step 1 // Get number of vertical divisions, step 1
ds << TQString("GETHORIZONTALDIVCOUNT"); ds << TQString("GETVERTICALDIVCOUNT");
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(7) SET_NEXT_STATE(7)
@ -346,11 +350,11 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get number of horizontal divisions, step 2 // Get number of vertical divisions, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_hdivs; ds >> m_vdivs;
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
@ -369,8 +373,8 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 8) { else if (m_commHandlerState == 8) {
// Get number of vertical divisions, step 1 // Get number of channels, step 1
ds << TQString("GETVERTICALDIVCOUNT"); ds << TQString("GETNUMBEROFCHANNELS");
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(9) SET_NEXT_STATE(9)
@ -381,15 +385,19 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get number of vertical divisions, step 2 // Get number of channels, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_vdivs; ds >> m_maxNumberOfTraces;
if (m_maxNumberOfTraces > MAXTRACES) {
m_maxNumberOfTraces = MAXTRACES;
}
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
if (result == "ACK") { if (result == "ACK") {
m_currentOpChannel = 1;
SET_NEXT_STATE(10) SET_NEXT_STATE(10)
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
@ -404,8 +412,9 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 10) { else if (m_commHandlerState == 10) {
// Get reference power level, step 1 // Get channel status, step 1
ds << TQString("GETREFERENCEPOWERLEVEL"); ds << TQString("GETCHANNELACTIVE");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(11) SET_NEXT_STATE(11)
@ -416,16 +425,31 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get reference power level, step 2 // Get channel status, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_rpower; TQ_INT16 active;
ds >> active;
m_channelActive[m_currentOpChannel] = (active != 0);
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
if (result == "ACK") { if (result == "ACK") {
if (m_currentOpChannel < m_maxNumberOfTraces) {
m_currentOpChannel++;
SET_NEXT_STATE(10)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(12) SET_NEXT_STATE(12)
}
else {
m_currentOpChannel = 1;
SET_NEXT_STATE(8)
}
}
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else { else {
@ -439,8 +463,9 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 12) { else if (m_commHandlerState == 12) {
// Get vertical division scale, step 1 // Get number of samples in trace, step 1
ds << TQString("GETVERTDIVSCALE"); ds << TQString("GETTRACESAMPLECOUNT");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(13) SET_NEXT_STATE(13)
@ -451,16 +476,23 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get vertical division scale, step 2 // Get number of samples in trace, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_vscale; ds >> m_samplesInTrace[m_currentOpChannel];
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
if (result == "ACK") { if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(12)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(14) SET_NEXT_STATE(14)
}
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else { else {
@ -474,8 +506,9 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 14) { else if (m_commHandlerState == 14) {
// Get center frequency, step 1 // Get volts per division, step 1
ds << TQString("GETCENTERFREQUENCY"); ds << TQString("GETVOLTSDIV");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(15) SET_NEXT_STATE(15)
@ -486,16 +519,23 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get center frequency, step 2 // Get volts per division, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_centerfreq; ds >> m_voltsDiv[m_currentOpChannel];
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
if (result == "ACK") { if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(14)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(16) SET_NEXT_STATE(16)
}
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else { else {
@ -509,8 +549,9 @@ void ScopePart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 16) { else if (m_commHandlerState == 16) {
// Get frequency span, step 1 // Get seconds per division, step 1
ds << TQString("GETFREQUENCYSPAN"); ds << TQString("GETSECONDSSDIV");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(17) SET_NEXT_STATE(17)
@ -521,11 +562,11 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get frequency span, step 2 // Get seconds per division, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> m_spanfreq; ds >> m_secsDiv[m_currentOpChannel];
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
@ -535,7 +576,14 @@ void ScopePart::mainEventLoop() {
} }
if (result == "ACK") { if (result == "ACK") {
SET_NEXT_STATE(18) m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(16)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(50)
}
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else { else {
@ -548,57 +596,52 @@ void ScopePart::mainEventLoop() {
} }
} }
} }
else if (m_commHandlerState == 18) { else if (m_commHandlerState == 50) {
// Get trace, step 1 // Get trace, step 1
ds << TQString("GETSPECTRUMTRACE"); ds << TQString("GETCHANNELTRACE");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
SET_NEXT_STATE(19) SET_NEXT_STATE(51)
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else if (m_commHandlerState == 19) { else if (m_commHandlerState == 51) {
// Get response data // Get response data
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Get trace, step 2 // Get trace, step 2
TQDoubleArray trace; TQDoubleArray trace;
TQDoubleArray positions;
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") { if (result == "ACK") {
ds >> trace; ds >> trace;
ds >> positions;
} }
m_socket->clearFrameTail(); m_socket->clearFrameTail();
if (result == "ACK") { if (result == "ACK") {
#if 1
// Trace grap is slow on most instruments
// Put in the next trace request before processing the trace we just got so as to increase the overall update rate
if (m_commHandlerMode == 0) {
// Get trace, step 1
ds << TQString("GETSPECTRUMTRACE");
m_socket->writeEndOfFrame();
}
#endif
// Update display widget(s) // Update display widget(s)
m_traceWidget->setSamples(0, trace); m_traceWidget->setSamples(m_currentOpChannel, trace);
m_base->traceZoomWidget->setSamples(0, trace); m_base->traceZoomWidget->setSamples(m_currentOpChannel, trace);
m_traceWidget->setPositions(m_currentOpChannel, positions);
m_base->traceZoomWidget->setPositions(m_currentOpChannel, positions);
postProcessTrace(); postProcessTrace();
m_traceWidget->repaint(true); m_traceWidget->repaint(true);
m_base->traceZoomWidget->repaint(true); m_base->traceZoomWidget->repaint(true);
} }
if (result == "ACK") { if (result == "ACK") {
#if 0 m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
//SET_NEXT_STATE(2) if (m_currentOpChannel > 0) {
SET_NEXT_STATE(18) SET_NEXT_STATE(50)
EXEC_NEXT_STATE_IMMEDIATELY }
#else else {
SET_NEXT_STATE(19) m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(50)
}
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
#endif
} }
else { else {
COMMUNICATIONS_FAILED COMMUNICATIONS_FAILED
@ -625,9 +668,10 @@ void ScopePart::mainEventLoop() {
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
} }
else if (m_commHandlerCommandState == 1) { else if (m_commHandlerCommandState == 1) {
// Set reference power level // Set channel active
ds << TQString("SETREFERENCEPOWERLEVEL"); ds << TQString("SETCHANNELACTIVE");
ds << m_rpower; ds << m_nextOpChannel;
ds << m_nextOpParameter16;
m_socket->writeEndOfFrame(); m_socket->writeEndOfFrame();
m_commHandlerCommandState = 2; m_commHandlerCommandState = 2;
@ -638,49 +682,11 @@ void ScopePart::mainEventLoop() {
if (m_socket->canReadFrame()) { if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER PAT_WATCHDOG_TIMER
// Set reference power level, step 2 // Set channel active, step 2
TQString result;
ds >> result;
m_socket->clearFrameTail();
if (result == "ACK") {
m_commHandlerCommandState = 3;
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerCommandState == 3) {
// Get reference power level, step 1
ds << TQString("GETREFERENCEPOWERLEVEL");
m_socket->writeEndOfFrame();
m_commHandlerCommandState = 4;
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerCommandState == 4) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get reference power level, step 2
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "ACK") {
ds >> m_rpower;
}
m_socket->clearFrameTail(); m_socket->clearFrameTail();
// Update display as needed
updateGraticule();
if (result == "ACK") { if (result == "ACK") {
m_commHandlerCommandState = 0; m_commHandlerCommandState = 0;
EXEC_NEXT_STATE_IMMEDIATELY EXEC_NEXT_STATE_IMMEDIATELY
@ -722,42 +728,39 @@ void ScopePart::updateZoomWidgetLimits(const TQRectF& zoomRect) {
} }
void ScopePart::updateGraticule() { void ScopePart::updateGraticule() {
m_traceWidget->setNumberOfSamples(0, m_samplesInTrace);
m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs); m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs);
m_traceWidget->setNumberOfVerticalDivisions(m_vdivs); m_traceWidget->setNumberOfVerticalDivisions(m_vdivs);
m_base->traceZoomWidget->setNumberOfSamples(0, m_samplesInTrace);
m_base->traceZoomWidget->setNumberOfHorizontalDivisions(m_hdivs); m_base->traceZoomWidget->setNumberOfHorizontalDivisions(m_hdivs);
m_base->traceZoomWidget->setNumberOfVerticalDivisions(m_vdivs); m_base->traceZoomWidget->setNumberOfVerticalDivisions(m_vdivs);
m_leftFrequency = m_centerfreq - (m_spanfreq/2.0); for (int traceno=1; traceno<=m_maxNumberOfTraces; traceno++) {
m_rightFrequency = m_centerfreq + (m_spanfreq/2.0); m_traceWidget->setTraceEnabled(traceno, m_channelActive[traceno]);
m_traceWidget->setTraceName(traceno, TQString("Channel %1").arg(traceno));
m_traceWidget->setTraceHorizontalUnits(traceno, "s");
m_traceWidget->setTraceVerticalUnits(traceno, "V");
m_traceWidget->setNumberOfSamples(traceno, m_samplesInTrace[traceno]);
m_base->traceZoomWidget->setNumberOfSamples(traceno, m_samplesInTrace[traceno]);
m_traceWidget->setDisplayLimits(traceno, TQRectF(0.0, (m_voltsDiv[traceno]*m_vdivs)/2.0, (m_secsDiv[traceno]*m_hdivs), (m_voltsDiv[traceno]*m_vdivs)/-2.0));
double freqincr = (m_rightFrequency-m_leftFrequency)/m_samplesInTrace; printf("[RAJA DEBUG 700.0] m_voltsDiv[%d]: %f m_vdivs: %d m_secsDiv[%d]: %f m_hdivs: %d\n\r", traceno, m_voltsDiv[traceno], m_vdivs, traceno, m_secsDiv[traceno], m_hdivs); fflush(stdout);
double freqpos = m_leftFrequency;
TQDoubleArray tracepositions;
tracepositions.resize(m_samplesInTrace);
for (int i=0; i<m_samplesInTrace; i++) {
tracepositions[i] = freqpos;
freqpos = freqpos + freqincr;
} }
m_traceWidget->setPositions(0, tracepositions);
m_traceWidget->setDisplayLimits(0, TQRectF(m_leftFrequency, m_rpower, m_rightFrequency, m_rpower-(m_vscale*m_vdivs)));
m_base->traceZoomWidget->setPositions(0, tracepositions);
updateZoomWidgetLimits(m_traceWidget->zoomBox()); updateZoomWidgetLimits(m_traceWidget->zoomBox());
// Also update controls // // Also update controls
m_base->saRefLevel->blockSignals(true); // m_base->saRefLevel->blockSignals(true);
m_base->saRefLevel->setFloatValue(m_rpower); // m_base->saRefLevel->setFloatValue(m_voltsDiv);
m_base->saRefLevel->blockSignals(false); // m_base->saRefLevel->blockSignals(false);
} }
void ScopePart::saRefLevelChanged(double newval) { void ScopePart::saRefLevelChanged(double newval) {
if (m_commHandlerMode < 2) { // if (m_commHandlerMode < 2) {
m_rpower = newval; // m_voltsDiv = newval;
m_commHandlerMode = 1; // m_commHandlerMode = 1;
m_commHandlerCommandState = 1; // m_commHandlerCommandState = 1;
mainEventLoop(); // mainEventLoop();
} // }
} }
KAboutData* ScopePart::createAboutData() { KAboutData* ScopePart::createAboutData() {

@ -11,6 +11,8 @@
#include <tqtrla.h> #include <tqtrla.h>
#define MAXTRACES 255
class KAboutData; class KAboutData;
using KParts::StatusBarExtension; using KParts::StatusBarExtension;
class TraceWidget; class TraceWidget;
@ -59,15 +61,16 @@ namespace RemoteLab
TQTimer* m_updateTimeoutTimer; TQTimer* m_updateTimeoutTimer;
bool m_connectionActiveAndValid; bool m_connectionActiveAndValid;
unsigned char m_tickerState; unsigned char m_tickerState;
TQ_INT16 m_samplesInTrace; TQ_INT16 m_maxNumberOfTraces;
double m_leftFrequency; TQ_INT32 m_currentOpChannel;
double m_rightFrequency; TQ_INT32 m_nextOpChannel;
TQ_INT16 m_nextOpParameter16;
TQ_INT16 m_hdivs; TQ_INT16 m_hdivs;
TQ_INT16 m_vdivs; TQ_INT16 m_vdivs;
double m_centerfreq; TQ_INT32 m_samplesInTrace[MAXTRACES+1];
double m_spanfreq; bool m_channelActive[MAXTRACES+1];
double m_rpower; double m_voltsDiv[MAXTRACES+1];
double m_vscale; double m_secsDiv[MAXTRACES+1];
ScopeBase* m_base; ScopeBase* m_base;
TQMutex* m_instrumentMutex; TQMutex* m_instrumentMutex;
bool stopTraceUpdate; bool stopTraceUpdate;

@ -263,7 +263,17 @@ void GPIBSocket::commandLoop() {
if (m_instrumentCommand != "") { if (m_instrumentCommand != "") {
if (m_activeDeviceType == 2) { if (m_activeDeviceType == 2) {
// Oscilloscope // 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; double value;
ds >> value; ds >> value;
if (scope_set_timebase(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { 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); traceLength = scope_get_channel_trace(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket);
if (traceLength > 0) { if (traceLength > 0) {
int i; int i;
TQFloatArray traceData; TQDoubleArray traceData;
TQDoubleArray positionData;
traceData.resize(traceLength); traceData.resize(traceLength);
positionData.resize(traceLength);
for (i=0; i<traceLength; i++) { for (i=0; i<traceLength; i++) {
traceData[i] = scope_raw_trace_data[i]; traceData[i] = scope_raw_trace_data[i];
positionData[i] = scope_raw_position_data[i];
} }
ds << TQString("ACK"); ds << TQString("ACK");
ds << traceData; ds << traceData;
ds << positionData;
writeEndOfFrame(); writeEndOfFrame();
} }
else { else {
@ -310,6 +324,49 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); 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 else if (m_instrumentCommand == "SETRUNNING") { // Want to change run status
TQ_INT32 value; TQ_INT32 value;
ds >> value; ds >> value;
@ -325,7 +382,7 @@ void GPIBSocket::commandLoop() {
else if (m_instrumentCommand == "SETCHANNELACTIVE") { // Want to change channel enable else if (m_instrumentCommand == "SETCHANNELACTIVE") { // Want to change channel enable
TQ_INT32 value1; TQ_INT32 value1;
ds >> value1; ds >> value1;
TQ_INT32 value2; TQ_INT16 value2;
ds >> value2; ds >> value2;
if (scope_set_channel_state(value1, value2, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { if (scope_set_channel_state(value1, value2, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) {
ds << TQString("ACK"); ds << TQString("ACK");
@ -374,6 +431,60 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); 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) { else if (m_activeDeviceType == 3) {
// Function generator // Function generator
@ -476,6 +587,9 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); 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) { else if (m_activeDeviceType == 4) {
// Communications analyzer // Communications analyzer
@ -714,8 +828,8 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); writeEndOfFrame();
} }
} }
else if (m_instrumentCommand == "GETVERTICALDIVCOUNT") { // Want the number of vertical divisions available else if (m_instrumentCommand == "GETHORIZONTALDIVCOUNT") { // Want the number of horizontal divisions available
TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket);
if (divisions >= 0) { if (divisions >= 0) {
ds << TQString("ACK"); ds << TQString("ACK");
ds << divisions; ds << divisions;
@ -726,8 +840,8 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); writeEndOfFrame();
} }
} }
else if (m_instrumentCommand == "GETTRACESAMPLECOUNT") { // Want the number of samples in a trace else if (m_instrumentCommand == "GETVERTICALDIVCOUNT") { // Want the number of vertical divisions available
TQ_INT16 divisions = commanalyzerTraceLength(m_serverParent->m_commanalyzerType.ascii()); TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket);
if (divisions >= 0) { if (divisions >= 0) {
ds << TQString("ACK"); ds << TQString("ACK");
ds << divisions; ds << divisions;
@ -738,8 +852,8 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); writeEndOfFrame();
} }
} }
else if (m_instrumentCommand == "GETHORIZONTALDIVCOUNT") { // Want the number of horizontal divisions available else if (m_instrumentCommand == "GETTRACESAMPLECOUNT") { // Want the number of samples in a trace
TQ_INT16 divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(m_serverParent->m_commanalyzerType.ascii(), m_serverParent->m_commanalyzerDeviceSocket); TQ_INT16 divisions = commanalyzerTraceLength(m_serverParent->m_commanalyzerType.ascii());
if (divisions >= 0) { if (divisions >= 0) {
ds << TQString("ACK"); ds << TQString("ACK");
ds << divisions; ds << divisions;
@ -798,6 +912,9 @@ void GPIBSocket::commandLoop() {
writeEndOfFrame(); writeEndOfFrame();
} }
} }
else {
printf("[WARNING] Received unknown command %s from host %s\n\r", m_instrumentCommand.ascii(), m_remoteHost.ascii()); fflush(stdout);
}
} }
else { else {
// Unknown // Unknown
@ -970,6 +1087,7 @@ int GPIBServer::readConfig() {
printf("[INFO] %s\n\r", timebuffer); printf("[INFO] %s\n\r", timebuffer);
if (gpib_write(m_scopeDeviceSocket, timebuffer) == 0) { if (gpib_write(m_scopeDeviceSocket, timebuffer) == 0) {
gpib_write(m_scopeDeviceSocket, datebuffer); gpib_write(m_scopeDeviceSocket, datebuffer);
scope_perform_initial_setup(m_scopeType.ascii(), m_scopeDeviceSocket);
printf("[INFO] Communication verified\n\r"); printf("[INFO] Communication verified\n\r");
} }
else { else {

@ -37,6 +37,7 @@
extern char falpha[1024]; extern char falpha[1024];
unsigned char scope_raw_screenshot_data[4194304]; unsigned char scope_raw_screenshot_data[4194304];
double scope_raw_trace_data[65535]; double scope_raw_trace_data[65535];
double scope_raw_position_data[65535];
unsigned long scopeScreenWidth (const char * scopeType) { unsigned long scopeScreenWidth (const char * scopeType) {
if (strcmp("HP54600OS", scopeType) == 0) { if (strcmp("HP54600OS", scopeType) == 0) {
@ -175,6 +176,11 @@ int scope_get_screenshot_stage2(const char * scopeType, int gpibDevice) {
return 1; return 1;
} }
int scope_reset(const char * funcgenType, int gpibDevice) {
// FIXME
// GNDN
return 0;
}
int scope_get_screenshot(const char * scopeType, int gpibDevice) { int scope_get_screenshot(const char * scopeType, int gpibDevice) {
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { 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; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
@ -288,6 +297,9 @@ int scope_set_volts_div(int desired_channel, float desired_volts,const char * sc
return 2; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
@ -326,6 +338,9 @@ int scope_set_acquisition(int status,const char * scopeType, int gpibDevice) {
return 2; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
@ -375,12 +390,63 @@ int scope_set_channel_state(int desired_channel, int status,const char * scopeTy
return 2; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; 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) { int scope_set_trigger_channel(int desired_channel,const char * scopeType, int gpibDevice) {
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope trigger channel to %d\n\r", desired_channel); 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; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
@ -441,6 +510,9 @@ int scope_set_trigger_level(float desired_level,const char * scopeType, int gpib
return 2; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
@ -474,36 +546,24 @@ int scope_set_channel_position(int desired_channel, float desired_level,const ch
return 2; return 2;
} }
} }
else {
return -1;
}
} }
else { else {
return 1; return 1;
} }
} }
int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) { int scope_perform_initial_setup(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 // Send request
printf("[INFO] Getting oscilloscope trace for channel %d [Stage 1]\n\r", desired_channel); printf("[INFO] Configuring oscilloscope\n\r");
if (strcmp("HP54600OS", scopeType) == 0) { if (strcmp("HP54600OS", scopeType) == 0) {
// FIXME // FIXME
// Not supported (yet) // Not supported (yet)
return -1; return -1;
} }
else if (strcmp("TDS744AOS", scopeType) == 0) { 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"); sprintf(falpha,"DATA:ENCDG RIBINARY");
#ifdef ENABLE_EXTRA_DEBUGGING #ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha); printf("[DEBG] Writing: %s\n\r", falpha);
@ -523,6 +583,43 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi
#ifdef ENABLE_EXTRA_DEBUGGING #ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha); printf("[DEBG] Writing: %s\n\r", falpha);
#endif #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];
long array_pointer;
long ai;
// 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) { if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"WFMPRE?"); sprintf(falpha,"WFMPRE?");
#ifdef ENABLE_EXTRA_DEBUGGING #ifdef ENABLE_EXTRA_DEBUGGING
@ -551,37 +648,15 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi
double xincr; double xincr;
double xposition; double xposition;
const char* xunits; const char* xunits;
for (TQStringList::Iterator it = resultPairs.begin(); it != resultPairs.end(); ++it) {
TQString curVal = *it; ymult = resultPairs[13].toDouble();
if (curVal.startsWith("YMULT ")) { yoffset = resultPairs[14].toDouble()*ymult;
curVal.replace("YMULT ", ""); yposition = resultPairs[15].toDouble()*ymult;
ymult = curVal.toDouble(); yunits = strdup(resultPairs[12]);
} xincr = resultPairs[9].toDouble();
else if (curVal.startsWith("YOFF ")) { xposition = resultPairs[10].toDouble();
curVal.replace("YOFF ", ""); xunits = strdup(resultPairs[8]);
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 // Get the curve data now
sprintf(falpha,"CURVE?"); sprintf(falpha,"CURVE?");
#ifdef ENABLE_EXTRA_DEBUGGING #ifdef ENABLE_EXTRA_DEBUGGING
@ -601,12 +676,15 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi
#endif #endif
// Interpret the results // Interpret the results
long pointCount = ai/2; long pointCount = ai/2;
double horizPos = 0.0;
for (array_pointer=0; array_pointer<pointCount; array_pointer++) { for (array_pointer=0; array_pointer<pointCount; array_pointer++) {
TQ_INT16 tempvalue; TQ_INT16 tempvalue;
tempvalue = segarray[(array_pointer*2)+1]; // LSB tempvalue = segarray[(array_pointer*2)+1]; // LSB
tempvalue = tempvalue | (segarray[(array_pointer*2)+0] << 8); // MSB tempvalue = tempvalue | (segarray[(array_pointer*2)+0] << 8); // MSB
scope_raw_trace_data[array_pointer] = tempvalue; scope_raw_trace_data[array_pointer] = tempvalue;
scope_raw_trace_data[array_pointer] = scope_raw_trace_data[array_pointer] * ymult; scope_raw_trace_data[array_pointer] = (scope_raw_trace_data[array_pointer] * ymult)-yoffset;
scope_raw_position_data[array_pointer] = horizPos;
horizPos = horizPos + xincr;
} }
} }
} }
@ -622,23 +700,244 @@ int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpi
else { else {
return -2; return -2;
} }
return array_pointer;
} }
else { else {
return -2; 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 { else {
return -2; 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 { else {
return -2; 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 { else {
return -2; return -1;
}
} }
return array_pointer; 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;
} }
} }

@ -22,18 +22,28 @@
extern unsigned char scope_raw_screenshot_data[4194304]; extern unsigned char scope_raw_screenshot_data[4194304];
extern double scope_raw_trace_data[65535]; extern double scope_raw_trace_data[65535];
extern double scope_raw_position_data[65535];
unsigned long scopeScreenSize (const char * scopeType); unsigned long scopeScreenSize (const char * scopeType);
unsigned long scopeScreenWidth (const char * scopeType); unsigned long scopeScreenWidth (const char * scopeType);
unsigned long scopeScreenHeight (const char * scopeType); unsigned long scopeScreenHeight (const char * scopeType);
int gpib_read_binary(int ud, int max_num_bytes); 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(const char * scopeType, int gpibDevice);
int scope_get_screenshot_stage2(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_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, float desired_volts,const char * scopeType, int gpibDevice);
int scope_set_acquisition(int status,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_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_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_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_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); 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);
Loading…
Cancel
Save