def wait_card_insert(connection, chip = False, timeout = 0): """ TODO. """ i = 0 while timeout == 0 or (timeout > 0 and i <= timeout): print('Please insert a chip card ...') ack = Protocol.recv_system_status(connection, timeout) cr_status = ack['Entry'].get(0x10) if cr_status: sts = cr_status['Status'] ext = cr_status['StatusExt'] if sts == 1 and (((ext&3) == 3) if chip else ((ext&1) == 1)): return True i += 1 time.sleep(1) return False