添加项目文件。
This commit is contained in:
28
口罩泄露定制款/Data/BoolSign.cs
Normal file
28
口罩泄露定制款/Data/BoolSign.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 口罩泄露定制款.Data
|
||||
{
|
||||
|
||||
public class BoolSignal
|
||||
{
|
||||
private bool _previousValue;
|
||||
|
||||
public event Action OnRisingEdge;
|
||||
// bool value = true;
|
||||
public bool Value { get; set; }
|
||||
|
||||
public void CheckRisingEdge()
|
||||
{
|
||||
if (Value && !_previousValue)
|
||||
{
|
||||
OnRisingEdge?.Invoke();
|
||||
}
|
||||
_previousValue = Value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
74
口罩泄露定制款/Data/DataChange.cs
Normal file
74
口罩泄露定制款/Data/DataChange.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public class DataChange
|
||||
{
|
||||
/// <summary>
|
||||
/// ushort转为float类型
|
||||
/// </summary>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <returns>float型数据</returns>
|
||||
public float UshortToFloat(ushort P1, ushort P2)
|
||||
{
|
||||
int intSign, intSignRest, intExponent, intExponentRest;
|
||||
float faResult, faDigit;
|
||||
intSign = P1 / 32768;
|
||||
intSignRest = P1 % 32768;
|
||||
intExponent = intSignRest / 128;
|
||||
intExponentRest = intSignRest % 128;
|
||||
faDigit = (float)(intExponentRest * 65536 + P2) / 8388608;
|
||||
faResult = (float)Math.Pow(-1, intSign) * (float)Math.Pow(2, intExponent - 127) * (faDigit + 1);
|
||||
return faResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// ushort转为int类型
|
||||
/// </summary>
|
||||
/// <param name="u1"></param>
|
||||
/// <param name="u2"></param>
|
||||
/// <returns>返回int型数据</returns>
|
||||
public int UshortToInt1(ushort u1, ushort u2)
|
||||
{
|
||||
ushort[] maidong = new ushort[2] { u1, u2 };
|
||||
byte[] bytes = new byte[maidong.Length * 2];
|
||||
Buffer.BlockCopy(maidong, 0, bytes, 0, bytes.Length);
|
||||
int result = BitConverter.ToInt32(bytes, 0);
|
||||
// 将字节数组转换为32位无符号整数
|
||||
return result;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Float转为Ushort数组发送
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>返回ushort数组</returns>
|
||||
public ushort[] SplitFloatToUShortArray(float value)
|
||||
{
|
||||
byte[] floatBytes = BitConverter.GetBytes(value);
|
||||
ushort[] ushortArray = new ushort[floatBytes.Length / 2];
|
||||
|
||||
for (int i = 0, j = 0; i < floatBytes.Length; i += 2, j++)
|
||||
{
|
||||
ushortArray[j] = BitConverter.ToUInt16(floatBytes, i);
|
||||
}
|
||||
|
||||
return ushortArray;
|
||||
}
|
||||
/// <summary>
|
||||
/// Int转为ushort数组发送
|
||||
/// </summary>
|
||||
/// <param name="res"></param>
|
||||
/// <returns>返回ushort数组</returns>
|
||||
public ushort[] intToushorts(int res)
|
||||
{
|
||||
ushort ust1 = (ushort)(res >> 16);
|
||||
ushort ust2 = (ushort)res;
|
||||
return new ushort[] { ust2, ust1 };
|
||||
}
|
||||
}
|
||||
}
|
||||
151
口罩泄露定制款/Data/ExperData.cs
Normal file
151
口罩泄露定制款/Data/ExperData.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public class ExperData: INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
#region 实验属性
|
||||
static string experName = "";
|
||||
/// <summary>
|
||||
/// 实验人员
|
||||
/// </summary>
|
||||
public string ExperName { get { return experName; } set { experName = value; } }
|
||||
|
||||
static string experDate = "";
|
||||
/// <summary>
|
||||
/// 实验日期
|
||||
/// </summary>
|
||||
public string ExperDate { get { return experDate; } set { experDate = value; } }
|
||||
|
||||
static string experNum = "";
|
||||
/// <summary>
|
||||
/// 实验编号
|
||||
/// </summary>
|
||||
public string ExperNum { get { return experNum; } set { experNum = value; } }
|
||||
|
||||
static string experType = " ";
|
||||
/// <summary>
|
||||
/// 实验种类
|
||||
/// </summary>
|
||||
public string ExperType { get { return experType; } set { experType = value; } }
|
||||
static float experMaskType = 2.0f;
|
||||
/// <summary>
|
||||
/// 口罩类型
|
||||
/// </summary>
|
||||
public float ExperMaskType { get { return experMaskType; } set { experMaskType = value; } }
|
||||
/// <summary>
|
||||
/// 面罩类型
|
||||
/// </summary>
|
||||
static string maskType;
|
||||
public string MaskType { get { return maskType; } set { maskType = value; } }
|
||||
static float _yangPinXiShu = 1.0f;
|
||||
/// <summary>
|
||||
/// 样品系数
|
||||
/// </summary>
|
||||
public float YangPinXiShu { get { return _yangPinXiShu; } set { _yangPinXiShu = value; } }
|
||||
static string _testStatus = "";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 实验状态
|
||||
/// </summary>
|
||||
public string TestStatus { get { return _testStatus; } set { _testStatus = value; } }
|
||||
static float benDiNongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 本底浓度
|
||||
/// </summary>
|
||||
public float BenDiNongDu { get { return benDiNongDu; } set { benDiNongDu = value; } }
|
||||
|
||||
static float huanJingWenDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 环境温度
|
||||
/// </summary>
|
||||
public float HuanJingWenDu { get { return huanJingWenDu; } set { huanJingWenDu = value; } }
|
||||
|
||||
|
||||
static float huanJingShiDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 环境湿度
|
||||
/// </summary>
|
||||
public float HuanJingShiDu { get { return huanJingShiDu; } set { huanJingShiDu = value; } }
|
||||
|
||||
static float o2NongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 环境氧浓度
|
||||
/// </summary>
|
||||
public float O2NongDu { get { return o2NongDu; } set { o2NongDu = value; } }
|
||||
|
||||
static float cO2NongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 环境C02浓度
|
||||
/// </summary>
|
||||
public float CO2NongDu_Indoor { get { return cO2NongDu; } set { cO2NongDu = value; } }
|
||||
|
||||
static float inDoor_TSINongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 环境气溶胶浓度
|
||||
/// </summary>
|
||||
public float InDoor_TSINongDu { get { return inDoor_TSINongDu; } set { inDoor_TSINongDu = value; } }
|
||||
|
||||
static float mask_CO2NongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 口罩内CO2浓度
|
||||
/// </summary>
|
||||
public float Mask_CO2NongDu { get { return mask_CO2NongDu; } set { mask_CO2NongDu = value; } }
|
||||
|
||||
static float mask_TSINongDu = 0.00f;
|
||||
/// <summary>
|
||||
/// 口罩内气溶胶浓度
|
||||
/// </summary>
|
||||
public float Mask_TSINongDu { get { return mask_TSINongDu; } set { mask_TSINongDu = value; } }
|
||||
|
||||
static float _liuLiang = 0.00f;
|
||||
/// <summary>
|
||||
/// 流量
|
||||
/// </summary>
|
||||
public float LiuLiang { get { return _liuLiang; } set { _liuLiang = value; } }
|
||||
static float _xieloulv = 0.00f;
|
||||
/// <summary>
|
||||
/// 泄露率
|
||||
/// </summary>
|
||||
public float XieLouLv { get { return _xieloulv; } set { _xieloulv = value; } }
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 泄露率计算
|
||||
//单独动作泄露率
|
||||
public float CumulativeLeakageRate(List<float> inDoor_Tsi,List<float> out_Door_Tsi,float benDiNongdu,float xiShu)
|
||||
{
|
||||
if (inDoor_Tsi.Count != 0 && out_Door_Tsi.Count != 0)
|
||||
{
|
||||
//计算室内Tsi浓度平均值
|
||||
float inDoor_Tsi_Avg = inDoor_Tsi.Average();
|
||||
//计算室外Tsi浓度平均值
|
||||
float out_Door_Tsi_Avg = out_Door_Tsi.Average();
|
||||
//计算泄露率
|
||||
float leakageRate = ((out_Door_Tsi_Avg - benDiNongdu ) * xiShu)*100 / inDoor_Tsi_Avg;
|
||||
return leakageRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.00f;
|
||||
}
|
||||
|
||||
}
|
||||
//全部动作泄露率
|
||||
public float CumulativeLeakageRate_All(List<float> All_Cv_List)
|
||||
|
||||
{
|
||||
return All_Cv_List.Average();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
102
口罩泄露定制款/Data/Function.cs
Normal file
102
口罩泄露定制款/Data/Function.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using Modbus.Device;
|
||||
using Sunny.UI;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public class Function
|
||||
{
|
||||
ModbusMaster master;
|
||||
DataChange dc = new DataChange();
|
||||
public enum ButtonType
|
||||
{
|
||||
复归型,
|
||||
切换型,
|
||||
置位型,
|
||||
复位型
|
||||
}
|
||||
public enum DataType
|
||||
{
|
||||
整形,
|
||||
浮点型
|
||||
}
|
||||
public Function(ModbusMaster master_in)
|
||||
{
|
||||
this.master = master_in;
|
||||
}
|
||||
|
||||
public void BtnClickFunction(ButtonType buttonType, ushort address)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (buttonType)
|
||||
{
|
||||
case ButtonType.复归型:
|
||||
master?.WriteSingleCoil(1, address, true);
|
||||
Thread.Sleep(100);
|
||||
master?.WriteSingleCoil(1, address, false);
|
||||
Thread.Sleep(100);
|
||||
break;
|
||||
case ButtonType.切换型:
|
||||
if (master.ReadCoils(1, address, 1)[0])
|
||||
{
|
||||
master?.WriteSingleCoil(1, address, false);Thread.Sleep(100); }
|
||||
else
|
||||
{ master?.WriteSingleCoil(1, address, true); Thread.Sleep(100); }
|
||||
break;
|
||||
case ButtonType.置位型:
|
||||
master?.WriteSingleCoil(1, address, true);
|
||||
Thread.Sleep(100);
|
||||
break;
|
||||
case ButtonType.复位型:
|
||||
master?.WriteSingleCoil(1, address, false);
|
||||
Thread.Sleep(100);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public void WriteToPLC(string inPutValue, ushort address, DataType dataType)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
switch (dataType)
|
||||
{
|
||||
case DataType.浮点型:
|
||||
double value = inPutValue.ToDouble();
|
||||
if (UIInputDialog.ShowInputDoubleDialog(ref value, UIStyle.Inherited, desc: "请输入值", showMask: false))
|
||||
{
|
||||
|
||||
master.WriteMultipleRegisters(1, address, dc.SplitFloatToUShortArray((float)value));
|
||||
}
|
||||
break;
|
||||
case DataType.整形:
|
||||
int value_int = inPutValue.ToInt();
|
||||
if (UIInputDialog.ShowInputIntegerDialog(ref value_int, UIStyle.Inherited, desc: "请输入数据:"))
|
||||
{
|
||||
|
||||
master.WriteMultipleRegisters(1, address, dc.intToushorts(value_int));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("操作失败!" + "\n" + "\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
口罩泄露定制款/Data/IDGenerator.cs
Normal file
31
口罩泄露定制款/Data/IDGenerator.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public class IDGenerator
|
||||
{
|
||||
private static int currentID;
|
||||
private static readonly object lockObject = new object();
|
||||
private const string prefix = "ID-";
|
||||
private const string filePath = "currentID.txt";
|
||||
|
||||
static IDGenerator()
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
var idString = File.ReadAllText(filePath);
|
||||
int.TryParse(idString, out currentID);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateID()
|
||||
{
|
||||
lock (lockObject)
|
||||
{
|
||||
currentID++;
|
||||
File.WriteAllText(filePath, currentID.ToString());
|
||||
return $"{prefix}{currentID:D5}"; // 生成形如 "ID-00001" 的编号
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
口罩泄露定制款/Data/LoginData.cs
Normal file
21
口罩泄露定制款/Data/LoginData.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace 口罩泄露定制款
|
||||
{
|
||||
public class LoginData
|
||||
{
|
||||
static string _userName = "";
|
||||
public string UserName
|
||||
{
|
||||
get { return _userName; }
|
||||
set { _userName = value; }
|
||||
}
|
||||
|
||||
//登陆权限
|
||||
static int _userPower = 0;//0为普通用户,1为管理员
|
||||
public int UserPower
|
||||
{
|
||||
get { return _userPower; }
|
||||
set { _userPower = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
口罩泄露定制款/Data/PLC_Data.cs
Normal file
13
口罩泄露定制款/Data/PLC_Data.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 口罩泄露定制款.Data
|
||||
{
|
||||
internal class PLC_Data
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user