本文整理汇总了Python中pymavlink.mavutil.auto_detect_serial函数的典型用法代码示例。如果您正苦于以下问题:Python auto_detect_serial函数的具体用法?Python auto_detect_serial怎么用?Python auto_detect_serial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了auto_detect_serial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cmd_link_ports
def cmd_link_ports(self):
"""show available ports"""
ports = mavutil.auto_detect_serial(
preferred_list=["*FTDI*", "*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", "*PX4*", "*FMU*"]
)
for p in ports:
print("%s : %s : %s" % (p.device, p.description, p.hwid))
示例2: main
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument('port', metavar='PORT', nargs='?', default = None,
help='Mavlink port name: serial: DEVICE[,BAUD], udp: IP:PORT, tcp: tcp:IP:PORT. Eg: \
/dev/ttyUSB0 or 0.0.0.0:14550. Auto-detect serial if not given.')
parser.add_argument("--baudrate", "-b", dest="baudrate", type=int,
help="Mavlink port baud rate (default=115200)", default=115200)
args = parser.parse_args()
if args.port == None:
serial_list = mavutil.auto_detect_serial(preferred_list=['*FTDI*',
"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", '*PX4*', '*FMU*'])
if len(serial_list) == 0:
print("Error: no serial connection found")
return
if len(serial_list) > 1:
print('Auto-detected serial ports are:')
for port in serial_list:
print(" {:}".format(port))
print('Using port {:}'.format(serial_list[0]))
args.port = serial_list[0].device
print("Connecting to MAVLINK...")
mav_serialport = MavlinkSerialPort(args.port, args.baudrate, devnum=10)
mav_serialport.write('\n') # make sure the shell is started
try:
while True:
i, o, e = select.select([sys.stdin], [], [], 0.001)
if (i):
data = sys.stdin.readline()
# Erase stdin output (otherwise we have it twice)
# FIXME: this assumes a prompt of 5 chars, and does not work in all cases
CURSOR_UP_ONE = '\x1b[1A'
CURSOR_RIGHT = '\x1b[5C'
ERASE_LINE = '\x1b[2K'
ERASE_END_LINE = '\x1b[K'
sys.stdout.write(CURSOR_UP_ONE + CURSOR_RIGHT + ERASE_END_LINE)
# TODO: add a command history?
#sys.stdout.write(data)
mav_serialport.write(data)
data = mav_serialport.read(4096)
if data and len(data) > 0:
sys.stdout.write(data)
sys.stdout.flush()
except serial.serialutil.SerialException as e:
print(e)
except KeyboardInterrupt:
mav_serialport.close()
示例3: main
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument(
"port",
metavar="PORT",
nargs="?",
default=None,
help="Mavlink port name: serial: DEVICE[,BAUD], udp: IP:PORT, tcp: tcp:IP:PORT. Eg: \
/dev/ttyUSB0 or 0.0.0.0:14550. Auto-detect serial if not given.",
)
parser.add_argument(
"--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=115200)", default=115200
)
parser.add_argument("--output", "-o", dest="output", default=".", help="output file or directory (default=CWD)")
args = parser.parse_args()
if os.path.isdir(args.output):
filename = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S.ulg")
filename = os.path.join(args.output, filename)
else:
filename = args.output
print("Output file name: {:}".format(filename))
if args.port == None:
serial_list = mavutil.auto_detect_serial(
preferred_list=["*FTDI*", "*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", "*PX4*", "*FMU*"]
)
if len(serial_list) == 0:
print("Error: no serial connection found")
return
if len(serial_list) > 1:
print("Auto-detected serial ports are:")
for port in serial_list:
print(" {:}".format(port))
print("Using port {:}".format(serial_list[0]))
args.port = serial_list[0].device
print("Connecting to MAVLINK...")
mav_log_streaming = MavlinkLogStreaming(args.port, args.baudrate, filename)
try:
print("Starting log...")
mav_log_streaming.start_log()
mav_log_streaming.read_messages()
print("Stopping log")
mav_log_streaming.stop_log()
except KeyboardInterrupt:
print("Stopping log")
mav_log_streaming.stop_log()
示例4: get_serial
def get_serial():
ret = None
serial_list = mavutil.auto_detect_serial(
preferred_list=[
'*FTDI*',
'*Arduino_Mega_2560*',
'*3D_Robotics*',
'*USB_to_UART*',
'*USB to UART*',
'*PX4*',
'*FMU*',
'*串行设备*',
]
)
# print(dir(serial_list[0]))
# print(serial_list[0].description)
if len(serial_list) > 0:
ret = serial_list[0].device
return ret
示例5: detect_pixhawk
def detect_pixhawk():
'''
Detect the serial port where pixhawk is connected automatically. Adapted from Mavproxy code.
'''
serial_list = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*"])
if len(serial_list) == 1:
return serial_list[0].device
else:
print('''
Please choose a MAVLink master with --master
For example:
--master=com14
--master=/dev/ttyUSB0
--master=127.0.0.1:14550
Auto-detected serial ports are:
''')
for port in serial_list:
print("%s" % port)
sys.exit(1)
示例6: MPState
from pymavlink import mavutil, mavparm
mavutil.set_dialect(opts.dialect)
# global mavproxy state
mpstate = MPState()
mpstate.status.exit = False
mpstate.command_map = command_map
mpstate.continue_mode = opts.continue_mode
if opts.speech:
# start the speech-dispatcher early, so it doesn't inherit any ports from
# modules/mavutil
load_module('speech')
if not opts.master:
serial_list = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*"])
if len(serial_list) == 1:
opts.master = [serial_list[0].device]
else:
print('''
Please choose a MAVLink master with --master
For example:
--master=com14
--master=/dev/ttyUSB0
--master=127.0.0.1:14550
Auto-detected serial ports are:
''')
for port in serial_list:
print("%s" % port)
sys.exit(1)
示例7: complete_serial_ports
def complete_serial_ports(self, text):
'''return list of serial ports'''
ports = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", '*PX4*', '*FMU*'])
return [ p.device for p in ports ]
示例8: MPState
# global mavproxy state
mpstate = MPState()
mpstate.status.exit = False
mpstate.command_map = command_map
mpstate.continue_mode = opts.continue_mode
# queues for logging
mpstate.logqueue = Queue.Queue()
mpstate.logqueue_raw = Queue.Queue()
if opts.speech:
# start the speech-dispatcher early, so it doesn't inherit any ports from
# modules/mavutil
load_module('speech')
serial_list = mavutil.auto_detect_serial(preferred_list=preferred_ports)
if not opts.master:
print('Auto-detected serial ports are:')
for port in serial_list:
print("%s" % port)
# container for status information
mpstate.settings.target_system = opts.TARGET_SYSTEM
mpstate.settings.target_component = opts.TARGET_COMPONENT
mpstate.mav_master = []
mpstate.rl = rline.rline("MAV> ", mpstate)
def quit_handler(signum = None, frame = None):
#print('Signal handler called with signal', signum)
示例9: initMAVProxy
def initMAVProxy():
from optparse import OptionParser
parser = OptionParser("mavproxy.py [options]")
parser.add_option("--master", dest="master", action='append',
metavar="DEVICE[,BAUD]", help="MAVLink master port and optional baud rate",
default=[])
parser.add_option("--out", dest="output", action='append',
metavar="DEVICE[,BAUD]", help="MAVLink output port and optional baud rate",
default=[])
parser.add_option("--baudrate", dest="baudrate", type='int',
help="default serial baud rate", default=115200)
parser.add_option("--sitl", dest="sitl", default=None, help="SITL output port")
parser.add_option("--streamrate",dest="streamrate", default=4, type='int',
help="MAVLink stream rate")
parser.add_option("--source-system", dest='SOURCE_SYSTEM', type='int',
default=255, help='MAVLink source system for this GCS')
parser.add_option("--target-system", dest='TARGET_SYSTEM', type='int',
default=1, help='MAVLink target master system')
parser.add_option("--target-component", dest='TARGET_COMPONENT', type='int',
default=1, help='MAVLink target master component')
parser.add_option("--logfile", dest="logfile", help="MAVLink master logfile",
default='mav.tlog')
parser.add_option("-a", "--append-log", dest="append_log", help="Append to log files",
action='store_true', default=False)
parser.add_option("--quadcopter", dest="quadcopter", help="use quadcopter controls",
action='store_true', default=False)
parser.add_option("--setup", dest="setup", help="start in setup mode",
action='store_true', default=False)
parser.add_option("--nodtr", dest="nodtr", help="disable DTR drop on close",
action='store_true', default=False)
parser.add_option("--show-errors", dest="show_errors", help="show MAVLink error packets",
action='store_true', default=False)
parser.add_option("--speech", dest="speech", help="use text to speach",
action='store_true', default=False)
parser.add_option("--num-cells", dest="num_cells", help="number of LiPo battery cells",
type='int', default=0)
parser.add_option("--aircraft", dest="aircraft", help="aircraft name", default=None)
parser.add_option("--cmd", dest="cmd", help="initial commands", default=None)
parser.add_option("--console", action='store_true', help="use GUI console")
parser.add_option("--map", action='store_true', help="load map module")
parser.add_option(
'--load-module',
action='append',
default=[],
help='Load the specified module. Can be used multiple times, or with a comma separated list')
parser.add_option("--mav09", action='store_true', default=False, help="Use MAVLink protocol 0.9")
parser.add_option("--auto-protocol", action='store_true', default=False, help="Auto detect MAVLink protocol version")
parser.add_option("--nowait", action='store_true', default=False, help="don't wait for HEARTBEAT on startup")
parser.add_option("--continue", dest='continue_mode', action='store_true', default=False, help="continue logs")
parser.add_option("--dialect", default="ardupilotmega", help="MAVLink dialect")
parser.add_option("--rtscts", action='store_true', help="enable hardware RTS/CTS flow control")
(opts, args) = parser.parse_args()
mavproxy.opts=opts
if opts.mav09:
os.environ['MAVLINK09'] = '1'
from pymavlink import mavutil, mavparm
mavutil.set_dialect(opts.dialect)
# global mavproxy state
mpstate = MPState()
mavproxy.mpstate=mpstate
mpstate.status.exit = False
mpstate.command_map = command_map
mpstate.continue_mode = opts.continue_mode
if opts.speech:
# start the speech-dispatcher early, so it doesn't inherit any ports from
# modules/mavutil
load_module('speech')
if not opts.master:
serial_list = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*"])
if len(serial_list) == 1:
opts.master = [serial_list[0].device]
else:
print('''
Please choose a MAVLink master with --master
For example:
--master=com14
--master=/dev/ttyUSB0
--master=127.0.0.1:14550
Auto-detected serial ports are:
''')
for port in serial_list:
print("%s" % port)
sys.exit(1)
# container for status information
mpstate.status.target_system = opts.TARGET_SYSTEM
mpstate.status.target_component = opts.TARGET_COMPONENT
mpstate.mav_master = []
# open master link
for mdev in opts.master:
if ',' in mdev and not os.path.exists(mdev):
#.........这里部分代码省略.........
示例10: complete_serial_ports
def complete_serial_ports(self, text):
'''return list of serial ports'''
ports = mavutil.auto_detect_serial(preferred_list=preferred_ports)
return [ p.device for p in ports ]
示例11: cmd_link_ports
def cmd_link_ports(self):
'''show available ports'''
ports = mavutil.auto_detect_serial(preferred_list=preferred_ports)
for p in ports:
print("%s : %s : %s" % (p.device, p.description, p.hwid))
示例12: scanForSerials
def scanForSerials(self):
print "detecting serial ports..."
return mavutil.auto_detect_serial(['*ttyUSB*', '*ttyACM*', '*tty.usb*'])
示例13: main
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument('port', metavar='PORT', nargs='?', default = None,
help='Mavlink port name: serial: DEVICE[,BAUD], udp: IP:PORT, tcp: tcp:IP:PORT. Eg: \
/dev/ttyUSB0 or 0.0.0.0:14550. Auto-detect serial if not given.')
parser.add_argument("--baudrate", "-b", dest="baudrate", type=int,
help="Mavlink port baud rate (default=115200)", default=115200)
args = parser.parse_args()
if args.port == None:
serial_list = mavutil.auto_detect_serial(preferred_list=['*FTDI*',
"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", '*PX4*', '*FMU*'])
if len(serial_list) == 0:
print("Error: no serial connection found")
return
if len(serial_list) > 1:
print('Auto-detected serial ports are:')
for port in serial_list:
print(" {:}".format(port))
print('Using port {:}'.format(serial_list[0]))
args.port = serial_list[0].device
print("Connecting to MAVLINK...")
mav_serialport = MavlinkSerialPort(args.port, args.baudrate, devnum=10)
mav_serialport.write('\n') # make sure the shell is started
# setup the console, so we can read one char at a time
fd_in = sys.stdin.fileno()
old_attr = termios.tcgetattr(fd_in)
new_attr = termios.tcgetattr(fd_in)
new_attr[3] = new_attr[3] & ~termios.ECHO # lflags
new_attr[3] = new_attr[3] & ~termios.ICANON
try:
termios.tcsetattr(fd_in, termios.TCSANOW, new_attr)
cur_line = ''
command_history = []
cur_history_index = 0
def erase_last_n_chars(N):
if N == 0: return
CURSOR_BACK_N = '\x1b['+str(N)+'D'
ERASE_END_LINE = '\x1b[K'
sys.stdout.write(CURSOR_BACK_N + ERASE_END_LINE)
while True:
while True:
i, o, e = select.select([sys.stdin], [], [], 0)
if not i: break
ch = sys.stdin.read(1)
# provide a simple shell with command history
if ch == '\n':
if len(cur_line) > 0:
# erase current text (mavlink shell will echo it as well)
erase_last_n_chars(len(cur_line))
# add to history
if len(command_history) == 0 or command_history[-1] != cur_line:
command_history.append(cur_line)
if len(command_history) > 50:
del command_history[0]
cur_history_index = len(command_history)
mav_serialport.write(cur_line+'\n')
cur_line = ''
elif ord(ch) == 127: # backslash
if len(cur_line) > 0:
erase_last_n_chars(1)
cur_line = cur_line[:-1]
sys.stdout.write(ch)
elif ord(ch) == 033:
ch = sys.stdin.read(1) # skip one
ch = sys.stdin.read(1)
if ch == 'A': # arrow up
if cur_history_index > 0:
cur_history_index -= 1
elif ch == 'B': # arrow down
if cur_history_index < len(command_history):
cur_history_index += 1
# TODO: else: support line editing
erase_last_n_chars(len(cur_line))
if cur_history_index == len(command_history):
cur_line = ''
else:
cur_line = command_history[cur_history_index]
sys.stdout.write(cur_line)
elif ord(ch) > 3:
cur_line += ch
sys.stdout.write(ch)
sys.stdout.flush()
data = mav_serialport.read(4096)
if data and len(data) > 0:
#.........这里部分代码省略.........
示例14: complete_serial_ports
def complete_serial_ports(self, text):
"""return list of serial ports"""
ports = mavutil.auto_detect_serial(
preferred_list=["*FTDI*", "*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", "*PX4*", "*FMU*"]
)
return [p.device for p in ports]
示例15: main
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument(
"port",
metavar="PORT",
nargs="?",
default=None,
help="Mavlink port name: serial: DEVICE[,BAUD], udp: IP:PORT, tcp: tcp:IP:PORT. Eg: \
/dev/ttyUSB0 or 0.0.0.0:14550. Auto-detect serial if not given.",
)
parser.add_argument(
"--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600
)
args = parser.parse_args()
if args.port == None:
if sys.platform == "darwin":
args.port = "/dev/tty.usbmodem1"
else:
serial_list = mavutil.auto_detect_serial(
preferred_list=["*FTDI*", "*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", "*PX4*", "*FMU*"]
)
if len(serial_list) == 0:
print("Error: no serial connection found")
return
if len(serial_list) > 1:
print("Auto-detected serial ports are:")
for port in serial_list:
print(" {:}".format(port))
print("Using port {:}".format(serial_list[0]))
args.port = serial_list[0].device
print("Connecting to MAVLINK...")
mav_serialport = MavlinkSerialPort(args.port, args.baudrate, devnum=10)
mav_serialport.write("\n") # make sure the shell is started
# setup the console, so we can read one char at a time
fd_in = sys.stdin.fileno()
old_attr = termios.tcgetattr(fd_in)
new_attr = termios.tcgetattr(fd_in)
new_attr[3] = new_attr[3] & ~termios.ECHO # lflags
new_attr[3] = new_attr[3] & ~termios.ICANON
try:
termios.tcsetattr(fd_in, termios.TCSANOW, new_attr)
cur_line = ""
command_history = []
cur_history_index = 0
def erase_last_n_chars(N):
if N == 0:
return
CURSOR_BACK_N = "\x1b[" + str(N) + "D"
ERASE_END_LINE = "\x1b[K"
sys.stdout.write(CURSOR_BACK_N + ERASE_END_LINE)
next_heartbeat_time = timer()
while True:
while True:
i, o, e = select.select([sys.stdin], [], [], 0)
if not i:
break
ch = sys.stdin.read(1)
# provide a simple shell with command history
if ch == "\n":
if len(cur_line) > 0:
# erase current text (mavlink shell will echo it as well)
erase_last_n_chars(len(cur_line))
# add to history
if len(command_history) == 0 or command_history[-1] != cur_line:
command_history.append(cur_line)
if len(command_history) > 50:
del command_history[0]
cur_history_index = len(command_history)
mav_serialport.write(cur_line + "\n")
cur_line = ""
elif ord(ch) == 127: # backslash
if len(cur_line) > 0:
erase_last_n_chars(1)
cur_line = cur_line[:-1]
sys.stdout.write(ch)
elif ord(ch) == 27:
ch = sys.stdin.read(1) # skip one
ch = sys.stdin.read(1)
if ch == "A": # arrow up
if cur_history_index > 0:
cur_history_index -= 1
elif ch == "B": # arrow down
if cur_history_index < len(command_history):
cur_history_index += 1
# TODO: else: support line editing
erase_last_n_chars(len(cur_line))
if cur_history_index == len(command_history):
#.........这里部分代码省略.........