using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace FLY.Modbus
{
    /// <summary>
    /// 异常有异常事件
    /// </summary>
    public interface IModbusClient 
    {

        /// <summary>
        /// 读多个 COIL
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_01(UInt16 addr, UInt16 cnt, Action<bool[],object> AsyncDelegate, object AsyncState);


        /// <summary>
        /// 读多个Holding REGs
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_03(UInt16 addr, UInt16 cnt, Action<UInt16[], object> AsyncDelegate, object AsyncState);

        /// <summary>
        /// Write Single Coil
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_05(UInt16 addr, bool data);


        /// <summary>
        /// Write Single Coil,带返回
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="data"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_05(UInt16 addr, bool data, Action<object> AsyncDelegate, object AsyncState);


        /// <summary>
        /// 写多个coil
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="datas"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_0F(UInt16 addr, bool[] datas);


        /// <summary>
        /// 写多个coil,带返回
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="datas"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_0F(UInt16 addr, bool[] datas, Action<object> AsyncDelegate, object AsyncState);


        /// <summary>
        /// 写多个REG
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="datas"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_10(UInt16 addr, UInt16[] datas);


        /// <summary>
        /// 写多个REG,带返回
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="datas"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        /// <returns></returns>
        ModbusClient_Errno Do_10(UInt16 addr, UInt16[] datas, Action<object> AsyncDelegate, object AsyncState);
    }

    /// <summary>
    /// modbus客户端，指令返回值
    /// </summary>
    public enum ModbusClient_Errno
    {
        /// <summary>
        /// 成功
        /// </summary>
        OK = 0,
        /// <summary>
        /// 失败，trans 出错
        /// </summary>
        TOO_MUCH_TRANS = -1,
    }
}
