RfmUsb.Net 3.0.0

dotnet add package RfmUsb.Net --version 3.0.0                
NuGet\Install-Package RfmUsb.Net -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RfmUsb.Net" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RfmUsb.Net --version 3.0.0                
#r "nuget: RfmUsb.Net, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RfmUsb.Net as a Cake Addin
#addin nuget:?package=RfmUsb.Net&version=3.0.0

// Install RfmUsb.Net as a Cake Tool
#tool nuget:?package=RfmUsb.Net&version=3.0.0                

RfmUsb

Build Status

NuGet Badge

Api for the USB Rfm69 and Rfm9x serial device. The api allows for all configuration parameters of the Rfm69 and Rfm9x radio module to be configured via a command line interface.

Installing RfmUsb

Install the RfmUsb package via nuget package manager console:

Install-Package RfmUsb.Net

Supported .Net Runtimes

The RfmUsb.Net package is compatible with the following runtimes:

  • .Net Core 8.0

Creating Instance

An instance of an RfmUsb class can be created by providing an instance of an ILogger and a ISerialPortFactory

var logger = GetLogger();

var serialPortFactory = GetSerialPortFactory();

var rfmUsbDevice = Rfm69(logger, serialPortFactory);

Alternatively an instance can be configured using the standard microsoft DI framework.

var serviceCollection = new ServiceCollection()
                .AddLogging(builder => builder.AddSerilog())
                .AddLogging()
                .AddRfmUsb(); // Add the RfmUsb

Open

The RfmUsb instance must be opened prior to usage.

 rfmUsbDevice.Open(comPort, 115200);

Configuration

All of the configuration settings are assigned via properties of the IRfmUsb interface.

_rfmUsb.Open(serialPort, baudrate);

_rfmUsb.Reset();

_rfmUsb.Timeout = 5000;

_rfmUsb.Modulation = Modulation.Fsk;
_rfmUsb.FrequencyDeviation = 0x01EC;
_rfmUsb.Frequency = 434300000;
_rfmUsb.RxBw = 14;
_rfmUsb.BitRate = 4800;
_rfmUsb.Sync = new List<byte>() { 0x2D, 0xD4 };
_rfmUsb.SyncSize = 1;
_rfmUsb.SyncEnable = true;
_rfmUsb.SyncBitErrors = 0;
_rfmUsb.PacketFormat = true;
_rfmUsb.DcFree = DcFree.Manchester;
_rfmUsb.CrcOn = false;
_rfmUsb.CrcAutoClear = false;
_rfmUsb.AddressFiltering = AddressFilter.None;
_rfmUsb.PayloadLength = 66;

Transmit

Transmit a packet of data with the default transmit timeout. The transmit control registers need to be configured to allow transmission of the packet data.

// Transmit data with default transmission timeouts
rfmUsbDevice.Transmit(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA });

Transmit a packet of data with a specific transmit timeout. The transmit control registers need to be configured to allow transmission of the packet data.

// Transmit data with a timeout
rfmUsbDevice.Transmit(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }, 1000);

Interrupts

Set the Dio pin Irq mask.

AutoResetEvent IrqSignal;

void RfmDeviceDioInterrupt(object? sender, DioIrq e)
{
    Console.WriteLine("Dio Irq [{e}]", e);

    if ((e & DioIrq.Dio0) == DioIrq.Dio0)
    {
        IrqSignal.Set();
    }
}

// Setup the radio irq pin enables
rfmUsbDevice.DioInterruptMask = DioIrq.Dio0;

rfmUsbDevice.DioInterrupt += RfmDeviceDioInterrupt;

Wait for an IRQ to occur

IrqSignal.WaitOne(timeout);

// Check the irq
if ((rfmUsbDevice.Irq & Irq.PayloadReady) == Irq.PayloadReady)
{
    // Process packet
}

Buffered Read And Writes

The maximum message size supported by direct read and write of the FIFO is limited to 64 bytes. To support message transmission and reception up to a maximum size of X bytes the RfmUsb IO buffer must be used.

Receive IO Buffer

The steps required to receive a message via the IO buffer.

  • Configure the RfmUsb radio
  • Set the Dio mapping for Dio0 to DioMapping1 to capture the PayloadReady Irq
  • Set the Dio mapping for Dio1 to DioMapping2 to capture the FifoNotEmpty Irq
  • Setup the PacketFormat to either fixed or variable length
  • Set PayloadLength to 0xFF
  • Enable the IO buffer via the BufferedIoEnable setting
  • Set the radio Mode to RX
  • Wait for the PayloadReady Irq
  • Read the message bytes to the IO buffer via the Stream
// Configure the radio
InitialiseRadioOpenThings(SerialPort, BaudRate);

// Attach event handlers
AttachEventHandlers(console);

// Enable DIO0 to capture payload ready IRQ 
rfmUsbDevice.SetDioMapping(Dio.Dio0, DioMapping.DioMapping1);
// Enable DIO1 to capture fifo level IRQ for buffered read
rfmUsbDevice.SetDioMapping(Dio.Dio1, DioMapping.DioMapping2);
// Set the Irq mask
rfmUsbDevice.DioInterruptMask = DioIrq.Dio0 | DioIrq.Dio1;
// Enable the Buffered Io
rfmUsbDevice.BufferedIoEnable = true;
// Set the the payload length to 0xFF
rfmUsbDevice.PayloadLength = 0xFF;
// Set the mode to rx
rfmUsbDevice.Mode = Mode.Rx;

// Wait for Irq signal
SignalSource signalSource = WaitForSignal();

if (signalSource == SignalSource.Irq)
{
    if ((rfmUsbDevice.IrqFlags & Rfm69IrqFlags.PayloadReady) == Rfm69IrqFlags.PayloadReady)
    {
        rfmUsbDevice.Mode = Mode.Standby;

        byte[] payload = new byte[rfmUsbDevice.Stream.Length];

        // Read the stream
        rfmUsbDevice.Stream.Read(payload, 0, payload.Length);

        // Process the payload
        // .............

Transmit IO Buffer

The steps required to transmit a message via the IO buffer.

  • Configure the RfmUsb radio
  • Setup the PacketFormat to either fixed or variable length
  • Enable the IO buffer via the BufferedIoEnable setting
  • Set the radio Mode to TX
  • Write the message bytes to the IO buffer via the Stream
// Configure the radio
InitialiseRadioOpenThings(SerialPort, BaudRate);

// Attach event handlers
AttachEventHandlers(console);

// Enable DIO0 to capture payload ready IRQ 
rfmUsbDevice.SetDioMapping(Dio.Dio0, DioMapping.DioMapping0);
// Set the Irq mask
rfmUsbDevice.DioInterruptMask = DioIrq.Dio0;
// Enable the Buffered Io
rfmUsbDevice.BufferedIoEnable = true;
// Set the the payload length to 0xFF
rfmUsbDevice.PayloadLength = 0xFF;
// Set the mode to TX
rfmUsbDevice.Mode = Mode.Tx;

// Prepare payload
byte[] payload = new byte[10];

// Write the stream
rfmUsbDevice.Stream.Write(payload, 0, payload.Length);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on RfmUsb.Net:

Package Downloads
RfmOta

A service for Ota updates for Rfm69 devices

RfmUsbConsole

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 118 6/11/2024
2.1.0 154 3/9/2024
2.0.5 249 11/13/2023
2.0.4 128 11/6/2023
2.0.3 159 11/5/2023
2.0.1 152 10/20/2023
2.0.0 232 8/2/2023

1.0.0 Initial Version
1.0.6 Bug fixes
1.0.13 Added strong name key
1.0.14 Prevent operation being called when device not open
1.0.15 Added package xml document
1.0.18 Updated open check
1.0.19 Updated reset operation
2.0.0 Added support for Rfm95
2.0.1 Updated Irq handling
2.0.2 Refactored open
2.0.3 Set default timeout
2.0.4 Updated logging
2.0.5 Updated enter and exit conditions
2.1.0 Added stream function and removed TxRx functions
3.0.0 Updated .Net Core 8