I have written this class that connects to a relay board and allows me to send the commands to turn off and on the different relays upon it.
class relay_board:
def __init__(self, com_port):
self.com_port = com_port
self.ser = serial.Serial(self.com_port, 9600, timeout=2)
self.shorttime = 0.01
def send_command(self, bank, ports):
self.bank = bank
self.ports = ports
message = bank+ports
self.ser.write(message)
time.sleep(0.01)
And I am calling it like this,
relay_one = relay_board.relay_board('COM3')
relay_one.send_command(b'\x42', b'\x00')
relay_one.send_command(b'\x43', b'\x3F')
Does the class destroy the self.ser when the program is finished or do I have to add a __del__
or a def close_serial()
function to close the serial connection at the end?