288 lines
9.2 KiB
C#
288 lines
9.2 KiB
C#
using CapMachine.Model;
|
||
using CapMachine.Wpf.Models.ProModelPars;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace CapMachine.Wpf.Tool
|
||
{
|
||
public class CALCHelper
|
||
{
|
||
/// <summary>
|
||
/// 计算斜率-分
|
||
/// </summary>
|
||
public static int GetSlop(double Value1, double Value2, int TimeSed)
|
||
{
|
||
var diff = Value2 - Value1;
|
||
var TimeMin = TimeSed * 1.0 / 60;
|
||
if (TimeSed == 0) return 0;
|
||
var Result = (int)Math.Ceiling(diff / TimeMin);
|
||
if (Result > 9999)
|
||
{
|
||
return 9999;
|
||
}
|
||
if (Result < -1999)
|
||
{
|
||
return -1999;
|
||
}
|
||
return Result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算斜率-秒-DB表
|
||
/// </summary>
|
||
public static int GetSlopSed(double Value1, double Value2, int TimeSed)
|
||
{
|
||
var diff = Value2 - Value1;
|
||
//var TimeMin = TimeSed * 1.0 / 60;
|
||
if (TimeSed == 0) return 0;//0应该是OFF功能
|
||
var Result = diff / TimeSed;
|
||
if (Result > 2000)
|
||
{
|
||
return 2000;
|
||
}
|
||
if (Result < -1999.9)
|
||
{
|
||
return -1999;
|
||
}
|
||
if (Result >= 0)
|
||
{
|
||
return (int)Math.Ceiling(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
else
|
||
{
|
||
return (int)Math.Floor(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
|
||
//return (int)Math.Ceiling(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算斜率-分鐘-DB表
|
||
/// </summary>
|
||
public static int GetSlopMinute(double Value1, double Value2, int TimeSed)
|
||
{
|
||
var diff = Value2 - Value1;
|
||
var TimeMin = TimeSed * 1.0 / 60;
|
||
if (TimeSed == 0) return 0;//0应该是OFF功能
|
||
var Result = diff / TimeMin;
|
||
if (Result > 2000)
|
||
{
|
||
return 2000;
|
||
}
|
||
if (Result < -1999.9)
|
||
{
|
||
return -1999;
|
||
}
|
||
if (Result >= 0)
|
||
{
|
||
return (int)Math.Ceiling(Result * 10);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
else
|
||
{
|
||
return (int)Math.Floor(Result * 10);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算斜率-小时-DB表
|
||
/// </summary>
|
||
public static int GetSlopHour(double Value1, double Value2, int TimeSed)
|
||
{
|
||
var diff = Value2 - Value1;
|
||
var TimeHour = TimeSed * 1.0 / 3600;
|
||
if (TimeSed == 0) return 0;//0应该是OFF功能
|
||
var Result = diff / TimeHour;
|
||
if (Result > 2000)
|
||
{
|
||
return 2000;
|
||
}
|
||
if (Result < -1999.9)
|
||
{
|
||
return -1999;
|
||
}
|
||
if (Result >= 0)
|
||
{
|
||
return (int)Math.Ceiling(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
else
|
||
{
|
||
return (int)Math.Floor(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 计算斜率-秒-DB表 CV
|
||
/// </summary>
|
||
public static int GetSlopCVMinute(double Value1, double Value2, int TimeSed)
|
||
{
|
||
var diff = Value2 - Value1;
|
||
//var TimeMin = TimeSed * 1.0 / 60;
|
||
if (TimeSed == 0) return 0;//0应该是OFF功能
|
||
var Result = diff / TimeSed;
|
||
if (Result > 2000)
|
||
{
|
||
return 2000;
|
||
}
|
||
if (Result < -1999.9)
|
||
{
|
||
return -1999;
|
||
}
|
||
if (Result >= 0)
|
||
{
|
||
return (int)Math.Ceiling(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
else
|
||
{
|
||
return (int)Math.Floor(Result);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
}
|
||
|
||
}
|
||
|
||
///// <summary>
|
||
///// 计算斜率-秒-DB表
|
||
///// </summary>
|
||
//public static int GetSlopSed(double Value1, double Value2, int TimeSed)
|
||
//{
|
||
// var diff = Value2 - Value1;
|
||
// //var TimeMin = TimeSed * 1.0 / 60;
|
||
// if (TimeSed == 0) return 0;//0应该是OFF功能
|
||
// var Result = diff / TimeSed;
|
||
// if (Result > 2000)
|
||
// {
|
||
// return 2000 * 10;
|
||
// }
|
||
// if (Result < -1999.9)
|
||
// {
|
||
// return -1999 * 10;
|
||
// }
|
||
// return (int)Math.Ceiling(Result * 10);//乘以10是DB表的通信上的范围数据要求的,实际显示x.x
|
||
//}
|
||
|
||
/// <summary>
|
||
/// SV值的数据获取
|
||
/// </summary>
|
||
/// <param name="sourceData"></param>
|
||
/// <param name="accuracy"></param>
|
||
/// <returns></returns>
|
||
public static int GetQuickSV(double sourceData, short accuracy)
|
||
{
|
||
return (int)(sourceData * (int)Math.Pow(10, accuracy));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 比较是否有改变的数据
|
||
/// </summary>
|
||
/// <param name="NextData"></param>
|
||
/// <param name="CurrentData"></param>
|
||
/// <param name="Field"></param>
|
||
/// <returns></returns>
|
||
public static bool CpStepExecuteCompareInfo(ProStepExe NextData, ProStepExe CurrentData, string Field)
|
||
{
|
||
switch (Field)
|
||
{
|
||
case "PID":
|
||
if (NextData.PIDNo == CurrentData.PIDNo) return true;
|
||
return false;
|
||
case "SV":
|
||
if (NextData.EndSV == CurrentData.EndSV) return true;
|
||
return false;
|
||
case "Limit":
|
||
if (NextData.LimitNo == CurrentData.LimitNo) return true;
|
||
return false;
|
||
case "Alarm":
|
||
if (NextData.AlarmNo == CurrentData.AlarmNo) return true;
|
||
return false;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 比较是否有改变的数据
|
||
/// </summary>
|
||
/// <param name="NextData"></param>
|
||
/// <param name="CurrentData"></param>
|
||
/// <param name="Field"></param>
|
||
/// <returns></returns>
|
||
public static bool KpStepExecuteCompareInfo(ProStepExe NextData, ProStepExe CurrentData, string Field)
|
||
{
|
||
switch (Field)
|
||
{
|
||
case "PID":
|
||
if (NextData.PIDNo == CurrentData.PIDNo) return true;
|
||
return false;
|
||
case "SV":
|
||
if (NextData.EndSV == CurrentData.EndSV) return true;
|
||
return false;
|
||
case "Limit":
|
||
if (NextData.LimitNo == CurrentData.LimitNo) return true;
|
||
return false;
|
||
case "Alarm":
|
||
if (NextData.AlarmNo == CurrentData.AlarmNo) return true;
|
||
return false;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 判断Limit下载的次序
|
||
/// </summary>
|
||
/// <param name="NextData"></param>
|
||
/// <param name="CurrentData"></param>
|
||
/// <returns></returns>
|
||
public static int CpStepExecuteLimitCompareInfo(ProStepExe NextData, ProStepExe CurrentData)
|
||
{
|
||
if (NextData.CurConfigLimitDto.Down >= CurrentData.CurConfigLimitDto.Up)
|
||
{
|
||
//先下载Up,后下载Down
|
||
return 1;
|
||
}
|
||
if (NextData.CurConfigLimitDto.Up <= CurrentData.CurConfigLimitDto.Down)
|
||
{
|
||
//先下载Down,后下载Up
|
||
return 3;
|
||
}
|
||
|
||
//正常下载 Down和Up顺序都可以
|
||
return 2;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断Limit下载的次序
|
||
/// </summary>
|
||
/// <param name="NextData"></param>
|
||
/// <param name="CurrentData"></param>
|
||
/// <returns></returns>
|
||
public static int KpStepExecuteLimitCompareInfo(ProStepExe NextData, ProStepExe CurrentData)
|
||
{
|
||
if (NextData.CurConfigLimitDto.Down >= CurrentData.CurConfigLimitDto.Up)
|
||
{
|
||
//先下载Up,后下载Down
|
||
return 1;
|
||
}
|
||
if (NextData.CurConfigLimitDto.Up <= CurrentData.CurConfigLimitDto.Down)
|
||
{
|
||
//先下载Down,后下载Up
|
||
return 3;
|
||
}
|
||
|
||
//正常下载 Down和Up顺序都可以
|
||
return 2;
|
||
}
|
||
|
||
|
||
|
||
//private long GetProDur(QuickStep quickStep)
|
||
//{
|
||
// return 0;
|
||
//}
|
||
}
|
||
}
|