Files
FATrace/FATrace.WPLApp/Services/SysRunService.cs
2026-01-29 22:15:34 +08:00

193 lines
5.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FATrace.WPLApp.Models;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FATrace.WPLApp.Services
{
public class SysRunService : BindableBase
{
public SysRunService(IEventAggregator eventAggregator)
{
// 创建一个定时器设置间隔时间为2000毫秒即2秒
CurTimer = new System.Timers.Timer(5000);
CurTimer.AutoReset = true;
// 设置Elapsed事件处理程序
CurTimer.Elapsed += CurTimer_Elapsed;
// 启动定时器
CurTimer.Start();
}
private string _PlcIp;
/// <summary>
/// PLC IP
/// </summary>
public string PlcIp
{
get => _PlcIp;
set { _PlcIp = value; RaisePropertyChanged(); UpdatePlcEndPoint(); }
}
private int _PlcPort;
/// <summary>
/// PLC 端口
/// </summary>
public int PlcPort
{
get => _PlcPort;
set { _PlcPort = value; RaisePropertyChanged(); UpdatePlcEndPoint(); }
}
private string _PlcEndPoint;
/// <summary>
/// PLC 终端显示IP:Port
/// </summary>
public string PlcEndPoint
{
get => _PlcEndPoint;
private set { _PlcEndPoint = value; RaisePropertyChanged(); }
}
private void UpdatePlcEndPoint()
{
PlcEndPoint = string.IsNullOrWhiteSpace(PlcIp) ? string.Empty : $"{PlcIp}:{PlcPort}";
}
private bool _PlcLinkState = false;
/// <summary>
/// PLC连接状态
/// </summary>
public bool PlcLinkState
{
get { return _PlcLinkState; }
set { _PlcLinkState = value;RaisePropertyChanged(); }
}
private int _PlcScanState = 0;
/// <summary>
/// PLC扫描循环状态
/// 0=已停止1=运行中2=异常退出
/// </summary>
public int PlcScanState
{
get { return _PlcScanState; }
set
{
if (_PlcScanState != value)
{
_PlcScanState = value;
switch (value)
{
case 1:
PlcScanMsg = "扫描运行";
break;
case 2:
PlcScanMsg = "扫描异常";
break;
default:
PlcScanMsg = "扫描停止";
break;
}
RaisePropertyChanged();
}
}
}
private string? _PlcScanMsg = "扫描停止";
/// <summary>
/// PLC扫描循环状态消息
/// </summary>
public string? PlcScanMsg
{
get { return _PlcScanMsg; }
set { _PlcScanMsg = value; RaisePropertyChanged(); }
}
private string? _CurUser;
/// <summary>
/// 当前的用户
/// </summary>
public string? CurUser
{
get { return _CurUser; }
set
{
if (_CurUser != value)
{
_CurUser = value;
if (string.IsNullOrEmpty(value))
{
IsLogin = false;
CurAccessLevel = null;
}
else
{
IsLogin = true;
}
RaisePropertyChanged();
}
}
}
private string? _CurAccessLevel;
/// <summary>
/// 当前用户等级(管理员/操作员/访客)
/// </summary>
public string? CurAccessLevel
{
get { return _CurAccessLevel; }
set
{
if (_CurAccessLevel != value)
{
_CurAccessLevel = value;
RaisePropertyChanged();
}
}
}
private bool _IsLogin;
/// <summary>
/// 登录
/// </summary>
public bool IsLogin
{
get { return _IsLogin; }
set { _IsLogin = value; RaisePropertyChanged(); }
}
/// <summary>
/// 运行状态
/// </summary>
public SysRunState SysRunState { get; set; } = new SysRunState();
/// <summary>
/// 定时器
/// </summary>
private System.Timers.Timer CurTimer { get; set; }
private DateTime _CurDateTime;
/// <summary>
/// 当前时间信息
/// </summary>
public DateTime CurDateTime
{
get { return _CurDateTime; }
set { _CurDateTime = value; RaisePropertyChanged(); }
}
private void CurTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
CurDateTime = DateTime.Now;
}
}
}