2026-01-25 09:45:38 +08:00

117 lines
3.2 KiB
C#
Raw 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 S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RIZO.Model.PLC
{
/// <summary>
/// 单个数据点模型
/// </summary>
public class PlcDataItem
{
/// <summary>
/// 数据项的唯一标识符 "产品计数", "温度值", "电机状态"
/// </summary>
public string Name { get; set; }
/// <summary>
/// 存储PLC返回的原始数据类型根据实际VarType动态变化
/// </summary>
public object Value { get; set; }
/// <summary>
/// 最后一次成功读取数据的时间戳
/// </summary>
public DateTime LastUpdateTime { get; set; }
/// <summary>
/// 最近一次读取操作是否成功
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
/// 读取失败时保存的错误信息
/// </summary>
public string ErrorMessage { get; set; }
}
/// <summary>
/// 工站完整数据模型
/// </summary>
public class StationData
{
/// <summary>
/// 工站的唯一标识符
/// </summary>
public string StationName { get; set; }
/// <summary>
/// 该工站所有数据项的集合
/// </summary>
public Dictionary<string, PlcDataItem> DataItems { get; set; } = new();
/// <summary>
/// S7.Net库的PLC连接实例
/// </summary>
public Plc PlcConnection { get; set; }
/// <summary>
/// 当前PLC连接状态
/// </summary>
public bool IsConnected { get; set; }
/// <summary>
/// 最后一次成功读取所有数据项的时间
/// </summary>
public DateTime LastReadTime { get; set; }
public DateTime LastConnectTime { get; set; }
public int ReadFailureCount { get; set; }
}
// API响应DTO
public class StationDataDto
{
/// <summary>
/// 工站名称(直接传递)
/// </summary>
public string StationName { get; set; }
/// <summary>
/// 仅包含数据值的简化字典
///{
///"产品计数": { Value: 100, IsSuccess: true, LastUpdateTime: ..., ErrorMessage: "" },
///"温度值": { Value: 25.6f, IsSuccess: true, LastUpdateTime: ..., ErrorMessage: "" }
///}
/// </summary>
public Dictionary<string, object> CurrentValues { get; set; } = new();
/// <summary>
/// 工站连接状态
/// </summary>
public bool IsConnected { get; set; }
public DateTime LastUpdateTime { get; set; }
public DateTime LastReadTime { get; set; }
public DateTime LastConnectTime { get; set; }
public int ReadFailureCount { get; set; }
}
/// <summary>
/// 所有工站数据的集合
/// </summary>
public class AllStationsDataDto
{
public Dictionary<string, StationDataDto> Stations { get; set; } = new();
public DateTime ServerTime { get; set; } = DateTime.Now;
public int TotalStations { get; set; }
public int ConnectedStations { get; set; }
}
}