Edit spm6103_viewer.py
This commit is contained in:
parent
63f0a41a92
commit
ab977b3336
@ -0,0 +1,87 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from tkinter.font import Font
|
||||
import serial
|
||||
|
||||
# Serial configuration
|
||||
port = '/dev/ttyUSB0' # Adjust to your specific port
|
||||
baud_rate = 115200 # Adjust to your device's baud rate
|
||||
|
||||
try:
|
||||
ser = serial.Serial(port, baud_rate, timeout=1)
|
||||
except serial.SerialException as e:
|
||||
ser = None
|
||||
print(f"Serial port error: {e}")
|
||||
|
||||
def send_command(command):
|
||||
if not ser:
|
||||
return "Serial port not available"
|
||||
ser.write((command + '\n').encode('utf-8'))
|
||||
response = ser.readline().decode('utf-8').strip()
|
||||
return response
|
||||
|
||||
def get_id():
|
||||
return send_command('*IDN?')
|
||||
|
||||
def get_multimeter_data():
|
||||
rawdata = send_command(f'CONFigure:ALL?')
|
||||
return rawdata
|
||||
|
||||
def get_powersupply_data():
|
||||
rawdata = send_command(f'MEASure:ALL:INFO?')
|
||||
return rawdata
|
||||
|
||||
def set_res_mode():
|
||||
rawdata = send_command(f'[SENSe:]FUNCtion:RESistance')
|
||||
return rawdata
|
||||
|
||||
def set_cont_mode():
|
||||
rawdata = send_command(f'[SENSe:]FUNCtion:CONTinuity')
|
||||
return rawdata
|
||||
|
||||
# --- GUI Setup ---
|
||||
def fetch_device_info():
|
||||
# Fetch the device ID and Channel data
|
||||
device_id = get_id()
|
||||
multimeter_data = get_multimeter_data()
|
||||
|
||||
# Update the labels
|
||||
multimeter_type_var.set(multimeter_data.split(",")[0])
|
||||
multimeter_data_var.set(multimeter_data.split(",")[1])
|
||||
multimeter_range_var.set(multimeter_data.split(",")[3])
|
||||
|
||||
# Schedule this function to be called again after 100ms
|
||||
app.after(100, fetch_device_info)
|
||||
|
||||
app = tk.Tk()
|
||||
app.title("OWON SPM6103")
|
||||
app.geometry("1080x200")
|
||||
app.configure(bg="black")
|
||||
|
||||
multimeter_type_var = tk.StringVar()
|
||||
multimeter_data_var = tk.StringVar()
|
||||
multimeter_range_var = tk.StringVar()
|
||||
|
||||
# Create a font object
|
||||
fontSmall = Font(size=10)
|
||||
fontMedium = Font(size=20)
|
||||
fontBig = Font(size=80)
|
||||
|
||||
app.rowconfigure(0, weight=1)
|
||||
app.rowconfigure(1, weight=1)
|
||||
app.rowconfigure(2, weight=1)
|
||||
app.columnconfigure(0, weight=1)
|
||||
app.columnconfigure(1, weight=2)
|
||||
|
||||
# Labels
|
||||
tk.Label(app, textvariable=multimeter_type_var, font=fontMedium, bg="black", fg="lightgrey").grid(column=0, row=0, sticky=tk.W)
|
||||
tk.Label(app, textvariable=multimeter_range_var, font=fontMedium, bg="black", fg="lightgrey").grid(column=1, row=0, sticky=tk.E)
|
||||
tk.Label(app, textvariable=multimeter_data_var, font=fontBig, bg="black", fg="lightgrey").grid(column=0, columnspan=2, row=1, sticky=tk.W)
|
||||
tk.Button(app, text="RES", command=set_res_mode, font=fontSmall, bg="black", fg="lightgrey", border=False).grid(column=0, row=2, sticky=tk.W)
|
||||
tk.Button(app, text="CONT", command=set_cont_mode, font=fontSmall, bg="black", fg="lightgrey", border=False).grid(column=1, row=2, sticky=tk.W)
|
||||
|
||||
# Initial fetch to start the auto-update process
|
||||
fetch_device_info()
|
||||
|
||||
# Start GUI
|
||||
app.mainloop()
|
||||
Loading…
x
Reference in New Issue
Block a user