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> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition/> <RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel> <StackPanel>
@@ -72,5 +71,16 @@
</StackPanel> </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> </Grid>
</UserControl> </UserControl>

View File

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

View File

@@ -34,6 +34,16 @@ namespace MewtocolNet.Registers {
/// </summary> /// </summary>
object ValueObj { get; } 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> /// <summary>
/// The plc memory address of the register /// The plc memory address of the register
/// </summary> /// </summary>

View File

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

View File

@@ -64,19 +64,17 @@ namespace MewtocolNet.UnderlyingRegisters {
internal async Task<bool> RequestByteReadAsync(ulong addStart, ulong addEnd) { 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)}"; if (result != null) {
var result = await mewInterface.SendCommandAsync(requeststring);
if (result.Success) { SetUnderlyingBytes(result, addStart);
return true;
var resBytes = result.Response.ParseDTRawStringAsBytes();
SetUnderlyingBytes(resBytes, addStart);
} }
return result.Success; return false;
} }