Example #1
0
def run_script(args):
    if args.verbose:
        print(dedent("""
            accessing bus interface:
              - port     : %s
              - baudrate : %d
              - timeout  : %.3f s
              """)
              % (args.port, args.baudrate, args.timeout)
              )

    try:
        intf_class = USB2AX if args.xevel else USB2Dynamixel
        intf = intf_class(port=args.port, baudrate=args.baudrate, timeout=args.timeout)
    except Exception as e:
        cli.die(e)
    else:
        print('Scanning bus on %s from id=%d to id=%d...' % (args.port, args.from_id, args.to_id))
        ids = intf.scan(args.from_id, args.to_id)
        if ids:
            print ('%d servo(s) found with id(s) : %s' %
                   (len(ids), ', '.join([str(_id) for _id in ids]))
                   )

        else:
            print('No servo found.')

        return 0
Example #2
0
def run_script(args):  # pylint: disable=W0621
    # process the 'list registers' action which involves no equipment
    if args.list:
        list_registers()
        return

    try:
        intf_class = USB2AX if args.xevel else USB2Dynamixel
        intf = intf_class(
            port=args.port,
            baudrate=args.baudrate,
            timeout=args.timeout,
            debug=args.debug
        )
    except Exception as e:  # pylint: disable=W0703
        cli.die(e)

    else:
        if args.intf or intf.ping(args.id):

            if args.intf:
                print('Interface register(s) :')
            else:
                print('Servo id=%s register(s) :' % args.id)

            if args.readall:
                # we want to display all registers
                intf.dump_regs(args.id)
            elif args.read is not None:
                # we want to read a specific register
                display_register(intf, args.id, args.read)
            elif args.write:
                # we want to write to a specific register
                reg, value = WriteStatement.parse(args.write)
                if reg == Register.Id:
                    print(dedent("""
    Warning : Writing to register 0x%0.2x will change the servo id.
            Use dmxl_setid.py script for doing this in a secure way.
                            """) % Register.Id
                    )
                    return
                write_register(intf, args.id, reg, value)
                display_register(intf, args.id, reg)

        else:
            cli.print_err('no servo found with id=%d' % args.id)