using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlcCom
{
    public interface IPlcComProtocol
    {
        /// <summary>
        /// 通讯是否连通过
        /// </summary>
        bool IsConnected { get; set; }
        /// <summary>
        /// 连接PLC
        /// </summary>
        /// <returns>返回代码rt, 0：成功，其它：失败；errReason：原因</returns>
        (uint rt, string errReason) ConnectPLC();

        /// <summary>
        /// 关闭连接
        /// </summary>
        /// <returns>返回代码，0：成功，其它：失败</returns>
        uint Close();

        /// <summary>
        /// 读取指定地址和指定类型的值
        /// </summary>
        /// <param name="address">PLC地址字符串</param>
        /// <param name="result">返回的读取结果</param>
        /// <returns>返回代码，0：成功，其它：失败</returns>
        uint ReadValue(string address,out object result);

        /// <summary>
        /// 批量读取数据
        /// </summary>
        /// <param name="addresses">要读取的地址列表</param>
        /// <param name="results">返回读取结果列表</param>
        /// <returns>返回代码，0：成功，其它：失败</returns>
        uint ReadValue(List<string> addresses, out List<object> results);

        /// <summary>
        /// 写入值到指定地址
        /// </summary>
        /// <param name="address">要写入的地址</param>
        /// <param name="value">要写入的值</param>
        /// <param name="result">写入的结果</param>
        /// <returns>返回代码，0：成功，其它：失败</returns>
        uint WriteValue(string address, object value, ref uint result);

        /// <summary>
        /// 批量写入数据
        /// </summary>
        /// <param name="addresses">要读取的地址列表</param>
        /// <param name="values">要写入的值列表</param>
        /// <returns>返回代码，0：成功，其它：失败</returns>
        uint WriteValue(List<string> addresses, List<object> values,ref List<uint> resultList);
    }
}