Files
YuPu-OrpaonEMS/OrpaonEMS.Core/Model/LinkStateModel.cs
2025-02-28 22:23:13 +08:00

79 lines
2.2 KiB
C#

using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrpaonEMS.Core.Model
{
/// <summary>
/// 连接状态模型
/// 有些设备有时候会出现一次连接失败,但是下一次就会连接成功,那么不能判断为连接失败
/// </summary>
public class LinkStateModel : BindableBase
{
public LinkStateModel()
{
_LinkState = true;
}
private string _BmsLinkStateMsg = "失败";
/// <summary>
/// Bms通信状态Msg
/// </summary>
public string BmsLinkStateMsg
{
get { return _BmsLinkStateMsg; }
set { _BmsLinkStateMsg = value; RaisePropertyChanged(); }
}
private bool _LinkState;
/// <summary>
/// 通信连接状态
/// </summary>
public bool LinkState
{
get { return _LinkState; }
set
{
if (_LinkState != value)
{
if (value)//改变后连接成功
{
//连接成功了就把报错的设置为0
LinkErrCount = 0;
BmsLinkStateMsg = "正常";
_LinkState = value;
}
else//改变后连接失败
{
//
LinkErrCount = LinkErrCount + 1;
if (LinkErrCount >= 3)//连续达到三次算作报错
{
BmsLinkStateMsg = "失败";
//连接失败
_LinkState = false;
}
else
{
//小于三次的话则判定为没有问题
_LinkState = true;
}
}
}
}
}
/// <summary>
/// 通信连接失败次数
/// </summary>
public int LinkErrCount { get; set; }
}
}