mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2026-02-04 07:42:53 +00:00
Restructure and extens tests for converter
This commit is contained in:
@@ -7,7 +7,7 @@ namespace Sharp7.Rx;
|
||||
|
||||
internal static class S7ValueConverter
|
||||
{
|
||||
public static TValue ConvertToType<TValue>(byte[] buffer, S7VariableAddress address)
|
||||
public static TValue ReadFromBuffer<TValue>(byte[] buffer, S7VariableAddress address)
|
||||
{
|
||||
if (typeof(TValue) == typeof(bool))
|
||||
return (TValue) (object) (((buffer[0] >> address.Bit) & 1) > 0);
|
||||
|
||||
@@ -28,12 +28,15 @@ internal class S7VariableNameParser : IS7VariableNameParser
|
||||
{"real", DbType.Single},
|
||||
{"lreal", DbType.Double},
|
||||
|
||||
// used for legacy compatability
|
||||
{"b", DbType.Byte},
|
||||
{"d", DbType.Single},
|
||||
// S7 notation
|
||||
{"dbb", DbType.Byte},
|
||||
{"dbw", DbType.Int},
|
||||
{"dbx", DbType.Bit},
|
||||
{"dbd", DbType.DInt},
|
||||
|
||||
// used for legacy compatability
|
||||
{"b", DbType.Byte},
|
||||
{"d", DbType.Single},
|
||||
{"dul", DbType.ULInt},
|
||||
{"dulint", DbType.ULInt},
|
||||
{"dulong", DbType.ULInt},
|
||||
|
||||
@@ -90,7 +90,7 @@ public class Sharp7Plc : IPlc
|
||||
Observable.FromAsync(() => GetValue<TValue>(variableName))
|
||||
.Concat(
|
||||
disposeableContainer.Observable
|
||||
.Select(bytes => S7ValueConverter.ConvertToType<TValue>(bytes, address))
|
||||
.Select(bytes => S7ValueConverter.ReadFromBuffer<TValue>(bytes, address))
|
||||
);
|
||||
|
||||
if (transmissionMode == TransmissionMode.OnChange)
|
||||
@@ -121,7 +121,7 @@ public class Sharp7Plc : IPlc
|
||||
if (address == null) throw new ArgumentException("Input variable name is not valid", nameof(variableName));
|
||||
|
||||
var data = await s7Connector.ReadBytes(address.Operand, address.Start, address.Length, address.DbNr, token);
|
||||
return S7ValueConverter.ConvertToType<TValue>(data, address);
|
||||
return S7ValueConverter.ReadFromBuffer<TValue>(data, address);
|
||||
}
|
||||
|
||||
public async Task<bool> InitializeAsync()
|
||||
|
||||
Reference in New Issue
Block a user