EPS行业-预发机的WinFrom控制软件
一、 背景
- 一套完整的工业物联网框架,适用于任何上位机工程,减少开发时间,优化通讯,优化画面操作流畅度,优化数据库等
二、 运行框架
- 基于.NET Framework 4.8框架(点击下载)运行软件前需要安装框架。
三、 架构图
- orm框架:Sqlsugar(使用sqlite数据库,轻量化,运行程序通过实体自动创建数据库文件)
- ui框架:主SunnyUI使用双缓存的方式使界面操作流畅,辅HslControls
- PLC数据采集框架:HslCommunication
- Mqtt服务器:使用emqx服务器,上传PLC的数据提供第三方使用
四、 功能介绍
1. 画面介绍
1. 主画面
2. 配方管理
- 使用XML文件存储到本地独立文件,可进行U盘拷贝存储;
3. 参数管理
4. 日志查询
- 使用sqlite数据库,轻量化,不需要通过部署,运行程序后自动生成;(比mqsql、sqlserver等数据库更加实用)
5. 报表
- 可自定义报表内容,独立定制报表格式;
- 使用rdlc报表功能,制作报表;
2. 拓展按钮介绍
1. 主题
- 选择相应的主题改变样式如下图所示(多种主题颜色,减缓视觉疲劳)
2. 语言
- 支持国际所有语言
3. 登录
4. 许可证
- 机器码 PN,授权状态 License,当前的地理位置 Position
3. 键盘介绍
1. 数值键盘
2. 字符键盘
3. 键盘部分代码
定义委托
:
using Sunny.UI;
using System;
namespace CentralVacuum.Keyboard
{
public static class KeyboardClass
{
public static event Action<UITextBox> actionEvent;
public static void OpenNumberBoard(UITextBox textbox)
{
NumberBoard numb = new NumberBoard
{
Style = Properties.Settings.Default.UIStyle
};
actionEvent += numb.SetValue;
// 使用Action委托
actionEvent?.Invoke(textbox);
numb.ShowDialog();
textbox.Parent.Focus();
}
public static void OpenStringBoard(UITextBox textbox)
{
StringBoard numb = new StringBoard
{
Style = Properties.Settings.Default.UIStyle
};
actionEvent += numb.SetValue;
// 使用Action委托
actionEvent?.Invoke(textbox);
numb.ShowDialog();
textbox.Parent.Focus();
}
}
}
定义接口
:
using Sunny.UI;
namespace CentralVacuum.Keyboard
{
interface KeyboardInterface
{
void OpenNumberBoard(UITextBox textbox);
void OpenStringBoard(UITextBox textbox);
}
}
数字键盘
:
using Sunny.UI;
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace CentralVacuum.Keyboard
{
public partial class NumberBoard : UIForm
{
private UITextBox vUiTextBox;
private int initflag = 0; // 初始化标识
public NumberBoard()
{
InitializeComponent();
}
/// <summary>
/// 给控件赋值的方法
/// </summary>
/// <param name="strValue"></param>
public void SetValue(UITextBox strValue)
{
vUiTextBox = strValue;
this.uiTextBox1.DecimalPlaces = vUiTextBox.DecimalPlaces;
this.uiTextBox1.PasswordChar = vUiTextBox.PasswordChar;
//this.uiTextBox1.Maximum = vUiTextBox.Maximum;
//this.uiTextBox1.Minimum = vUiTextBox.Minimum;
this.uiTextBox1.Maximum = 200000000;
this.uiTextBox1.Minimum = -200000000;
}
private void NumberBoard_Load(object sender, EventArgs e)
{
if (this.vUiTextBox.Type.ToString() == "Double" && this.vUiTextBox.Text.Contains(".") == true)//浮点带小数点
{
if (this.vUiTextBox.Maximum.ToString().Contains(".") == false)//没有小数点
{
this.uiLabel3.Text = this.vUiTextBox.Maximum.ToString() + "." + new string('0', this.vUiTextBox.DecimalPlaces);// 最大值
}
else
{
this.uiLabel3.Text = this.vUiTextBox.Maximum.ToString(); // 最大值
}
if (this.vUiTextBox.Minimum.ToString().Contains(".") == false)//没有小数点
{
this.uiLabel4.Text = this.vUiTextBox.Minimum.ToString() + "." + new string('0', this.vUiTextBox.DecimalPlaces);// 最大值
}
else
{
this.uiLabel4.Text = this.vUiTextBox.Maximum.ToString(); // 最大值
}
/*string[] strArray_max = this.vUiTextBox.Maximum.ToString().Split('.');
if (strArray_max[1].Length < this.vUiTextBox.DecimalPlaces)
{
this.uiLabel3.Text = this.vUiTextBox.Maximum.ToString() + new string('0', this.uiTextBox1.DecimalPlaces - strArray_max[1].Length);// 最大值
}
else
{
this.uiLabel3.Text = this.vUiTextBox.Maximum.ToString(); // 最大值
}
string[] strArray_min = this.vUiTextBox.Minimum.ToString().Split('.');
if (strArray_min[1].Length < this.vUiTextBox.DecimalPlaces)
{
this.uiLabel4.Text = this.vUiTextBox.Minimum.ToString() + new string('0', this.uiTextBox1.DecimalPlaces - strArray_min[1].Length);// 最小值
}
else
{
this.uiLabel4.Text = this.vUiTextBox.Minimum.ToString(); // 最小值
}*/
}
else
{
this.uiLabel3.Text = this.vUiTextBox.Maximum.ToString(); // 最大值
this.uiLabel4.Text = this.vUiTextBox.Minimum.ToString(); // 最小值
}
this.uiTextBox1.Text = this.vUiTextBox.Text;
this.uiTextBox1.Type = this.vUiTextBox.Type;
}
private void AddNumber(string num)
{
if (initflag == 0)
{
this.uiTextBox1.Text = "";
initflag = 1;
}
if (this.uiTextBox1.Type.ToString() == "Integer")
{
this.uiTextBox1.Text += num;
this.uiTextBox1.Text = Convert.ToInt64(this.uiTextBox1.Text).ToString();
}
else if (this.uiTextBox1.Type.ToString() == "Double")
{
if (this.uiTextBox1.Text == "" && num == "0")
{
if (this.uiTextBox1.DecimalPlaces > 0)
{
this.uiTextBox1.Text = "0.";
}
else
{
this.uiTextBox1.Text = "0";
}
return;
}
else
{
if (this.uiTextBox1.Text.Contains(".") == true)//判断字符串是否包含“.”
{
string[] strArray = this.uiTextBox1.Text.Split('.');
if (strArray[1].Length < this.uiTextBox1.DecimalPlaces)
{
this.uiTextBox1.Text += num;
}
else
{
if (Convert.ToSingle(this.uiTextBox1.Text) == 0.0 && strArray[1].Length == this.uiTextBox1.DecimalPlaces)
{
this.uiTextBox1.Text = "";
this.uiTextBox1.Text += num;
}
if (num == "0")
{
if (this.uiTextBox1.DecimalPlaces == 0)
{
this.uiTextBox1.Text = "0";
}
else
{
this.uiTextBox1.Text = "0.";
}
return;
}
}
}
else
{
this.uiTextBox1.Text += num;
}
}
}
MatchCollection musicItem_matches_int = new Regex(@"^\-{0,1}[0-9]{1,}$").Matches(this.uiTextBox1.Text);//正则表达式匹配整数
MatchCollection musicItem_matches1_float = new Regex(@"^[-]?[0-9]+\.?[0-9]+$").Matches(this.uiTextBox1.Text);//正则表达式匹配浮点数
if (musicItem_matches_int.Count != 0 || musicItem_matches1_float.Count != 0)//***********整数跟小数*************
{
if (Convert.ToDouble(this.uiTextBox1.Text) > Convert.ToDouble(this.uiLabel3.Text))
{
if (this.vUiTextBox.Minimum.ToString().Length <= this.uiTextBox1.Text.Length)
{
this.uiTextBox1.Text = Math.Min(Convert.ToDouble(this.uiLabel3.Text), Convert.ToDouble(this.uiTextBox1.Text)).ToString();
}
}
else if (Convert.ToDouble(this.uiTextBox1.Text) < Convert.ToDouble(this.uiLabel4.Text))
{
if (this.vUiTextBox.Maximum.ToString().Length <= this.uiTextBox1.Text.Length)
{
this.uiTextBox1.Text = Math.Max(Convert.ToDouble(this.uiLabel4.Text), Convert.ToDouble(this.uiTextBox1.Text)).ToString();
}
}
}
}
// 按钮1
private void uiButton1_Click(object sender, EventArgs e)
{
AddNumber("1");
}
// 按钮2
private void uiButton2_Click(object sender, EventArgs e)
{
AddNumber("2");
}
// 按钮3
private void uiButton3_Click(object sender, EventArgs e)
{
AddNumber("3");
}
// 按钮4
private void uiButton4_Click(object sender, EventArgs e)
{
AddNumber("4");
}
// 按钮5
private void uiButton5_Click(object sender, EventArgs e)
{
AddNumber("5");
}
// 按钮6
private void uiButton6_Click(object sender, EventArgs e)
{
AddNumber("6");
}
// 按钮7
private void uiButton7_Click(object sender, EventArgs e)
{
AddNumber("7");
}
// 按钮8
private void uiButton8_Click(object sender, EventArgs e)
{
AddNumber("8");
}
// 按钮9
private void uiButton9_Click(object sender, EventArgs e)
{
AddNumber("9");
}
// 按钮小数点“.”
private void uiButton10_Click(object sender, EventArgs e)
{
if (initflag == 0 && this.uiTextBox1.Type.ToString() != "Integer")
{
this.uiTextBox1.Text = "";
initflag = 1;
}
//判断浮点,字符串,小数点最多出现一次
if (this.uiTextBox1.Type.ToString() == "Double")
{
if (this.uiTextBox1.Text.Count(i => ".".Contains(i)) < 1)//小数点个数小于1
{
if (this.uiTextBox1.Text == "")
{
if (this.uiTextBox1.DecimalPlaces > 0)
{
this.uiTextBox1.Text = "0.";
}
}
else
{
if (this.uiTextBox1.DecimalPlaces > 0)
{
this.uiTextBox1.Text = uiTextBox1.Text + ".";
}
}
}
}
else if (this.uiTextBox1.Type.ToString() == "String")
{
this.uiTextBox1.Text = uiTextBox1.Text + ".";
}
}
// 按钮0
private void uiButton11_Click(object sender, EventArgs e)
{
AddNumber("0");
}
// 按钮ESC
private void uiButton12_Click(object sender, EventArgs e)
{
this.Close(); // ESC按钮
}
// 按钮“+/-”
private void uiButton13_Click(object sender, EventArgs e)
{
MatchCollection musicItem_matches_int = new Regex(@"^\-{0,1}[0-9]{1,}$").Matches(this.uiTextBox1.Text);//正则表达式匹配整数
MatchCollection musicItem_matches1_float = new Regex(@"^[-]?[0-9]+\.?[0-9]+$").Matches(this.uiTextBox1.Text);//正则表达式匹配浮点数
if (musicItem_matches_int.Count != 0 || musicItem_matches1_float.Count != 0)//***********整数跟小数*************
{
this.uiTextBox1.Text = ((-1) * Convert.ToDouble(this.uiTextBox1.Text)).ToString();
if (Convert.ToDouble(this.uiTextBox1.Text) > Convert.ToDouble(this.uiLabel3.Text))
{
this.uiTextBox1.Text = Math.Min(Convert.ToDouble(this.uiLabel3.Text), Convert.ToDouble(this.uiTextBox1.Text)).ToString();
}
else if (Convert.ToDouble(this.uiTextBox1.Text) < Convert.ToDouble(this.uiLabel4.Text))
{
this.uiTextBox1.Text = Math.Max(Convert.ToDouble(this.uiLabel4.Text), Convert.ToDouble(this.uiTextBox1.Text)).ToString();
}
}
}
// 按钮ENTER
private void uiButton14_Click(object sender, EventArgs e)
{
/*if (initflag == 0)
{
this.uiTextBox1.Text = "";
initflag = 1;
}*/
if (this.uiTextBox1.Text != "")
{
if (this.uiTextBox1.Type.ToString() == "Double")
{
if (this.uiTextBox1.Text.Contains(".") == false)//没有小数点
{
if (this.uiTextBox1.DecimalPlaces > 0)
{
this.uiTextBox1.Text += ".";
this.uiTextBox1.Text = this.uiTextBox1.Text + new string('0', this.uiTextBox1.DecimalPlaces);
}
}
else
{
if (this.uiTextBox1.Text.EndsWith("."))
{
this.uiTextBox1.Text += new string('0', this.uiTextBox1.DecimalPlaces);
}
else
{
string[] strArray = this.uiTextBox1.Text.Split('.');
if (strArray[1].Length < this.uiTextBox1.DecimalPlaces)
{
this.uiTextBox1.Text += new string('0', this.uiTextBox1.DecimalPlaces - strArray[1].Length);
}
}
}
}
vUiTextBox.Text = this.uiTextBox1.Text;
}
this.Close();
}
// 按钮Clear
private void uiButton15_Click(object sender, EventArgs e)
{
if (this.uiTextBox1.Type.ToString() == "Integer")
{
//this.uiTextBox1.Text = "0";
this.uiTextBox1.Text = "";
}
else if(this.uiTextBox1.Type.ToString() == "Double")
{
//this.uiTextBox1.Text = "0." + new string('0', this.vUiTextBox.DecimalPlaces);
this.uiTextBox1.Text = "";
}
else
{
this.uiTextBox1.Text = "";
}
}
}
}
4. 流程介绍
- 作用:指导操作员按照顺序操作,避免出错;
五、 PLC
1. 使用三菱FX5UPLC的通讯设置参数;
六、 工业一体机
- 屏幕分辨率1024*768;
- 4G内存,128G固态硬盘;
- CPU:i3(推荐),最低要求J1900;
- 系统要求:Windows 7系统以上;