初始化版本
This commit is contained in:
294
SLC1-N/yiqiParam.cs
Normal file
294
SLC1-N/yiqiParam.cs
Normal file
@@ -0,0 +1,294 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SLC1_N
|
||||
{
|
||||
public class yiqiParam // 仪器参数类
|
||||
{
|
||||
public bool opmode { get; set; } // 开口/容积
|
||||
|
||||
// 时间
|
||||
public int fulltime { get; set; } // 充气时间
|
||||
public int balantime { get; set; } // 平衡时间
|
||||
public int testtime1 { get; set; } // 检测时间
|
||||
public int exhausttime { get; set; } // 排气时间
|
||||
|
||||
// 延时
|
||||
public int relievedelay { get; set; } // 解除2延时
|
||||
public int delaytime1 { get; set; } // 延时1
|
||||
public int delaytime2 { get; set; } // 延时2
|
||||
public float evolume { get; set; } // 等效容积
|
||||
|
||||
// 压力
|
||||
public float fptoplimit { get; set; } // 充气上限
|
||||
public float fplowlimit { get; set; } // 充气下限
|
||||
public float balanpremax { get; set; } // 平衡上限
|
||||
public float balanpremin { get; set; } // 平衡下限
|
||||
|
||||
// 泄漏量
|
||||
public float leaktoplimit { get; set; } // 泄漏量上限
|
||||
public float leaklowlimit { get; set; } // 泄漏量下限
|
||||
|
||||
// 单位
|
||||
public int punit { get; set; } // 压力单位
|
||||
public int lunit { get; set; } // 泄漏量单位
|
||||
|
||||
// 获取需要上传的数据帧
|
||||
public int[] GetArray()
|
||||
{
|
||||
// 拆分 float 值为两个16位整数
|
||||
int[] FPtoplimitBytes = Fun_SplitBytes(fptoplimit);
|
||||
int[] FPlowlimitBytes = Fun_SplitBytes(fplowlimit);
|
||||
int[] BalanPreMaxBytes = Fun_SplitBytes(balanpremax);
|
||||
int[] BalanPreMinBytes = Fun_SplitBytes(balanpremin);
|
||||
int[] LeaktoplimitBytes = Fun_SplitBytes(leaktoplimit);
|
||||
int[] LeaklowlimitBytes = Fun_SplitBytes(leaklowlimit);
|
||||
int[] EvolumeBytes = Fun_SplitBytes(evolume);
|
||||
|
||||
return new int[]
|
||||
{
|
||||
fulltime * 10, // 充气时间
|
||||
balantime * 10, // 平衡时间
|
||||
testtime1 * 10, // 检测时间
|
||||
exhausttime * 10, // 排气时间
|
||||
|
||||
relievedelay, // 解除2延时
|
||||
delaytime1, // 延时1
|
||||
delaytime2, // 延时2
|
||||
|
||||
FPtoplimitBytes[0], FPtoplimitBytes[1], // 充气上限
|
||||
FPlowlimitBytes[0], FPlowlimitBytes[1], // 充气下限
|
||||
BalanPreMaxBytes[0], BalanPreMaxBytes[1], // 平衡上限
|
||||
BalanPreMinBytes[0], BalanPreMinBytes[1], // 平衡下限
|
||||
LeaktoplimitBytes[0], LeaktoplimitBytes[1],// 泄漏量上限
|
||||
LeaklowlimitBytes[0], LeaklowlimitBytes[1],// 泄漏量下限
|
||||
|
||||
EvolumeBytes[0], EvolumeBytes[1], // 等效容积
|
||||
punit, // 压力单位
|
||||
lunit, // 泄漏量单位
|
||||
};
|
||||
}
|
||||
|
||||
// 将 float 拆分为两个(低字在前,高字在后)
|
||||
public int[] Fun_SplitBytes(float value)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(value);
|
||||
ushort lowWord = BitConverter.ToUInt16(bytes, 0); // 低位(地址1015)
|
||||
ushort highWord = BitConverter.ToUInt16(bytes, 2); // 高位(地址1016)
|
||||
return new int[] { lowWord, highWord }; // 返回 [low, high]
|
||||
}
|
||||
|
||||
// 复制
|
||||
public yiqiParam Copy()
|
||||
{
|
||||
return new yiqiParam
|
||||
{
|
||||
fulltime = this.fulltime,
|
||||
balantime = this.balantime,
|
||||
testtime1 = this.testtime1,
|
||||
exhausttime = this.exhausttime,
|
||||
|
||||
relievedelay = this.relievedelay,
|
||||
delaytime1 = this.delaytime1,
|
||||
delaytime2 = this.delaytime2,
|
||||
evolume = this.evolume,
|
||||
|
||||
fptoplimit = this.fptoplimit,
|
||||
fplowlimit = this.fplowlimit,
|
||||
balanpremax = this.balanpremax,
|
||||
balanpremin = this.balanpremin,
|
||||
|
||||
leaktoplimit = this.leaktoplimit,
|
||||
leaklowlimit = this.leaklowlimit,
|
||||
punit = this.punit,
|
||||
lunit = this.lunit
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 测试记录
|
||||
/// <summary>
|
||||
/// 添加一次测试记录到链表,导出的时候再集成链表为string
|
||||
/// </summary>
|
||||
public class TestRecord
|
||||
{
|
||||
private int ch;
|
||||
|
||||
public string Code { get; set; } // 条码
|
||||
|
||||
// 仪器参数配置
|
||||
public yiqiParam yiqiP_Param { get; set; } // 正压参数
|
||||
public yiqiParam yiqiN_Param { get; set; } // 负压参数
|
||||
|
||||
// 测试状态
|
||||
public bool IsPTested { get; set; } // 正压是否已测试
|
||||
public bool IsNTested { get; set; } // 负压是否已测试
|
||||
|
||||
// 测试结果
|
||||
public bool Result { get; set; } // 测试结果
|
||||
|
||||
// 正压
|
||||
public string PTestPressure { get; set; } // 正压测试压力
|
||||
public string PLeak { get; set; } // 正压泄漏量
|
||||
|
||||
// 负压
|
||||
public string NTestPressure { get; set; } // 负压测试压力
|
||||
public string NLeak { get; set; } // 负压泄漏量
|
||||
|
||||
List<string> testRecord_list = new List<string>();
|
||||
|
||||
public TestRecord(int ch)
|
||||
{
|
||||
this.ch = ch;
|
||||
}
|
||||
|
||||
// 添加一次记录
|
||||
public void AddRecord()
|
||||
{
|
||||
testRecord_list.Add(GetRecord());
|
||||
}
|
||||
|
||||
// 获取记录数据
|
||||
private string GetRecord()
|
||||
{
|
||||
string currentTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
string resultText = Result ? "OK" : "NG";
|
||||
|
||||
List<string> records = new List<string>();
|
||||
|
||||
// 正压记录
|
||||
if (IsPTested && yiqiP_Param != null)
|
||||
{
|
||||
string pressureUnit = GetPUnit(yiqiP_Param.punit);
|
||||
string leakageUnit = GetLUnitText(yiqiP_Param.lunit);
|
||||
|
||||
string positiveRecord = $"CH{ch}[正压] 时间 {currentTime} 条形码{Code} 结果{resultText} " +
|
||||
$"充气时间{yiqiP_Param.fulltime}s " +
|
||||
$"平衡时间{yiqiP_Param.balantime}s " +
|
||||
$"测试时间{yiqiP_Param.testtime1}s " +
|
||||
$"排气时间{yiqiP_Param.exhausttime}s " +
|
||||
$"测试压力{PTestPressure}{pressureUnit} " +
|
||||
$"泄漏量{PLeak}{leakageUnit}";
|
||||
records.Add(positiveRecord);
|
||||
}
|
||||
|
||||
// 负压记录
|
||||
if (IsNTested && yiqiN_Param != null)
|
||||
{
|
||||
string pressureUnit = GetPUnit(yiqiN_Param.punit);
|
||||
string leakageUnit = GetLUnitText(yiqiN_Param.lunit);
|
||||
|
||||
string negativeRecord = $"CH{ch}[负压] 时间 {currentTime} 条形码{Code} 结果{resultText} " +
|
||||
$"充气时间{yiqiN_Param.fulltime}s " +
|
||||
$"平衡时间{yiqiN_Param.balantime}s " +
|
||||
$"测试时间{yiqiN_Param.testtime1}s " +
|
||||
$"排气时间{yiqiN_Param.exhausttime}s " +
|
||||
$"测试压力{NTestPressure}{pressureUnit} " +
|
||||
$"泄漏量{NLeak}{leakageUnit}";
|
||||
records.Add(negativeRecord);
|
||||
}
|
||||
|
||||
return string.Join(Environment.NewLine, records);
|
||||
}
|
||||
|
||||
// 获取记录集合
|
||||
public string GetRecordList()
|
||||
{
|
||||
return string.Join(Environment.NewLine, testRecord_list) + "\n";
|
||||
}
|
||||
|
||||
// 获取正压记录
|
||||
public string GetPRecord()
|
||||
{
|
||||
if (!IsPTested || yiqiP_Param == null)
|
||||
return null;
|
||||
|
||||
string currentTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
string resultText = Result ? "OK" : "NG";
|
||||
string pressureUnit = GetPUnit(yiqiP_Param.punit);
|
||||
string leakageUnit = GetLUnitText(yiqiP_Param.lunit);
|
||||
|
||||
return $"CH4 时间 {currentTime} 条形码{Code} 结果{resultText} " +
|
||||
$"正压充气时间{yiqiP_Param.fulltime}s " +
|
||||
$"正压平衡时间{yiqiP_Param.balantime}s " +
|
||||
$"正压测试时间{yiqiP_Param.testtime1}s " +
|
||||
$"正压排气时间{yiqiP_Param.exhausttime}s " +
|
||||
$"正压测试压力{PTestPressure:0.00}{pressureUnit} " +
|
||||
$"正压泄漏量{PLeak:0.00}{leakageUnit}";
|
||||
}
|
||||
|
||||
// 获取负压记录
|
||||
public string GetNRecord()
|
||||
{
|
||||
if (!IsNTested || yiqiN_Param == null)
|
||||
return null;
|
||||
|
||||
string currentTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
string resultText = Result ? "OK" : "NG";
|
||||
string pressureUnit = GetPUnit(yiqiN_Param.punit);
|
||||
string leakageUnit = GetLUnitText(yiqiN_Param.lunit);
|
||||
|
||||
return $"CH4 时间 {currentTime} 条形码{Code} 结果{resultText} " +
|
||||
$"负压充气时间{yiqiN_Param.fulltime}s " +
|
||||
$"负压平衡时间{yiqiN_Param.balantime}s " +
|
||||
$"负压测试时间{yiqiN_Param.testtime1}s " +
|
||||
$"负压排气时间{yiqiN_Param.exhausttime}s " +
|
||||
$"负压测试压力{NTestPressure:0.00}{pressureUnit} " +
|
||||
$"负压泄漏量{NLeak:0.00}{leakageUnit}";
|
||||
}
|
||||
|
||||
// 重置
|
||||
public void Reset()
|
||||
{
|
||||
Code = string.Empty;
|
||||
IsPTested = false;
|
||||
IsNTested = false;
|
||||
Result = false;
|
||||
PTestPressure = string.Empty;
|
||||
PLeak = string.Empty;
|
||||
NTestPressure = string.Empty;
|
||||
NLeak = string.Empty;
|
||||
|
||||
testRecord_list.Clear();
|
||||
}
|
||||
|
||||
// 获取压力单位文本
|
||||
private string GetPUnit(int unit)
|
||||
{
|
||||
string PUnit = "Pa"; // 默认值
|
||||
switch (unit)
|
||||
{
|
||||
case 0: PUnit = "Pa"; break;
|
||||
case 1: PUnit = "KPa"; break;
|
||||
case 2: PUnit = "MPa"; break;
|
||||
case 3: PUnit = "bar"; break;
|
||||
case 4: PUnit = "Psi"; break;
|
||||
case 5: PUnit = "kg/cm^2"; break;
|
||||
case 6: PUnit = "atm"; break;
|
||||
case 7: PUnit = "mmHg"; break;
|
||||
}
|
||||
return PUnit;
|
||||
}
|
||||
|
||||
// 获取泄漏量单位文本
|
||||
private string GetLUnitText(int unit)
|
||||
{
|
||||
string LUnit = "Pa"; // 默认值
|
||||
switch (unit)
|
||||
{
|
||||
case 0: LUnit = "Pa"; break;
|
||||
case 1: LUnit = "KPa"; break;
|
||||
case 2: LUnit = "mbar"; break;
|
||||
case 3: LUnit = "atm"; break;
|
||||
case 4: LUnit = "sccm"; break;
|
||||
case 5: LUnit = "ccm3/s"; break;
|
||||
case 6: LUnit = "Pa/s"; break;
|
||||
}
|
||||
return LUnit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user