Commit be2ae018 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 称重服务器添加吸料

parent b3d1346e
...@@ -109,10 +109,5 @@ namespace FLY.DownBlowing.UI.Server ...@@ -109,10 +109,5 @@ namespace FLY.DownBlowing.UI.Server
/// 路径 /// 路径
/// </summary> /// </summary>
public string Path { get; set; } public string Path { get; set; }
/// <summary>
/// 版本
/// </summary>
public int Version { get; set; }
} }
} }
...@@ -339,7 +339,9 @@ namespace FLY.DownBlowing.Client ...@@ -339,7 +339,9 @@ namespace FLY.DownBlowing.Client
public string[] GetSyncPropNames() public string[] GetSyncPropNames()
{ {
return new string[]{ return new string[]{
nameof(TAreasCnt) nameof(TAreasCnt),
nameof(FeederCntOfEachs),
nameof(Version)
}; };
} }
......
...@@ -74,6 +74,9 @@ ...@@ -74,6 +74,9 @@
<Compile Include="PgMain.xaml.cs"> <Compile Include="PgMain.xaml.cs">
<DependentUpon>PgMain.xaml</DependentUpon> <DependentUpon>PgMain.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="WdSetupFeeder.xaml.cs">
<DependentUpon>WdSetupFeeder.xaml</DependentUpon>
</Compile>
<Compile Include="WdSetup.xaml.cs"> <Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon> <DependentUpon>WdSetup.xaml</DependentUpon>
</Compile> </Compile>
...@@ -101,6 +104,10 @@ ...@@ -101,6 +104,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="WdSetupFeeder.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="WdSetup.xaml"> <Page Include="WdSetup.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
......
...@@ -5,17 +5,20 @@ ...@@ -5,17 +5,20 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FLY.Weight.UI.Server" xmlns:local="clr-namespace:FLY.Weight.UI.Server"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignWidth="450" Title="PgMain" Height="270" Width="765">
Title="PgMain">
<Page.Resources> <Page.Resources>
<local:PgMainVmUt x:Key="viewModel"/> <local:PgMainVmUt x:Key="viewModel"/>
</Page.Resources> </Page.Resources>
<Grid d:DataContext="{StaticResource viewModel}"> <Grid d:DataContext="{StaticResource viewModel}">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid x:Name="grid_plc"/> <Grid x:Name="grid_plc"/>
<Grid x:Name="grid_plcos"/> <Grid x:Name="grid_plcos"/>
<Grid x:Name="grid_WeightSystem"/> <Grid x:Name="grid_WeightSystem"/>
<StackPanel Margin="5"> <Grid Margin="5">
<Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
<ColumnDefinition/> <ColumnDefinition/>
...@@ -31,7 +34,17 @@ ...@@ -31,7 +34,17 @@
IsChecked="{Binding BindingTotalFilmWidth}"/> IsChecked="{Binding BindingTotalFilmWidth}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<GroupBox Header="称重">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ItemsControl x:Name="itemcontrol" ItemsSource="{Binding PLCs}"> <ItemsControl x:Name="itemcontrol" ItemsSource="{Binding PLCs}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
...@@ -68,8 +81,58 @@ ...@@ -68,8 +81,58 @@
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button> <Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
</StackPanel> </StackPanel>
</Grid>
</GroupBox>
<GroupBox Header="吸料" Grid.Column="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ItemsControl x:Name="itemcontrol_feeder" ItemsSource="{Binding PLCs}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" >
<StackPanel Margin="4" >
<TextBlock Text="更新速度" />
<TextBlock FontSize="20">
<Run Text="{Binding ActUpdateInterval,StringFormat=\{0:sfff\}, 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" Padding="5,2" Content="..." Tag="{Binding .}" Click="btnMoreClick"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Grid.Row="1" Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnFeederSetupClick"></Button>
</Grid>
</GroupBox>
</Grid>
</Grid> </Grid>
</Page> </Page>
...@@ -37,6 +37,9 @@ namespace FLY.Weight.UI.Server ...@@ -37,6 +37,9 @@ namespace FLY.Weight.UI.Server
this.itemcontrol.ItemsSource = plsos.PLCs; this.itemcontrol.ItemsSource = plsos.PLCs;
sp_sysParam.DataContext = gage.mSysParam; sp_sysParam.DataContext = gage.mSysParam;
if (gage.mFeederSystem != null) {
this.itemcontrol_feeder.ItemsSource = gage.mFeederSystem.plcos.PLCs;
}
} }
private void btnSetupClick(object sender, RoutedEventArgs e) private void btnSetupClick(object sender, RoutedEventArgs e)
{ {
...@@ -55,6 +58,14 @@ namespace FLY.Weight.UI.Server ...@@ -55,6 +58,14 @@ namespace FLY.Weight.UI.Server
w.Init(plc); w.Init(plc);
w.ShowDialog(); w.ShowDialog();
} }
private void btnFeederSetupClick(object sender, RoutedEventArgs e)
{
WdSetupFeeder w = new WdSetupFeeder();
w.Init(gage);
w.Owner = App.Current.MainWindow;
w.ShowDialog();
}
} }
public class PgMainVmUt : INotifyPropertyChanged public class PgMainVmUt : INotifyPropertyChanged
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<StackPanel> <StackPanel>
<GroupBox Header="配置文件"> <GroupBox Header="称重配置文件">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<StackPanel> <StackPanel>
<StackPanel Margin="5"> <StackPanel Margin="5">
...@@ -54,6 +54,5 @@ ...@@ -54,6 +54,5 @@
</GroupBox> </GroupBox>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Window> </Window>
<Window x:Class="FLY.Weight.UI.Server.WdSetupFeeder"
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"
xmlns:local="clr-namespace:FLY.Weight.UI.Server"
mc:Ignorable="d"
Title="WdSetup" SizeToContent="WidthAndHeight" >
<Window.Resources>
</Window.Resources>
<Grid>
<StackPanel>
<StackPanel x:Name="sp_sysParam" Orientation="Horizontal" Grid.Column="1" Margin="5">
<CheckBox Content="有吸料"
IsChecked="{Binding HasFeeder}"/>
</StackPanel>
<GroupBox Header="吸料配置文件">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="5">
<TextBlock Text="plcgroup配置文件" Margin="2"/>
<ComboBox MinWidth="200" Margin="2" x:Name="comboBox" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<Button Content="确定" Padding="20,5" Margin="5" VerticalAlignment="Bottom"
Click="btnOkClick" />
</StackPanel>
</GroupBox>
</StackPanel>
</Grid>
</Window>
using FLY.Modbus;
using FLY.OBJComponents.Common;
using FLY.Weight.IService;
using FLY.Weight.Server;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
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.Weight.UI.Server
{
/// <summary>
/// WdSetup.xaml 的交互逻辑
/// </summary>
public partial class WdSetupFeeder : Window
{
public event PropertyChangedEventHandler PropertyChanged;
string plcgroups_dirPath = "feeder_plcgroups";
string plcgroup_filePath = "feeder_plcgroup.json";
TDGage gage;
public WdSetupFeeder()
{
InitializeComponent();
}
public void Init(TDGage gage)
{
this.gage = gage;
var items = new List<PlcGroupItem>();
//查找 脚本/称重 下的全部 设备连接变量表_xxx 的文件夹
DirectoryInfo directoryInfo = new DirectoryInfo(plcgroups_dirPath);
if (!directoryInfo.Exists)
{
//异常
return;
}
var dirs = directoryInfo.GetDirectories();
foreach (var dir in dirs)
{
if (dir.Name.StartsWith("设备连接变量表_"))
{
PlcGroupItem item = new PlcGroupItem();
item.Name = dir.Name.Substring("设备连接变量表_".Length);
item.Path = System.IO.Path.Combine(dir.FullName, "Generated", "plcgroup.json");
items.Add(item);
}
}
comboBox.ItemsSource = items;
foreach (var item in items)
{
if (IsSameContent(item.Path, plcgroup_filePath))
{
//找到了
comboBox.SelectedItem = item;
break;
}
}
sp_sysParam.DataContext = gage.mSysParam;
}
public static bool IsSameContent(string filePath1, string filePath2)
{
//创建一个哈希算法对象
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(filePath1, FileMode.Open), file2 = new FileStream(filePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//哈希算法根据文本得到哈希码的字节数组
byte[] hashByte2 = hash.ComputeHash(file2);
return Enumerable.SequenceEqual(hashByte1, hashByte2);
//string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串
//string str2 = BitConverter.ToString(hashByte2);
//return (str1 == str2);//比较哈希码
}
}
}
private void btnOkClick(object sender, RoutedEventArgs e)
{
var item = comboBox.SelectedItem as PlcGroupItem;
if (item == null)
{
MessageBox.Show("请选择型号!!!");
return;
}
if (MessageBox.Show("需要重启,才能生效", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
File.Copy(item.Path, plcgroup_filePath, true);
gage.mSysParam.Save();
//切换为exe的目录,这样程序再次进入时,才能 进入Gage1 文件夹
System.Environment.CurrentDirectory = "../";
//重启软件
AppHelper.AppJustOne.Restart();
}
}
}
}
using FLY.OBJComponents.Client;
using FLY.OBJComponents.IService;
using FLY.Weight.Common;
using FLY.Weight.IService;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Weight.Client
{
public class FeederSystemServiceClient : FObjServiceClient, IFeederSystemService, IPropertyOpt
{
#region IFeederSystemService
#region 吸料
/// <summary>
/// 吸料
/// </summary>
public ObservableCollection<FeederData> FeederDatas { get; } = new ObservableCollection<FeederData>();
public FeederAccessory FeederAccy { get; } = new FeederAccessory();
/// <summary>
/// 每层吸料的吸料数量
/// </summary>
public int[] FeederCntOfEachs { get; set; }
#endregion
PLCProxySystemServiceClient plcos;
public IPLCProxySystemService PLCos => plcos;
/// <summary>
/// 版本
/// </summary>
public string Version { get; set; } = "1";
#endregion
SyncPropServiceClient syncPropServiceClient;
public event Action ResetFeederDatasEvent;
/// <summary>
/// 当前 INotifyPropertyChanged 对象 引发了 PropertyChanged, 是由于 接收到数据导致的
/// </summary>
public bool IsInPushValue
{
get
{
return syncPropServiceClient.IsInPushValue;
}
}
public FeederSystemServiceClient(UInt32 serviceId) : base(serviceId)
{
Init();
}
public FeederSystemServiceClient(UInt32 serviceId, string connName) : base(serviceId)
{
Init();
ConnName = connName;
FObjServiceClientManager.Instance.Connect_to_Another_OBJSys(connName, this);
}
string FeederIndex2Number(int index)
{
string number = ((char)('A' + (index))).ToString();
return number;
}
void FeederDatasAdd(int i, int feederCnt) {
string number = FeederIndex2Number(i);
var feederData = new FeederData();
feederData.Init(number, feederCnt);
FeederDatas.Add(feederData);
}
void Init()
{
Load();
for (int i = 0; i < FeederCntOfEachs.Count(); i++)
{
FeederDatasAdd(i, FeederCntOfEachs[i]);
}
//--------------------------------------------------------------
//属性同步
Dictionary<string, INotifyPropertyChanged> objnames = GetObjNames();
objnames.Add(".", this);
syncPropServiceClient = new SyncPropServiceClient(mServerID + 1, objnames);
//--------------------------------------------------------------
//PLC代理,用于添加更新任务
objnames = GetObjNames();
plcos = new PLCProxySystemServiceClient(mServerID + 2);
this.PropertyChanged += DownBlowingSystemServiceClient_PropertyChanged;
}
Dictionary<string, INotifyPropertyChanged> GetObjNames()
{
Dictionary<string, INotifyPropertyChanged> objnames = new Dictionary<string, INotifyPropertyChanged>();
objnames.Add(nameof(FeederAccy), FeederAccy);
for (int i = 0; i < FeederDatas.Count(); i++)
objnames.Add($"{nameof(FeederDatas)}[{i}]", FeederDatas[i]);
return objnames;
}
string filePath = "feederSystemClient.json";
void Save()
{
FeederSystemServiceClientJsonDb.Save(this, filePath);
}
void Load()
{
FeederSystemServiceClientJsonDb.Load(this, filePath);
}
private void DownBlowingSystemServiceClient_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(FeederCntOfEachs))
{
if (IsFeederCntOfEachsChanged())
{
ResetFeederDatas();
Save();
}
}
}
bool IsFeederCntOfEachsChanged()
{
var feederCnts = FeederDatas.Select(i => i.FeederCnt).ToArray();
return !Enumerable.SequenceEqual(FeederCntOfEachs, feederCnts);
}
/// <summary>
/// 重新创建 FeederDatas
/// </summary>
void ResetFeederDatas()
{
int remove_cnt = FeederDatas.Count() - FeederCntOfEachs.Count();
if (remove_cnt > 0)
{
//多出来的Item 都要删除
for (int i = 0; i < remove_cnt; i++)
{
int index = FeederDatas.Count() - 1;
FeederDatas.RemoveAt(index);
string objname = $"{nameof(FeederDatas)}[{index}]";
syncPropServiceClient.Remove(objname);
}
}
else if (remove_cnt < 0)
{
//少了,需要添加
for (int i = 0; i < -remove_cnt; i++)
{
int index = FeederDatas.Count();
FeederDatasAdd(index, FeederCntOfEachs[index]);
string objname = $"{nameof(FeederDatas)}[{index}]";
syncPropServiceClient.Add(objname, FeederDatas[index]);
}
}
//现在数量一样, 重新初始化每层的吸料数量
for (int i = 0; i < FeederCntOfEachs.Count(); i++)
{
if (FeederDatas[i].FeederCnt != FeederCntOfEachs[i])
{
FeederDatas[i].Init(FeederIndex2Number(i), FeederCntOfEachs[i]);
}
}
ResetFeederDatasEvent?.Invoke();
return;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override UInt32[] GetIDs()
{
List<UInt32> IDs = new List<uint>();
IDs.Add(ID);
IDs.Add(syncPropServiceClient.ID);
IDs.AddRange(((PLCProxySystemServiceClient)PLCos).GetIDs());
return IDs.ToArray();
}
public override void ConnectNotify(IFConn from)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
CurrObjSys.SenseConfigEx(mConn, mServerID, ID,
0xffffffff, SENSE_CONFIG.ADD);
}
}
public string[] GetSyncPropNames()
{
return new string[]{
nameof(FeederCntOfEachs),
nameof(Version)
};
}
public string[] GetNoSyncPropNames()
{
return null;
}
}
public class FeederSystemServiceClientJsonDb
{
/// <summary>
/// 每层吸料的吸料数量
/// </summary>
public int[] FeederCntOfEachs = new int[] { 4, 4, 4, 4, 4 };
public string Version = "1";
public static bool Save(FeederSystemServiceClient src, string filePath)
{
try
{
FeederSystemServiceClientJsonDb jsonDb = new FeederSystemServiceClientJsonDb()
{
FeederCntOfEachs = src.FeederCntOfEachs,
Version = src.Version
};
string json = Newtonsoft.Json.JsonConvert.SerializeObject(jsonDb);
File.WriteAllText(filePath, json);
return true;
}
catch {
return false;
}
}
public static bool Load(FeederSystemServiceClient src, string filePath)
{
if (!File.Exists(filePath))
return false;
try
{
string json = File.ReadAllText(filePath);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FeederSystemServiceClientJsonDb>(json);
src.FeederCntOfEachs = p.FeederCntOfEachs;
src.Version = p.Version;
return true;
}
catch
{
//失败就算了。。。
return false;
}
}
}
}
using Misc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Weight.Common
{
public class FeederAccessory : INotifyPropertyChanged
{
public FeederAccessory()
{
}
#region 辅助代码生成
/// <summary>
/// 1号电机运行时间
/// </summary>
[Description("1号电机运行时间")]
public float No1MotorRunTime { get; set; }
/// <summary>
/// 2号电机运行时间
/// </summary>
[Description("2号电机运行时间")]
public float No2MotorRunTime { get; set; }
/// <summary>
/// 吸料急停开启!!!请检查
/// </summary>
[Description("吸料急停开启!!!请检查")]
[IsError()]
public bool Warning001 { get; set; }
/// <summary>
/// 吸料1号电机过载!!!请检查
/// </summary>
[Description("吸料1号电机过载!!!请检查")]
[IsError()]
public bool Warning002 { get; set; }
/// <summary>
/// 吸料2号电机过载!!!请检查
/// </summary>
[Description("吸料2号电机过载!!!请检查")]
[IsError()]
public bool Warning003 { get; set; }
#endregion
public event PropertyChangedEventHandler PropertyChanged;
}
}
This diff is collapsed.
...@@ -49,17 +49,23 @@ ...@@ -49,17 +49,23 @@
<ItemGroup> <ItemGroup>
<Compile Include="Client\BulkDbMixServiceClient.cs" /> <Compile Include="Client\BulkDbMixServiceClient.cs" />
<Compile Include="Client\BulkDbFlowServiceClient.cs" /> <Compile Include="Client\BulkDbFlowServiceClient.cs" />
<Compile Include="Client\FeederSystemServiceClient.cs" />
<Compile Include="Client\MixBufferCollection.cs" /> <Compile Include="Client\MixBufferCollection.cs" />
<Compile Include="Common\FeederAccessory.cs" />
<Compile Include="Common\FeederData.cs" />
<Compile Include="Common\WeighterAccessory.cs" /> <Compile Include="Common\WeighterAccessory.cs" />
<Compile Include="IService\IBulkDbMixService.cs" /> <Compile Include="IService\IBulkDbMixService.cs" />
<Compile Include="IService\IBulkDbFlowService.cs" /> <Compile Include="IService\IBulkDbFlowService.cs" />
<Compile Include="IService\IFeederSystemService.cs" />
<Compile Include="OBJ_INTERFACE\OBJ_INTERFACE.cs" /> <Compile Include="OBJ_INTERFACE\OBJ_INTERFACE.cs" />
<Compile Include="Common\WeighterC.cs" /> <Compile Include="Common\WeighterC.cs" />
<Compile Include="Client\WeightSystemServiceClient.cs" /> <Compile Include="Client\WeightSystemServiceClient.cs" />
<Compile Include="IService\IWeightSystemService.cs" /> <Compile Include="IService\IWeightSystemService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.OBJProxy\FeederSystem_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\OBJProxy.cs" /> <Compile Include="Server.OBJProxy\OBJProxy.cs" />
<Compile Include="Server.OBJProxy\WeightSystem_OBJProxy.cs" /> <Compile Include="Server.OBJProxy\WeightSystem_OBJProxy.cs" />
<Compile Include="Server\FeederSystem.cs" />
<Compile Include="Server\Model\BulkDbMix.cs" /> <Compile Include="Server\Model\BulkDbMix.cs" />
<Compile Include="Server\Model\DbModel.cs" /> <Compile Include="Server\Model\DbModel.cs" />
<Compile Include="Server\Model\DbTable.cs" /> <Compile Include="Server\Model\DbTable.cs" />
......
using FLY.OBJComponents.IService;
using FLY.Weight.Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Weight.IService
{
public interface IFeederSystemService : INotifyPropertyChanged
{
/// <summary>
/// 吸料
/// </summary>
ObservableCollection<FeederData> FeederDatas { get; }
/// <summary>
/// 吸料其它附件
/// </summary>
FeederAccessory FeederAccy { get; }
/// <summary>
/// 每层吸料的吸料数量
/// </summary>
int[] FeederCntOfEachs { get; }
/// <summary>
/// 吸料版本
/// </summary>
string Version { get; }
/// <summary>
/// PLC代理系统
/// </summary>
IPLCProxySystemService PLCos { get; }
}
}
...@@ -20,6 +20,12 @@ namespace FLY.Weight.OBJ_INTERFACE ...@@ -20,6 +20,12 @@ namespace FLY.Weight.OBJ_INTERFACE
public const UInt32 WEIGHTS_OBJ_FLOW_ID = 35004; public const UInt32 WEIGHTS_OBJ_FLOW_ID = 35004;
public const UInt32 WEIGHTS_OBJ_MIX_BASE_ID = 35005; public const UInt32 WEIGHTS_OBJ_MIX_BASE_ID = 35005;
/// <summary>
/// 4个
/// </summary>
public const UInt32 FEEDER_OBJ_ID = 35050;
/// <summary> /// <summary>
/// 每次配料记录列表, 1~5 /// 每次配料记录列表, 1~5
/// </summary> /// </summary>
......
using FLY.OBJComponents.IService;
using FLY.OBJComponents.Server.OBJProxy;
using FLY.Weight.Server;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Weight.Server.OBJProxy
{
class FeederSystem_OBJProxy : FObj
{
FeederSystem data;
public FeederSystem_OBJProxy(int objsys_idx, FeederSystem data) : base(objsys_idx)
{
ID = FLY.Weight.OBJ_INTERFACE.OBJ_INTERFACE.FEEDER_OBJ_ID;
this.data = data;
//--------------------------------------------------------------
//属性同步
Dictionary<string, INotifyPropertyChanged> objnames = new Dictionary<string, INotifyPropertyChanged>();
objnames.Add(".", data);
objnames.Add(nameof(FeederSystem.FeederAccy), data.FeederAccy);
for (int i = 0; i < data.FeederDatas.Count(); i++)
objnames.Add($"{nameof(FeederSystem.FeederDatas)}[{i}]", data.FeederDatas[i]);
var syncProp_OBJProxy = new SyncProp_OBJProxy(
objsys_idx, ID + 1, objnames);
var plcOS_OBJProxy = new FObjBase.Reflect.Reflect_Proxy(
objsys_idx,
ID + 2,
typeof(IPLCProxySystemService),
data.PLCos
);
}
}
}
...@@ -42,6 +42,12 @@ namespace FLY.Weight.Server.OBJProxy ...@@ -42,6 +42,12 @@ namespace FLY.Weight.Server.OBJProxy
typeof(IWarningSystem2Service), typeof(IWarningSystem2Service),
gage.mWarning); gage.mWarning);
if (gage.mFeederSystem != null) {
var feederSystemOBJProxy = new FeederSystem_OBJProxy(objsys_idx, gage.mFeederSystem);
}
weightSystemOBJProxy.CurrObjSys.Start_Conn_Server( weightSystemOBJProxy.CurrObjSys.Start_Conn_Server(
new IPEndPoint(IPAddress.Any, gage.mSysParam.OBJ_Port)); new IPEndPoint(IPAddress.Any, gage.mSysParam.OBJ_Port));
} }
......
using FLY.Modbus;
using FLY.OBJComponents.IService;
using FLY.OBJComponents.Server;
using FLY.Weight.Common;
using FLY.Weight.IService;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace FLY.Weight.Server
{
public class FeederSystem : IFeederSystemService, IPropertyOpt
{
/// <summary>
/// 吸料
/// </summary>
public ObservableCollection<FeederData> FeederDatas { get; } = new ObservableCollection<FeederData>();
/// <summary>
/// 吸料其它附件
/// </summary>
public FeederAccessory FeederAccy { get; } = new FeederAccessory();
/// <summary>
/// 每层吸料的吸料数量
/// </summary>
public int[] FeederCntOfEachs { get; private set; }
/// <summary>
/// 吸料版本
/// </summary>
public string Version { get; set; } = "1";
public PLCProxySystem plcos = new PLCProxySystem();
/// <summary>
/// PLC代理系统
/// </summary>
public IPLCProxySystemService PLCos { get { return plcos; } }
/// <summary>
/// 报警系统
/// </summary>
WarningSystem2 warning;
/// <summary>
/// 报警配置
/// </summary>
ErrorConf errorConf;
public event PropertyChangedEventHandler PropertyChanged;
PLCGroup plcgroup;
public FeederSystem()
{
}
public void Init(WarningSystem2 warning)
{
this.warning = warning;
//--------------------------------------------------------------------------------
//step 1 加载PLC寄存器 文件
AddConfigFile();
//--------------------------------------------------------------------------------
//step 2 报警配置
errorConf = new ErrorConf(plcos, this.warning, plcgroup.Devices.Select(d => d.PlcName).ToArray());
errorConf.AddErrorAction(FeederAccy);
foreach (var feederdata in FeederDatas)
{
errorConf.AddErrorAction(feederdata,
(ref string description, object state) => {
var fd = state as FeederData;
description = fd.Number + "层 " + description;
},
feederdata);
}
errorConf.InitError();
Misc.BindingOperations.SetBinding(this.warning, nameof(this.warning.IsRinging), () =>
{
if (!this.warning.IsRinging)
{
//把全部报警都复位, 当复位无效,该属性还是true,下次查寄存器时,还是能触发报警
errorConf.ResetError();
}
});
//--------------------------------------------------------------------------------
//step 3 历史数据记录
//--------------------------------------------------------------------------------
//last step PLC 更新计划服务初始化
plcos.Init();
}
void AddConfigFile()
{
plcos.AddConfigFile("feeder_plcgroup.json", (plcgroup) =>
{
this.plcgroup = plcgroup;
Version = plcgroup.Version;
//从plcgroup 分析出 有多少层,每层的仓数
//吸料
List<int> feederCntOfEachs = new List<int>();
Regex r = new Regex($@"{nameof(FeederDatas)}\[([0-9])\]");
Regex r2 = new Regex(@"IsFeederOn([1-9])");
foreach (PLCGroup.PLCVariable var in plcgroup.Variables)
{
Match m = r.Match(var.OwnerName);
if (m.Success)
{
int feederdata_idx = int.Parse(m.Groups[1].Value);
if (feederCntOfEachs.Count() <= feederdata_idx)
{
while (feederCntOfEachs.Count() <= feederdata_idx)
feederCntOfEachs.Add(0);
}
Match m2 = r2.Match(var.PropertyName);
if (m2.Success)
{
int feederCnt = int.Parse(m2.Groups[1].Value);
if (feederCntOfEachs[feederdata_idx] < feederCnt)
feederCntOfEachs[feederdata_idx] = feederCnt;
}
}
}
FeederCntOfEachs = feederCntOfEachs.ToArray();
for (int i = 0; i < FeederCntOfEachs.Count(); i++)
{
string number = FeederIndex2Number(i);
FeederData fd = new FeederData();
fd.Init(number, FeederCntOfEachs[i]);
FeederDatas.Add(fd);
}
//objname 转 obj
Dictionary<string, INotifyPropertyChanged> objnames = new Dictionary<string, INotifyPropertyChanged>();
objnames.Add(nameof(FeederAccy), FeederAccy);
if (FeederDatas != null)
{
for (int i = 0; i < FeederDatas.Count(); i++)
objnames.Add($"{nameof(FeederDatas)}[{i}]", FeederDatas[i]);
}
return objnames;
});
}
string FeederIndex2Number(int index)
{
string number = ((char)('A' + (index))).ToString();
return number;
}
public string[] GetSyncPropNames()
{
return new string[]{
nameof(FeederCntOfEachs),
nameof(Version)
};
}
public string[] GetNoSyncPropNames()
{
return null;
}
}
}
...@@ -25,6 +25,11 @@ namespace FLY.Weight.Server ...@@ -25,6 +25,11 @@ namespace FLY.Weight.Server
/// </summary> /// </summary>
public bool BindingTotalFilmWidth { get; set; } = true; public bool BindingTotalFilmWidth { get; set; } = true;
/// <summary>
/// 有吸料系统
/// </summary>
public bool HasFeeder { get; set; } = false;
public SysParam() public SysParam()
{ {
} }
......
...@@ -23,6 +23,7 @@ namespace FLY.Weight.Server ...@@ -23,6 +23,7 @@ namespace FLY.Weight.Server
#region 本地数据---------------------------------------------------------------- #region 本地数据----------------------------------------------------------------
public SysParam mSysParam; public SysParam mSysParam;
public WeightSystem mData; public WeightSystem mData;
public FeederSystem mFeederSystem;
public HistoryDb mHistoryDb; public HistoryDb mHistoryDb;
/// <summary> /// <summary>
/// 报警系统 /// 报警系统
...@@ -63,6 +64,9 @@ namespace FLY.Weight.Server ...@@ -63,6 +64,9 @@ namespace FLY.Weight.Server
mHistoryDb = new HistoryDb(); mHistoryDb = new HistoryDb();
mWarning = new WarningSystem2(); mWarning = new WarningSystem2();
if (mSysParam.HasFeeder) {
mFeederSystem = new FeederSystem();
}
} }
/// <summary> /// <summary>
/// 第1步, 加载本地数据 /// 第1步, 加载本地数据
...@@ -92,6 +96,10 @@ namespace FLY.Weight.Server ...@@ -92,6 +96,10 @@ namespace FLY.Weight.Server
mData.Init(mHistoryDb, mWarning); mData.Init(mHistoryDb, mWarning);
if (mFeederSystem != null) {
mFeederSystem.Init(mWarning);
}
string connName = "blowing"; string connName = "blowing";
#region 与服务器同步的数据 #region 与服务器同步的数据
FObjServiceClientManager.Instance.ConnAddrs.Add(new ConnAddr() { ConnName = connName, Addr = mSysParam.BlowingAddr }); FObjServiceClientManager.Instance.ConnAddrs.Add(new ConnAddr() { ConnName = connName, Addr = mSysParam.BlowingAddr });
......
...@@ -59,6 +59,7 @@ namespace FLY.Weight.Server ...@@ -59,6 +59,7 @@ namespace FLY.Weight.Server
#endregion #endregion
/// <summary> /// <summary>
/// 报警系统 /// 报警系统
/// </summary> /// </summary>
...@@ -81,9 +82,6 @@ namespace FLY.Weight.Server ...@@ -81,9 +82,6 @@ namespace FLY.Weight.Server
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
//step 1 加载PLC寄存器 文件 //step 1 加载PLC寄存器 文件
AddConfigFile(); AddConfigFile();
} }
public void Init(HistoryDb historyDb, WarningSystem2 warning) public void Init(HistoryDb historyDb, WarningSystem2 warning)
...@@ -91,6 +89,8 @@ namespace FLY.Weight.Server ...@@ -91,6 +89,8 @@ namespace FLY.Weight.Server
this.historyDb = historyDb; this.historyDb = historyDb;
this.warning = warning; this.warning = warning;
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
//step 2 报警配置 //step 2 报警配置
errorConf = new ErrorConf(plcos, this.warning, "称重"); errorConf = new ErrorConf(plcos, this.warning, "称重");
......
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