Skip to content

pdat-cz/go-mbus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-mbus

A Go implementation of the M-Bus (Meter-Bus) protocol for remote reading of utility meters.

Overview

go-mbus is a library that provides functionality for communicating with devices using the M-Bus (Meter-Bus) protocol, which is a European standard (EN 13757-2, EN 13757-3) for remote reading of utility meters (water, gas, electricity, heat, etc.).

The library allows you to:

  • Ping M-Bus devices to check if they are alive
  • Read data from M-Bus devices
  • Parse and interpret M-Bus telegrams
  • Work with various M-Bus frame types (Short Frame, Long Frame, Control Frame)

Installation

go get github.com/pdat-cz/go-mbus

Dependencies

This library depends on the following packages:

  • github.com/tarm/serial - For serial port communication
  • tycho-edge/pkg/log - For logging (you'll need to provide this package or modify the code to use a different logging mechanism)
  • gopkg.in/yaml.v3 - For YAML parsing

Usage

Basic Example

package main

import (
    "fmt"
    "github.com/pdat-cz/go-mbus"
)

func main() {
    // Ping a device at address 1 on port /dev/ttyUSB0
    pingState := mbus.Ping("/dev/ttyUSB0", 1)

    if pingState.State {
        fmt.Printf("Device at address %d is alive\n", pingState.Address)

        // Read data from the device
        deviceState := mbus.Read("/dev/ttyUSB0", 1)

        if deviceState.Error == "" {
            fmt.Printf("Device data: %+v\n", deviceState.Data)
        } else {
            fmt.Printf("Error reading device: %s\n", deviceState.Error)
        }
    } else {
        fmt.Printf("Device at address %d is not responding: %s\n", 
            pingState.Address, pingState.Error)
    }
}

Scanning for Devices

package main

import (
    "fmt"
    "github.com/pdat-cz/go-mbus"
)

func main() {
    // Scan for devices on port /dev/ttyUSB0, addresses 1-250
    fmt.Println("Scanning for M-Bus devices...")

    for address := 1; address <= 250; address++ {
        pingState := mbus.Ping("/dev/ttyUSB0", address)

        if pingState.State {
            fmt.Printf("Found device at address %d\n", address)
        }
    }
}

Documentation

For more detailed information about the M-Bus protocol and how to use this library, see:

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

References

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages