Exemplo n.º 1
0
def test_read_register_range_exactly_right_edge_case():
    registers = {
        1: 1,
        124: 2,
    }

    client = mock.Mock()
    modbus.read_registers(client, unit=0x01, registers=registers)
    client.read_holding_registers.assert_called_once_with(1, 125, unit=0x01)
Exemplo n.º 2
0
def test_read_registers_requests_the_correct_address_range():
    registers = {
        0xC550: 2,
        0xC552: 2,
        0xC556: 3
    }

    client = mock.Mock()
    modbus.read_registers(client, unit=0x01, registers=registers)
    client.read_holding_registers.assert_called_once_with(
            0xC550,
            0xC559-0xC550,
            unit=0x01)
Exemplo n.º 3
0
def _make_random_request(client, units, table):
    unit = random.sample(units, 1)[0]
    registers = _choose_random_registers(table)
    start = time.time()
    response = modbus.read_registers(client, registers=registers, unit=unit)
    elapsed_time = time.time() - start
    return elapsed_time
Exemplo n.º 4
0
def main(host, port, delay, unit, table_num):
    client = ModbusClient(host, port=port)
    client.connect()
    
    min_response_time = 100
    max_response_time = 0
    sum_response_time = 0
    N = 0

    register_widths = diris_registers.TABLES[table_num-1].copy()
    register_labels = DEMO_REGISTERS.copy()
    registers = dict((addr, register_widths[addr]) \
                        for addr in DEMO_REGISTERS.keys() \
                        if addr in register_widths)

    label_width = max([len(label) for label in DEMO_REGISTERS.values()]) + 1

    while True:
    
        start = time.time()
        try:
            response = modbus.read_registers(client,
                                             registers=registers,
                                             unit=unit)
        except exceptions.ModbusExceptionResponse, e:
            response=None
    
        response_time = time.time() - start

        os.system('clear')

        print "Request Times:"

        min_response_time = min(min_response_time, response_time)
        max_response_time = max(max_response_time, response_time)
        sum_response_time += response_time
        N += 1
    
        print "Min".rjust(label_width) + ": " + str(min_response_time)
        print "Max".rjust(label_width) + ": " + str(max_response_time)
        print "Avg".rjust(label_width) + ": " + str(sum_response_time/N)

        print "Response Values:"
        for addr in sorted(registers.keys()):
            if response is None:
                break
            print (u"{label:>" + str(label_width) + u"s}: {value:f}").format(
                    label=register_labels[addr],
                    value=response.read_register(addr))

        print
        time.sleep(delay)
Exemplo n.º 5
0
def _read_table(msg, out_q, conn):
    #msg = in_q.get()

    for registers in _table_requests(msg.table_addr.id):
        start_time = time.time()
        response = modbus.read_registers(conn,
                                         registers=registers,
                                         unit=msg.table_addr.device_addr.unit)
        end_time = time.time()

        result = messages.ResponseMsg(
                table_addr = msg.table_addr,
                values = _read_values_from_response(response, registers),
                timing_info = domain.TimingInfo(start_time, end_time),
                error = None,
                request_info = {'recording_id': msg.recording_id})

        print "SUCCESS: %s : %s" % (msg, result)
        out_q.put(result)