mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-16 11:42:52 +00:00
Remove ReadBit
Using ReadBytes to allow for later unification of Byte conversion logic
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user