mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Fixed canceling messages
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Examples.WPF"
|
||||
xmlns:conv="clr-namespace:Examples.WPF.Converters"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
<conv:NegationConverter x:Key="bInv"/>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
14
Examples.WPF/Converters/NegationConverter.cs
Normal file
14
Examples.WPF/Converters/NegationConverter.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Examples.WPF.Converters;
|
||||
|
||||
[ValueConversion(typeof(bool), typeof(bool))]
|
||||
public class NegationConverter : IValueConverter {
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value != null ? !(bool)value : false;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value != null ? !(bool)value : false;
|
||||
|
||||
}
|
||||
@@ -59,10 +59,30 @@ public partial class ConnectView : UserControl {
|
||||
s.TryReconnectAttempts = 30;
|
||||
s.TryReconnectDelayMs = 2000;
|
||||
})
|
||||
.WithCustomPollLevels(l => {
|
||||
l.SetLevel(2, 3);
|
||||
l.SetLevel(3, TimeSpan.FromSeconds(5));
|
||||
l.SetLevel(4, TimeSpan.FromSeconds(10));
|
||||
})
|
||||
.WithRegisters(b => {
|
||||
b.Struct<short>("DT0").Build();
|
||||
b.Struct<short>("DT0").AsArray(30).Build();
|
||||
b.Struct<Word>("DT1002").Build();
|
||||
|
||||
//b.Struct<short>("DT0").Build();
|
||||
//b.Struct<short>("DT0").AsArray(30).Build();
|
||||
|
||||
b.Struct<short>("DT1000").Build();
|
||||
//b.Struct<Word>("DT1000").Build();
|
||||
b.Struct<ushort>("DT1001").PollLevel(2).Build();
|
||||
b.Struct<Word>("DT1002").PollLevel(2).Build();
|
||||
|
||||
b.Struct<int>("DDT1010").PollLevel(2).Build();
|
||||
b.Struct<uint>("DDT1012").PollLevel(2).Build();
|
||||
b.Struct<DWord>("DDT1014").PollLevel(2).Build();
|
||||
b.Struct<float>("DDT1016").PollLevel(2).Build();
|
||||
b.Struct<TimeSpan>("DDT1018").PollLevel(2).Build();
|
||||
|
||||
b.String("DT1024", 32).PollLevel(3).Build();
|
||||
b.String("DT1042", 5).PollLevel(4).Build();
|
||||
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -9,14 +9,25 @@
|
||||
d:DataContext="{d:DesignInstance vm:PlcDataViewViewModel, IsDesignTimeCreatable=True}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800">
|
||||
<Grid Margin="10">
|
||||
<Grid>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel>
|
||||
<Menu>
|
||||
<MenuItem Header="PLC">
|
||||
<MenuItem Header="Disconnect" IsEnabled="{Binding Plc.IsConnected}"
|
||||
Click="ClickedDisconnect"/>
|
||||
<MenuItem Header="Connect" IsEnabled="{Binding Plc.IsConnected, Converter={StaticResource bInv}}"
|
||||
Click="ClickedConnect"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
<StackPanel Margin="10"
|
||||
Grid.Row="1">
|
||||
|
||||
<TextBlock>
|
||||
|
||||
@@ -71,15 +82,16 @@
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<DataGrid Grid.Row="1"
|
||||
<DataGrid Grid.Row="2"
|
||||
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="FP Address" Binding="{Binding PLCAddressName}"/>
|
||||
<DataGridTextColumn Header="Type" Binding="{Binding UnderlyingSystemType.Name}"/>
|
||||
<DataGridTextColumn Header="Value" Binding="{Binding ValueStr}"/>
|
||||
<!--<DataGridTextColumn Header="Value" Binding="{Binding PollLevel, Mode=OneWay}"/>-->
|
||||
<DataGridTextColumn Header="Poll Level" Binding="{Binding PollLevel, Mode=OneWay}"/>
|
||||
<DataGridTextColumn Header="Update Frequency" Binding="{Binding UpdateFreqHz, StringFormat='{}{0} Hz',Mode=OneWay}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
||||
@@ -29,4 +29,16 @@ public partial class PlcDataView : UserControl {
|
||||
|
||||
}
|
||||
|
||||
private void ClickedDisconnect(object sender, RoutedEventArgs e) {
|
||||
|
||||
viewModel.Plc.Disconnect();
|
||||
|
||||
}
|
||||
|
||||
private async void ClickedConnect(object sender, RoutedEventArgs e) {
|
||||
|
||||
await viewModel.Plc.ConnectAsync();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user