Ejemplo n.º 1
0
 def start_disconnect_watcher(self):
     logging.info(
         "DYNAMIC SERIAL: Opened serial and spun off %s-disconnect-watcher thread",
         self.name)
     self.old_ports = [port_info.device for port_info in list_ports()]
     threading.Thread(target=self.device_disconnect_watch,
                      name="%s-disconnect-watcher" % self.name).start()
Ejemplo n.º 2
0
    def __init__(self, name, ser, verbose):
        log = sys.stdout if verbose else open(os.devnull, 'w')
        logging.basicConfig(stream=log, level=logging.DEBUG)
        self.ser = ser
        self.verbose = verbose
        self.fmt = '%s: %%s' % name
        self.name = name
        self.lock = threading.Lock()
        self.connected = False
        self.port = ''
        self.baudrate = 115200
        self.old_ports = [port_info.device for port_info in list_ports()]

        #enum values for message types
        self.REQUEST_NAME               = 0x00
        self.RETURN_NAME                = 0x01
        self.REQUEST_CARD_SIGNATURE     = 0x02
        self.RETURN_CARD_SIGNATURE      = 0x03
        self.REQUEST_HSM_NONCE          = 0x04
        self.RETURN_HSM_NONCE           = 0x05
        self.REQUEST_HSM_UUID           = 0x06
        self.RETURN_HSM_UUID            = 0x07
        self.REQUEST_WITHDRAWAL         = 0x08
        self.RETURN_WITHDRAWAL          = 0x09
        self.REQUEST_BALANCE            = 0x0A
        self.RETURN_BALANCE             = 0x0B
        self.REQUEST_NEW_PK             = 0x0C
        self.RETURN_NEW_PK              = 0x0D
        self.SYNC_REQUEST_PROV          = 0x15
        self.SYNC_REQUEST_NO_PROV       = 0x16
        self.SYNC_CONFIRMED_PROV        = 0x17
        self.SYNC_CONFIRMED_NO_PROV     = 0x18
        self.SYNC_FAILED_NO_PROV        = 0x19
        self.SYNC_FAILED_PROV           = 0x1A
        self.SYNCED                     = 0x1B
        self.SYNC_TYPE_HSM_N            = 0x1C
        self.SYNC_TYPE_HSM_P            = 0x3C
        self.SYNC_TYPE_CARD_N           = 0x1D
        self.SYNC_TYPE_CARD_P           = 0x3D
        self.PSOC_DEVICE_REQUEST        = 0x1E
        self.INITIATE_PROVISION         = 0x25
        self.REQUEST_PROVISION          = 0x26
        self.INITIATE_BILLS_REQUEST     = 0x27
        self.BILLS_REQUEST              = 0x28
        self.BILL_RECEIVED              = 0x29

        # General enums for accepted/rejected flags
        self.ACCEPTED                   = 0x20
        self.REJECTED                   = 0x21

        self.sync_name_n = '%s_N' % name
        self.sync_name_p = '%s_P' % name


        if ser:
            self.connected = True
        else:
            self.start_connect_watcher()
Ejemplo n.º 3
0
def main():
    "Main procedure of this f*****g program"
    ports = list_ports()
    if not ports:
        print("None device attached. Review the cables.")
        return
    port = ports[0]
    conn = connect(port.device)
    print("Connected at {}".format(port.device))
    stream = stream_connection(conn)
    print("Streaming started.")
    for signal in stream:
        try:
            interpreter(signal)
        except ValueError as e:
            print('Exception ignored: ', e)
Ejemplo n.º 4
0
    def __init__(self, name, ser, verbose):
        log = sys.stdout if verbose else open(os.devnull, 'w')
        logging.basicConfig(stream=log, level=logging.DEBUG)
        self.ser = ser
        self.verbose = verbose
        self.fmt = '%s: %%s' % name
        self.name = name
        self.lock = threading.Lock()
        self.connected = False
        self.port = ''
        self.baudrate = 115200
        self.old_ports = [port_info.device for port_info in list_ports()]
        self.sync_name_n = '%s_N' % name
        self.sync_name_p = '%s_P' % name

        if not ser:
            self.start_connect_watcher()
Ejemplo n.º 5
0
    def device_connect_watch(self):
        """Threaded function that connects to new serial devices"""

        # Read current ports
        connecting = []

        # Has a new device connected?
        while len(connecting) == 0:
            new_ports = [port_info.device for port_info in list_ports()]
            connecting = list(set(new_ports) - set(self.old_ports))
            self.old_ports = new_ports
            time.sleep(.25)
        self.port = connecting[0]
        logging.info("DYNAMIC SERIAL: Found new serial device")
        self.open()
        if self.name == 'CARD':
            self.start_disconnect_watcher()
Ejemplo n.º 6
0
    def device_disconnect_watch(self):
        """Threaded function that connects to new serial devices"""

        # Read current ports
        disconnecting = []

        # Has a new device connected?
        while not disconnecting and self.port not in disconnecting:
            new_ports = [port_info.device for port_info in list_ports()]
            disconnecting = list(set(self.old_ports) - set(new_ports))
            self.old_ports = new_ports

        logging.info("DYNAMIC SERIAL: %s disconnected", self.name)
        self.port = ''
        self.connected = False
        self.lock.acquire()
        self.ser.close()
        self.lock.release()
        self.start_connect_watcher()
Ejemplo n.º 7
0
                prev_intens = new_intens  # update old intensity value
        if len(channels) == 1:
            return channels[0].reshape(self.rows, self.cols)
        return cv2.merge(channels).reshape(self.rows, self.cols, 3)


if __name__ == '__main__':
    # allow input from file or via questionaire
    sep = ';'
    filename = input('settings filename (press enter if none): ')
    if filename:
        with open(filename, 'r') as in_file:
            port, baud, timeout, rows, cols, min_val, max_val, blur, \
                    colour_map = in_file.readline().split(sep)
    else:
        list_ports()
        port = input('Port: ')
        baud = input('Baudrate: ')
        timeout = input('Timeout (s): ')
        rows = input('Number of rows: ')
        cols = input('Number of cols: ')
        min_val = input('Minimum expected value: ')
        max_val = input('Maximum expected value: ')
        blur = input('Blur (int >=0, larger values blur more: ')
        colour_map = input('Colour map:\n\te.g. grey: [[0,0],[0.5,0.3],[1,1]]'\
                           '\n\t\t coloured: [[0,[0,1,1]],[1,[0,0.1,1]]]\n\t'\
                           '\t default linear greyscale intensity: <Enter>\n')

        filename = input('Save settings to: ')
        if filename:
            try:
Ejemplo n.º 8
0
def listDevices():
    ret = []
    for p in list_ports():
        ret.append(p.device)
    return ret