Examples Overview

These examples illustrate how to use the class libraries.

AntUsbStick Class Library

This example implements the Small Earth Technology ANT radio interface. This class library is used by the example applications. It supports Garmin/Dynastream ANT USB sticks and some development boards with USB interfaces. It is also available on NuGet.

  Important

Projects that consume this library must set the platform target to x86. This is due to the native DLLs that are a part of this library.

AntUsbStick provides two primary classes to consuming applications - AntRadio and AntChannel. AntRadio handles global ANT USB stick radio settings and operation. AntChannel handles individual channel configuration and communication with ANT devices.

AntRadio implements IAntRadio, IAntConfiguration, IAntControl, ICrypto, IFitSettings, and IAntUsbRadio interfaces. This is specific to Garmin/Dynastream ANT USB sticks. UsbAntResponse derives from AntResponse. It provides access to ANT response messages specific to Garmin/Dynastream ANT USB sticks. UsbDeviceCapabilities derives from DeviceCapabilities. It provides access to ANT device capabilities specific to Garmin/Dynastream ANT USB sticks.

WpfUsbStickApp WPF Application

The WpfUsbStickApp example demonstrates a host builder, using the hosting extensions, connecting to a Garmin/Dynastream ANT USB stick, enumerating ANT devices via the AntCollection service, and interacting with ANT devices. The ANT USB stick class library is initialized for continuous receive scan mode.

  Note

This project uses the AntUsbSick library. Therefore, the platform target is set to x86. This is due to the native DLLs that are a part of this project.

AntMulticastServer Console Application

  Caution

This application is no longer being updated or maintained. It was intended to support Xamarin apps. Xamarin has been superceded by .NET MAUI.

This application creates an IPv6 UdpClient bound to port number 2000. The UdpClient directs all messages received from the AntDeviceCollection to the multicast group [::] (all interfaces on the local subnet), port number 55436. A Xamarin client example (Android only) is available as a separate solution at XamAntClientApp.

The MAUI Example Projects

This group of examples is comprised of four projects. AntGrpcShared is a class library providing a gRPC client/server to be consumed by the other projects. AntGrpcService is a Windows service that provides services to connect to and communicate with an ANT USB stick. The MauiAntClientApp is a .NET MAUI project and gRPC client that is used to demonstrate Windows/Android applications that work with the remote server application on a local subnet. I have not tested the other platforms supported by .NET MAUI.

  About gRPC

gRPC is a Google defined protocol for remote procedure calls. It is the recommended RPC to use instead of WCF. Do not confuse gRPC channels with ANT radio channels. gRPC is a network protocol, ANT radio channels are a Dynastream/Garmin protocol for ANT radios.

The intent of AntGrpcService is to make the ANT USB stick accessible not only to client applications running on the local host but mobile device emulators and mobile devices connected to the network the service is running on.

AntGrpcShared is the glue that facilitates communication between clients and the service. The benefit of using gRPC is that multiple clients can run simultaneously, both on the local PC and over the network.

AntGrpcShared

This class library is configured as a gRPC client/server library. The .proto files define the messages and data exchanged between client and server implementations.

AntGrpcService

The server is a Windows service that runs on the host PC that has an ANT USB stick connected to it. Three services are provided.

The DiscoveryService replies to client messages over a UDP multicast port on the local subnet. This allows clients to obtain the URI of the server and connect to the gRPC channel. Think of it as a poor man's service discovery protocol. No authentication or validation is performed.

The AntRadioService provides methods to get information about the connected ANT USB stick, initialize for continuous scan mode, and get channels to communicate with ANT devices via the AntChannelService.

The AntChannelService has a method to subscribe to a gRPC stream of ANT messages when the ANT USB stick has been initialized for continuous scan mode. The remaining gRPC/ANT radio channels are used to send extended acknowledged messages to individual ANT devices.

The service can be debugged! Make sure the service is not installed or disable it in the service controller (services.msc). Select the Debug solution configuration and launch it from Visual Studio. A console window will open. Logging output is displayed in the console window and breakpoints can be set.

MauiAntClientApp

The client app is the consumer of the client services provided by AntGrpcShared project. The server URI is first obtained via a UDP multicast message, a gRPC connection to the server is established, and then requests to initialize and communicate with the remote ANT USB stick are invoked.

AntGrpcServicePackage

The AntGrpcServicePackage installs the AntGrpcService on the local Windows PC and creates a firewall exception allowing network traffic between the service and any clients on the network. Wix is used to create the MSI file. You must install the Wix toolset to build this project.