Wie man Multimeter ausliest und bei Hotkey-Druck in Excel-Tabellenzelle einfügt mit Python
Das folgende Python-Skript verwendet PyVISA / LabInstruments, um ein Rigol DM3058(E)-Multimeter auszulesen und die Spannungsablesung automatisch bei Shift+Alt+Q-Druck in eine geöffnete Tabelle einzufügen.
Klonen Sie zuerst LabInstruments in das aktuelle Verzeichnis mit
clone_labinstruments.sh
git clone https://github.com/ulikoehler/LabInstruments.gitInstallieren Sie nun die Anforderungen aus der folgenden requirements.txt
requirements.txt
system_hotkey310
pyperclip
pyvisa
pyvisa-pyund führen Sie das Skript aus:
read_multimeter_paste_excel.py
#!/usr/bin/env python3
"""
This script allows quick reading of multimeter, automatically pasting the reading
into the current e.g. excel spreadsheet and pressing "Enter" to advance to the next cell.
Press Shift+Alt+Q to read the multimeter and paste the reading into the current cell.
"""
import subprocess
import pyautogui
import time
import re
import pyperclip
import sexpdata
import pyvisa
from LabInstruments.DM3058 import DM3058
import locale
locale.setlocale(locale.LC_NUMERIC, f"{locale.getdefaultlocale()[0]}.utf-8")
rm = pyvisa.ResourceManager()
rm.list_resources()
inst = rm.open_resource('USB0::6833::2500::DM3R245003970::0::INSTR')
multimeter = DM3058(inst)
multimeter.set_speed("S")
multimeter.mode_dc_voltage()
def run():
voltage = multimeter.read_voltage()
locale_formatted_voltage = locale.format_string("%.5f", voltage, grouping=False)
print("Voltage: ", locale_formatted_voltage)
# Copy locale-formatted voltage to clipboard
pyperclip.copy(locale_formatted_voltage)
# Paste into cell
pyautogui.hotkey('ctrl', 'v')
# Wait for excel
time.sleep(0.1)
# Press Enter key to save
pyautogui.press('enter')
# Register hotkeys
from system_hotkey import SystemHotkey
hk = SystemHotkey()
hk.register(('shift', 'alt', 'q'), callback=lambda x: run())
# Wait for exit
while True:
time.sleep(10)Check out similar posts by category:
Electronics, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow