Browse Source

申唐配料系统修改

master
pry 1 year ago
parent
commit
fa783064f7
8 changed files with 315 additions and 13 deletions
  1. +2
    -1
      BPASmartClient.CustomResource/UserControls/ConveyBelt2.xaml
  2. +39
    -10
      BPASmartClient.CustomResource/UserControls/ConveyBelt2.xaml.cs
  3. +2
    -1
      BPASmartClient.DosingSystemSingle/App.xaml
  4. +1
    -1
      BPASmartClient.S7Net/SiemensHelper.cs
  5. +29
    -0
      DosingSystem/App.xaml.cs
  6. +99
    -0
      DosingSystem/View/TempManageControlView.xaml
  7. +28
    -0
      DosingSystem/View/TempManageControlView.xaml.cs
  8. +115
    -0
      DosingSystem/ViewModel/TempManageControlViewModel.cs

+ 2
- 1
BPASmartClient.CustomResource/UserControls/ConveyBelt2.xaml View File

@@ -83,7 +83,7 @@
Duration="0:0:20" />
</Storyboard>
</VisualState>
<VisualState Name="Stop" />
<!--<VisualState Name="Stop" />-->
</VisualStateGroup>
<VisualStateGroup Name="DirectionGroup">
<VisualState Name="LeftState">
@@ -96,6 +96,7 @@
Duration="0:0:20" />
</Storyboard>
</VisualState>
<VisualState Name="Stop" />
<VisualState Name="RightState">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation


+ 39
- 10
BPASmartClient.CustomResource/UserControls/ConveyBelt2.xaml.cs View File

@@ -37,7 +37,22 @@ namespace BPASmartClient.CustomResource.UserControls

private static void OnRunningChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
VisualStateManager.GoToState(d as ConveyBelt2, (bool)e.NewValue ? "RunState" : "Stop", false);
string status = "Stop";
if ((bool)e.NewValue)
{
if ((d as ConveyBelt2)?.BeltDirection == 0)
{
VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
return;
}
else
{
VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
return;
}
}
VisualStateManager.GoToState(d as ConveyBelt2, status, false);
//VisualStateManager.GoToState(d as ConveyBelt2, (bool)e.NewValue ? "RunState" : "Stop", false);
}

public double BeltWidth
@@ -59,7 +74,7 @@ namespace BPASmartClient.CustomResource.UserControls
if (BeltHeight > 100)
{
pathFigure.StartPoint = new Point(0, 35 + (BeltHeight - 100) / 2);
pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35 + (BeltHeight - 100)/2), true));
pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35 + (BeltHeight - 100) / 2), true));
}
else
{
@@ -74,7 +89,7 @@ namespace BPASmartClient.CustomResource.UserControls
{
this.recDown.Margin = new Thickness(0, BeltHeight - 20, 0, 0);
}
else
else
{
this.recDown.Margin = new Thickness(0, 80, 0, 0);
}
@@ -115,15 +130,29 @@ namespace BPASmartClient.CustomResource.UserControls

private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{

if ((d as ConveyBelt2)?.BeltDirection == 0)
{
VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
}
else
string status = "Stop";
if ((d as ConveyBelt2).IsRun)
{
VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
if ((d as ConveyBelt2)?.BeltDirection == 0)
{
VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
return;
}
else
{
VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
return;
}
}
VisualStateManager.GoToState(d as ConveyBelt2, status, false);
//if ((d as ConveyBelt2)?.BeltDirection == 0)
//{
// VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
//}
//else
//{
// VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
//}

}
}


+ 2
- 1
BPASmartClient.DosingSystemSingle/App.xaml View File

@@ -1,4 +1,5 @@
<Application x:Class="BPASmartClient.DosingSystemSingle.App"
<Application
x:Class="BPASmartClient.DosingSystemSingle.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters;assembly=BPASmartClient.CustomResource"


+ 1
- 1
BPASmartClient.S7Net/SiemensHelper.cs View File

@@ -120,7 +120,7 @@ namespace BPASmartClient.S7Net
}
public void WriteInt16(int db, short txt, int startAddress = 0)
{
var bytes =BitConverter.GetBytes(txt);
var bytes = BitConverter.GetBytes(txt);
myPlc.WriteBytes(DataType.DataBlock, db, startAddress, bytes);

}


+ 29
- 0
DosingSystem/App.xaml.cs View File

@@ -17,6 +17,9 @@ using BPASmartClient.DosingSystem.Model;
using System.Diagnostics;
using System.IO;
using BPASmartClient.Update.Model;
using BPASmartClient.DosingSystem.ViewModel;
using System.Drawing;
using System.Windows.Media;

namespace BPASmartClient.DosingSystem
{
@@ -31,6 +34,22 @@ namespace BPASmartClient.DosingSystem
protected override void OnStartup(StartupEventArgs e)
{
bool createNew;
MessageLog.GetInstance.NotifyShow = new Action<string>(o =>
{
DebugLogViewModel.MessageModels.Add(new MessageModel()
{
LogInfo = o,
Forground = System.Windows.Media.Brushes.DeepSkyBlue
});
});
MessageLog.GetInstance.NotifyShowEx = new Action<string>(o =>
{
DebugLogViewModel.MessageModels.Add(new MessageModel()
{
LogInfo = o,
Forground = System.Windows.Media.Brushes.Red
});
});
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "DosingSystem", out createNew);
if (!createNew)
{
@@ -42,6 +61,7 @@ namespace BPASmartClient.DosingSystem
BPASmartClient.Helper.SystemHelper.GetInstance.CreateDesktopShortcut();
MenuInit();
DataInit();
SiemensTest.GetInstance.Init();
DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
MainView mv = new MainView();
mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
@@ -173,6 +193,15 @@ namespace BPASmartClient.DosingSystem
AssemblyName = "BPASmartClient.DosingSystem",
ToggleWindowPath = "View.ConveyerBeltManualView"
});

ManualControl.Add(new SubMenumodel()
{
SubMenuName = "配料输送带控制",
SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
AssemblyName = "BPASmartClient.DosingSystem",
ToggleWindowPath = "View.TempManageControlView"
});

//ManualControl.Add(new SubMenumodel()
//{
// SubMenuName = "料仓控制",


+ 99
- 0
DosingSystem/View/TempManageControlView.xaml View File

@@ -0,0 +1,99 @@
<UserControl
x:Class="BPASmartClient.DosingSystem.View.TempManageControlView"
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:local="clr-namespace:BPASmartClient.DosingSystem.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource"
xmlns:vm="clr-namespace:BPASmartClient.DosingSystem.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<UserControl.DataContext>
<vm:TempManageControlViewModel />
</UserControl.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid Margin="8">
<Grid
Name="cy"
Grid.Row="0"
Margin="5">
<pry:ImageBorder
Grid.RowSpan="2"
Width="{Binding ElementName=cy, Path=ActualWidth}"
Height="{Binding ElementName=cy, Path=ActualHeight}" />

<StackPanel Background="Transparent">
<Grid Height="40">
<Image
Margin="2,3,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="/BPASmartClient.CustomResource;component/Image/标签.png" />
<TextBlock
Margin="10,10,0,0"
VerticalAlignment="Top"
FontSize="16"
Foreground="Aqua"
Text="{Binding Name}" />
<StackPanel
Margin="0,0,20,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
<TextBlock
Margin="0,0,2,0"
Style="{StaticResource TextBlockStyle}"
Text="输送带反转控制" />
<ToggleButton
Width="80"
Height="30"
Margin="5,0,5,0"
Background="Transparent"
FontSize="20"
IsChecked="{Binding Reversal}"
Style="{StaticResource SwitchToggleButtonStyle}" />

<TextBlock
Margin="20,0,5,0"
VerticalAlignment="Center"
FontSize="20"
Foreground="#00c2f4"
Text="输送带正转控制" />

<ToggleButton
Width="80"
Height="30"
Margin="5,0,5,0"
Background="Transparent"
FontSize="20"
IsChecked="{Binding Foreward}"
Style="{StaticResource SwitchToggleButtonStyle}" />

</StackPanel>

</Grid>
<Grid Name="gr" Height="200">
<pry:ConveyBelt2
Grid.RowSpan="4"
Margin="-12,0,10,0"
BeltDashThickess="50"
BeltDirection="{Binding BeltDirection}"
BeltHeight="{Binding ElementName=gr, Path=ActualHeight}"
BeltWidth="{Binding ElementName=gr, Path=ActualWidth}"
IsRun="{Binding IsRun}" />
</Grid>
</StackPanel>
</Grid>
</Grid>

</Grid>
</UserControl>

+ 28
- 0
DosingSystem/View/TempManageControlView.xaml.cs View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
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.Navigation;
using System.Windows.Shapes;

namespace BPASmartClient.DosingSystem.View
{
/// <summary>
/// TempManageControlView.xaml 的交互逻辑
/// </summary>
public partial class TempManageControlView : UserControl
{
public TempManageControlView()
{
InitializeComponent();
}
}
}

+ 115
- 0
DosingSystem/ViewModel/TempManageControlViewModel.cs View File

@@ -0,0 +1,115 @@
using BPA.Helper;
using BPASmartClient.S7Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.ViewModel
{
public class TempManageControlViewModel : NotifyBase
{
public TempManageControlViewModel()
{

}

/// <summary>
/// 正转
/// </summary>
public bool Foreward
{
get { return _mForeward; }
set
{
_mForeward = value;
BeltDirection = 0;
IsRun = _mForeward;
OnPropertyChanged();
Task.Factory.StartNew(() =>
{
if (Reversal || !_mForeward)
{
SiemensTest.GetInstance.sh.Write("M1000.1", true);
Thread.Sleep(2000);
SiemensTest.GetInstance.sh.Write("M1000.1", false);
}
if (_mForeward)
{
SiemensTest.GetInstance.sh.Write("M1000.0", true);
Thread.Sleep(2000);
SiemensTest.GetInstance.sh.Write("M1000.0", false);
}
});
}
}
private bool _mForeward;

/// <summary>
/// 反转
/// </summary>
public bool Reversal
{
get { return _mReversal; }
set
{
_mReversal = value;
BeltDirection = 1;
IsRun = _mReversal;
OnPropertyChanged();
Task.Factory.StartNew(() =>
{
if (Foreward || !_mReversal)
{
SiemensTest.GetInstance.sh.Write("M1000.1", true);
Thread.Sleep(2000);
SiemensTest.GetInstance.sh.Write("M1000.1", false);
}
if (_mReversal)
{
SiemensTest.GetInstance.sh.Write("M1000.3", true);
Thread.Sleep(2000);
SiemensTest.GetInstance.sh.Write("M1000.3", false);
}
});
}
}
private bool _mReversal;

public bool IsRun { get { return _mIsRun; } set { _mIsRun = value; OnPropertyChanged(); } }
private bool _mIsRun;


public int BeltDirection { get { return _mBeltDirection; } set { _mBeltDirection = value; OnPropertyChanged(); } }
private int _mBeltDirection;

}

public class SiemensTest
{

private volatile static SiemensTest _Instance;
public static SiemensTest GetInstance => _Instance ?? (_Instance = new SiemensTest());
private SiemensTest() { }

public SiemensHelper sh { get; set; } = new SiemensHelper();

public void Init()
{
Task.Run(() =>
{
//sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12");
sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15");
if (sh.IsConnected)
MessageLog.GetInstance.Show("西门子PLC连接成功");
else
MessageLog.GetInstance.Show("西门子PLC连接失败");
});
//sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12");
//sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15");
}

}
}

Loading…
Cancel
Save