添加项目文件。
This commit is contained in:
78
OrpaonEMS.Core/Model/LinkStateModel.cs
Normal file
78
OrpaonEMS.Core/Model/LinkStateModel.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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; }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user