34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
|
|
import sys
|
||
|
|
|
||
|
|
if "--sim-multimeter" in sys.argv:
|
||
|
|
from components.dummies.serial import serial
|
||
|
|
else:
|
||
|
|
import serial
|
||
|
|
|
||
|
|
from PyQt5.QtWidgets import QMessageBox
|
||
|
|
|
||
|
|
from .component import Component
|
||
|
|
|
||
|
|
|
||
|
|
class SerialMultimeter(Component):
|
||
|
|
def __init__(self, config=None, name=None):
|
||
|
|
super().__init__(config=config, name=name, threaded=False)
|
||
|
|
|
||
|
|
def write(self, command):
|
||
|
|
try:
|
||
|
|
conn = serial.Serial(
|
||
|
|
self.address,
|
||
|
|
baudrate=self.baudrate,
|
||
|
|
stopbits=self.stopbits,
|
||
|
|
parity=self.parity,
|
||
|
|
bytesize=self.bytesize,
|
||
|
|
)
|
||
|
|
conn.write(bytes(command, encoding="ascii"))
|
||
|
|
conn.close()
|
||
|
|
except serial.serialutil.SerialException as e:
|
||
|
|
QMessageBox.critical(
|
||
|
|
None,
|
||
|
|
"Errore Connessione Multimetro",
|
||
|
|
"Non e stato possibile connettersi al multimetro digitale.\n Verificare che lo strumento sia acceso e collegato\nErrore: " + str(e)
|
||
|
|
)
|