Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Generate Interfaces

Damian edited this page Jul 21, 2022 · 5 revisions

Generating with Tmds.DBus

Generating interfaces with Tmds.DBus v0.10.1.

Skip ahead to the Generate Interfaces section, if you already have it installed.

TL;DR

$ dotnet tool install -g Tmds.DBus.Tool
$ dotnet dbus codegen --bus system --service org.bluez

Install Tmds.DBus.Tool

.NET Prerequisites

The following actions were tested against Ubuntu v20.04 LTS. Please note, NET Core 3.1 or NET 6 is required for this step.

Verify that .NET 3.1, 5.0, or 6.0 is installed.

$ dotnet --list-sdk

If the required SDK it's not installed, continue. Referenced by Install the SDK - Ubuntu v20.04 LTS

$ sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

After installation, validate it again.

$ dotnet --list-sdk

Download Tmds.DBus.Tool

Open a new console application (create project space)

$ dotnet new console -o GenBluez
$ cd GenBluez

Add a reference to Tmds.DBus in the GenBluez.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Tmds.DBus" Version="0.11.0" />
  </ItemGroup>
</Project>

Restore dependencies

$ dotnet restore
$ dotnet tool install -g Tmds.DBus.Tool

Upgrading Tmds.DBus

Did you receive error, Tool 'tmds.dbus.tool' is already installed.?

Simply, validate your version installed and upgrade if necessary.

  1. Go to your DotNet installation's .store folder - /.dotnet/tools/.store/tmds.dbus.tool
  2. Validate the version
  3. To update, dotnet tool update -g Tmds.DBus.Tool

Validation

Listing Services

List available DBus services

dotnet dbus list services

BlueZ is a system service, which is referenced in /usr/share/dbus-1/system-service as org.bluez.service. To uncover all other system services you can execute one of the following:

dotnet dbus list services --bus system

Validate Existance of BlueZ Service

To get moving on listing the objects and generating code for BlueZ over DBus, perform the following:

$ dotnet dbus list services --bus system | grep bluez

OUTPUT:
org.bluez

In the results you will find, org.bluez if you have it installed (Raspberr PI 4B does).

Generate Interfaces

Get the Objects

To obtain the objects of org.bluez input the following and you should get similar results.

$ dotnet dbus list objects --bus system --service org.bluez

OUTPUT:
/ : org.freedesktop.DBus.ObjectManager
/org/bluez : org.bluez.AgentManager1 org.bluez.HealthManager1 org.bluez.ProfileManager1
/org/bluez/hci0 : org.bluez.Adapter1 org.bluez.GattManager1 org.bluez.LEAdvertisingManager1 org.bluez.Media1 org.bluez.NetworkServer1

Generating Code

$ dotnet dbus codegen --bus system --service org.bluez
Generated: /home/.../bluez.DBus.cs