Beispiel #1
0
async def _register_query(client, registers, reg_type):
    request = mp.RegisterRequest()
    for reg in registers:
        if '-' in reg:
            start, end = (int(x) for x in reg.split('-'))
            request.read_multiple(start, end - start + 1, reg_type)
        else:
            request.read_single(int(reg), reg_type)
    return await client.register_query(request)
Beispiel #2
0
async def _write_registers(client, registers, reg_type):
    request = mp.RegisterRequest()

    def _parse_value(text):
        if reg_type == 3:
            return float(text)
        return int(text)

    for item in registers:
        assert '=' in item
        reg, values = item.split('=')
        if ',' in values:
            request.write_multiple(
                int(reg), [mp.RegisterValue(_parse_value(x), reg_type)
                           for x in values.split(',')])
        else:
            request.write_single(
                int(reg), mp.RegisterValue(_parse_value(values), reg_type))
    return await client.register_write(request)