Tag模型
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
using HslCommunication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CapMachine.Wpf.Models.Tag
|
||||
{
|
||||
public interface IRegisterValue<T>
|
||||
/// <summary>
|
||||
/// 寄存器类型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IRegisterValue<T> : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
T Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值原始数据
|
||||
/// </summary>
|
||||
OperateResult<T> OperateResultSource { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Prism.Mvvm;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,10 +7,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.Models.Tag
|
||||
{
|
||||
/// <summary>
|
||||
/// 标签的接口
|
||||
/// </summary>
|
||||
public interface ITag
|
||||
{
|
||||
/// <summary>
|
||||
/// 中文名称
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
T RtValue { get; set; }
|
||||
/// <summary>
|
||||
/// 英文名称
|
||||
/// </summary>
|
||||
string EnName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using HslCommunication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.Models.Tag
|
||||
{
|
||||
public class RegisterValue : IRegisterValue<byte>
|
||||
{
|
||||
public byte Value { get; set; }
|
||||
public OperateResult<byte>? OperateResultSource { get; set; }
|
||||
}
|
||||
}
|
||||
31
CapMachine.Wpf/Models/Tag/ShortRegisterValue.cs
Normal file
31
CapMachine.Wpf/Models/Tag/ShortRegisterValue.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using HslCommunication;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.Models.Tag
|
||||
{
|
||||
/// <summary>
|
||||
/// Short类型的寄存器数据
|
||||
/// </summary>
|
||||
public class ShortRegisterValue :BindableBase, IRegisterValue<short>
|
||||
{
|
||||
private short _Value;
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public short Value
|
||||
{
|
||||
get { return _Value; }
|
||||
set { _Value = value;RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 寄存器原始数据
|
||||
/// </summary>
|
||||
public OperateResult<short>? OperateResultSource { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,39 +7,39 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
///// <summary>
|
||||
///// 字变量模型
|
||||
///// </summary>
|
||||
//public class ShortTag: BaseTag
|
||||
//public class ShortTag : BaseTag
|
||||
//{
|
||||
// public ShortTag(string name, string enName, string unit, ComEnum.TagType tagType) : base(name, enName, unit, tagType)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// private short _RtValue;
|
||||
// private TestType _RtValue;
|
||||
// /// <summary>
|
||||
// /// 实时值
|
||||
// /// </summary>
|
||||
// public override short RtValue
|
||||
// public override TestType RtValue
|
||||
// {
|
||||
// get { return _RtValue; }
|
||||
// set { _RtValue = value; RaisePropertyChanged(); }
|
||||
// }
|
||||
|
||||
// private OperateResult<short> _OperateResultSource;
|
||||
// /// <summary>
|
||||
// /// 原始值
|
||||
// /// </summary>
|
||||
// public override OperateResult<short> OperateResultSource
|
||||
// {
|
||||
// get { return _OperateResultSource; }
|
||||
// set
|
||||
// {
|
||||
// if (value != _OperateResultSource)
|
||||
// {
|
||||
// RtValue= value.Content;
|
||||
// }
|
||||
// _OperateResultSource = value;
|
||||
// }
|
||||
// }
|
||||
// //private OperateResult<short> _OperateResultSource;
|
||||
// ///// <summary>
|
||||
// ///// 原始值
|
||||
// ///// </summary>
|
||||
// //public override OperateResult<short> OperateResultSource
|
||||
// //{
|
||||
// // get { return _OperateResultSource; }
|
||||
// // set
|
||||
// // {
|
||||
// // if (value != _OperateResultSource)
|
||||
// // {
|
||||
// // RtValue = value.Content;
|
||||
// // }
|
||||
// // _OperateResultSource = value;
|
||||
// // }
|
||||
// //}
|
||||
|
||||
// private DataType _DataTypeInfo;
|
||||
// /// <summary>
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using HslCommunication;
|
||||
using ImTools;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static CapMachine.Wpf.Models.ComEnum;
|
||||
|
||||
namespace CapMachine.Wpf.Models.Tag
|
||||
@@ -14,7 +7,7 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
/// <summary>
|
||||
/// 基础模型
|
||||
/// </summary>
|
||||
public abstract class BaseTag : BindableBase
|
||||
public class Tag<T> : BindableBase, ITag
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
@@ -22,13 +15,16 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
/// <param name="name"></param>
|
||||
/// <param name="enName"></param>
|
||||
/// <param name="tagType"></param>
|
||||
public BaseTag(string name, string enName, string unit, TagType tagType)
|
||||
public Tag(string name, string enName, string unit, TagType tagType, IRegisterValue<T> registerValue)
|
||||
{
|
||||
TagTypeInfo = tagType;
|
||||
Name = name;
|
||||
Unit = unit;
|
||||
EnName = enName;
|
||||
|
||||
//实例化
|
||||
RtValue = registerValue;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,16 +37,25 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
/// </summary>
|
||||
public string EnName { get; set; }
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 实时值
|
||||
///// </summary>
|
||||
public abstract IRegisterValue<T> RtValue { get; set; }
|
||||
//public abstract IRegisterValue<short> RtValue { get; set; }
|
||||
|
||||
/////// <summary>
|
||||
/////// 原始值实时值
|
||||
/////// </summary>
|
||||
//public abstract OperateResult<T> OperateResultSource { get; set; } //
|
||||
private IRegisterValue<T> _RtValue;
|
||||
/// <summary>
|
||||
/// 寄存器
|
||||
/// </summary>
|
||||
public IRegisterValue<T> RtValue
|
||||
{
|
||||
get { return _RtValue; }
|
||||
set { _RtValue = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原始值实时值
|
||||
/// </summary>
|
||||
public OperateResult<T> OperateResultSource { get; set; } //
|
||||
|
||||
/// <summary>
|
||||
/// 标签类型信息
|
||||
@@ -60,7 +65,7 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
/// <summary>
|
||||
/// 数据类型信息
|
||||
/// </summary>
|
||||
public abstract DataType DataTypeInfo { get; set; }
|
||||
public DataType DataTypeInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址信息
|
||||
@@ -98,4 +103,12 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
/// </summary>
|
||||
public int SamplingPeriod { get; set; }
|
||||
}
|
||||
|
||||
public struct TestType
|
||||
{
|
||||
public short shortValue { get; set; }
|
||||
public byte byteValue { get; set; }
|
||||
public double doubleValue { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using NPOI.SS.Formula.PTG;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -9,35 +10,68 @@ namespace CapMachine.Wpf.Models.Tag
|
||||
{
|
||||
/// <summary>
|
||||
/// 标签管理中心
|
||||
/// 对标签的操作在这里进行
|
||||
/// </summary>
|
||||
public class TagManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
public TagManager()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标签集合数据
|
||||
/// </summary>
|
||||
public List<BaseTag> ListTag = new List<BaseTag>();
|
||||
public Dictionary<string, ITag> DicTags = new Dictionary<string, ITag>();
|
||||
|
||||
///// <summary>
|
||||
///// 增加标签
|
||||
///// </summary>
|
||||
//public void AddTag(BaseTag baseTag)
|
||||
//{
|
||||
// ListTag.Add(baseTag);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 增加标签
|
||||
/// </summary>
|
||||
public void AddTag<T>(Tag<T> baseTag)
|
||||
{
|
||||
DicTags[baseTag.Name] = baseTag;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 增加集合标签
|
||||
///// </summary>
|
||||
///// <param name="baseTags"></param>
|
||||
//public void AddRange(List<BaseTag<object>> baseTags)
|
||||
//{
|
||||
// ListTag.AddRange(baseTags);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 获取标签信息
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public Tag<T>? GetTagByName<T>(string name)
|
||||
{
|
||||
//return ListTag.OfType<BaseTag<T>>()
|
||||
// .FirstOrDefault(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// 尝试从字典中获取标签,并使用 as 关键字避免类型转换失败抛出异常
|
||||
if (DicTags.TryGetValue(name, out var FindTag))
|
||||
{
|
||||
return FindTag as Tag<T>;// 成功转换返回具体类型的标签,失败返回 null
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取标签的值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public T? GetTagValueByName<T>(string name)
|
||||
{
|
||||
var FindTag = GetTagByName<T>(name);
|
||||
|
||||
// 如果找到标签,则返回其值,否则返回默认值
|
||||
if (FindTag != null)
|
||||
{
|
||||
return FindTag!.RtValue.Value;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user