Source code for ppf_moke.gaussmeter

import serial


[docs]class Gaussmeter: """ Class initializing Serial communication and read value. """ def __init__(self): """ initialize serial port. Values are hardcoded, the port needs to be changed for other configurations. """ self.ser = serial.Serial() self.ser.port = 'COM4' self.ser.baudrate = 9600 self.ser.bytesize = serial.EIGHTBITS self.ser.parity = serial.PARITY_NONE self.ser.stopbits = serial.STOPBITS_ONE self.ser.timeout = 10
[docs] def open_communication(self): """ opens serial communication with the gaussmeter """ self.ser.open()
[docs] def read_field(self): """ returns the current field value """ befehl = ":MEAS?\r" self.ser.flushInput() self.ser.flushOutput() self.ser.write(befehl.encode()) res = (self.ser.readline()).decode() return float(res.rstrip('\n'))
[docs] def close_communication(self): """ closes serial communication with the gaussmeter """ self.ser.close()
[docs]def test(): """ prints a confirmation to the console if the module is properly loaded """ print("gaussmeter module is working")
# Gauss = Gaussmeter() # Gauss.openCommunication() # res = Gauss.readMagneticField() # print(res) # Gauss.closeGaussmeter()