1100 lines
28 KiB
C#
1100 lines
28 KiB
C#
using Community;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Web.Services.Description;
|
||
using System.Windows;
|
||
|
||
namespace Model
|
||
{
|
||
/// <summary>
|
||
/// 机种类
|
||
/// </summary>
|
||
public class MachineModel : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// ID
|
||
/// </summary>
|
||
public int ID { get; set; }
|
||
|
||
private string machineName;
|
||
/// <summary>
|
||
/// 机种名称
|
||
/// </summary>
|
||
public string MachineName
|
||
{
|
||
get { return machineName; }
|
||
set
|
||
{
|
||
machineName = value;
|
||
this.RaisePropertyChanged("MachineName");
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<RangeValueModel> measureRangeValue;
|
||
/// <summary>
|
||
/// 测量范围值
|
||
/// </summary>
|
||
public ObservableCollection<RangeValueModel> MeasureRangeValue
|
||
{
|
||
get { return measureRangeValue; }
|
||
set
|
||
{
|
||
measureRangeValue = value != null ? value : new ObservableCollection<RangeValueModel>();
|
||
|
||
this.RaisePropertyChanged("MeasureRangeValue");
|
||
}
|
||
}
|
||
|
||
|
||
private DateTime addTime;
|
||
/// <summary>
|
||
/// 添加时间
|
||
/// </summary>
|
||
public DateTime AddTime
|
||
{
|
||
get { return addTime; }
|
||
set
|
||
{
|
||
addTime = value;
|
||
this.RaisePropertyChanged("AddTime");
|
||
}
|
||
}
|
||
|
||
private bool enableS;
|
||
/// <summary>
|
||
/// 是否启用
|
||
/// </summary>
|
||
public bool EnableS
|
||
{
|
||
get { return enableS; }
|
||
set
|
||
{
|
||
enableS = value;
|
||
this.RaisePropertyChanged("EnableS");
|
||
}
|
||
}
|
||
|
||
private long cumulativeQuantity;
|
||
/// <summary>
|
||
/// 累计生产数量
|
||
/// </summary>
|
||
public long CumulativeQuantity
|
||
{
|
||
get { return cumulativeQuantity; }
|
||
set
|
||
{
|
||
cumulativeQuantity = value;
|
||
|
||
try
|
||
{
|
||
if (value > 0 && CumulativeProduce > 0)
|
||
{
|
||
CumulativeRejectRatio = Math.Round(((decimal)CumulativeProduce / value), 4);
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
this.RaisePropertyChanged("CumulativeQuantity");
|
||
}
|
||
}
|
||
|
||
|
||
private int cumulativeProduce;
|
||
/// <summary>
|
||
/// 累计产出
|
||
/// </summary>
|
||
public int CumulativeProduce
|
||
{
|
||
get { return cumulativeProduce; }
|
||
set
|
||
{
|
||
cumulativeProduce = value;
|
||
try
|
||
{
|
||
if (value > 0 && CumulativeQuantity > 0)
|
||
{
|
||
CumulativeRejectRatio = Math.Round(((decimal)value / CumulativeQuantity), 4);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
this.RaisePropertyChanged("CumulativeProduce");
|
||
}
|
||
}
|
||
|
||
private int cumulativeBads;
|
||
/// <summary>
|
||
/// 累计不良
|
||
/// </summary>
|
||
public int CumulativeBads
|
||
{
|
||
get { return cumulativeBads; }
|
||
set
|
||
{
|
||
cumulativeBads = value;
|
||
this.RaisePropertyChanged("CumulativeBads");
|
||
}
|
||
}
|
||
|
||
private decimal cumulativeRejectRatio;
|
||
/// <summary>
|
||
/// 累计良率
|
||
/// </summary>
|
||
public decimal CumulativeRejectRatio
|
||
{
|
||
get { return cumulativeRejectRatio; }
|
||
set
|
||
{
|
||
cumulativeRejectRatio = value;
|
||
this.RaisePropertyChanged("CumulativeRejectRatio");
|
||
}
|
||
}
|
||
|
||
private int quantitys;
|
||
/// <summary>
|
||
/// 生产数量(投入数量)
|
||
/// </summary>
|
||
public int Quantitys
|
||
{
|
||
get { return quantitys; }
|
||
set
|
||
{
|
||
|
||
if (value > 0 && quantitys > 0 && value > quantitys)
|
||
{
|
||
if (CumulativeQuantity > 0)
|
||
{
|
||
CumulativeQuantity += (value - quantitys);
|
||
}
|
||
else
|
||
{
|
||
CumulativeQuantity = value;
|
||
}
|
||
}
|
||
|
||
quantitys = value;
|
||
|
||
try
|
||
{
|
||
if (value > 0 && Produce > 0)
|
||
{
|
||
RejectRatio = Math.Round(((decimal)Produce / value), 4);
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
this.RaisePropertyChanged("Quantitys");
|
||
}
|
||
}
|
||
|
||
private int produce;
|
||
/// <summary>
|
||
/// 产出数量
|
||
/// </summary>
|
||
public int Produce
|
||
{
|
||
get { return produce; }
|
||
set
|
||
{
|
||
if (value > 0 && produce > 0 && value > produce)
|
||
{
|
||
if (CumulativeProduce > 0)
|
||
{
|
||
CumulativeProduce += (value - produce);
|
||
}
|
||
else
|
||
{
|
||
CumulativeProduce = value;
|
||
}
|
||
}
|
||
|
||
if (CumulativeProduce <= 0)
|
||
{
|
||
CumulativeProduce = value;
|
||
}
|
||
|
||
|
||
produce = value;
|
||
try
|
||
{
|
||
if (value > 0 && Quantitys > 0)
|
||
{
|
||
RejectRatio = Math.Round(((decimal)value / Quantitys), 4);
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
this.RaisePropertyChanged("Produce");
|
||
}
|
||
}
|
||
|
||
|
||
private int bads;
|
||
/// <summary>
|
||
/// 不良数量
|
||
/// </summary>
|
||
public int Bads
|
||
{
|
||
get { return bads; }
|
||
set
|
||
{
|
||
if (value > 0 && bads > 0 && value > bads)
|
||
{
|
||
CumulativeBads += (value - bads);
|
||
}
|
||
if (CumulativeBads <= 0)
|
||
{
|
||
CumulativeBads = value;
|
||
}
|
||
|
||
bads = value;
|
||
this.RaisePropertyChanged("Bads");
|
||
}
|
||
}
|
||
|
||
private decimal rejectRatio;
|
||
/// <summary>
|
||
/// 良率
|
||
/// </summary>
|
||
public decimal RejectRatio
|
||
{
|
||
get { return rejectRatio; }
|
||
set
|
||
{
|
||
rejectRatio = value;
|
||
|
||
this.RaisePropertyChanged("RejectRatio");
|
||
}
|
||
}
|
||
|
||
|
||
private double capacity;
|
||
/// <summary>
|
||
/// 产能
|
||
/// </summary>
|
||
public double Capacity
|
||
{
|
||
get { return capacity; }
|
||
set
|
||
{
|
||
capacity = value;
|
||
this.RaisePropertyChanged("Capacity");
|
||
}
|
||
}
|
||
|
||
private bool runningMode;
|
||
/// <summary>
|
||
/// 空跑模式
|
||
/// </summary>
|
||
public bool RunningMode
|
||
{
|
||
get { return runningMode; }
|
||
set
|
||
{
|
||
runningMode = value;
|
||
|
||
this.RaisePropertyChanged("RunningMode");
|
||
}
|
||
}
|
||
|
||
|
||
private MyParmeterModel myPar;
|
||
/// <summary>
|
||
/// 其他参数
|
||
/// </summary>
|
||
public MyParmeterModel MyPar
|
||
{
|
||
get { return myPar; }
|
||
set
|
||
{
|
||
myPar = value == null ? new MyParmeterModel() : value;
|
||
this.RaisePropertyChanged("MyPar");
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<CommandGroup> commandGroupList;
|
||
/// <summary>
|
||
/// 指令组集合
|
||
/// </summary>
|
||
public ObservableCollection<CommandGroup> CommandGroupList
|
||
{
|
||
get { return commandGroupList; }
|
||
set
|
||
{
|
||
commandGroupList = value != null ? value : new ObservableCollection<CommandGroup>() {
|
||
new CommandGroup(){ Number=1, Enable=true,NameStr="新来的"}
|
||
};
|
||
//RaisePropertyChanged("CommandGroupList");
|
||
}
|
||
}
|
||
|
||
#region 机器人点位参数集合
|
||
|
||
private List<RobotPoint> robotPointList;
|
||
/// <summary>
|
||
/// 机器人点位参数集合
|
||
/// </summary>
|
||
public List<RobotPoint> RobotPointList
|
||
{
|
||
get { return robotPointList; }
|
||
set
|
||
{
|
||
robotPointList = value;
|
||
this.RaisePropertyChanged("RobotPointList");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
public MachineModel()
|
||
{
|
||
RejectRatio = 1;
|
||
MyPar = new MyParmeterModel();
|
||
CommandGroupList = new ObservableCollection<CommandGroup>() { new CommandGroup() { Number = 1, Enable = true, NameStr = "新来的" } };
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 结果对象
|
||
/// </summary>
|
||
public class RangeValueModel : NotificationObject
|
||
{
|
||
private int rangeType;
|
||
/// <summary>
|
||
/// 解析方式 0:不解析 1:数值 2:ASCII
|
||
/// </summary>
|
||
public int RangeType
|
||
{
|
||
get { return rangeType; }
|
||
set
|
||
{
|
||
rangeType = value;
|
||
RaisePropertyChanged("RangeType");
|
||
}
|
||
}
|
||
|
||
private double maxValue;
|
||
/// <summary>
|
||
/// 最大值
|
||
/// </summary>
|
||
public double MaxValue
|
||
{
|
||
get { return maxValue; }
|
||
set
|
||
{
|
||
maxValue = value;
|
||
RaisePropertyChanged("MaxValue");
|
||
}
|
||
}
|
||
|
||
private double minValue;
|
||
/// <summary>
|
||
/// 最小值
|
||
/// </summary>
|
||
public double MinValue
|
||
{
|
||
get { return minValue; }
|
||
set
|
||
{
|
||
minValue = value;
|
||
RaisePropertyChanged("MinValue");
|
||
}
|
||
}
|
||
|
||
|
||
private string baseValue;
|
||
/// <summary>
|
||
/// 标准件值
|
||
/// </summary>
|
||
public string BaseValue
|
||
{
|
||
get { return baseValue; }
|
||
set
|
||
{
|
||
baseValue = value;
|
||
RaisePropertyChanged("BaseValue");
|
||
}
|
||
}
|
||
|
||
private string actualValue;
|
||
/// <summary>
|
||
/// 实际值
|
||
/// </summary>
|
||
public string ActualValue
|
||
{
|
||
get { return actualValue; }
|
||
set
|
||
{
|
||
actualValue = value;
|
||
RaisePropertyChanged("ActualValue");
|
||
}
|
||
}
|
||
|
||
private double fixValue;
|
||
/// <summary>
|
||
/// 对标差
|
||
/// </summary>
|
||
public double FixValue
|
||
{
|
||
get { return fixValue; }
|
||
set
|
||
{
|
||
fixValue = value;
|
||
RaisePropertyChanged("FixValue");
|
||
}
|
||
}
|
||
|
||
private double scalingFactor;
|
||
/// <summary>
|
||
/// 结果换算系数
|
||
/// </summary>
|
||
public double ScalingFactor
|
||
{
|
||
get { return scalingFactor; }
|
||
set { scalingFactor = value; RaisePropertyChanged("ScalingFactor"); }
|
||
}
|
||
|
||
|
||
private int result;
|
||
/// <summary>
|
||
/// 结果 0 未测 1 OK 2 NG
|
||
/// </summary>
|
||
public int Result
|
||
{
|
||
get { return result; }
|
||
set
|
||
{
|
||
result = value;
|
||
switch (value)
|
||
{
|
||
case 1:
|
||
ResultStr = "OK";
|
||
break;
|
||
case 2:
|
||
ResultStr = "NG";
|
||
break;
|
||
default:
|
||
ResultStr = "";
|
||
break;
|
||
}
|
||
|
||
RaisePropertyChanged("Result");
|
||
}
|
||
}
|
||
|
||
private string resultStr;
|
||
/// <summary>
|
||
/// 结果字符串
|
||
/// </summary>
|
||
public string ResultStr
|
||
{
|
||
get { return resultStr; }
|
||
set
|
||
{
|
||
resultStr = value;
|
||
RaisePropertyChanged("ResultStr");
|
||
}
|
||
}
|
||
|
||
private bool notControlled;
|
||
/// <summary>
|
||
/// 如果不受控 有值就OK
|
||
/// </summary>
|
||
public bool NotControlled
|
||
{
|
||
get { return notControlled; }
|
||
set { notControlled = value; RaisePropertyChanged("NotControlled"); }
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 计算结果
|
||
/// </summary>
|
||
public int GetResult()
|
||
{
|
||
if (NotControlled)//不受控 直接Ok
|
||
{
|
||
if (!string.IsNullOrEmpty(ActualValue))
|
||
{
|
||
Result = 1;
|
||
}else
|
||
{
|
||
Result = 2;
|
||
}
|
||
}
|
||
else if (RangeType == 1)
|
||
{
|
||
if (!string.IsNullOrEmpty(ActualValue))
|
||
{
|
||
double res = Convert.ToDouble(ActualValue);
|
||
Result = res >= MinValue && res <= MaxValue ? 1 : 2;
|
||
}else
|
||
{
|
||
Result = 2;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(BaseValue)&&!string.IsNullOrEmpty(ActualValue))
|
||
{
|
||
Result = ActualValue.Contains(BaseValue) ? 1 : 2;
|
||
}else
|
||
{
|
||
Result = 2;
|
||
}
|
||
}
|
||
|
||
return Result;
|
||
|
||
}
|
||
|
||
public RangeValueModel()
|
||
{
|
||
ScalingFactor = 1;
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 其他参数模型
|
||
/// </summary>
|
||
public class MyParmeterModel : NotificationObject
|
||
{
|
||
private int testTime;
|
||
/// <summary>
|
||
/// 测试时间
|
||
/// </summary>
|
||
public int TestTime
|
||
{
|
||
get { return testTime; }
|
||
set { testTime = value; RaisePropertyChanged("TestTime"); }
|
||
}
|
||
|
||
private double testHeatMin;
|
||
/// <summary>
|
||
/// 测试温度Min
|
||
/// </summary>
|
||
public double TestHeatMin
|
||
{
|
||
get { return testHeatMin; }
|
||
set { testHeatMin = value; RaisePropertyChanged("TestHeatMin"); }
|
||
}
|
||
|
||
private double testHeatMax;
|
||
/// <summary>
|
||
/// 测试温度Max
|
||
/// </summary>
|
||
public double TestHeatMax
|
||
{
|
||
get { return testHeatMax; }
|
||
set { testHeatMax = value; RaisePropertyChanged("TestHeatMax"); }
|
||
}
|
||
|
||
private int testModel;
|
||
/// <summary>
|
||
/// 测试模式 0:Can 1:Lin
|
||
/// </summary>
|
||
public int TestModel
|
||
{
|
||
get { return testModel; }
|
||
set { testModel = value; RaisePropertyChanged("TestModel"); }
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 产品状态集合
|
||
/// </summary>
|
||
public List<ShowInfo> StatusList { get; set; }
|
||
|
||
|
||
private double _ReadDelay = 1000;
|
||
public double ReadDelay
|
||
{
|
||
get { return _ReadDelay; }
|
||
set
|
||
{
|
||
_ReadDelay = value;
|
||
this.RaisePropertyChanged("ReadDelay");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指令组对象模型
|
||
/// </summary>
|
||
public class CommandGroup : NotificationObject
|
||
{
|
||
private int number;
|
||
/// <summary>
|
||
/// 序号
|
||
/// </summary>
|
||
public int Number
|
||
{
|
||
get { return number; }
|
||
set { number = value; RaisePropertyChanged("Number"); }
|
||
}
|
||
|
||
private string nameStr;
|
||
/// <summary>
|
||
/// 名称
|
||
/// </summary>
|
||
public string NameStr
|
||
{
|
||
get { return nameStr; }
|
||
set { nameStr = value; RaisePropertyChanged("NameStr"); }
|
||
}
|
||
|
||
private bool enable;
|
||
/// <summary>
|
||
/// 启用
|
||
/// </summary>
|
||
public bool Enable
|
||
{
|
||
get { return enable; }
|
||
set { enable = value; RaisePropertyChanged("Enable"); }
|
||
}
|
||
|
||
private string notes;
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
public string Notes
|
||
{
|
||
get { return notes; }
|
||
set { notes = value; RaisePropertyChanged("Notes"); }
|
||
}
|
||
|
||
private ObservableCollection<CommandModel> commandList;
|
||
/// <summary>
|
||
/// 指令集合
|
||
/// </summary>
|
||
public ObservableCollection<CommandModel> CommandList
|
||
{
|
||
get { return commandList; }
|
||
set
|
||
{
|
||
commandList = value == null ? new ObservableCollection<CommandModel>() : value;
|
||
RaisePropertyChanged("CommandList");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 运行是否完成
|
||
/// </summary>
|
||
public bool RunOK { get; set; }
|
||
|
||
/// <summary>
|
||
/// 结果
|
||
/// </summary>
|
||
public bool ResOK { get; set; }
|
||
|
||
public CommandGroup()
|
||
{
|
||
CommandList = new ObservableCollection<CommandModel>() { new CommandModel() };
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 指令采集模型
|
||
/// </summary>
|
||
public class CommandModel : NotificationObject
|
||
{
|
||
private string id;
|
||
/// <summary>
|
||
/// 指令ID (hex)
|
||
/// </summary>
|
||
public string ID
|
||
{
|
||
get { return id; }
|
||
set { id = value; RaisePropertyChanged("ID"); }
|
||
}
|
||
|
||
private string txID;
|
||
/// <summary>
|
||
/// 请求ID
|
||
/// </summary>
|
||
public string TxID
|
||
{
|
||
get { return txID; }
|
||
set { txID = value; RaisePropertyChanged("TxID"); }
|
||
}
|
||
|
||
private string rxID;
|
||
/// <summary>
|
||
/// 响应ID
|
||
/// </summary>
|
||
public string RxID
|
||
{
|
||
get { return rxID; }
|
||
set { rxID = value; RaisePropertyChanged("RxID"); }
|
||
}
|
||
|
||
private bool enable;
|
||
/// <summary>
|
||
/// 启用
|
||
/// </summary>
|
||
public bool Enable
|
||
{
|
||
get { return enable; }
|
||
set { enable = value; RaisePropertyChanged("Enable"); }
|
||
}
|
||
|
||
private string nameStr;
|
||
/// <summary>
|
||
/// 指令名称
|
||
/// </summary>
|
||
public string NameStr
|
||
{
|
||
get { return nameStr; }
|
||
set
|
||
{
|
||
nameStr = value;
|
||
RaisePropertyChanged("NameStr");
|
||
}
|
||
}
|
||
|
||
private int mytype;
|
||
/// <summary>
|
||
/// 类型 1:工厂模式 2:头部+响应 3:读取电流
|
||
/// </summary>
|
||
public int MyType
|
||
{
|
||
get { return mytype; }
|
||
set
|
||
{
|
||
mytype = value;
|
||
RaisePropertyChanged("MyType");
|
||
}
|
||
}
|
||
|
||
private int timeInterval;
|
||
/// <summary>
|
||
/// 时间间隔(毫秒)
|
||
/// </summary>
|
||
public int TimeInterval
|
||
{
|
||
get { return timeInterval; }
|
||
set
|
||
{
|
||
timeInterval = value;
|
||
RaisePropertyChanged("TimeInterval");
|
||
}
|
||
}
|
||
|
||
private string dataHex;
|
||
/// <summary>
|
||
/// 指令数据 (hex)
|
||
/// </summary>
|
||
public string DataHex
|
||
{
|
||
get { return dataHex; }
|
||
set
|
||
{
|
||
dataHex = value;
|
||
RaisePropertyChanged("DataHex");
|
||
}
|
||
}
|
||
|
||
private int dataLength;
|
||
/// <summary>
|
||
/// 数据长度
|
||
/// </summary>
|
||
public int DataLength
|
||
{
|
||
get { return dataLength; }
|
||
set
|
||
{
|
||
dataLength = value;
|
||
RaisePropertyChanged("DataLength");
|
||
}
|
||
}
|
||
|
||
private int parsingModel;
|
||
/// <summary>
|
||
/// 解析方式 0:不解析 1:数值 2:ASCII 3:带通道号的数字解析 4:不解析,隐藏显示
|
||
/// </summary>
|
||
public int ParsingModel
|
||
{
|
||
get { return parsingModel; }
|
||
set
|
||
{
|
||
parsingModel = value;
|
||
RaisePropertyChanged("ParsingModel");
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 运行完成
|
||
/// </summary>
|
||
public bool RunOK { get; set; }
|
||
|
||
/// <summary>
|
||
/// 结果
|
||
/// </summary>
|
||
public bool ResOK { get; set; }
|
||
|
||
|
||
private int sendCount;
|
||
/// <summary>
|
||
/// 发送次数
|
||
/// </summary>
|
||
public int SendCount
|
||
{
|
||
get { return sendCount; }
|
||
set
|
||
{
|
||
sendCount = value;
|
||
RaisePropertyChanged("SendCount");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private string returnValue;
|
||
/// <summary>
|
||
/// 返回值
|
||
/// </summary>
|
||
public string ReturnValue
|
||
{
|
||
get { return returnValue; }
|
||
set
|
||
{
|
||
returnValue = value;
|
||
RaisePropertyChanged("ReturnValue");
|
||
}
|
||
}
|
||
|
||
private RangeValueModel myValue;
|
||
/// <summary>
|
||
/// 执行结果 用于记录测试值
|
||
/// </summary>
|
||
public RangeValueModel MyValue
|
||
{
|
||
get { return myValue; }
|
||
set
|
||
{
|
||
myValue = value ?? new RangeValueModel();
|
||
|
||
RaisePropertyChanged("MyValue");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 结果解析
|
||
/// </summary>
|
||
public void ParsingResult()
|
||
{
|
||
try
|
||
{
|
||
List<string> strArr = ReturnValue.Trim().Split('-').ToList();
|
||
DataLength = DataLength >= 64 ? 8 : DataLength;//如果需要的字符长度大于等64 则直接取8位 追溯码 特殊情况
|
||
strArr = strArr.GetRange(5, DataLength);
|
||
if (ParsingModel == 0)
|
||
{
|
||
MyValue.ActualValue = string.Join("-", strArr);
|
||
}else
|
||
if (ParsingModel == 1)
|
||
{
|
||
// Hex转byte数组
|
||
byte[] dataBytes = strArr.Select(h => Convert.ToByte(h, 16)).ToArray();
|
||
// 1. 大端 32位无符号整数
|
||
// uint bigEndUint = BitConverter.ToUInt32(dataBytes.Reverse().ToArray(), 0);
|
||
|
||
// 2. 小端 32位无符号整数
|
||
uint res = BitConverter.ToUInt32(dataBytes, 0);
|
||
|
||
double jg = Math.Round((res * MyValue.ScalingFactor), 6);//转换系数 为了到达客户需求单位
|
||
MyValue.ActualValue = jg.ToString();
|
||
}
|
||
else if (ParsingModel == 2)
|
||
{
|
||
// Hex转byte数组
|
||
byte[] dataBytes = strArr.Select(h => Convert.ToByte(h, 16)).ToArray();
|
||
//按照指定编码将字节数组变为字符串
|
||
MyValue.ActualValue = System.Text.Encoding.ASCII.GetString(dataBytes);
|
||
}
|
||
else if (ParsingModel == 3)
|
||
{
|
||
strArr = strArr.GetRange(1, strArr.Count - 1);
|
||
if (strArr.Count > 2)
|
||
{
|
||
// Hex转byte数组
|
||
byte[] dataBytes = strArr.Select(h => Convert.ToByte(h, 16)).ToArray();
|
||
// 1. 大端 32位无符号整数
|
||
//uint res = BitConverter.ToUInt32(dataBytes.Reverse().ToArray(), 0);
|
||
|
||
// 2. 小端 32位无符号整数
|
||
uint res = BitConverter.ToUInt32(dataBytes, 0);
|
||
|
||
double jg = Math.Round((res * MyValue.ScalingFactor), 6);//转换系数 为了到达客户需求单位
|
||
MyValue.ActualValue = jg.ToString();
|
||
}
|
||
else
|
||
{
|
||
// Hex转byte数组
|
||
byte[] dataBytes = strArr.Select(h => Convert.ToByte(h, 16)).ToArray();
|
||
|
||
// 大端ushort
|
||
//ushort res = BitConverter.ToUInt16(dataBytes.Reverse().ToArray(), 0);
|
||
// 小端ushort
|
||
ushort res = BitConverter.ToUInt16(dataBytes, 0);
|
||
|
||
double jg = Math.Round((res * MyValue.ScalingFactor), 6);//转换系数 为了到达客户需求单位
|
||
MyValue.ActualValue = jg.ToString();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
//结算结果
|
||
MyValue.RangeType = ParsingModel;
|
||
MyValue.GetResult();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public CommandModel()
|
||
{
|
||
NameStr = "新来的";
|
||
MyValue = new RangeValueModel();
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指令返回值模型
|
||
/// </summary>
|
||
public class CommandReceive : NotificationObject
|
||
{
|
||
private string dir;
|
||
/// <summary>
|
||
/// TX代表PC-->MCU,RX代表MCU-->PC
|
||
/// </summary>
|
||
public string Dir
|
||
{
|
||
get { return dir; }
|
||
set
|
||
{
|
||
dir = value;
|
||
RaisePropertyChanged("ID");
|
||
}
|
||
}
|
||
|
||
private string id;
|
||
/// <summary>
|
||
/// 放回ID
|
||
/// </summary>
|
||
public string ID
|
||
{
|
||
get { return id; }
|
||
set
|
||
{
|
||
id = value;
|
||
RaisePropertyChanged("ID");
|
||
}
|
||
}
|
||
|
||
private int datalength;
|
||
/// <summary>
|
||
/// 数据长度
|
||
/// </summary>
|
||
public int Datalength
|
||
{
|
||
get { return datalength; }
|
||
set { datalength = value; RaisePropertyChanged("Datalength"); }
|
||
}
|
||
|
||
|
||
private int hexDataLength;
|
||
/// <summary>
|
||
/// 返回值Hex长度
|
||
/// </summary>
|
||
public int HexDataLength
|
||
{
|
||
get { return hexDataLength; }
|
||
set { hexDataLength = value; }
|
||
}
|
||
|
||
private string dataHex;
|
||
/// <summary>
|
||
/// 返回数据的Hex格式
|
||
/// </summary>
|
||
public string DataHex
|
||
{
|
||
get { return dataHex; }
|
||
set
|
||
{
|
||
dataHex = value;
|
||
ReceiptCompleted = GetLenght(value);
|
||
RaisePropertyChanged("DataHex");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数据接受完成
|
||
/// </summary>
|
||
public bool ReceiptCompleted { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 获取数据长度
|
||
/// </summary>
|
||
/// <param name="hex"></param>
|
||
/// <returns></returns>
|
||
public bool GetLenght(string hex)
|
||
{
|
||
bool bl = false;
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(hex))
|
||
{
|
||
List<string> strArr = hex.Split('-').ToList();
|
||
if (strArr.Count >= 8)
|
||
{
|
||
HexDataLength = strArr.Count - 6;//减6的目的是 去出头字符以及校验码
|
||
strArr = strArr.GetRange(2, 2);
|
||
// Hex转byte数组
|
||
byte[] dataBytes = strArr.Select(h => Convert.ToByte(h, 16)).ToArray();
|
||
// 1. 大端 32位无符号整数
|
||
//Datalength = BitConverter.ToUInt16(dataBytes.Reverse().ToArray(), 0);
|
||
// 2. 小端 32位无符号整数
|
||
Datalength = BitConverter.ToUInt16(dataBytes, 0);
|
||
|
||
if (HexDataLength >= Datalength)
|
||
{
|
||
bl = true;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
return bl;
|
||
}
|
||
|
||
}
|
||
|
||
}
|