ganehag / pyMeterBus

Pure Python implementation of the Meter-Bus (M-Bus EN13757-3) protocol.
BSD 3-Clause "New" or "Revised" License
74 stars 40 forks source link

MBusFrameDecodeError: ('empty frame', None) #31

Open omaar25 opened 1 month ago

omaar25 commented 1 month ago

Hi

I run this code and i get MBusFrameDecodeError: ('empty frame', None)

!/usr/bin/python

import serial import meterbus address = 254 serial_port = 'COM3'

try: with serial.Serial(serial_port, 115200, bytesize=8, parity='N', stopbits=1, timeout=0.5) as ser: meterbus.send_ping_frame(ser, address) frame = meterbus.load(meterbus.recv_frame(ser, 1)) assert isinstance(frame, meterbus.TelegramACK)

    meterbus.send_request_frame(ser, address)
    frame = meterbus.load(meterbus.recv_frame(ser, meterbus.FRAME_DATA_LENGTH))
    assert isinstance(frame, meterbus.TelegramLong)

    print(frame.to_JSON())

except serial.SerialException as e: print(f"Could not open serial port {serial_port}: {e}")

ganehag commented 1 month ago

Try executing meterbus.debug(True) before the recv_frame(ser, meterbus.FRAME_DATA_LENGTH). It will enable debug logging in the terminal.

Also, It's been a while, but I don't think you can use address 254 to request data, only for ping request. Address 253 is probably what you are looking for.

omaar25 commented 1 month ago

thanks for you assistance. Still the same problem

ganehag commented 1 month ago

You can always try doing a very short time.sleep(0.3) between the ACK frame and the sending of the request frame.

Another approach would be to test with the tools from https://github.com/rscada/libmbus, just to ensure that the device is actually responding. If the tools from libmbus aren't working either, it's probably something else, maybe the device expects a specific request frame.

Similar to how another developer had to craft their own request frame for a specific device; https://github.com/prein2/pyMeterBus/blob/e45fc0d19afaaaca0f3ac6412a642caa587c8239/tools/mbus-serial-request-data-multi-reply_Aestron630#L71