示例#1
0
import sys
import time

from minimalmodbus import Instrument

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print 'Usage: %s [COM]' % sys.argv[0]
        exit(1)

    port = sys.argv[1]

    inst = Instrument(port, 1)
    inst.serial.baudrate = 57600
    inst.serial.timeout = 0.1

    for i in range(1, 16):
        try:
            inst.address = i
            response = inst.read_registers(0x0001, 1)
        except IOError:
            pass
        else:
            print hex(response[0])
            fw_version = response[0] & 0x0FFF
            hw_version = response[0] >> 12
            print 'Slave {}: FW {:03X}, HW {:01X}'.format(i, fw_version, hw_version)
        time.sleep(0.01)

    print 'Done.'
示例#2
0
    # print inst
    # inst.debug = True

    # Try to reset FW and run bootloader.
    print 'Sending reset to FW... ',
    try:
        inst.write_registers(RESET_ADDRESS, [0xFFFF])
    except IOError:
        print '[no response]'
    except ValueError:
        print '[wrong response]'
    else:
        print '[OK]'

    # Bootloader slave address has MSB set.
    inst.address = BOOTLOADER_SLAVE_ADDRESS | slave_address
    time.sleep(0.5)

    start_time = time.time()

    # Unlock bootloader.
    print 'Sending secret key',
    unlocked = False
    for i in range(10):
        try:
            inst.write_registers(UNLOCK_ADDRESS, UNLOCK_SECRET)
            sys.stdout.write('.')
            sys.stdout.flush()
            unlocked = True
            break
        except IOError:
示例#3
0
    # print inst
    # inst.debug = True

    # Try to reset FW and run bootloader.
    print 'Sending reset to FW... ',
    try:
        inst.write_registers(RESET_ADDRESS, [0xFFFF])
    except IOError:
        print '[no response]'
    except ValueError:
        print '[wrong response]'
    else:
        print '[OK]'

    # Bootloader slave address has MSB set.
    inst.address = BOOTLOADER_SLAVE_ADDRESS | slave_address
    time.sleep(0.5)

    start_time = time.time()

    # Unlock bootloader.
    print 'Sending secret key',
    unlocked = False
    for i in range(10):
        try:
            inst.write_registers(UNLOCK_ADDRESS, UNLOCK_SECRET)
            sys.stdout.write('.')
            sys.stdout.flush()
            unlocked = True
            break
        except IOError:
示例#4
0
import time

from minimalmodbus import Instrument

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print 'Usage: %s [COM]' % sys.argv[0]
        exit(1)

    port = sys.argv[1]

    inst = Instrument(port, 1)
    inst.serial.baudrate = 57600
    inst.serial.timeout = 0.1

    for i in range(1, 16):
        try:
            inst.address = i
            response = inst.read_registers(0x0001, 1)
        except IOError:
            pass
        else:
            print hex(response[0])
            fw_version = response[0] & 0x0FFF
            hw_version = response[0] >> 12
            print 'Slave {}: FW {:03X}, HW {:01X}'.format(
                i, fw_version, hw_version)
        time.sleep(0.01)

    print 'Done.'