• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mavutil.auto_detect_serial函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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))
开发者ID:FredJodd,项目名称:MAVProxy,代码行数:7,代码来源:mavproxy_link.py


示例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()
开发者ID:agneevguin,项目名称:Firmware,代码行数:60,代码来源:mavlink_shell.py


示例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()
开发者ID:jingego,项目名称:Firmware,代码行数:53,代码来源:mavlink_ulog_streaming.py


示例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
开发者ID:kamijawa,项目名称:pi_server,代码行数:19,代码来源:groundcontrol.py


示例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)
开发者ID:serbuh,项目名称:multicopter,代码行数:20,代码来源:comm_get_messages.py


示例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)
开发者ID:geeksville,项目名称:MAVProxy,代码行数:31,代码来源:mavproxy.py


示例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 ]
开发者ID:arthurbenemann,项目名称:MAVProxy,代码行数:4,代码来源:mavproxy_link.py


示例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)
开发者ID:rmackay9,项目名称:MAVProxy,代码行数:31,代码来源:mavproxy.py


示例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):
#.........这里部分代码省略.........
开发者ID:third-person-immersion,项目名称:quadcopter-control,代码行数:101,代码来源:regulator.py


示例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 ]
开发者ID:rmackay9,项目名称:MAVProxy,代码行数:4,代码来源:mavproxy_link.py


示例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))
开发者ID:rmackay9,项目名称:MAVProxy,代码行数:5,代码来源:mavproxy_link.py


示例12: scanForSerials

 def scanForSerials(self):
     print "detecting serial ports..."
     return mavutil.auto_detect_serial(['*ttyUSB*',  '*ttyACM*', '*tty.usb*'])
开发者ID:fschill,项目名称:mavue,代码行数:3,代码来源:mavlink_receiver.py


示例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:
#.........这里部分代码省略.........
开发者ID:2013-8-15,项目名称:Firmware,代码行数:101,代码来源:mavlink_shell.py


示例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]
开发者ID:FredJodd,项目名称:MAVProxy,代码行数:6,代码来源:mavproxy_link.py


示例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):
#.........这里部分代码省略.........
开发者ID:nxajh,项目名称:Firmware,代码行数:101,代码来源:mavlink_shell.py



注:本文中的pymavlink.mavutil.auto_detect_serial函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mavutil.evaluate_condition函数代码示例发布时间:2022-05-27
下一篇:
Python testing.PymatgenTest类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap