mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Fixed bool support and duplicate register refs
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
MinWidth="500"
|
||||
MinHeight="400"
|
||||
Height="850"
|
||||
Width="800"
|
||||
Width="1200"
|
||||
Title="MewtocolNet WPF Demo">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
31
Examples.WPF/RegisterCollections/TestRegisterCollection.cs
Normal file
31
Examples.WPF/RegisterCollections/TestRegisterCollection.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using MewtocolNet;
|
||||
using MewtocolNet.RegisterAttributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Examples.WPF.RegisterCollections;
|
||||
|
||||
public class TestRegisterCollection : RegisterCollection {
|
||||
|
||||
[Register("R11A")]
|
||||
public bool? TestR11A { get; set; }
|
||||
|
||||
[Register("R11A")]
|
||||
public bool TestR11A_Duplicate_NonNullable { get; set; }
|
||||
|
||||
[Register("R16B")]
|
||||
public bool TestR16B { get; set; }
|
||||
|
||||
[BitRegister("DT1000", 0), PollLevel(3)]
|
||||
public bool? TestDT100_Word_Duplicate_SingleBit { get; set; }
|
||||
|
||||
[Register("DT1000")]
|
||||
public Word TestDT100_Word_Duplicate { get; set; }
|
||||
|
||||
[BitRegister("DDT1010", 1)]
|
||||
public bool? TestDDT1010_DWord_Duplicate_SingleBit { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using MewtocolNet;
|
||||
using Examples.WPF.RegisterCollections;
|
||||
using MewtocolNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,6 +11,7 @@ namespace Examples.WPF.ViewModels {
|
||||
public class AppViewModel : ViewModelBase {
|
||||
|
||||
private IPlc? plc;
|
||||
private TestRegisterCollection testRegCollection = null!;
|
||||
|
||||
public bool PlcIsNull => plc == null;
|
||||
|
||||
@@ -25,6 +27,14 @@ namespace Examples.WPF.ViewModels {
|
||||
}
|
||||
}
|
||||
|
||||
public TestRegisterCollection TestRegCollection {
|
||||
get => testRegCollection;
|
||||
set {
|
||||
testRegCollection = value;
|
||||
OnPropChange();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MewtocolNet;
|
||||
using Examples.WPF.RegisterCollections;
|
||||
using MewtocolNet;
|
||||
using MewtocolNet.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,6 +15,8 @@ public class PlcDataViewViewModel : ViewModelBase {
|
||||
|
||||
public IPlc Plc => App.ViewModel.Plc!;
|
||||
|
||||
public TestRegisterCollection RegCollection => App.ViewModel.TestRegCollection;
|
||||
|
||||
public ReconnectArgs PlcCurrentReconnectArgs {
|
||||
get => plcCurrentReconnectArgs;
|
||||
set {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Examples.WPF.ViewModels;
|
||||
using Examples.WPF.RegisterCollections;
|
||||
using Examples.WPF.ViewModels;
|
||||
using MewtocolNet;
|
||||
using MewtocolNet.ComCassette;
|
||||
using MewtocolNet.Registers;
|
||||
@@ -55,31 +56,46 @@ public partial class ConnectView : UserControl {
|
||||
var parsedInt = int.Parse(viewModel.SelectedPort);
|
||||
|
||||
IRegister<short> heartbeatSetter = null!;
|
||||
IRegister<bool> outputContactReference = null!;
|
||||
IRegister<bool> testBoolReference = null!;
|
||||
IRegister<Word> wordRefTest = null!;
|
||||
|
||||
//build a new interface
|
||||
App.ViewModel.Plc = Mewtocol.Ethernet(viewModel.SelectedIP, parsedInt)
|
||||
.WithPoller()
|
||||
.WithInterfaceSettings(setting => {
|
||||
setting.TryReconnectAttempts = 0;
|
||||
|
||||
setting.TryReconnectAttempts = 10;
|
||||
setting.TryReconnectDelayMs = 2000;
|
||||
setting.SendReceiveTimeoutMs = 1000;
|
||||
setting.HeartbeatIntervalMs = 3000;
|
||||
setting.MaxDataBlocksPerWrite = 12;
|
||||
setting.MaxDataBlocksPerWrite = 20;
|
||||
setting.MaxOptimizationDistance = 10;
|
||||
|
||||
})
|
||||
.WithCustomPollLevels(lvl => {
|
||||
|
||||
lvl.SetLevel(2, 3);
|
||||
lvl.SetLevel(3, TimeSpan.FromSeconds(5));
|
||||
lvl.SetLevel(4, TimeSpan.FromSeconds(10));
|
||||
|
||||
})
|
||||
.WithRegisterCollections(collector => {
|
||||
|
||||
App.ViewModel.TestRegCollection = collector.AddCollection<TestRegisterCollection>();
|
||||
|
||||
})
|
||||
.WithRegisters(b => {
|
||||
|
||||
//b.Struct<short>("DT0").Build();
|
||||
//b.Struct<short>("DT0").AsArray(30).Build();
|
||||
|
||||
b.Bool("R10A").Build();
|
||||
b.Bool("X4").Build();
|
||||
b.Bool("Y4").Build(out outputContactReference);
|
||||
b.Bool("R10A").PollLevel(PollLevel.FirstIteration).Build(out testBoolReference);
|
||||
|
||||
b.Struct<short>("DT1000").Build(out heartbeatSetter);
|
||||
b.Struct<Word>("DT1000").Build();
|
||||
|
||||
//these will be merged into one
|
||||
b.Struct<Word>("DT1000").Build(out wordRefTest);
|
||||
b.Struct<Word>("DT1000").Build(out wordRefTest);
|
||||
|
||||
b.Struct<ushort>("DT1001").PollLevel(2).Build();
|
||||
b.Struct<Word>("DT1002").PollLevel(2).Build();
|
||||
@@ -98,9 +114,16 @@ public partial class ConnectView : UserControl {
|
||||
|
||||
await heartbeatSetter.WriteAsync((short)new Random().Next(short.MinValue, short.MaxValue));
|
||||
|
||||
if (outputContactReference.Value != null)
|
||||
await outputContactReference.WriteAsync(!outputContactReference.Value.Value);
|
||||
|
||||
if(testBoolReference.Value != null)
|
||||
await testBoolReference.WriteAsync(!testBoolReference.Value.Value);
|
||||
|
||||
})
|
||||
.Build();
|
||||
|
||||
//connect to it
|
||||
await App.ViewModel.Plc.ConnectAsync();
|
||||
|
||||
if (App.ViewModel.Plc.IsConnected) {
|
||||
|
||||
@@ -145,25 +145,148 @@
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<DataGrid Grid.Row="2"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding Plc.Registers, Mode=OneWay}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="FP Address" Binding="{Binding PLCAddressName}"/>
|
||||
<DataGridTextColumn Header="Type" Binding="{Binding UnderlyingSystemType.Name}"/>
|
||||
<DataGridTextColumn Header="Value" Binding="{Binding ValueStr}"/>
|
||||
<DataGridTextColumn Header="Poll Level" Binding="{Binding PollLevel, Mode=OneWay}"/>
|
||||
<DataGridTextColumn Header="Update Frequency" Binding="{Binding UpdateFreqHz, StringFormat='{}{0} Hz',Mode=OneWay}"/>
|
||||
<DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="{Binding MemoryAreaHash, Mode=OneWay, Converter={StaticResource hashColor}}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Grid Grid.Row="2">
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.5*"/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<GridSplitter Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="Gray"
|
||||
ShowsPreview="true"
|
||||
Width="10">
|
||||
<GridSplitter.Template>
|
||||
<ControlTemplate>
|
||||
<Rectangle Fill="Gray"
|
||||
Width="2"
|
||||
Margin="2"/>
|
||||
</ControlTemplate>
|
||||
</GridSplitter.Template>
|
||||
</GridSplitter>
|
||||
|
||||
<TextBlock Text="Underlying Registers"
|
||||
FontSize="18"
|
||||
Margin="10"/>
|
||||
|
||||
<DataGrid Grid.Row="1"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding Plc.Registers, Mode=OneWay}">
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsAutoGenerated}" Value="True">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="FP Address" Binding="{Binding PLCAddressName}"/>
|
||||
<DataGridTextColumn Header="Type" Binding="{Binding UnderlyingSystemType.Name}"/>
|
||||
<DataGridTemplateColumn Header="Value" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Border HorizontalAlignment="Left"
|
||||
Padding="2,0">
|
||||
<TextBlock Text="{Binding ValueStr}"/>
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ValueStr}" Value="True">
|
||||
<Setter Property="Background" Value="Blue"/>
|
||||
<Setter Property="TextElement.Foreground" Value="White"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="Poll Level" Binding="{Binding PollLevel, Mode=OneWay}"/>
|
||||
<DataGridTextColumn Header="Update Frequency" Binding="{Binding UpdateFreqHz, StringFormat='{}{0} Hz',Mode=OneWay}"/>
|
||||
<DataGridTemplateColumn Width="15">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="{Binding MemoryAreaHash, Mode=OneWay, Converter={StaticResource hashColor}}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<TextBlock Text="Property Bindings"
|
||||
Grid.Column="2"
|
||||
FontSize="18"
|
||||
Margin="10"/>
|
||||
|
||||
<Border Grid.Column="2"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
BorderBrush="LightBlue"
|
||||
BorderThickness="1.5">
|
||||
|
||||
<ScrollViewer>
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<TextBlock Text="Boolean internal relays"/>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="R11A Nullable property: "/>
|
||||
<Run Text="{Binding RegCollection.TestR11A}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="R11A Duplicate non nullable property: "/>
|
||||
<Run Text="{Binding RegCollection.TestR11A_Duplicate_NonNullable}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="R16B"/>
|
||||
<Run Text="{Binding RegCollection.TestR16B}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="DT1000 Word duplicate: "/>
|
||||
<Run Text="{Binding RegCollection.TestDT100_Word_Duplicate, Mode=OneWay}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="DT1000 Word direct bit read (Idx 0): "/>
|
||||
<Run Text="{Binding RegCollection.TestDT100_Word_Duplicate_SingleBit, Mode=OneWay}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="DDT1010 DWord direct bit read (Idx 1): "/>
|
||||
<Run Text="{Binding RegCollection.TestDDT1010_DWord_Duplicate_SingleBit, Mode=OneWay}"
|
||||
FontWeight="Bold"/>
|
||||
</TextBlock>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</ScrollViewer>
|
||||
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user