Skip to content

Commit

Permalink
add cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-demin committed Sep 10, 2016
1 parent 2bca5dc commit 395aa2f
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 96 deletions.
119 changes: 79 additions & 40 deletions PyQtScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

from PyQt5.uic import loadUiType
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget, QDialog, QFileDialog
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget, QDialog, QFileDialog, QProgressDialog

Ui_PyQtScope, QMainWindow = loadUiType('PyQtScope.ui')

def metric_prefix(x):
if x == 0.0:
return '0'
return '0 '
elif abs(x) >= 1.0e6:
return '%g M' % (x * 1.0e-6)
elif abs(x) >= 1.0e3:
Expand All @@ -59,6 +59,9 @@ def metric_prefix(x):


class PyQtScope(QMainWindow, Ui_PyQtScope):

cursors = {'OFF':'OFF', 'HBARS':'AMPLITUDE', 'VBARS':'TIME'}

def __init__(self):
super(PyQtScope, self).__init__()
self.setupUi(self)
Expand Down Expand Up @@ -155,45 +158,81 @@ def read_data(self):
# 10: NR_Pt <NR1> - number of points
# Xn = XZEro + XINcr * n
# Yn = YZEro + YMUlt * (yn - YOFf)
self.transmit_command(b'CH1:SCA?;:CH2:SCA?;:HOR:MAI:SCA?')
sca = self.receive_result()[:-1].decode("utf-8").rsplit(';')
if self.sca1: self.sca1.remove()
self.sca1 = self.axes.text(0, -110, 'CH1 %sV' % metric_prefix(float(sca[0])), color = '#EEDD00')
if self.sca2: self.sca2.remove()
self.sca2 = self.axes.text(750, -110, 'CH2 %sV' % metric_prefix(float(sca[1])), color = '#00DDEE')
if self.scam: self.scam.remove()
self.scam = self.axes.text(1500, -110, 'M %ss' % metric_prefix(float(sca[2])))
self.transmit_command(b'WFMPre:CH1?')
self.format1 = self.receive_result()[:-1].decode("utf-8").rsplit(';')
self.transmit_command(b'WFMPre:CH2?')
self.format2 = self.receive_result()[:-1].decode("utf-8").rsplit(';')
self.transmit_command(b'DAT:SOU CH1;:CURV?')
self.buffer1[:] = self.receive_result()[6:-1]
self.curve1.set_ydata(self.data1)
self.transmit_command(b'DAT:SOU CH2;:CURV?')
self.buffer2[:] = self.receive_result()[6:-1]
self.curve2.set_ydata(self.data2)
self.canvas.draw()
self.transmit_command(b'MEASU:MEAS1?;:MEASU:MEAS1:VAL?;:MEASU:MEAS2?;:MEASU:MEAS2:VAL?;:MEASU:MEAS3?;:MEASU:MEAS3:VAL?')
result = self.receive_result()[:-1] + b';'
self.transmit_command(b'MEASU:MEAS4?;:MEASU:MEAS4:VAL?;:MEASU:MEAS5?;:MEASU:MEAS5:VAL?')
result += self.receive_result()[:-1]
meas = result.decode("utf-8").rsplit(';')
for i in range(0, 5):
typ = meas[i * 4 + 0]
uni = meas[i * 4 + 1]
sou = meas[i * 4 + 2]
val = meas[i * 4 + 3]
if typ == 'NONE':
val = ''
uni = ''
elif val == '9.9E37':
val = '?'
uni = ''
progress = QProgressDialog('Data transfer status', 'Cancel', 0, 5)
progress.setModal(True)
progress.setMinimumDuration(0)
try:
progress.setValue(0)
# read channel and time scales
self.transmit_command(b'CH1:SCA?;:CH2:SCA?;:HOR:MAI:SCA?')
sca = self.receive_result()[:-1].decode("utf-8").rsplit(';')
if self.sca1:
self.sca1.remove()
self.sca1 = None
self.sca1 = self.axes.text(0, -110, 'CH1 %sV' % metric_prefix(float(sca[0])), color = '#EEDD00')
if self.sca2:
self.sca2.remove()
self.sca2 = None
self.sca2 = self.axes.text(750, -110, 'CH2 %sV' % metric_prefix(float(sca[1])), color = '#00DDEE')
if self.scam:
self.scam.remove()
self.scam = None
self.scam = self.axes.text(1500, -110, 'M %ss' % metric_prefix(float(sca[2])))
progress.setValue(1)
# read formats
self.transmit_command(b'WFMPre:CH1?')
self.format1 = self.receive_result()[:-1].decode("utf-8").rsplit(';')
self.transmit_command(b'WFMPre:CH2?')
self.format2 = self.receive_result()[:-1].decode("utf-8").rsplit(';')
progress.setValue(2)
# read curves
self.transmit_command(b'DAT:SOU CH1;:CURV?')
self.buffer1[:] = self.receive_result()[6:-1]
self.curve1.set_ydata(self.data1)
self.transmit_command(b'DAT:SOU CH2;:CURV?')
self.buffer2[:] = self.receive_result()[6:-1]
self.curve2.set_ydata(self.data2)
self.canvas.draw()
progress.setValue(3)
# read measurements
self.transmit_command(b'MEASU:MEAS1?;:MEASU:MEAS1:VAL?;:MEASU:MEAS2?;:MEASU:MEAS2:VAL?;:MEASU:MEAS3?;:MEASU:MEAS3:VAL?')
result = self.receive_result()[:-1] + b';'
self.transmit_command(b'MEASU:MEAS4?;:MEASU:MEAS4:VAL?;:MEASU:MEAS5?;:MEASU:MEAS5:VAL?')
result += self.receive_result()[:-1]
meas = result.decode("utf-8").rsplit(';')
for i in range(0, 5):
typ = meas[i * 4 + 0]
uni = meas[i * 4 + 1]
sou = meas[i * 4 + 2]
val = meas[i * 4 + 3]
if typ == 'NONE':
val = ''
uni = ''
elif val == '9.9E37':
val = '?'
uni = ''
else:
val = metric_prefix(float(meas[i * 4 + 3]))
uni = uni.strip('"')
getattr(self, 'meas%d' % (i + 1)).setText('%s %s %s%s' % (sou, typ, val, uni))
progress.setValue(4)
# read cursors
self.transmit_command(b'CURS?;:CURS:VBA:HPOS1?;:CURS:VBA:HPOS2?')
curs = self.receive_result()[:-1].decode("utf-8").rsplit(';')
self.curst.setText('%s %s' % (curs[1], self.cursors[curs[0]]))
if curs[0] == 'VBARS':
self.curs1.setText('%ss\t%sV' % (metric_prefix(float(curs[3])), metric_prefix(float(curs[8]))))
self.curs2.setText('%ss\t%sV' % (metric_prefix(float(curs[4])), metric_prefix(float(curs[9]))))
elif curs[0] == 'HBARS':
self.curs1.setText('%sV' % metric_prefix(float(curs[6])))
self.curs2.setText('%sV' % metric_prefix(float(curs[7])))
else:
val = metric_prefix(float(meas[i * 4 + 3]))
uni = uni.strip('"')
getattr(self, 'meas%d' % (i + 1)).setText('%s %s %s%s' % (sou, typ, val, uni))
self.curs1.setText('')
self.curs2.setText('')
progress.setValue(5)
except:
print("Error: %s" % sys.exc_info()[1])
progress.setValue(5)

def save_data(self):
dialog = QFileDialog(self, 'Write csv file', '.', '*.csv')
Expand Down
150 changes: 94 additions & 56 deletions PyQtScope.ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@
<pointsize>10</pointsize>
</font>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<spacer name="spacer2">
<layout class="QVBoxLayout" name="controlLayout">
<item>
<widget class="QPushButton" name="readButton">
<property name="text">
<string>Read data</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand All @@ -71,57 +78,72 @@
</property>
</spacer>
</item>
<item row="8" column="0">
<widget class="QLabel" name="meas5">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="meas3">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="meas4">
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string/>
<string>Save data</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="meas2">
<property name="text">
<string/>
<item>
<spacer name="spacer2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="readButton">
<property name="text">
<string>Read data</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="measLabel">
<property name="text">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>MEASUREMENTS</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="meas4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="meas1">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="meas2">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="meas3">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="meas5">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="cursLabel">
<property name="text">
<string>CURSORS</string>
</property>
</widget>
</item>
<item row="11" column="0">
<spacer name="spacer1">
<item>
<spacer name="spacer3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand All @@ -133,22 +155,38 @@
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="meas1">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save data</string>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>CURSORS</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="curst">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="curs1">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="curs2">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="9" column="0">
<spacer name="spacer3">
<item>
<spacer name="spacer4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand Down

0 comments on commit 395aa2f

Please sign in to comment.