diff --git a/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs b/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs
index 96a0fa4f..b8da7d9b 100644
--- a/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs
+++ b/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows;
using BPASmartClient.Model;
using System.Windows.Media;
+using BPASmartClient.CustomResource.Pages.View;
namespace BPASmartClient.CustomResource.Pages.Model
{
@@ -44,7 +45,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
{
lock (userlock)
{
- if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString())&& !string.IsNullOrEmpty(info))
+ if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString()) && !string.IsNullOrEmpty(info))
{
UserLog userLog = new UserLog()
{
@@ -76,7 +77,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
RunLog?.Invoke(info);
}
}
-
+
int AlarmID;
public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
{
@@ -97,5 +98,39 @@ namespace BPASmartClient.CustomResource.Pages.Model
AlarmLog?.Invoke(info);
}
}
+
+ public bool ShowDialog(string info, DialogType dialogType = DialogType.Information)
+ {
+ PromptView PV = new PromptView();
+ switch (dialogType)
+ {
+ case DialogType.Warning:
+ PV.TextBlockIcon = "";
+ PV.TextBlockForeground = Brushes.Yellow;
+ PV.TextBlockInfo = $"警告:{info}";
+ break;
+ case DialogType.Error:
+ PV.TextBlockIcon = "";
+ PV.TextBlockForeground = Brushes.Red;
+ PV.TextBlockInfo = $"错误:{info}";
+ break;
+ case DialogType.Information:
+ PV.TextBlockIcon = "";
+ PV.TextBlockForeground = Brushes.DeepSkyBlue;
+ PV.TextBlockInfo = $"提示:{info}";
+ break;
+ default:
+ break;
+ }
+ var res = PV.ShowDialog();
+ return res == null ? false : (bool)res;
+ }
+ }
+
+ public enum DialogType
+ {
+ Warning,
+ Error,
+ Information,
}
}
diff --git a/BPASmartClient.CustomResource/Pages/View/PromptView.xaml b/BPASmartClient.CustomResource/Pages/View/PromptView.xaml
index 917ceb69..78dc8238 100644
--- a/BPASmartClient.CustomResource/Pages/View/PromptView.xaml
+++ b/BPASmartClient.CustomResource/Pages/View/PromptView.xaml
@@ -13,6 +13,21 @@
WindowStartupLocation="CenterScreen"
WindowStyle="None"
mc:Ignorable="d">
+
+
+
+
+
@@ -34,8 +49,12 @@
-
+
+
+
+
+
diff --git a/BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs b/BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs
index d1961c58..11ddd2f5 100644
--- a/BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs
+++ b/BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -24,6 +25,34 @@ namespace BPASmartClient.CustomResource.Pages.View
InitializeComponent();
}
+ public string TextBlockIcon
+ {
+ get { return this.icon.Text.Trim(); }
+ set { this.icon.Text = Regex.Unescape(StringToUnicode(value.ToString())); }
+ }
+
+ public Brush TextBlockForeground
+ {
+ get { return this.icon.Foreground; }
+ set { this.icon.Foreground = value; this.info.Foreground = value; }
+ }
+
+ public string TextBlockInfo
+ {
+ get { return this.info.Text.Trim(); }
+ set { this.info.Text = value; }
+ }
+
+ private string StringToUnicode(string s)
+ {
+ if (!string.IsNullOrEmpty(s))
+ {
+ //这里把格式 转为 \ue625
+ return s.Replace(@"", @"\u").Replace(";", "");
+ }
+ return s;
+ }
+
private void Button_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs
index 641d84b0..8734228e 100644
--- a/BPASmartClient.Modbus/ModbusTcp.cs
+++ b/BPASmartClient.Modbus/ModbusTcp.cs
@@ -1,5 +1,5 @@
using BPASmartClient.Helper;
-using BPASmartClient.Message;
+//using BPASmartClient.Message;
using NModbus;
using System;
using System.Collections.Generic;
@@ -25,6 +25,8 @@ namespace BPASmartClient.Modbus
private ManualResetEvent mre = new ManualResetEvent(false);
public string IPAdress;
public int Port;
+ public Action Show { get; set; }
+ public Action ShowEx { get; set; }
///
/// 连接plc 原料设备成功
@@ -49,7 +51,7 @@ namespace BPASmartClient.Modbus
/// 端口号,默认502
public void ModbusTcpConnect(string ip, int port = 502)
{
- MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接中。。。。");
+ Show?.Invoke($"设备【{ip}:{port}】连接中。。。。");
IPAdress = ip;
Port = port;
modbusFactory = new ModbusFactory();
@@ -60,7 +62,7 @@ namespace BPASmartClient.Modbus
master.Transport.WriteTimeout = 2000;//写入超时时间
master.Transport.Retries = 10;//重试次数
ConnectOk?.Invoke();
- MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接成功");
+ Show?.Invoke($"设备【{ip}:{port}】连接成功");
}
else
{
@@ -94,15 +96,15 @@ namespace BPASmartClient.Modbus
{
if (!ErrorFlag)
{
- MessageLog.GetInstance.ShowEx($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
- MessageLog.GetInstance.ShowEx(ex.ToString());
+ ShowEx?.Invoke($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
+ ShowEx?.Invoke(ex.ToString());
ErrorFlag = true;
}
if (!IsReconnect) break;
Thread.Sleep(3000);
}
}
- if (ErrorFlag && IsReconnect) MessageLog.GetInstance.Show("ModbusTcp 重连成功!");
+ if (ErrorFlag && IsReconnect) Show?.Invoke("ModbusTcp 重连成功!");
}
///
@@ -244,18 +246,54 @@ namespace BPASmartClient.Modbus
}
catch (Exception ex)
{
- MessageLog.GetInstance.ShowEx($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}");
+ ShowEx?.Invoke($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}");
ExceptionHandling(ex);
}
return default(object);
}
-
-
+ ///
+ /// 写入数据
+ ///
+ ///
+ /// 写入地址
+ /// 写入值
+ /// 重试次数
+ /// 从站地址
+ ///
+ public bool Write(string address, T value, int Retries = 1, byte slaveAddress = 1)
+ {
+ int count = 0;
+ if (Retries == 1 || Retries == 0)
+ {
+ return TempWrite(address, value, slaveAddress);
+ }
+ else if (Retries > 1)
+ {
+ bool isok = false;
+ while (count < Retries)
+ {
+ count++;
+ TempWrite(address, value, slaveAddress);
+ var res = Read(address);
+ if (res != null && res.ToString() == value.ToString())
+ {
+ isok = true;
+ break;
+ }
+ }
+ return isok;
+ }
+ return false;
+ }
- public string Write(string address, T value, byte slaveAddress = 1)
+ private bool TempWrite(string address, T value, byte slaveAddress = 1)
{
- if (address == null || tcpClient == null) return "失败,地址为空或断开连接";
+ if (address == null || tcpClient == null)
+ {
+ Show?.Invoke("写入失败,地址为空或断开连接");
+ return false;
+ }
ushort startAddress = (ushort)GetAddress(address);
CommandType commandType = CommandType.Coils;
try
@@ -305,16 +343,14 @@ namespace BPASmartClient.Modbus
{
commandType = CommandType.Inputs;
}
-
- return $"成功,地址:{address},值:{value}";
+ Show?.Invoke($"成功,地址:{address},值:{value}");
+ return true;
}
catch (Exception ex)
{
- MessageLog.GetInstance.ShowEx($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}");
-
+ ShowEx?.Invoke($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}");
ExceptionHandling(ex);
-
- return $"异常,地址:{address},值:{value},发送异常";
+ return false;
}
}
diff --git a/FryPot_DosingSystem/View/NewRecipeView.xaml b/FryPot_DosingSystem/View/NewRecipeView.xaml
index 44808a81..6d22f265 100644
--- a/FryPot_DosingSystem/View/NewRecipeView.xaml
+++ b/FryPot_DosingSystem/View/NewRecipeView.xaml
@@ -1,21 +1,27 @@
-
+
-
+
-
+
@@ -40,35 +46,44 @@
-
-
-
+
+
+
-
-
+
+
@@ -183,70 +246,160 @@
-
-
-
+
-
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
@@ -256,42 +409,73 @@
-
+
-
-
-
+
+
+
-
+
-
-
+
+
-
-
-
-
-
+ BorderBrush="#e69519"
+ FontSize="14"
+ Foreground="LightGray"
+ Text="{Binding MaterialWeight}" />
+
+
+