From ffa4ee6236b19d89f5ff48501aeaeb091411ef32 Mon Sep 17 00:00:00 2001 From: Peter Butzhammer Date: Tue, 6 Feb 2024 14:36:32 +0100 Subject: [PATCH] Remove ReadBit Using ReadBytes to allow for later unification of Byte conversion logic --- Sharp7.Rx/Interfaces/IS7Connector.cs | 1 - Sharp7.Rx/Sharp7Connector.cs | 15 --------------- Sharp7.Rx/Sharp7Plc.cs | 5 ++--- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Sharp7.Rx/Interfaces/IS7Connector.cs b/Sharp7.Rx/Interfaces/IS7Connector.cs index 612dd82..309f750 100644 --- a/Sharp7.Rx/Interfaces/IS7Connector.cs +++ b/Sharp7.Rx/Interfaces/IS7Connector.cs @@ -14,7 +14,6 @@ namespace Sharp7.Rx.Interfaces Task Connect(); Task Disconnect(); - Task ReadBit(Operand operand, ushort byteAddress, byte bitAdress, ushort dbNr, CancellationToken token); Task ReadBytes(Operand operand, ushort startByteAddress, ushort bytesToRead, ushort dBNr, CancellationToken token); Task WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token); diff --git a/Sharp7.Rx/Sharp7Connector.cs b/Sharp7.Rx/Sharp7Connector.cs index 484118f..99c6644 100644 --- a/Sharp7.Rx/Sharp7Connector.cs +++ b/Sharp7.Rx/Sharp7Connector.cs @@ -270,21 +270,6 @@ namespace Sharp7.Rx } return (ushort)(data.Length); } - - - public async Task ReadBit(Operand operand, ushort byteAddress, byte bitAdress, ushort dbNr, CancellationToken token) - { - EnsureConnectionValid(); - - var byteValue = await ReadBytes(operand, byteAddress, 1, dbNr, token); - token.ThrowIfCancellationRequested(); - - if (byteValue.Length != 1) - throw new InvalidOperationException("Read bytes does not have length 1"); - - return Convert.ToBoolean(byteValue[0] & (1 << bitAdress)); - } - public async Task WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token) { EnsureConnectionValid(); diff --git a/Sharp7.Rx/Sharp7Plc.cs b/Sharp7.Rx/Sharp7Plc.cs index 3f733cb..95b690c 100644 --- a/Sharp7.Rx/Sharp7Plc.cs +++ b/Sharp7.Rx/Sharp7Plc.cs @@ -144,9 +144,8 @@ namespace Sharp7.Rx if (typeof(TValue) == typeof(bool)) { - var b = await s7Connector.ReadBit(address.Operand, address.Start, address.Bit, address.DbNr, token); - token.ThrowIfCancellationRequested(); - return (TValue)(object)b; + var b = await s7Connector.ReadBytes(address.Operand, address.Start, address.Length, address.DbNr, token); + return ConvertToType(b, address); } if (typeof(TValue) == typeof(int))