将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HslCommunication;
|
||||
using XP.Hardware.PLC.Configs;
|
||||
|
||||
namespace XP.Hardware.Plc.Abstractions
|
||||
{
|
||||
public interface IPlcClient : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 连接状态
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用配置连接PLC
|
||||
/// </summary>
|
||||
/// <param name="config">PLC配置</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> ConnectAsync(PlcConfig config);
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接
|
||||
/// </summary>
|
||||
void Disconnect();
|
||||
|
||||
/// <summary>
|
||||
/// 读取任意类型数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T">期望的数据类型</typeparam>
|
||||
/// <param name="address">地址 (如 "DB1.0.5" 或 "DB1.0" for byte)</param>
|
||||
/// <returns></returns>
|
||||
Task<T> ReadAsync<T>(string address);
|
||||
|
||||
/// <summary>
|
||||
/// 写入任意类型数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据类型</typeparam>
|
||||
/// <param name="address">地址</param>
|
||||
/// <param name="value">值</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> WriteAsync<T>(string address, T value);
|
||||
|
||||
/// <summary>
|
||||
/// 按指定长度读取字符串 | Read string with specified length
|
||||
/// </summary>
|
||||
/// <param name="address">地址 | Address</param>
|
||||
/// <param name="length">字符串长度(字节数)| String length in bytes</param>
|
||||
/// <returns>读取的字符串 | Read string</returns>
|
||||
Task<string> ReadStringAsync(string address, ushort length);
|
||||
|
||||
/// <summary>
|
||||
/// 按指定长度写入字符串 | Write string with specified length
|
||||
/// </summary>
|
||||
/// <param name="address">地址 | Address</param>
|
||||
/// <param name="value">字符串值 | String value</param>
|
||||
/// <param name="length">字符串长度(字节数)| String length in bytes</param>
|
||||
/// <returns>是否成功 | Whether succeeded</returns>
|
||||
Task<bool> WriteStringAsync(string address, string value, ushort length);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 批量读取字节数据 (对应旧代码中的 ReadDatas)
|
||||
/// </summary>
|
||||
/// <param name="dbBlock">数据块</param>
|
||||
/// <param name="startAddress">起始地址</param>
|
||||
/// <param name="length">读取长度(字节)</param>
|
||||
/// <returns></returns>
|
||||
Task<byte[]> ReadBytesAsync(string dbBlock, int startAddress, int length);
|
||||
|
||||
/// <summary>
|
||||
/// 写入字节数据
|
||||
/// </summary>
|
||||
/// <param name="dbBlock">数据块</param>
|
||||
/// <param name="startAddress">起始地址</param>
|
||||
/// <param name="data">数据</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> WriteBytesAsync(string dbBlock, int startAddress, byte[] data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using XP.Hardware.PLC.Configs;
|
||||
using XP.Hardware.PLC.Helpers;
|
||||
using XP.Hardware.PLC.Models;
|
||||
|
||||
namespace XP.Hardware.Plc.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC 服务接口,供跨模块使用 | PLC service interface for cross-module usage
|
||||
/// 提供 PLC 连接状态查询、信号管理和属性变更通知 | Provides PLC connection status query, signal management and property change notification
|
||||
/// </summary>
|
||||
public interface IPlcService : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC 连接状态 | PLC connection status
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态文本,用于 UI 显示 | Status text for UI display
|
||||
/// </summary>
|
||||
string StatusText { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 PLC 连接 | Initialize PLC connection
|
||||
/// </summary>
|
||||
/// <param name="config">PLC 配置 | PLC configuration</param>
|
||||
/// <returns>连接是否成功 | Whether connection succeeded</returns>
|
||||
Task<bool> InitializeAsync(PlcConfig config);
|
||||
|
||||
/// <summary>
|
||||
/// 加载信号定义文件 | Load signal definitions from XML file
|
||||
/// </summary>
|
||||
/// <param name="xmlFilePath">XML 信号定义文件路径 | XML signal definition file path</param>
|
||||
void LoadSignalDefinitions(string xmlFilePath);
|
||||
|
||||
/// <summary>
|
||||
/// 按名称查找信号定义 | Find signal definition by name
|
||||
/// </summary>
|
||||
/// <param name="signalName">信号逻辑名称 | Signal logical name</param>
|
||||
/// <returns>信号条目 | Signal entry</returns>
|
||||
SignalEntry FindSignal(string signalName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前批量读取缓存快照 | Get current bulk read cache snapshot
|
||||
/// </summary>
|
||||
/// <returns>缓存快照,缓存为空时返回 null | Cache snapshot, returns null when cache is empty</returns>
|
||||
PlcDataBlock GetCacheSnapshot();
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源 | Dispose resources
|
||||
/// </summary>
|
||||
void Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XP.Hardware.Plc.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC 信号数据交互服务接口 | PLC signal data interaction service interface
|
||||
/// 提供基于信号逻辑名称的读写操作 | Provides read/write operations based on signal logical names
|
||||
/// </summary>
|
||||
public interface ISignalDataService
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据信号名称读取解析值(非泛型)| Read parsed value by signal name (non-generic)
|
||||
/// 批量读取 DB 中的信号使用缓存解析,其他 DB 的信号使用单点读取
|
||||
/// Signals in bulk read DB use cache parsing, others use single-point read
|
||||
/// </summary>
|
||||
/// <param name="signalName">信号逻辑名称 | Signal logical name</param>
|
||||
/// <returns>解析后的信号值 | Parsed signal value</returns>
|
||||
/// <exception cref="XP.Hardware.PLC.Exceptions.PlcException">
|
||||
/// 信号未找到、数据缓存未就绪或单点读取失败时抛出 | Thrown when signal not found, cache not ready, or single-point read failed
|
||||
/// </exception>
|
||||
object GetValueByName(string signalName);
|
||||
|
||||
/// <summary>
|
||||
/// 根据信号名称读取解析值(泛型)| Read parsed value by signal name (generic)
|
||||
/// 批量读取 DB 中的信号使用缓存解析,其他 DB 的信号使用单点读取
|
||||
/// Signals in bulk read DB use cache parsing, others use single-point read
|
||||
/// </summary>
|
||||
/// <typeparam name="T">期望的返回类型 | Expected return type</typeparam>
|
||||
/// <param name="signalName">信号逻辑名称 | Signal logical name</param>
|
||||
/// <returns>解析后的信号值 | Parsed signal value</returns>
|
||||
/// <exception cref="XP.Hardware.PLC.Exceptions.PlcException">
|
||||
/// 信号未找到、数据缓存未就绪、单点读取失败或类型转换失败时抛出
|
||||
/// Thrown when signal not found, cache not ready, single-point read failed, or type conversion failed
|
||||
/// </exception>
|
||||
T GetValueByName<T>(string signalName);
|
||||
|
||||
/// <summary>
|
||||
/// 将写入任务提交到写入队列 | Enqueue write task to write queue
|
||||
/// </summary>
|
||||
/// <param name="signalName">信号逻辑名称 | Signal logical name</param>
|
||||
/// <param name="value">要写入的值 | Value to write</param>
|
||||
/// <returns>入队成功返回 true,队列已满或已停止返回 false | Returns true if enqueued, false if queue full or stopped</returns>
|
||||
/// <exception cref="XP.Hardware.PLC.Exceptions.PlcException">
|
||||
/// 信号未找到或类型不兼容时抛出 | Thrown when signal not found or type incompatible
|
||||
/// </exception>
|
||||
bool EnqueueWrite(string signalName, object value);
|
||||
|
||||
/// <summary>
|
||||
/// 直接写入并回读校验 | Direct write with read-back verification
|
||||
/// 绕过写入队列,使用独立通道高优先级写入 | Bypasses write queue, uses independent channel for high-priority write
|
||||
/// </summary>
|
||||
/// <param name="signalName">信号逻辑名称 | Signal logical name</param>
|
||||
/// <param name="value">要写入的值 | Value to write</param>
|
||||
/// <returns>回读校验通过返回 true,否则返回 false | Returns true if verification passed, false otherwise</returns>
|
||||
/// <exception cref="XP.Hardware.PLC.Exceptions.PlcException">
|
||||
/// 信号未找到或类型不兼容时抛出 | Thrown when signal not found or type incompatible
|
||||
/// </exception>
|
||||
Task<bool> WriteDirectWithVerify(string signalName, object value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using XP.Hardware.PLC.Models;
|
||||
|
||||
namespace XP.Hardware.PLC.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// XML 信号地址定义解析器接口 | XML signal address definition parser interface
|
||||
/// 提供 PlcAddrDfn.xml 的加载和保存功能 | Provides loading and saving of PlcAddrDfn.xml
|
||||
/// </summary>
|
||||
public interface IXmlSignalParser
|
||||
{
|
||||
/// <summary>
|
||||
/// 从文件加载信号分组列表 | Load signal group list from file
|
||||
/// </summary>
|
||||
/// <param name="filePath">XML 文件路径 | XML file path</param>
|
||||
/// <returns>信号分组列表 | Signal group list</returns>
|
||||
List<SignalGroup> LoadFromFile(string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// 按 SignalGroup 结构保存信号配置到文件 | Save signal configuration to file by SignalGroup structure
|
||||
/// </summary>
|
||||
/// <param name="filePath">XML 文件路径 | XML file path</param>
|
||||
/// <param name="groups">信号分组列表 | Signal group list</param>
|
||||
void SaveToFile(string filePath, List<SignalGroup> groups);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user