Commit 95a11ca0 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 下吹服务器 添加 查看PLC寄存器更新状态

parent 14337dd6
......@@ -68,6 +68,9 @@
<Compile Include="PgMain.xaml.cs">
<DependentUpon>PgMain.xaml</DependentUpon>
</Compile>
<Compile Include="WdDRList.xaml.cs">
<DependentUpon>WdDRList.xaml</DependentUpon>
</Compile>
<Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon>
</Compile>
......@@ -91,6 +94,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WdDRList.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="WdSetup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......
......@@ -14,21 +14,42 @@
</Page.Resources>
<Grid d:DataContext="{StaticResource viewModel}">
<StackPanel>
<ListView x:Name="listView" ItemsSource="{Binding PLCs}" Margin="5">
<ListView.View>
<GridView >
<GridViewColumn Header="更新速度(ms)" DisplayMemberBinding="{Binding ActUpdateInterval,Converter={StaticResource timespan2msConv}}"></GridViewColumn>
<GridViewColumn Header="地址" DisplayMemberBinding="{Binding Client.RemoteAddr}"></GridViewColumn>
<GridViewColumn Header="寄存器更新数" DisplayMemberBinding="{Binding DRNeedUpdateCnt}"></GridViewColumn>
<GridViewColumn Header="寄存器总数" DisplayMemberBinding="{Binding DRCnt}"></GridViewColumn>
<GridViewColumn Header="连接状态" DisplayMemberBinding="{Binding Client.IsConnected}"></GridViewColumn>
<GridViewColumn Header="异常次数" DisplayMemberBinding="{Binding ErrorCnt}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ItemsControl x:Name="itemcontrol" ItemsSource="{Binding PLCs}" Margin="5">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" >
<StackPanel Margin="4" >
<TextBlock Text="更新速度" />
<TextBlock FontSize="20">
<Run Text="{Binding ActUpdateInterval,Converter={StaticResource timespan2msConv}, Mode=OneWay}" />
<Run Text="ms" FontSize="15"/>
</TextBlock>
</StackPanel>
<StackPanel Margin="4" >
<TextBlock Text="{Binding Client.RemoteAddr,Mode=OneWay}" />
<TextBlock >
连接状态[<Run Text="{Binding Client.IsConnected,Mode=OneWay}" FontSize="20"/>]
</TextBlock>
</StackPanel>
<StackPanel Margin="4" >
<TextBlock Text="异常次数" />
<TextBlock Text="{Binding ErrorCnt}" FontSize="20"/>
</StackPanel>
<StackPanel Margin="4" >
<TextBlock Text="寄存器更新数" />
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="20">
<Run Text="{Binding DRNeedUpdateCnt,Mode=OneWay}"/>/<Run Text="{Binding DRCnt,Mode=OneWay}"/>
</TextBlock>
</StackPanel>
</StackPanel>
<Button Margin="4" Content="..." Height="40" Width="40" Tag="{Binding .}" Click="btnMoreClick"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
</StackPanel>
......
......@@ -30,7 +30,7 @@ namespace FLY.DownBlowing.UI.Server
FLY.OBJComponents.Server.PLCProxySystem plsos =
gage.mData.PLCos as FLY.OBJComponents.Server.PLCProxySystem;
this.listView.ItemsSource = plsos.PLCs;
this.itemcontrol.ItemsSource = plsos.PLCs;
}
private void btnSetupClick(object sender, RoutedEventArgs e)
......@@ -39,6 +39,16 @@ namespace FLY.DownBlowing.UI.Server
w.Owner = App.Current.MainWindow;
w.ShowDialog();
}
private void btnMoreClick(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
var plc = button.Tag as Modbus.WithThread.ModbusMapper_Client;
WdDRList w = new WdDRList();
w.Init(plc);
w.ShowDialog();
}
}
public class PgMainVmUt : INotifyPropertyChanged
......
<Window x:Class="FLY.DownBlowing.UI.Server.WdDRList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="DRList" Height="450" Width="800">
<Grid>
<DataGrid x:Name="dataGrid" AutoGenerateColumns="True" IsReadOnly="True"/>
</Grid>
</Window>
using FLY.Modbus;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace FLY.DownBlowing.UI.Server
{
/// <summary>
/// DRList.xaml 的交互逻辑
/// </summary>
public partial class WdDRList : Window
{
ObservableCollection<DataToRegsView> dataToRegsViews = new ObservableCollection<DataToRegsView>();
Modbus.WithThread.ModbusMapper_Client plc;
public WdDRList()
{
InitializeComponent();
}
public void Init(Modbus.WithThread.ModbusMapper_Client plc)
{
this.plc = plc;
for (int i = 0; i < plc.DRmap.Count(); i++)
{
var dr = plc.DRmap[i];
//获取描述
var type = dr.owner.GetType();
var propertyInfo = type.GetProperty(dr.propertyName);
var attributes = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
string description = "";
if (attributes.Length > 0) {
description = (attributes.First() as DescriptionAttribute).Description;
}
dataToRegsViews.Add(new DataToRegsView()
{
dr = dr,
Addr = dr.addr,
DataArea = dr.dataArea,
IsNeedUpdate = dr.isNeedUpdate,
PropertyName =dr.propertyName,
Description = description,
Value = dr.value
});
}
plc.PropertyChanged += Plc_PropertyChanged;
plc.NameDataChanged += Plc_NameDataChanged;
dataGrid.ItemsSource = dataToRegsViews;
}
private void Plc_NameDataChanged(object sender, DataToRegs dr)
{
var drViews = from _drView in dataToRegsViews
where _drView.dr == dr
select _drView;
if (drViews.Count() == 0)
return;
var drView = drViews.First();
drView.Value = dr.value;
}
private void Plc_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(plc.PlanUpdateTime)) {
for (int i = 0; i < plc.DRmap.Count(); i++)
{
var dr = plc.DRmap[i];
dataToRegsViews[i].IsNeedUpdate = dr.isNeedUpdate;
}
}
}
}
/// <summary>
/// 数据映射的类;
/// Data: PC 属性
/// Regs: PLC 对象(寄存器、线圈)
/// </summary>
public class DataToRegsView:INotifyPropertyChanged
{
public DataToRegs dr;
/// <summary>
/// 对应 PLC寄存器区 coil or register
/// </summary>
public PLCAddressArea DataArea { get; set; }
/// <summary>
/// PLC 首地址
/// </summary>
public int Addr { get; set; }
/// <summary>
/// object 的 property 名称, 只能是 数字类型都是double, 剩下就是 bool
/// </summary>
public string PropertyName { get; set; }
/// <summary>
/// property 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// property 的值, 没有缩小. 只有 double 与 bool
/// </summary>
public object Value { get; set; }
/// <summary>
/// 需要从PLC读取数据更新
/// </summary>
public bool IsNeedUpdate { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return PropertyName + " [" + ((int)DataArea).ToString() + "](" + Addr + ")";
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment