Bladeren bron

S7协议修改

样式分支
pry 2 jaren geleden
bovenliggende
commit
ff1c576060
7 gewijzigde bestanden met toevoegingen van 300 en 51 verwijderingen
  1. +30
    -2
      BPASmartClient.S7Net/SiemensHelper.cs
  2. +2
    -2
      DosingSystem/App.xaml.cs
  3. +3
    -39
      DosingSystem/Model/DevicePar.cs
  4. +56
    -0
      DosingSystem/Model/DeviceParModel.cs
  5. +170
    -7
      DosingSystem/View/NewMaterialDeviceParView.xaml
  6. +29
    -1
      DosingSystem/View/NewMaterialDeviceParView.xaml.cs
  7. +10
    -0
      DosingSystem/ViewModel/NewMaterialDeviceParViewModel.cs

+ 30
- 2
BPASmartClient.S7Net/SiemensHelper.cs Bestand weergeven

@@ -4,9 +4,7 @@ namespace BPASmartClient.S7Net
{
public class SiemensHelper
{

Plc myPlc;

public bool IsConnected => myPlc is null ? false : myPlc.IsConnected;

/// <summary>
@@ -37,6 +35,36 @@ namespace BPASmartClient.S7Net
return myPlc?.Read(address);
}

public bool[] ReadBools(int address, int count)
{
if (!IsConnected) return default;
var res = Read(DataType.Memory, 0, address, VarType.Bit, count);
if (res != null && res is bool[] bools) return bools;
return default;
}

public ushort[] ReadMW(int address, int count)
{
if (!IsConnected) return default;
var res = Read(DataType.Memory, 0, address, VarType.Word, count);
if (res != null && res is ushort[] ReturnValue) return ReturnValue;
return default;
}

public float[] ReadMD(int address, int count)
{
if (!IsConnected) return default;
var res = Read(DataType.Memory, 0, address, VarType.Real, count);
if (res != null && res is float[] ReturnValue) return ReturnValue;
return default;
}

private object Read(DataType dataType, int db, int address, VarType varType, int count)
{
if (!IsConnected) return default;
return myPlc?.Read(dataType, db, address, varType, count);
}

public void Write(string address, object value)
{
myPlc?.Write(address, value);


+ 2
- 2
DosingSystem/App.xaml.cs Bestand weergeven

@@ -30,8 +30,8 @@ namespace BPASmartClient.DosingSystem
MenuInit();
DataInit();
DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
NewMaterialDeviceParView newMaterialDeviceParView = new NewMaterialDeviceParView();
newMaterialDeviceParView.ShowDialog();
//NewMaterialDeviceParView newMaterialDeviceParView = new NewMaterialDeviceParView();
//newMaterialDeviceParView.ShowDialog();
MainView mv = new MainView();
//mv.Show();
LoginView lv = new LoginView();


+ 3
- 39
DosingSystem/Model/DevicePar.cs Bestand weergeven

@@ -3,49 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;

namespace BPASmartClient.DosingSystem.Model
{
public class DevicePar
{
/// <summary>
/// 慢加重量
/// </summary>
public float SlowlyAddWeight { get; set; }

/// <summary>
/// 提前关阀重量
/// </summary>
public float PreCloseValveWeight { get; set; }

/// <summary>
/// 快加速度
/// </summary>
public int RapidAcceleration { get; set; }

/// <summary>
/// 慢加速度
/// </summary>
public int SlowAcceleration { get; set; }

/// <summary>
/// 伺服手动速度
/// </summary>
public int ServoManualSpeed { get; set; }

/// <summary>
/// 料仓上限重量
/// </summary>
public int SiloUpperLimitWeight { get; set; }

/// <summary>
/// 料仓下限重量
/// </summary>
public int LowerLimitWeightOfSilo { get; set; }

/// <summary>
/// 搅拌速度
/// </summary>
public int StirringSpeed { get; set; }
public ObservableCollection<DeviceParModel> deviceParModels { get; set; } = new ObservableCollection<DeviceParModel>();
}
}

+ 56
- 0
DosingSystem/Model/DeviceParModel.cs Bestand weergeven

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.Model
{
public class DeviceParModel
{
/// <summary>
/// 原料名称
/// </summary>
public string MaterialName { get; set; } = string.Empty;

/// <summary>
/// 慢加重量
/// </summary>
public float SlowlyAddWeight { get; set; }

/// <summary>
/// 提前关阀重量
/// </summary>
public float PreCloseValveWeight { get; set; }

/// <summary>
/// 快加速度
/// </summary>
public int RapidAcceleration { get; set; }

/// <summary>
/// 慢加速度
/// </summary>
public int SlowAcceleration { get; set; }

/// <summary>
/// 伺服手动速度
/// </summary>
public int ServoManualSpeed { get; set; }

/// <summary>
/// 料仓上限重量
/// </summary>
public int SiloUpperLimitWeight { get; set; }

/// <summary>
/// 料仓下限重量
/// </summary>
public int LowerLimitWeightOfSilo { get; set; }

/// <summary>
/// 搅拌速度
/// </summary>
public int StirringSpeed { get; set; }
}
}

+ 170
- 7
DosingSystem/View/NewMaterialDeviceParView.xaml Bestand weergeven

@@ -2,6 +2,7 @@
x:Class="BPASmartClient.DosingSystem.View.NewMaterialDeviceParView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Themes1="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
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"
@@ -47,6 +48,150 @@
</Setter>
</Style>
<!--#endregion-->

<!--#region Combox 样式-->
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}" />
<Setter Property="Foreground" Value="{DynamicResource foreground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource borderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Height" Value="24" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="true" />
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="IsTextSearchCaseSensitive" Value="true" />
<Setter Property="IsEditable" Value="true" />
<Setter Property="StaysOpenOnEdit" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<Grid>
<Themes1:ClassicBorderDecorator
x:Name="Border"
BorderBrush="{x:Static Themes1:ClassicBorderDecorator.ClassicBorderBrush}"
BorderStyle="None"
BorderThickness="2">
<Popup
x:Name="PART_Popup"
AllowsTransparency="true"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<Themes1:SystemDropShadowChrome
x:Name="Shdw"
MinWidth="{Binding ActualWidth, ElementName=Border}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
Color="Transparent">
<Border
x:Name="DropDownBorder"
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="#264c73" />
</Border.Background>
<ScrollViewer x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas
Width="0"
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Rectangle
x:Name="OpaqueRect"
Width="{Binding ActualWidth, ElementName=DropDownBorder}"
Height="{Binding ActualHeight, ElementName=DropDownBorder}"
Fill="{Binding Background, ElementName=DropDownBorder}" />
</Canvas>
<ItemsPresenter
x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ScrollViewer>
</Border>
</Themes1:SystemDropShadowChrome>
</Popup>
</Themes1:ClassicBorderDecorator>
<DockPanel Margin="2">
<FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" />
<Border x:Name="SelectedItemBorder" Margin="{TemplateBinding Padding}">
<ContentPresenter
Margin="1,1,1,1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</DockPanel>
<ToggleButton
Width="Auto"
MinWidth="0"
MinHeight="0"
Margin="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxTransparentButtonStyle}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsDropDownOpen" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
</MultiTrigger>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
</MultiTrigger>
<Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="true">
<Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" />
<Setter TargetName="Shdw" Property="Color" Value="#71000000" />
</Trigger>
<Trigger SourceName="DropDownScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false">
<Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Padding" Value="1" />
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
<!--#endregion-->

</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
@@ -107,11 +252,29 @@
Foreground="#FF2AB2E7"
Text="请输入原料名称:" />

<TextBox
<!--<TextBox
Grid.Column="1"
Margin="3"
Style="{StaticResource TextBoxStyle}"
Text="{Binding RawMaterialName}" />
Text="{Binding RawMaterialName}" />-->

<ComboBox
Grid.Column="1"
Margin="3"
FontSize="14"
ItemsSource="{Binding DataContext.materialNames, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
KeyUp="ComboBox_KeyUp"
LostFocus="ComboBox_LostFocus"
Style="{StaticResource ComboBoxStyle1}"
Text="{Binding MaterialName}">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="#e69519" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>


<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button
@@ -140,7 +303,7 @@
Text="慢加重量:" />

<TextBox
Grid.Row="1"
Grid.Row="1"
Grid.Column="1"
Margin="3"
Style="{StaticResource TextBoxStyle}"
@@ -154,7 +317,7 @@
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="单位" />
Text="g" />
<!--#endregion-->

<!--#region 提前关阀重量-->
@@ -182,7 +345,7 @@
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="单位" />
Text="g" />
<!--#endregion-->

<!--#region 快加速度-->
@@ -294,7 +457,7 @@
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="单位" />
Text="g" />
<!--#endregion-->

<!--#region 料仓下限重量-->
@@ -322,7 +485,7 @@
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="单位" />
Text="g" />
<!--#endregion-->

<!--#region 搅拌速度-->


+ 29
- 1
DosingSystem/View/NewMaterialDeviceParView.xaml.cs Bestand weergeven

@@ -1,4 +1,6 @@
using System;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -22,6 +24,32 @@ namespace BPASmartClient.DosingSystem.View
public NewMaterialDeviceParView()
{
InitializeComponent();
this.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
this.DragMove();
}

private void ComboBox_KeyUp(object sender, KeyEventArgs e)
{
var res = sender as ComboBox;
Json<DevicePar>.Read();
if (res.Text != null && res.Text != String.Empty)
{
var datas = Json<DevicePar>.Data.deviceParModels.Where(s => s.MaterialName.Contains(res.Text.Trim()));
if (datas.Count() > 0)
{
res.ItemsSource = datas;
res.IsDropDownOpen = true;
}
else
{
res.IsDropDownOpen = false;
}
}
}

private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
{

}
}
}

+ 10
- 0
DosingSystem/ViewModel/NewMaterialDeviceParViewModel.cs Bestand weergeven

@@ -4,10 +4,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;

namespace BPASmartClient.DosingSystem.ViewModel
{
public class NewMaterialDeviceParViewModel : ObservableObject
{
public NewMaterialDeviceParViewModel()
{

}

public RelayCommand Save { get; set; }

public RelayCommand Cancle { get; set; }

}
}

Laden…
Annuleren
Opslaan