Commit 4c058262 authored by Martin Drechsler's avatar Martin Drechsler

added rigol drivers, frame for control and frame for measuremeent

parent ee54d8c1
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 19:16:28 2019
@author: nicon
"""
import visa
import numpy as np
import time
class GeneradorFuncionesRigol(object):
def __init__(self, instrument_addres='TCPIP0::10.99.45.51::INSTR'):
self.rm = visa.ResourceManager()
try:
self.inst = self.rm.open_resource(instrument_addres)
except:
raise 'no rigo gen in lan detected'
if self.inst != []:
try:
print('El IDN del instrumento es ', self.inst.query("*IDN?"))
except:
print('El instrumento no respondió cuando se le preguntó el nombre.')
def TurnOn(self, channel = 1):
self.inst.write("OUTPut{}:STATe ON".format(channel))
def TurnOff(self, channel = 1):
self.inst.write("OUTPut{}:STATe OFF".format(channel))
def State(self, channel = 1):
print(self.inst.query('OUTP{}:STAT?'.format(channel)))
@property
def Frequency(self, channel = 1):
"""
The frequency you set is in Hz
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[1]
@Frequency.setter
def Frequency(self, freq, channel = 1):
self.inst.write("SOURce{}:FREQuency {}".format(channel,freq))
@property
def Shape(self, channel = 1):
"""
SINusoid|SQUare|RAMP|PULSe|NOISe|USER|DC|SINC|EXPRise|EXPFall|CARDiac|GAUSsian
|HAVersine|LORentz|ARBPULSE|DUAltone
"""
print(self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[0])
@Shape.setter
def Shape(self, shape, channel = 1):
self.inst.write('SOURce{}:FUNCtion {}'.format(channel, shape))
@property
def Voltage(self, channel = 1):
"""
The voltage you set is in Vpp
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[2]
@Voltage.setter
def Voltage(self, voltage, channel = 1):
self.inst.write('SOURce{}:VOLTage:LEVel:IMMediate:AMPLitude {}'.format(channel, voltage))
@property
def Offset(self, channel = 1):
"""
The offset you set is in Vpp
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[3]
@Offset.setter
def Offset(self, offset, channel = 1):
self.inst.write('SOURce{}:VOLTage:LEVel:IMMediate:OFFSet {}'.format(channel, offset))
def GeneralSet(self, freq, voltage, offset = '0 V', shape = 'SIN', channel = 1):
self.SetFrequency(freq, channel)
self.SetVoltage(voltage, channel)
self.SetOffset(offset, channel)
def DiscreteSweep(self, freqini, freqfin, step, timeoff = 1, channel = 1):
Frequencies = np.arange(freqini, freqfin + step, step)
for Fr in Frequencies:
self.inst.write("SOURce{}:FREQuency {}".format(channel, Fr))
time.sleep(timeoff)
def __del__(self):
self.TurnOff()
self.rm.close()
\ No newline at end of file
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'measurement.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(578, 423)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(20, 90, 231, 211))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.selectScanSignal = QtWidgets.QComboBox(self.gridLayoutWidget)
self.selectScanSignal.setObjectName("selectScanSignal")
self.gridLayout.addWidget(self.selectScanSignal, 0, 1, 1, 1)
self.comments = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.comments.setObjectName("comments")
self.gridLayout.addWidget(self.comments, 4, 1, 1, 1)
self.label = QtWidgets.QLabel(self.gridLayoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1)
self.startValue = SpinBox(self.gridLayoutWidget)
self.startValue.setObjectName("startValue")
self.gridLayout.addWidget(self.startValue, 1, 1, 1, 1)
self.endValue = QtWidgets.QDoubleSpinBox(self.gridLayoutWidget)
self.endValue.setObjectName("endValue")
self.gridLayout.addWidget(self.endValue, 2, 1, 1, 1)
self.stepsNum = QtWidgets.QSpinBox(self.gridLayoutWidget)
self.stepsNum.setObjectName("stepsNum")
self.gridLayout.addWidget(self.stepsNum, 3, 1, 1, 1)
self.startMeasureButton = QtWidgets.QPushButton(Frame)
self.startMeasureButton.setGeometry(QtCore.QRect(20, 320, 171, 23))
self.startMeasureButton.setObjectName("startMeasureButton")
self.measureProgressBar = QtWidgets.QProgressBar(Frame)
self.measureProgressBar.setGeometry(QtCore.QRect(20, 350, 171, 23))
self.measureProgressBar.setProperty("value", 24)
self.measureProgressBar.setObjectName("measureProgressBar")
self.treeView = QtWidgets.QTreeView(Frame)
self.treeView.setGeometry(QtCore.QRect(270, 110, 281, 111))
self.treeView.setObjectName("treeView")
self.label_6 = QtWidgets.QLabel(Frame)
self.label_6.setGeometry(QtCore.QRect(340, 80, 161, 20))
self.label_6.setObjectName("label_6")
self.folderButton = QtWidgets.QPushButton(Frame)
self.folderButton.setGeometry(QtCore.QRect(30, 20, 80, 23))
self.folderButton.setObjectName("folderButton")
self.folderBrowser = QtWidgets.QTextBrowser(Frame)
self.folderBrowser.setGeometry(QtCore.QRect(120, 20, 441, 21))
self.folderBrowser.setObjectName("folderBrowser")
self.saveMeasureButton = QtWidgets.QPushButton(Frame)
self.saveMeasureButton.setGeometry(QtCore.QRect(199, 320, 151, 23))
self.saveMeasureButton.setObjectName("saveMeasureButton")
self.abortMeasureButton = QtWidgets.QPushButton(Frame)
self.abortMeasureButton.setGeometry(QtCore.QRect(30, 380, 151, 23))
self.abortMeasureButton.setObjectName("abortMeasureButton")
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label.setText(_translate("Frame", "Scan signal"))
self.label_2.setText(_translate("Frame", "Start value"))
self.label_3.setText(_translate("Frame", "End value"))
self.label_4.setText(_translate("Frame", "Steps num"))
self.label_5.setText(_translate("Frame", "Comments"))
self.startMeasureButton.setText(_translate("Frame", "Start measurement"))
self.label_6.setText(_translate("Frame", "Info about measurement"))
self.folderButton.setText(_translate("Frame", "Folder"))
self.saveMeasureButton.setText(_translate("Frame", "Save measurement"))
self.abortMeasureButton.setText(_translate("Frame", "Abort measurement"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'rigol_gen.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(469, 343)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 441, 321))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1)
self.cb_onOff = QtWidgets.QCheckBox(self.gridLayoutWidget)
self.cb_onOff.setObjectName("cb_onOff")
self.gridLayout.addWidget(self.cb_onOff, 0, 1, 1, 1)
self.label = QtWidgets.QLabel(self.gridLayoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
self.sb_freq = SpinBox(self.gridLayoutWidget)
self.sb_freq.setObjectName("sb_freq")
self.gridLayout.addWidget(self.sb_freq, 1, 1, 1, 1)
self.sb_amp = SpinBox(self.gridLayoutWidget)
self.sb_amp.setObjectName("sb_amp")
self.gridLayout.addWidget(self.sb_amp, 2, 1, 1, 1)
self.sb_offset = SpinBox(self.gridLayoutWidget)
self.sb_offset.setObjectName("sb_offset")
self.gridLayout.addWidget(self.sb_offset, 3, 1, 1, 1)
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label_3.setText(_translate("Frame", "On/Off"))
self.label_2.setText(_translate("Frame", "Offset"))
self.cb_onOff.setText(_translate("Frame", "Ch 1 On"))
self.label.setText(_translate("Frame", "Amplitude"))
self.label_4.setText(_translate("Frame", "Frequency"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Frame</class>
<widget class="QFrame" name="Frame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>333</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>231</width>
<height>211</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Start freq </string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="comments"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="stepsNum"/>
</item>
<item row="0" column="1">
<widget class="SpinBox" name="startValue"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>End freq</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Steps num</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="SpinBox" name="endValue"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Comments</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="startMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Start measurement</string>
</property>
</widget>
<widget class="QTreeView" name="treeView">
<property name="geometry">
<rect>
<x>250</x>
<y>30</y>
<width>281</width>
<height>111</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>260</x>
<y>10</y>
<width>161</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Info about measurement</string>
</property>
</widget>
<widget class="QPushButton" name="saveMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save measurement</string>
</property>
</widget>
<widget class="QPushButton" name="abortMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Abort measurement</string>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>SpinBox</class>
<extends>QDoubleSpinBox</extends>
<header location="global">pyqtgraph</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'rigol_measurement.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(592, 333)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 231, 211))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
self.comments = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.comments.setObjectName("comments")
self.gridLayout.addWidget(self.comments, 3, 1, 1, 1)
self.stepsNum = QtWidgets.QSpinBox(self.gridLayoutWidget)
self.stepsNum.setObjectName("stepsNum")
self.gridLayout.addWidget(self.stepsNum, 2, 1, 1, 1)
self.startValue = SpinBox(self.gridLayoutWidget)
self.startValue.setObjectName("startValue")
self.gridLayout.addWidget(self.startValue, 0, 1, 1, 1)
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1)
self.endValue = SpinBox(self.gridLayoutWidget)
self.endValue.setObjectName("endValue")
self.gridLayout.addWidget(self.endValue, 1, 1, 1, 1)
self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 3, 0, 1, 1)
self.startMeasureButton = QtWidgets.QPushButton(Frame)
self.startMeasureButton.setGeometry(QtCore.QRect(10, 240, 171, 23))
self.startMeasureButton.setObjectName("startMeasureButton")
self.treeView = QtWidgets.QTreeView(Frame)
self.treeView.setGeometry(QtCore.QRect(250, 30, 281, 111))
self.treeView.setObjectName("treeView")
self.label_6 = QtWidgets.QLabel(Frame)
self.label_6.setGeometry(QtCore.QRect(260, 10, 161, 20))
self.label_6.setObjectName("label_6")
self.saveMeasureButton = QtWidgets.QPushButton(Frame)
self.saveMeasureButton.setGeometry(QtCore.QRect(10, 270, 151, 23))
self.saveMeasureButton.setObjectName("saveMeasureButton")
self.abortMeasureButton = QtWidgets.QPushButton(Frame)
self.abortMeasureButton.setGeometry(QtCore.QRect(10, 300, 151, 23))
self.abortMeasureButton.setObjectName("abortMeasureButton")
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label_2.setText(_translate("Frame", "Start freq "))
self.label_3.setText(_translate("Frame", "End freq"))
self.label_4.setText(_translate("Frame", "Steps num"))
self.label_5.setText(_translate("Frame", "Comments"))
self.startMeasureButton.setText(_translate("Frame", "Start measurement"))
self.label_6.setText(_translate("Frame", "Info about measurement"))
self.saveMeasureButton.setText(_translate("Frame", "Save measurement"))
self.abortMeasureButton.setText(_translate("Frame", "Abort measurement"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 24 13:07:06 2019
@author: martindrech
"""
from rigol_gen_ui import Ui_Frame
from GeneradorFuncionesRigol import GeneradorFuncionesRigol
from PyQt5 import QtWidgets, QtCore
import sys
rigGen = GeneradorFuncionesRigol()
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
@QtCore.pyqtSlot(object)
def set_freq(sb):
rigGen.Frequency = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def set_amp(sb):
rigGen.Voltage = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def set_offset(sb):
rigGen.Offset = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def turn_on_off():
if ui.cb_onOff.isChecked():
rigGen.TurnOn()
else:
rigGen.TurnOff()
ui.sb_amp.setValue(1)
ui.sb_amp.setRange(0, 20)
ui.sb_amp.setSuffix('V')
ui.sb_amp.setSingleStep(.2)
ui.sb_amp.setOpts(siPrefix=True)
ui.sb_freq.setValue(50)
ui.sb_freq.setRange(0, 10000000)
ui.sb_freq.setSingleStep(200)
ui.sb_freq.setOpts(siPrefix=True)
ui.sb_freq.setSuffix('Hz')
ui.sb_offset.setValue(0)
ui.sb_offset.setRange(-7.5, 7.5)
ui.sb_offset.setSuffix('V')
ui.sb_offset.setSingleStep(.2)
ui.sb_offset.setOpts(siPrefix=True)
ui.cb_onOff.stateChanged.connect(turn_on_off)
ui.sb_amp.sigValueChanging.connect(set_amp)
ui.sb_freq.sigValueChanging.connect(set_freq)
ui.sb_offset.sigValueChanging.connect(set_offset)
Frame.show()
sys.exit(app.exec_())
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
tip: pyuic5 -x ventana.ui -o ventana_ui.py
@author: martindrech
Control of rigol function generator
"""
from resources.rigol_gen_ui import Ui_Frame
from PyQt5 import QtCore, QtWidgets, QtGui
class RigolGenGui(QtWidgets.QFrame, Ui_Frame):
registry = []
def __init__(self, rigGen):
super().__init__()
self.setupUi(self)
self.registry.append(self)
self.rigGen = rigGen
self.sb_amp.setRange(0, 20)
self.sb_amp.setSuffix('V')
self.sb_amp.setSingleStep(.2)
self.sb_amp.setOpts(siPrefix=True)
self.sb_freq.setRange(0, 10000000)
self.sb_freq.setSingleStep(200)
self.sb_freq.setOpts(siPrefix=True)
self.sb_freq.setSuffix('Hz')
self.sb_offset.setRange(-7.5, 7.5)
self.sb_offset.setSuffix('V')
self.sb_offset.setSingleStep(.2)
self.sb_offset.setOpts(siPrefix=True)
self.make_connections()
self.sb_amp.setValue(1)
self.rigGen.Voltage = 1
self.sb_freq.setValue(50)
self.rigGen.Frequency = 50
self.sb_offset.setValue(0)
self.rigGen.Offset = 0
self.show()
def make_connections(self):
self.cb_onOff.stateChanged.connect(self.turn_on_off)
self.sb_amp.sigValueChanging.connect(self.set_amp)
self.sb_freq.sigValueChanging.connect(self.set_freq)
self.sb_offset.sigValueChanging.connect(self.set_offset)
@QtCore.pyqtSlot(object)
def set_freq(self, sb):
self.rigGen.Frequency = sb.value()
@QtCore.pyqtSlot(object)
def set_amp(self, sb):
self.rigGen.Voltage = sb.value()
@QtCore.pyqtSlot(object)
def set_offset(self, sb):
self.rigGen.Offset = sb.value()
@QtCore.pyqtSlot()
def turn_on_off(self):
if self.cb_onOff.isChecked():
self.rigGen.TurnOn()
else:
self.rigGen.TurnOff()
def __del__(self):
self.rigGen.__del__()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment