157 lines
4.0 KiB
C#
157 lines
4.0 KiB
C#
using OrpaonEMS.Core.Enums;
|
||
using Prism.Mvvm;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace OrpaonEMS.App.Models
|
||
{
|
||
/// <summary>
|
||
/// 读写信号
|
||
/// BMS的保持寄存器(功能码:读 0x03,写 0x06、0x10)
|
||
/// 一些阀值的设置及参数配置
|
||
/// </summary>
|
||
public class BmsRwCell : BindableBase
|
||
{
|
||
/// <summary>
|
||
/// 实例化函数
|
||
/// </summary>
|
||
public BmsRwCell(string name, int offset, double ratio, int index, int lengh, string address, bool focus, string unit, ValueRange valueRange, string WR)
|
||
{
|
||
this.Name = name;
|
||
this.Offset = offset;
|
||
this.Ratio = ratio;
|
||
this.Index = index;
|
||
this.Unit = unit;
|
||
this.Address = address;
|
||
//this.ValueRangeInfo = valueRange;
|
||
this.Lengh = lengh;
|
||
this.Focus = focus;
|
||
ValueRangeInfo = valueRange;
|
||
switch (WR)
|
||
{
|
||
case "读/写":
|
||
IOTypeInfo = IOType.RW;
|
||
break;
|
||
case "读":
|
||
IOTypeInfo = IOType.R;
|
||
break;
|
||
case "写":
|
||
IOTypeInfo = IOType.W;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private short _SrRtValue;
|
||
/// <summary>
|
||
/// 标签原始的实时值
|
||
/// </summary>
|
||
public short SrRtValue
|
||
{
|
||
get { return _SrRtValue; }
|
||
set
|
||
{
|
||
_SrRtValue = value;
|
||
RtValue = (value * Ratio) + Offset;
|
||
//LastUpdateTime = DateTime.Now;
|
||
}
|
||
}
|
||
|
||
private double _RtValue;
|
||
/// <summary>
|
||
/// 标签实时值
|
||
/// 工程含义值
|
||
/// </summary>
|
||
public double RtValue
|
||
{
|
||
get { return _RtValue; }
|
||
set { _RtValue = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写入的值
|
||
/// </summary>
|
||
public double WriteValue { get; set; }
|
||
|
||
///// <summary>
|
||
///// 写入设备的值
|
||
///// </summary>
|
||
//public ushort WriteDeviceValue { get; set; }
|
||
|
||
/// <summary>
|
||
/// 获取写入设备的值
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public ushort GetWriteDeviceValue()
|
||
{
|
||
//RtValue = (value * Ratio) + Offset;
|
||
|
||
if (Ratio != 0)
|
||
{
|
||
return (ushort)((RtValue - Offset) / Ratio);
|
||
}
|
||
|
||
//如果数据有问题的话,则返回之前的值
|
||
return (ushort)SrRtValue;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 偏移值
|
||
/// </summary>
|
||
public int Offset { get; set; }
|
||
|
||
/// <summary>
|
||
/// 分辨率
|
||
/// </summary>
|
||
public double Ratio { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// Index 连续区域的位置
|
||
/// </summary>
|
||
public int Index { get; set; }
|
||
|
||
/// <summary>
|
||
/// 值长度
|
||
/// </summary>
|
||
public int Lengh { get; set; }
|
||
|
||
/// <summary>
|
||
/// 地址标签
|
||
/// </summary>
|
||
public string Address { get; set; }
|
||
|
||
/// <summary>
|
||
/// 标签名称
|
||
/// </summary>
|
||
public string Name { get; set; }
|
||
|
||
/// <summary>
|
||
/// 单位
|
||
/// </summary>
|
||
public string Unit { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否关注这个数据,比如关注后,那么就在界面上展示,此时RaisePropertyChanged()就会被使能,单独在界面上展示否则就可以在表格里面展示
|
||
/// </summary>
|
||
public bool Focus { get; set; }
|
||
|
||
/// <summary>
|
||
/// 当前数据的范围
|
||
/// </summary>
|
||
public ValueRange ValueRangeInfo { get; set; }
|
||
|
||
/// <summary>
|
||
/// 读写类型
|
||
/// </summary>
|
||
public IOType IOTypeInfo { get; set; }
|
||
}
|
||
}
|