From 7b15813422fe2da75eae2b17198209572ad0e658 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Fri, 27 Dec 2024 09:41:20 -0600 Subject: [PATCH] add read/write of voltaic modbus address --- .../Batteries.Voltaic.V10x/Driver/V10x.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Source/Meadow.Foundation.Peripherals/Batteries.Voltaic.V10x/Driver/V10x.cs b/Source/Meadow.Foundation.Peripherals/Batteries.Voltaic.V10x/Driver/V10x.cs index 5914769ba..fc84b0507 100644 --- a/Source/Meadow.Foundation.Peripherals/Batteries.Voltaic.V10x/Driver/V10x.cs +++ b/Source/Meadow.Foundation.Peripherals/Batteries.Voltaic.V10x/Driver/V10x.cs @@ -1,6 +1,7 @@ using Meadow.Modbus; using Meadow.Units; using System; +using System.Threading.Tasks; namespace Meadow.Foundation.Batteries.Voltaic; @@ -133,4 +134,28 @@ private object ConvertRegisterToRawValue(ushort[] registers) // value is one register in 1/100 of a unit return registers[0] / 100d; } + + /// + /// Reads the device's Modbus Address. + /// + /// + /// The device can be discovered using an initial broadcast address of 254, then the actual sensor can be read using this method + /// + public async Task ReadModbusAddress() + { + var registers = await base.ReadHoldingRegisters(9020, 1); + return (byte)registers[0]; + } + + /// + /// Reads the device's Modbus Address. + /// + /// + /// The device can be discovered using an initial broadcast address of 254, then the actual sensor can be read using this method + /// + public async Task WriteModbusAddress(byte address) + { + await base.WriteHoldingRegister(9020, address); + base.BusAddress = address; + } }