def ser(): ser = comms.open_serial_connection('COM3') yield ser ser.close()
def ser(): ser = comms.open_serial_connection('COM3') basic_cmd.synchronize(ser) yield ser ser.close()
returnvalue = ser.read(2) if returnvalue != b'': return list(returnvalue) def synchronize(ser): """ Tries to sync sender and receiver. Returns 0 on success Returns 1 on failiure """ _timeout = ser.timeout ser.timeout = 0.1 cmd = [0] for i in range(0, 100): comms.send_cmd(ser, cmd) returnvalue = ser.read(1) if returnvalue != b'': if int.from_bytes(returnvalue, byteorder='big') == 1: ser.timeout = _timeout return 0 ser.timeout = _timeout return 1 if __name__ == '__main__': ser = comms.open_serial_connection('COM3') while True: print(get_joystick(ser)) time.sleep(0.1)
def ser(): ser = comms.open_serial_connection('COM3') mcp.write_can_rx_flag(ser, 0) yield ser mcp.write_can_rx_flag(ser, 1) ser.close()