Python GUI app to control X6100 Armbian
[Main.py]
import sys
from PyQt5.QtWidgets import QDialog, QApplication
from FirstApp import *
import Hamlib
import time
cur_mode="CW"
#print("Hamlib")
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
my_rig = Hamlib.Rig(Hamlib.RIG_MODEL_NETRIGCTL)
#my_rig.set_conf("rig_patname","192.168.1.248:4532")
#print("here")
my_rig.set_conf("rig_pathname","127.0.0.1:4532")
my_rig.set_conf("retry","5")
my_rig.open()
#print("hamib open")
cur_freq = my_rig.get_freq()
#print("Current freq",cur_freq)
(mode, width) = my_rig.get_mode()
if mode==1:
cur_mode="AM"
elif mode==32:
cur_mode="NFM"
elif mode==2:
cur_mode="CW"
elif mode==128:
cur_mode="CWR"
elif mode==8:
cur_mode="LSB"
elif mode==4:
cur_mode="USB"
#print(cur_mode)
#print(cur_freq,mode)
#my_rig.set_freq(Hamlib.RIG_VFO_A, 28000000)
#time.sleep(5)
set_mode="USB"
set_freq=10000
class MyForm(QDialog):
def __init__(self):
global cur_mode
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.ui.curFreq.display(cur_freq)
self.ui.curMode.setText(cur_mode)
#set_mode=self.ui.modes.currentText()
self.ui.modes.currentTextChanged.connect(self.Modes)
#print(set_mode)
self.ui.setMode.clicked.connect(self.setModes)
self.ui.setFreq.clicked.connect(self.setFreq)
#self.ui.curFreq.setProperty("value", 1000.02)
def Modes(self):
global set_mode
set_mode=self.ui.modes.currentText()
#print("here",set_mode)
#set_mode=l_set_mode
def setModes(self):
#print("It's me",set_mode)
self.ui.curMode.setText(set_mode)
global my_rig
if set_mode=="CW":
my_rig.set_mode(Hamlib.RIG_MODE_CW)
elif set_mode=="LSB":
my_rig.set_mode(Hamlib.RIG_MODE_LSB)
elif set_mode=="USB":
my_rig.set_mode(Hamlib.RIG_MODE_USB)
elif set_mode=="AM":
my_rig.set_mode(Hamlib.RIG_MODE_AM)
elif set_mode=="NFM":
my_rig.set_mode(Hamlib.RIG_MODE_FM)
def setFreq(self):
#my_rig.set_freq(Hamlib.RIG_VFO_A, 28000000)
global freq
freq=self.ui.lineEdit.text()
#print(freq)
global my_rig
my_rig.set_freq(Hamlib.RIG_VFO_A, float(freq))
self.ui.curFreq.display(freq)
if __name__=="__main__":
app=QApplication(sys.argv)
myapp=MyForm()
myapp.show()
#print("After show")
sys.exit(app.exec_())
my_rig.close()
[FirstApp.py]
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'FirstApp.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(524, 307)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(100, 80, 121, 20))
self.label.setObjectName("label")
self.setMode = QtWidgets.QPushButton(Dialog)
self.setMode.setGeometry(QtCore.QRect(280, 180, 91, 22))
self.setMode.setObjectName("setMode")
self.modes = QtWidgets.QComboBox(Dialog)
self.modes.setGeometry(QtCore.QRect(120, 180, 111, 22))
self.modes.setObjectName("modes")
self.modes.addItem("")
self.modes.addItem("")
self.modes.addItem("")
self.modes.addItem("")
self.modes.addItem("")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(120, 130, 91, 20))
self.label_2.setObjectName("label_2")
self.curFreq = QtWidgets.QLCDNumber(Dialog)
self.curFreq.setGeometry(QtCore.QRect(250, 70, 131, 31))
self.curFreq.setSmallDecimalPoint(True)
self.curFreq.setDigitCount(10)
self.curFreq.setProperty("value", 100.0)
self.curFreq.setProperty("intValue", 100)
self.curFreq.setObjectName("curFreq")
self.curMode = QtWidgets.QLabel(Dialog)
self.curMode.setGeometry(QtCore.QRect(260, 130, 81, 16))
self.curMode.setText("")
self.curMode.setObjectName("curMode")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(120, 220, 113, 22))
self.lineEdit.setObjectName("lineEdit")
self.setFreq = QtWidgets.QPushButton(Dialog)
self.setFreq.setGeometry(QtCore.QRect(279, 220, 91, 22))
self.setFreq.setObjectName("setFreq")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "X6100"))
self.label.setText(_translate("Dialog", "Current Frequency:"))
self.setMode.setText(_translate("Dialog", "Set Mode"))
self.modes.setItemText(0, _translate("Dialog", "NFM"))
self.modes.setItemText(1, _translate("Dialog", "AM"))
self.modes.setItemText(2, _translate("Dialog", "LSB"))
self.modes.setItemText(3, _translate("Dialog", "USB"))
self.modes.setItemText(4, _translate("Dialog", "CW"))
self.label_2.setText(_translate("Dialog", "Current Mode:"))
self.setFreq.setText(_translate("Dialog", "Set Frequency"))
[FirstApp.ui]
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>307</height>
</rect>
</property>
<property name="windowTitle">
<string>X6100</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>100</x>
<y>80</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Current Frequency:</string>
</property>
</widget>
<widget class="QPushButton" name="setMode">
<property name="geometry">
<rect>
<x>280</x>
<y>180</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Set Mode</string>
</property>
</widget>
<widget class="QComboBox" name="modes">
<property name="geometry">
<rect>
<x>120</x>
<y>180</y>
<width>111</width>
<height>22</height>
</rect>
</property>
<item>
<property name="text">
<string>NFM</string>
</property>
</item>
<item>
<property name="text">
<string>AM</string>
</property>
</item>
<item>
<property name="text">
<string>LSB</string>
</property>
</item>
<item>
<property name="text">
<string>USB</string>
</property>
</item>
<item>
<property name="text">
<string>CW</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>120</x>
<y>130</y>
<width>91</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Current Mode:</string>
</property>
</widget>
<widget class="QLCDNumber" name="curFreq">
<property name="geometry">
<rect>
<x>250</x>
<y>70</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<property name="smallDecimalPoint">
<bool>true</bool>
</property>
<property name="digitCount">
<number>10</number>
</property>
<property name="value" stdset="0">
<double>100.000000000000000</double>
</property>
<property name="intValue" stdset="0">
<number>100</number>
</property>
</widget>
<widget class="QLabel" name="curMode">
<property name="geometry">
<rect>
<x>260</x>
<y>130</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>
</string></property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>120</x>
<y>220</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="setFreq">
<property name="geometry">
<rect>
<x>279</x>
<y>220</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Set Frequency</string>
</property>
</widget>
</widget>
<resources>
<connections>
</connections></resources></ui>
Comments