using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneralGommunication
{
    public class Modbus_Transaction
    {
        /// <summary>
        /// 输出调试信息
        /// </summary>
        public bool EnableLog = true;

        /// <summary>
        /// 交易描述
        /// </summary>
        public string desription;

        /// <summary>
        /// 设备编号 0~255 0是广播
        /// </summary>
        public int deviceNo;

        /// <summary>
        /// modbus 功能号
        /// </summary>
        public byte func;

        /// <summary>
        /// 数据地址
        /// </summary>
        public int addr;

        /// <summary>
        /// 操作的寄存器数量
        /// </summary>
        public int cnt;

        /// <summary>
        /// 期待接收的数据量
        /// </summary>
        public int expRecBytes;

        public List<byte> sendBuf = new List<byte>();

        /// <summary>
        /// 功能 的数据
        /// </summary>
        public List<byte> funcData = new List<byte>();


        /// <summary>
        /// u16 读取处理
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public delegate object ParseU16FuncPackHandler(List<UInt16> values);

        /// <summary>
        /// u16 数据回复处理
        /// </summary>
        public ParseU16FuncPackHandler parse16FuncPack;

        /// <summary>
        /// bool 读取处理
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public delegate object ParseBoolFuncPackHandler(List<bool> values);

        /// <summary>
        /// bool 数据回复处理
        /// </summary>
        public ParseBoolFuncPackHandler parseBoolFuncPack;


        /// <summary>
        /// 回复的数据，只用于调试而已
        /// </summary>
        public object retData;

        /// <summary>
        /// 回复 callback
        /// </summary>
        public CallBackHandler asyncDelegate;

        /// <summary>
        /// 上下文
        /// </summary>
        public object asyncContext;

    }

    public delegate void DeviceConnectEventHander(object sender, DeviceConnectEventArgs e);
    public class DeviceConnectEventArgs : EventArgs
    {
        public int deviceNo;
        public bool isConnected;
        public string errMsg;
    }

    public delegate void SendDataEventHandler(object sender, byte[] data);


    public delegate void TimeOutEventHandler(object sender);
}
