Remove ReadBit

Using ReadBytes to allow for later unification of Byte conversion logic
This commit is contained in:
Peter Butzhammer
2024-02-06 14:36:32 +01:00
parent fe68b1d565
commit ffa4ee6236
3 changed files with 2 additions and 19 deletions

View File

@@ -14,7 +14,6 @@ namespace Sharp7.Rx.Interfaces
Task<bool> Connect(); Task<bool> Connect();
Task Disconnect(); Task Disconnect();
Task<bool> ReadBit(Operand operand, ushort byteAddress, byte bitAdress, ushort dbNr, CancellationToken token);
Task<byte[]> ReadBytes(Operand operand, ushort startByteAddress, ushort bytesToRead, ushort dBNr, CancellationToken token); Task<byte[]> ReadBytes(Operand operand, ushort startByteAddress, ushort bytesToRead, ushort dBNr, CancellationToken token);
Task<bool> WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token); Task<bool> WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token);

View File

@@ -270,21 +270,6 @@ namespace Sharp7.Rx
} }
return (ushort)(data.Length); return (ushort)(data.Length);
} }
public async Task<bool> 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<bool> WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token) public async Task<bool> WriteBit(Operand operand, ushort startByteAddress, byte bitAdress, bool value, ushort dbNr, CancellationToken token)
{ {
EnsureConnectionValid(); EnsureConnectionValid();

View File

@@ -144,9 +144,8 @@ namespace Sharp7.Rx
if (typeof(TValue) == typeof(bool)) if (typeof(TValue) == typeof(bool))
{ {
var b = await s7Connector.ReadBit(address.Operand, address.Start, address.Bit, address.DbNr, token); var b = await s7Connector.ReadBytes(address.Operand, address.Start, address.Length, address.DbNr, token);
token.ThrowIfCancellationRequested(); return ConvertToType<TValue>(b, address);
return (TValue)(object)b;
} }
if (typeof(TValue) == typeof(int)) if (typeof(TValue) == typeof(int))