Преглед изворни кода

新设备PLC控制添加

reconfiguration
pry пре 3 месеци
родитељ
комит
f2e0ad4fd1
10 измењених фајлова са 2400 додато и 1 уклоњено
  1. +18
    -0
      BPASmartClient.Academy/50L/AddAttribute.cs
  2. +46
    -0
      BPASmartClient.Academy/50L/AddData.cs
  3. +38
    -0
      BPASmartClient.Academy/50L/BoolAddEnum.cs
  4. +71
    -0
      BPASmartClient.Academy/50L/FeedbackData.cs
  5. +26
    -0
      BPASmartClient.Academy/50L/FloatAddEnum.cs
  6. +50
    -0
      BPASmartClient.Academy/50L/PlcControl.cs
  7. +3
    -1
      BPASmartClient.Academy/App.xaml.cs
  8. +1775
    -0
      BPASmartClient.Academy/View/ReactionKettle500LView.xaml
  9. +357
    -0
      BPASmartClient.Academy/View/ReactionKettle500LView.xaml.cs
  10. +16
    -0
      BPASmartClient.Academy/ViewModel/ReactionKettle500LViewModel.cs

+ 18
- 0
BPASmartClient.Academy/50L/AddAttribute.cs Прегледај датотеку

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

namespace BPASmartClient.Academy._50L
{
public class AddAttribute : Attribute
{
public AddAttribute(string add)
{
Add = add;
}

public string Add { get; set; }
}
}

+ 46
- 0
BPASmartClient.Academy/50L/AddData.cs Прегледај датотеку

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

namespace BPASmartClient.Academy._50L
{
public class AddData
{
protected Dictionary<BoolAddEnum, string> boolAdds { get; set; } = new Dictionary<BoolAddEnum, string>();
protected Dictionary<FloatAddEnum, string> floatAdds { get; set; } = new Dictionary<FloatAddEnum, string>();

protected Dictionary<T, string> GetAdd<T>() where T : Enum
{
Dictionary<T, string> result = new Dictionary<T, string>();
Type type = typeof(T);
Enum.GetNames(typeof(T)).ToList().ForEach(x =>
{
MemberInfo[] memberInfo = type.GetMember(x);
if (memberInfo != null && memberInfo.Length > 0)
{
var attribute = memberInfo[0].GetCustomAttribute<AddAttribute>();
if (attribute != null)
{
if (x.TryToEnum<T>(out T eu))
{
if (!result.ContainsKey(eu))
{
result.Add(eu, attribute.Add);
}
}
}
}
});
return result;
}

public AddData()
{
boolAdds = GetAdd<BoolAddEnum>();
floatAdds = GetAdd<FloatAddEnum>();
}
}
}

+ 38
- 0
BPASmartClient.Academy/50L/BoolAddEnum.cs Прегледај датотеку

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

namespace BPASmartClient.Academy._50L
{
public enum BoolAddEnum
{
[Add("DB1.DBX1000.0")]
反应釜旋转电机,
[Add("DB1.DBX1000.1")]
负压风机,
[Add("DB1.DBX1000.2")]
反应釜回原点,
[Add("DB1.DBX1000.3")]
反应釜压缩空气进气阀,
[Add("DB1.DBX1000.4")]
反应釜排热空气阀,
[Add("DB1.DBX1000.5")]
反应釜泄压阀,
[Add("DB1.DBX1000.6")]
称重水罐负压阀,
[Add("DB1.DBX1000.7")]
称重水罐重量清零,
[Add("DB1.DBX1001.0")]
反应釜升温,
[Add("DB1.DBX1001.1")]
反应釜降温,
[Add("DB1.DBX1000.2")]
冷凝水罐降温,
[Add("DB1.DBX1002.0")]
系统启动,
[Add("DB1.DBX1003.7")]
心跳,
}
}

+ 71
- 0
BPASmartClient.Academy/50L/FeedbackData.cs Прегледај датотеку

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

namespace BPASmartClient.Academy._50L
{
public class FeedbackData
{
/// <summary>
/// 旋转电机启停反馈
/// </summary>
public bool RotatingMachines { get; set; }

/// <summary>
/// 负压风机启动反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 压缩空气进气阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 排热空气阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 泄压阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 进冷却水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 出冷却水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 蒸汽梳水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 冷凝水罐进水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 称重水罐负压阀
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 反应釜原点位置反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 心跳
/// </summary>
public string MachineName { get; set; }
}
}

+ 26
- 0
BPASmartClient.Academy/50L/FloatAddEnum.cs Прегледај датотеку

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

namespace BPASmartClient.Academy._50L
{
public enum FloatAddEnum
{
[Add("DB1.DBD1004")]
反应釜旋转电机速度,
[Add("DB1.DBD1008")]
反应釜设定升温温度,
[Add("DB1.DBD1016")]
反应釜设定降温温度,
[Add("DB1.DBD1020")]
反应釜温度校准,
[Add("DB1.DBD1024")]
冷凝水罐温度校准,
[Add("DB1.DBD1028")]
蒸汽比例阀开度,
[Add("DB1.DBD1032")]
反应釜蒸汽压力上限
}
}

+ 50
- 0
BPASmartClient.Academy/50L/PlcControl.cs Прегледај датотеку

@@ -0,0 +1,50 @@
using BPA.Communication.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Academy._50L
{
public class PlcControl : AddData
{
private volatile static PlcControl _Instance;
public static PlcControl GetInstance => _Instance ?? (_Instance = new PlcControl());
private PlcControl() { }

private ICommSiemens comm = CommHelper.Siemens;

public void Init()
{
CommHelper.CreateSiemens(CpuType.S71200, Json<DevicePar>.Data.IpAddress).OnSuccess(s =>
{
comm = s.Content;
});
}

private void Read()
{


}

public void Write(BoolAddEnum add, bool value)
{
if (boolAdds.ContainsKey(add))
{
comm.Write(boolAdds[add], value);
}
}

public void Write(FloatAddEnum add, float value)
{
if (floatAdds.ContainsKey(add))
{
comm.Write(floatAdds[add], value);
}
}

}
}

+ 3
- 1
BPASmartClient.Academy/App.xaml.cs Прегледај датотеку

@@ -1,4 +1,5 @@
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.Academy._50L;
using BPASmartClient.CustomResource.UserControls;
using LiveCharts;
using System.Collections.Specialized;
using System.Configuration;
@@ -48,6 +49,7 @@ namespace BPASmartClient.Academy
SystemHelper.GetInstance.CreateDesktopShortcut();
DataInit();
MenuInit();
PlcControl.GetInstance.Init();
MainView mv = new MainView();
MessageNotify.GetInstance.window = mv;
mv.TitleName = $"10L 反应釜焖制系统 V1.0.1";


+ 1775
- 0
BPASmartClient.Academy/View/ReactionKettle500LView.xaml
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 357
- 0
BPASmartClient.Academy/View/ReactionKettle500LView.xaml.cs Прегледај датотеку

@@ -0,0 +1,357 @@
using BPASmartClient.CustomResource.UserControls.MessageShow;
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.Academy.View
{
/// <summary>
/// ReactionKettle500LView.xaml 的交互逻辑
/// </summary>
public partial class ReactionKettle500LView : UserControl
{
public ReactionKettle500LView()
{
InitializeComponent();
this.DataContext = ReactionKettle500LViewModel.GetInstance;
this.Loaded += DeviceMotionView_Loaded;
}

private void DeviceMotionView_Loaded(object sender, RoutedEventArgs e)
{
Simens_PLC.GetInstance.connect = o =>
{
//App.Current.Dispatcher.Invoke(() =>
//{
// if (o)
// {
// ooo.Opacity = 1;
// ooo.IsHitTestVisible = true;
// state.Visibility = Visibility.Collapsed;
// }
// else
// {

// ooo.Opacity = 0.5;
// ooo.IsHitTestVisible = false;
// state.Text = "设 备 未 连 接";
// //MessageNotify.GetInstance.ShowRunLog("设备未连接");
// state.Visibility = Visibility.Visible;
// state.Foreground = Brushes.Red;
// }
//});

};
}

private string tempName = "配料罐升温";
private void auto_click(object sender, RoutedEventArgs e)
{
RadioButton radioButton = (RadioButton)sender;
switch (radioButton.Content.ToString())
{
case "反应釜升温":
tempName = "反应釜升温";
wokTemp.Visibility = Visibility.Visible;
caliTemp.Visibility = Visibility.Collapsed;
break;
case "配料罐升温":
tempName = "配料罐升温";
wokTemp.Visibility = Visibility.Visible;
caliTemp.Visibility = Visibility.Collapsed;
break;
case "反应釜降温":
tempName = "反应釜降温";
wokTemp.Visibility = Visibility.Visible;
caliTemp.Visibility = Visibility.Collapsed;
break;
case "温度校准":
tempName = "温度校准";
wokTemp.Visibility = Visibility.Collapsed;
caliTemp.Visibility = Visibility.Visible;
break;
default:
break;
}
}

private void Open_Click(object sender, RoutedEventArgs e)
{
RadioButton radioButton = sender as RadioButton;
if (radioButton.Content.ToString().Contains("配料搅拌"))
{
hzSet.Visibility = Visibility.Visible;
motorName.Text = "配料搅拌频率:";
ooo.Opacity = 0.5;
ooo.IsHitTestVisible = false;
}
if (radioButton.Content.ToString().Contains("反应釜搅拌"))
{
hzSet.Visibility = Visibility.Visible;
motorName.Text = "反应釜搅拌频率:";
ooo.Opacity = 0.5;
ooo.IsHitTestVisible = false;
}
if (Simens_PLC.GetInstance.IsConnected)
{

int bit = Convert.ToInt32(radioButton.Tag.ToString());
if (bit < 8)
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1000.{bit}", true);
}
else if (bit < 16)
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", true);
}
else
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", true);
}
}
}

private void Close_Click(object sender, RoutedEventArgs e)
{
RadioButton radioButton = sender as RadioButton;
if (Simens_PLC.GetInstance.IsConnected)
{
int bit = Convert.ToInt32(radioButton.Tag.ToString());
if (bit < 8)
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1000.{bit}", false);
}
else if (bit < 16)
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", false);
}
else
{
Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", false);
}
}

}






private void TempSet_CLick(object sender, RoutedEventArgs e)
{
bool suc;
switch (tempName)
{
case "反应釜升温":
int tempValue;
suc = int.TryParse(temp_1.Text.ToString(), out tempValue);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.7", true);
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1020", tempValue);
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
});
}

break;
case "配料罐升温":
suc = int.TryParse(temp_1.Text.ToString(), out tempValue);
//int time;
//suc = int.TryParse(time_1.Text.ToString(), out time);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.6", true);
//Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1016", tempValue);
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
});
}
break;
case "反应釜降温":
suc = int.TryParse(temp_1.Text.ToString(), out tempValue);
//int time;
//suc = int.TryParse(time_1.Text.ToString(), out time);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1003.0", true);
//Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1020", tempValue);
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
});
}
break;
case "温度校准":
bool val = true;
int value;
suc = int.TryParse(tempvent.Text.ToString(), out value);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1024", value).OnFailure(o =>
{
val = false;
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜排气温度写入失败", 1, 1);
});
});
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查排气温度校准输入", 1, 1);
});
}
suc = int.TryParse(tempmaterial.Text.ToString(), out value);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1028", value).OnFailure(o =>
{
val = false;
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "配料罐温度写入失败", 1, 1);
});
});
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查配料罐温度校准输入", 1, 1);
});
}
suc = int.TryParse(tempwok.Text.ToString(), out value);
if (suc)
{
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1032", value).OnFailure(o =>
{
val = false;
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜温度写入失败", 1, 1);
});
});
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查反应釜温度校准输入", 1, 1);
});
}
if (val)
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "成功", "校准完成", 1, 1);
});
}
break;
default:
break;
}
}

private void hzSet_Click(object sender, RoutedEventArgs e)
{
hzSet.Visibility = Visibility.Collapsed;
int value;
bool suc = int.TryParse(motorValue.Text.ToString(), out value);
if (suc && Simens_PLC.GetInstance.IsConnected && value >= 20 && value <= 100)
{
if (motorName.Text.ToString().Contains("配料搅拌"))
{
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1004", value).OnFailure(o =>
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1);
});
});
}
if (motorName.Text.ToString().Contains("反应釜搅拌"))
{
Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1008", value).OnFailure(o =>
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1);
});
});

}
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查频率设备连接、数据格式等", 1, 1);
});
}
ooo.Opacity = 1;
ooo.IsHitTestVisible = true;
}

private void hzCancel_Click(object sender, RoutedEventArgs e)
{
hzSet.Visibility = Visibility.Collapsed;
ooo.Opacity = 1;
ooo.IsHitTestVisible = true;
}

private void TempCLose_CLick(object sender, RoutedEventArgs e)
{
switch (tempName)
{
case "配料罐升温":
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.6", false);
break;
case "反应釜升温":
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.7", false);
break;
case "反应釜降温":
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1003.0", false);
break;
default:
break;
}
}

private void ClearBtn_CLick(object sender, RoutedEventArgs e)
{
if (Simens_PLC.GetInstance.IsConnected)
{
Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1002.7", true);
}
}

}
}

+ 16
- 0
BPASmartClient.Academy/ViewModel/ReactionKettle500LViewModel.cs Прегледај датотеку

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

namespace BPASmartClient.Academy.ViewModel
{
public class ReactionKettle500LViewModel : NotifyBase
{
private volatile static ReactionKettle500LViewModel _Instance;
public static ReactionKettle500LViewModel GetInstance => _Instance ?? (_Instance = new ReactionKettle500LViewModel());
private ReactionKettle500LViewModel() { }

}
}

Loading…
Откажи
Сачувај