添加项目文件。
This commit is contained in:
127
OrpaonEMS.App/Models/SwitchModel.cs
Normal file
127
OrpaonEMS.App/Models/SwitchModel.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using HslCommunication.ModBus;
|
||||
using OrpaonEMS.Model.Enums;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrpaonEMS.App.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 开关模型
|
||||
/// </summary>
|
||||
public class SwitchModel : BindableBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// 地址和ModbusPull一样
|
||||
/// 第一个合闸 第二个分闸
|
||||
/// </summary>
|
||||
public SwitchModel(string onAddress, string offAddress, ModbusTcpNet modbusTcpNet)
|
||||
{
|
||||
OnAddress = onAddress;
|
||||
OffAddress = offAddress;
|
||||
ModbusTcpNet = modbusTcpNet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开地址
|
||||
/// 开和关是不同的地址
|
||||
/// </summary>
|
||||
private string OnAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关地址
|
||||
/// 开和关是不同的地址
|
||||
/// </summary>
|
||||
private string OffAddress { get; set; }
|
||||
|
||||
private SwitchEm _CurSwtichState;
|
||||
/// <summary>
|
||||
/// 开关的状态
|
||||
/// 读取合闸的信号 DI读取
|
||||
/// </summary>
|
||||
public SwitchEm CurSwtichState
|
||||
{
|
||||
get { return _CurSwtichState; }
|
||||
set { _CurSwtichState = value; }
|
||||
}
|
||||
|
||||
private SwitchErr _CurSwtichErrInfo;
|
||||
/// <summary>
|
||||
/// 开关的故障状态
|
||||
/// 读取开关的Err信号 DI读取
|
||||
/// </summary>
|
||||
public SwitchErr CurSwtichErrInfo
|
||||
{
|
||||
get { return _CurSwtichErrInfo; }
|
||||
set { _CurSwtichErrInfo = value; }
|
||||
}
|
||||
|
||||
private SwitchStateInfo _CurSwitchStateInfo;
|
||||
/// <summary>
|
||||
/// 开关的状态
|
||||
/// </summary>
|
||||
public SwitchStateInfo CurSwitchStateInfo
|
||||
{
|
||||
get { return _CurSwitchStateInfo; }
|
||||
set { _CurSwitchStateInfo = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 开关的故障状态
|
||||
///// 读取开关的Err信号 DI读取
|
||||
///// </summary>
|
||||
//public SwitchErr CurSwtichErrInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 驱动
|
||||
/// </summary>
|
||||
public ModbusTcpNet ModbusTcpNet { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置Switch开和关
|
||||
/// 可实时赋值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool SetRtSwitch(SwitchEm state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case SwitchEm.On://开
|
||||
if (CurSwtichState == SwitchEm.Off)
|
||||
{
|
||||
Task.Run(new Action(() =>
|
||||
{
|
||||
ModbusTcpNet.Write(OnAddress, true);
|
||||
Thread.Sleep(100);
|
||||
ModbusTcpNet.Write(OnAddress, false);
|
||||
//可以判断DI的结果是否正确
|
||||
}));
|
||||
}
|
||||
break;
|
||||
case SwitchEm.Off://关
|
||||
if (CurSwtichState == SwitchEm.On)
|
||||
{
|
||||
Task.Run(new Action(() =>
|
||||
{
|
||||
ModbusTcpNet.Write(OffAddress, true);
|
||||
Thread.Sleep(100);
|
||||
ModbusTcpNet.Write(OffAddress, false);
|
||||
//可以判断DI的结果是否正确
|
||||
}));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user