def scan(self): """ Nysa will call this function when the user wants to scan for the platform specific boards Args: Nothing Returns: Dictionary of uart instances, where the key is the serial number or unique identifier of a board Raises: NysaError: An error occured when scanning for devices """ self.status.Verbose("Scanning") inst_dict = {} devs = os.listdir("/dev") for d in devs: if "ttyUSB" in d: path = os.path.join(os.path.sep, "dev", d) inst_dict[os.path.split(d)[1]] = Uart(path) #if self.status: self.status.Warning("Scan function not implemented yet!") return inst_dict
def __init__(self): Thread.__init__(self) # self.daemon = True self.events = Events() self.socket_server = SocketServer("", 50000) self.uart = Uart() self.manipulator = None self.mobile_platform = None self.unit0 = {} self.unit1 = {} self.TOP_MARKER = 9 self.SIDE_MARKER = 16 self.snaps = { "unit0": {"TOP_MARKER": [], "SIDE_MARKER": []}, "unit1": {"TOP_MARKER": [], "SIDE_MARKER": []} } self.distance = None
class Tool(object): def __init__(self, parent): self.err = 0 self.parent = parent print("Tool start.....") self.uart = Uart(self.parent.uart_port, self.parent.config_uart_baud) self.start_listen_uart() def start_listen_uart(self): threading.Thread(target=self.listen_uart_data_thread, daemon=True).start() def listen_uart_data_thread(self): print("start listen_uart_data_thread.") while (True): # print("listening....") # sleep(1) if not self.uart.is_queue_recv_empty(): recv_data = self.uart.get_queue_recv() # 调用自定义信号 self.parent.signal_recv_data.emit(recv_data)
from uart import Uart import time uart = Uart() uart2 = Uart() uart.send_data("PIcalling") time.sleep(3)
class Core(Thread): def __init__(self): Thread.__init__(self) # self.daemon = True self.events = Events() self.socket_server = SocketServer("", 50000) self.uart = Uart() self.manipulator = None self.mobile_platform = None self.unit0 = {} self.unit1 = {} self.TOP_MARKER = 9 self.SIDE_MARKER = 16 self.snaps = { "unit0": {"TOP_MARKER": [], "SIDE_MARKER": []}, "unit1": {"TOP_MARKER": [], "SIDE_MARKER": []} } self.distance = None def run(self): self.socket_server.start() self.uart.start() self.connect_events() def connect_events(self): self.uart.events.on_connected += self.start_control self.socket_server.events.on_connected += self.referencing_clients_to_core def start_control(self): # Only when serial is connected if self.uart.serial: self.manipulator = Manipulator(self.uart) self.mobile_platform = MobilePlatform(self.uart) Steerage(self.manipulator, self.mobile_platform) self.manipulator.events.on_data += self.update_manipulator_ui def distance(self, data): pass # pos is unused, but needed def make_snap(self, pos): logger.info("SNAP") def area(self): pass def __stop(self): self.manipulator.stop() self.uart.stop() self.socket_server.stop() self.join() # this looks really lame def referencing_clients_to_core(self, is_connected): if is_connected: self.unit0 = self.socket_server.threads[0] self.unit0.events.on_new_data += self.update_unit0 if len(self.socket_server.threads) > 1: self.unit1 = self.socket_server.threads[1] self.unit1.events.on_new_data += self.update_unit1 else: self.unit0 = {} self.unit1 = {} def update_unit0(self, data): # self.distance() self.events.update_unit0_ui(data["markers"]) def update_unit1(self, data): # self.distance() self.events.update_unit1_ui(data["markers"]) def update_manipulator_ui(self, data): self.events.update_manipulator_ui(data)
if received is not '': print(received) time.sleep(1) def write(uart): while True: send = input("Send over UART: ") uart.send_string(send) time.sleep(1) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('-p', "--platform", default="laptop", help="Options: laptop, nano, pi") parser.add_argument('-m', "--mode", default="listen", help="Options: listen, send") args = vars(parser.parse_args()) uart = Uart(state={"platform": args["platform"]}) if args["mode"] == "listen": listen(uart) else: write(uart)
def __init__(self, parent): self.err = 0 self.parent = parent print("Tool start.....") self.uart = Uart(self.parent.uart_port, self.parent.config_uart_baud) self.start_listen_uart()
#-------------------------------------------------------------------- #CONSTANTS #-------------------------------------------------------------------- LOG_LEVEL = 2 # Information level LOG_ALWAYS = 3 # Always log data #-------------------------------------------------------------------- #METHODS #-------------------------------------------------------------------- def log(msg, log_level=LOG_LEVEL): """ Print a message, and track, where the log is invoked Input: -msg: message to be printed, '' -log_level: informationlevel, i """ global LOG_LEVEL if log_level <= LOG_LEVEL: print(str(log_level) + ' : ' + __file__ + '.py::' + traceback.extract_stack()[-2][2] + ' : ' + msg) name = 'Ubuntu_Uart' name_rec = 'Dantracker' port = '/dev/ttyUSB1' uart = Uart(name) serial_ports = uart.serial_ports() print(serial_ports) serial_port = input("Type the the desired serial port, that you wanted to use, You are only allowed to type one serial port. End by pressing 'Enter'.") print(serial_port)
@date 2020.08.01 @author Alexander @email [email protected] @brief <вставьте сюда краткое описание модуля> ''' import time from uart import Uart from sdcard import Sdcard from leds import Leds if __name__ == "__main__": uart1 = Uart() card = Sdcard(uart1) leds1 = Leds(uart1) # leds1.test() time.sleep(1) print(''' Step 1 Set DI and CS high and apply 74 or more clock pulses to SCLK. Without this step under certain circumstances SD-card will not work. For instance, when multiple SPI devices are sharing the same bus (i.e. MISO, MOSI, CS).''') card.preInit() print()