#basic COM port functions
# -*- encoding=utf-8 -*-
import serial
import serial.tools.list_ports


class COM:
    def __init__(self):
        self.port = 0
        self.baud = 115200
        self.open_com = None
        self.get_data_flag = True
        self.real_time_data = ''
        self.ser = None

    def list_port(self):
        port_list = list(serial.tools.list_ports.comports())
        if len(port_list) <= 0:
           return ("None")
        else:
            return(port_list)

    def open_port(self,com,baudRate):
        self.ser = serial.Serial(com, baudRate)

    def close_port(self):
        self.ser.close()