Register str data auto updates

This commit is contained in:
Felix Weiß
2023-07-28 15:51:31 +02:00
parent 38b83affd7
commit f4af3dd05e
5 changed files with 44 additions and 13 deletions

View File

@@ -14,7 +14,6 @@
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel>
@@ -72,5 +71,16 @@
</StackPanel>
<DataGrid Grid.Row="1"
AutoGenerateColumns="False"
IsReadOnly="True"
ItemsSource="{Binding Plc.Registers, Mode=OneWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="Address" Binding="{Binding PLCAddressName}"/>
<DataGridTextColumn Header="Name" Binding="{Binding UnderlyingSystemType.Name}"/>
<DataGridTextColumn Header="Value" Binding="{Binding ValueStr}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>

View File

@@ -68,6 +68,8 @@ namespace MewtocolNet {
/// </summary>
int ConnectTimeout { get; set; }
IEnumerable<IRegister> Registers { get; }
/// <summary>
/// Tries to establish a connection with the device asynchronously
/// </summary>

View File

@@ -34,6 +34,16 @@ namespace MewtocolNet.Registers {
/// </summary>
object ValueObj { get; }
/// <summary>
/// The current value of the register as a string
/// </summary>
string ValueStr { get; }
/// <summary>
/// The system (.NET) type of the underlying value thats held inside the register
/// </summary>
Type UnderlyingSystemType { get; }
/// <summary>
/// The plc memory address of the register
/// </summary>

View File

@@ -39,14 +39,20 @@ namespace MewtocolNet.Registers {
internal bool wasOverlapFitted = false;
/// <inheritdoc/>
public RegisterCollection ContainedCollection => containedCollection;
internal RegisterCollection ContainedCollection => containedCollection;
/// <inheritdoc/>
public MewtocolInterface AttachedInterface => attachedInterface;
internal MewtocolInterface AttachedInterface => attachedInterface;
/// <inheritdoc/>
public Type UnderlyingSystemType => underlyingSystemType;
/// <inheritdoc/>
public object ValueObj => lastValue;
/// <inheritdoc/>
public string ValueStr => GetValueString();
/// <inheritdoc/>
public RegisterPrefix RegisterType { get; internal set; }
@@ -63,7 +69,12 @@ namespace MewtocolNet.Registers {
public event PropertyChangedEventHandler PropertyChanged;
public void TriggerNotifyChange() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueObj)));
public void TriggerNotifyChange() {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueObj)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueStr)));
}
#endregion

View File

@@ -64,19 +64,17 @@ namespace MewtocolNet.UnderlyingRegisters {
internal async Task<bool> RequestByteReadAsync(ulong addStart, ulong addEnd) {
var station = mewInterface.GetStationNumber();
var byteCount = (addEnd - addStart + 1) * 2;
var result = await mewInterface.ReadByteRangeNonBlocking((int)addStart, (int)byteCount);
string requeststring = $"%{station}#RD{GetMewtocolIdent(addStart, addEnd)}";
var result = await mewInterface.SendCommandAsync(requeststring);
if (result != null) {
if (result.Success) {
var resBytes = result.Response.ParseDTRawStringAsBytes();
SetUnderlyingBytes(resBytes, addStart);
SetUnderlyingBytes(result, addStart);
return true;
}
return result.Success;
return false;
}