From bf7169be9a5d71c3f9221b52b58d01f94664b453 Mon Sep 17 00:00:00 2001 From: David Lutton Date: Wed, 27 Dec 2023 16:35:32 +0000 Subject: [PATCH] Fixes prompted by linter --- .../AudioAnalyser/RaSCMU200Audio.py | 4 +- src/labtoolkit/Enviromental/hydrotherm.py | 86 +++++++++++-------- src/labtoolkit/FieldStrength/Narda601.py | 12 ++- src/labtoolkit/Formatter/plot.py | 2 + src/labtoolkit/Formula/Units.py | 2 +- src/labtoolkit/PowerAnalyser/VoltechPM100.py | 8 +- 6 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/labtoolkit/AudioAnalyser/RaSCMU200Audio.py b/src/labtoolkit/AudioAnalyser/RaSCMU200Audio.py index 5a56048..4aed716 100644 --- a/src/labtoolkit/AudioAnalyser/RaSCMU200Audio.py +++ b/src/labtoolkit/AudioAnalyser/RaSCMU200Audio.py @@ -1,14 +1,14 @@ import numpy as np from dataclasses import dataclass -from ..IEEE488 import IEEE488 +from ..Instrument import Instrument from ..SCPI import SCPI class RaSCMU200Audio(Instrument, SCPI): """.""" def __post__(self): - # if seconday + # if secondary self.write('INITiate:AFANalyzer:PRIMary') self.write('INITiate:AFGenerator:PRIMary') diff --git a/src/labtoolkit/Enviromental/hydrotherm.py b/src/labtoolkit/Enviromental/hydrotherm.py index 0aed8b3..7a9916e 100644 --- a/src/labtoolkit/Enviromental/hydrotherm.py +++ b/src/labtoolkit/Enviromental/hydrotherm.py @@ -1,37 +1,55 @@ +from dataclasses import dataclass -if read.startswith(b'\x02') == True: -data = bytes.decode(read) -#print(data) -# sample = b'\x0201041102330410\r' +from ..Instrument import Instrument -# sample = b'\x0201041102040606\r' -# 020.4 C -Bit = { - 'D15' : data[0], - 'D14' : data[1], - 'D13' : data[2], - 'D12' : data[3], - 'D11' : data[4], - 'D10' : data[5], - 'D9' : data[6], - 'D8' : data[7], - 'D7' : data[8], - 'D6' : data[9], - 'D5' : data[10], - 'D4' : data[11], - 'D3' : data[12], - 'D2' : data[13], - 'D1' : data[14], - 'D0' : data[15], -} -Value = { - 'Humidity' : Bit['D4']+Bit['D3']+Bit['D2']+'.'+Bit['D1'], - #'Temperature' : Bit['D5']+Bit['D6']+Bit['D7']+Bit['D8'], - 'Temperature' : Bit['D8']+Bit['D7']+Bit['D6']+'.'+Bit['D5'], - 'Udp' : Bit['D9'], - 'Ldp' : Bit['D10'], - 'USym' : Bit['D11']+Bit['D12'], - 'LSym' : Bit['D13'], - 'CPolarity' : Bit['D14'], -} +class TBC(Instrument): + """.""" + + @dataclass + class Results: + """Class for keeping results from HydroTherm meter.""" + Temperature: float + Humidity: float + + def Measurement(self): + read = Instrument.read() + if read.startswith(b'\x02') == True: + data = bytes.decode(read) + #print(data) + # sample = b'\x0201041102330410\r' + + # sample = b'\x0201041102040606\r' + # 020.4 C + Bit = { + 'D15' : data[0], + 'D14' : data[1], + 'D13' : data[2], + 'D12' : data[3], + 'D11' : data[4], + 'D10' : data[5], + 'D9' : data[6], + 'D8' : data[7], + 'D7' : data[8], + 'D6' : data[9], + 'D5' : data[10], + 'D4' : data[11], + 'D3' : data[12], + 'D2' : data[13], + 'D1' : data[14], + 'D0' : data[15], + } + Value = { + 'Humidity' : Bit['D4']+Bit['D3']+Bit['D2']+'.'+Bit['D1'], + #'Temperature' : Bit['D5']+Bit['D6']+Bit['D7']+Bit['D8'], + 'Temperature' : Bit['D8']+Bit['D7']+Bit['D6']+'.'+Bit['D5'], + 'Udp' : Bit['D9'], + 'Ldp' : Bit['D10'], + 'USym' : Bit['D11']+Bit['D12'], + 'LSym' : Bit['D13'], + 'CPolarity' : Bit['D14'], + } + return self.Results( + Temperature=Value['Temperature'], + Humidity=Value['Humidity'], + ) diff --git a/src/labtoolkit/FieldStrength/Narda601.py b/src/labtoolkit/FieldStrength/Narda601.py index 4803a69..75e1360 100644 --- a/src/labtoolkit/FieldStrength/Narda601.py +++ b/src/labtoolkit/FieldStrength/Narda601.py @@ -7,17 +7,15 @@ import serial from serial.tools import list_ports +from ..Instrument import Instrument -class Narda601(FieldStrength): + +class Narda601(Instrument): """Narda601. .. figure:: images/FieldStrength/Narda601.jpg """ - def __init__(self, instrument): - """.""" - super().__init__(instrument) - def setup(self): """Send setup commands to probe.""" pass @@ -41,11 +39,11 @@ def returnstr(self, binary=b'T\x00\x00\x00\x00'): return binary[1:].decode() # Remove leading character from binary and decode - def decode_example(self): + def decode_example(self, hexes): for hexstring in hexes: hexstring = hexstring.replace(' ', '') # Remove spaces in hexstring bins = binascii.unhexlify(hexstring) # encode to binary, as you would receive over serial - print('{}\t::\t{}\t::\t{}'.format(hexstring, binarytoVm(bins), bins)) # print(Hex, Value, Binary) + print('{}\t::\t{}\t::\t{}'.format(hexstring, self.binarytoVm(bins), bins)) # print(Hex, Value, Binary) def query(self, ser, command): diff --git a/src/labtoolkit/Formatter/plot.py b/src/labtoolkit/Formatter/plot.py index 70b98c5..24c382f 100644 --- a/src/labtoolkit/Formatter/plot.py +++ b/src/labtoolkit/Formatter/plot.py @@ -1,5 +1,7 @@ import matplotlib.pyplot as plt from matplotlib.ticker import EngFormatter +import numpy as np + def plot_add_minor_min_max_labels(ax): lo = np.inf diff --git a/src/labtoolkit/Formula/Units.py b/src/labtoolkit/Formula/Units.py index 7adfc11..f7d12a1 100644 --- a/src/labtoolkit/Formula/Units.py +++ b/src/labtoolkit/Formula/Units.py @@ -360,7 +360,7 @@ def dBuV_m(V_m): @classmethod def W_m2(V_m): - return (V/m**2) / 377 + return (V_m**2) / 377 class W_m2To: diff --git a/src/labtoolkit/PowerAnalyser/VoltechPM100.py b/src/labtoolkit/PowerAnalyser/VoltechPM100.py index 58fccdd..011f7fc 100644 --- a/src/labtoolkit/PowerAnalyser/VoltechPM100.py +++ b/src/labtoolkit/PowerAnalyser/VoltechPM100.py @@ -4,7 +4,7 @@ class VoltechPM1000P(IEEE488): # inst = rm.open_resource('GPIB1::13::INSTR', read_termination='\n', write_termination='\n') # , , **kwargs) - def get(self): - Hz = float(inst.query(':FNC:FRQ?')) - V = float(inst.query(':FNC:VLT?')) - return v, Hz + def Measurement(self): + Hz = float(self.query(':FNC:FRQ?')) + V = float(self.query(':FNC:VLT?')) + return V, Hz