Giter Site home page Giter Site logo

sympthom / valley.net.protocols.meterbus Goto Github PK

View Code? Open in Web Editor NEW
37.0 11.0 21.0 2.62 MB

M-Bus (meter bus, meterbus, mbus) C# project for communicating and parsing M-Bus (EN 13757-2 and EN 13757-3)

License: MIT License

C# 100.00%
m-bus meterbus mbus meter-bus meter wm-bus wmbus

valley.net.protocols.meterbus's Introduction

record screenshot

M-Bus (Meter Bus) project for communicating and parsing M-Bus over udp, tcp and serial. Implementation of protocol EN 13757-2 and EN 13757-3 (https://ec.europa.eu/eip/ageing/standards/ict-and-communication/data/en-13757_en).

M-Bus (Meter-Bus) is a European standard (EN 13757-2 physical and link layer, EN 13757-3 application layer) for the remote reading of gas, water or electricity meters. M-Bus is also usable for other types of consumption meters. The M-Bus interface is made for communication on two wires, making it cost-effective. A radio variant of M-Bus (Wireless M-Bus) is also specified in EN 13757-4.

The M-Bus was developed to fill the need for a system for the networking and remote reading of utility meters, for example to measure the consumption of gas or water in the home. This bus fulfills the special requirements of remotely powered or battery-driven systems, including consumer utility meters. When interrogated, the meters deliver the data they have collected to a common master, such as a hand-held computer, connected at periodic intervals to read all utility meters of a building. An alternative method of collecting data centrally is to transmit meter readings via a modem.

Other applications for the M-Bus such as alarm systems, flexible illumination installations, heating control, etc. are suitable.

Retrieving meter telemetry

var serialiser = new MeterbusFrameSerializer();
var endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.135"), 502);

// binding to the collector/gateway
var binding = new UdpBinding(endpoint, serializer);

// reqeust for telemetry on meter with address 0x0a
var response = await new MeterBusMaster(binding)
  .RequestData(0x0a, TimeSpan.FromSeconds(3));

Low level control

var serialiser = new MeterbusFrameSerializer();
var endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.135"), 502);

// binding to the collector/gateway
var binding = new UdpBinding(endpoint, serialiser);
binding.PacketReceived += (sender, e) => Debug.WriteLine("M-Bus packet received.");
    
// send a short frame/SND_NKE to the meter with address 0x0a
await binding.SendAsync(new ShortFrame((byte)ControlMask.SND_NKE, 0x0a));

Deserialize M-Bus frame and payload

var packet = "68 1F 1F 68 08 02 72 78 56 34 12 24 40 01 07 55 00 00 00 03 13 15 31 00 DA 02 3B 13 01 8B 60 04 37 18 02 18 16"
  .HexToBytes()
  .ToFrame()   // EN13757_2
  .ToPacket(); // EN13757_3

Changelog

v1.0.2 (2019.10.13)

  • serial communication capability

v1.0.1 (2019.10.12)

  • bug fixes

v1.0.0 (2018.09.29)

  • initial release

valley.net.protocols.meterbus's People

Contributors

sympthom avatar tomcollaboration avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

valley.net.protocols.meterbus's Issues

bug fix

I've detected an error on this class. and I fixed it.

(update line 174)
case DataTypes._24_Bit_Integer:
System.Diagnostics.Debug.Assert(value.Data.Length == 3);
//record.Value = BitConverter.ToInt32(new byte[] { 0 }.Concat(value.Data).ToArray(), 0); // Orj.
#region Coskun edit
byte[] temp = new byte[4];
temp[0] = value.Data[0];
temp[1] = value.Data[1];
temp[2] = value.Data[2];
record.Value = BitConverter.ToInt32(temp, 0);//coskun
#endregion
break;

for example;
input value = 0x112233;
bug result = 0x11223300;
update result=0x00112233;

Not supported frames

We are testing library for data below:
"68 47 47 68 08 FD 72 03 01 47 01 AE 4C 51 07 6C 60 00 00 0E 13 30 54 46 00 00 00 0E 93 3C 29 00 00 00 00 00 04 3B 21 00 00 00 0C 78 03 01 47 01 0C FD 10 00 00 00 00 04 6D 0A 12 6D 2C 0D FD 0C 09 4D 20 41 49 44 49 53 45 52 1F ED 16"

Library couldn't parse this frame. Could you fix it, please?
Regard,

Communication over Serial Port

I want to use MBusMaster with Serial port, From current code it looks like it is not possible. Would be a useful feature when using UART MBus receivers.

MeterbusFrameSerializer Serializing ControlFrames not complete

Hello.

In the lib, the serializer responsible for creating the ControlFrame data, it seems like the Control frame, Address, and ControlInformation is missing.

I added it to my code, should anyone not get a response from the meter, using this ControlFrame, be aware that this critical data pieces is missing.
EDIT: PR link: #15

wM-Bus Support

Is it possible to use this library with wM-Bus, currently it looks like wM-Bus is not supported, am I right?
If yes, is there a possibility if you can add support for wM-Bus in this library?

Merge Request not packaged in 1.0.3

Hi,
i just discovered that my merge request seems not or not fully part of the 1.0.3 package version. When I request the heat meter values I still have AveragingDuration as the name for VIF 74h. According to my fix it should be ActualityDuration. Can you please check?

TCP Connection (Binding) - only one requestData call works

I am using the TcpBinding and interacting with a Moxa (TCP to Serial) converter to read one MBUS Device.

To intialisation of the MBusMaster I use following code:
var serializer = new MeterbusFrameSerializer();
endpoint = new IPEndPoint(IPAddress.Parse(โ€œ192.168.100.41โ€), 4001);
binding = new TcpBinding(endpoint,serializer);
binding.Error += Binding_Error;
binding.IoCompleted += Binding_IoCompleted;
master = new MBusMaster(binding);
master.Meter += Master_Meter;

Afterwards I am calling RequestData every five seconds:
var response = master.RequestData((byte)MBusAdr, TimeSpan.FromSeconds(3)).Result as VariableDataPacket;

This works only for the first call. The second call rises following exception (Socket Exception):

AggregateException SocketException: A request to send or receive data was prevented because the socket is not connected and (when sending via a datagram socket with a sendto call) no address was specified

Is there anything wrong in my workflow or code?

Some Fixes

Hello,
i've created some fixes and would like to create a pull request for it. Unfortunately I always get 403 when I try to create a pull request from within Visual Studio. Whats the right workflow to do it? I've cloned the repository and made the changes on a local branch. Can I pull / merge request these changes somehow?

UDP Binding with configurable receive port

I am using this MBus implementation with the UdpBinding:

            var serializer = new MeterbusFrameSerializer();
            endpoint = new IPEndPoint(IPAddress.Parse(Address), Port); 
            binding = new UdpBinding(endpoint,serializer);
            binding.Error += Binding_Error;
            binding.IoCompleted += Binding_IoCompleted;
            master = new MBusMaster(binding);
            master.Meter += Master_Meter;

I am interacting with a Moxa (TCP to Serial) converter to read one MBUS Device. This device send the data to fix port. So I have to configure the receiving (listening) port additionally to the IPEndpoint.

VIF Code 0x7c causes a broken decoding

if a device is responding a user defined VIF 0x7c (Plain Text) is not supported and causes all next records to be broken or causen an exception!
See https://m-bus.com/assets/downloads/MBDOC48.PDF page 42.

It can be reproduced with following device response:
"68 56 56 68 08 5F 72 91 91 01 19 77 04 14 16 A0 00 00 00 0C 78 91 91 01 19 0D 7C 08 44 49 20 2E 74 73 75 63 0A 20 20 20 20 20 20 20 20 20 20 04 6D 00 0C 8A 26 02 7C 09 65 6D 69 74 20 2E 74 61 62 4A 14 04 14 0D 7A 05 00 04 94 7F 00 00 00 00 44 14 57 B0 04 00 0F 00 01 1F 22 16"

Serial communications

Hello, could You add some example how to use the serial protocol communication and binding please ?

Kind regards for help
Piotr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.