设计模式
/// <summary>
/// PLC处理器
/// </summary>
public interface IPlcHandler
{
void Request(IPlcContext context);
}
/// <summary>
/// PLC的数据上下文
/// </summary>
public interface IPlcContext
{
PlcRequest Request { get; }
PlcResponse Response { get; }
//PLC处理器
IPlcHandler Handler { get; }
//请求参数
IDictionary<string, object?> Parameters { get; }
}
public class PlcRequest: PlcBase
{
//目标IP
public string Ip { get; set; }
//保持连接
public bool KeepAlive { get; set; }
public FastData[] DefaultData { get; set; }
}
public class PlcResponse: PlcBase
{
public PlcStatusCode StatusCode { get; set; } = PlcStatusCode.Ok;
//状态描述
public string? StatusDescription { get; set; }
}
//里面封装了一些简单的经常会用到的,公共区数据,
public class FastData
{
public DateTime DateTime { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public string Type { get; set; }
public string TypeCode { get; set; }
public void SaveData()
{
}
}
/// <summary>
/// PLC和上位机通信的状态码
/// </summary>
public enum PlcStatusCode
{
Ok=200,
Error=404,
Fail=500,
}
//PLC的基类
public abstract class PlcBase
{
public int ContentLength { get; set; } = -1;
public string? ContentType { get; set; }
public IDictionary<string, string> Headers { get; set; } = new NullableDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public string this[string key]
{
get
{
return Headers[key] ?? "";
}
set
{
Headers[key] = value;
}
}
}
本文作者:孤沉
本文链接:https://www.cnblogs.com/guchen33/p/17983378
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步