using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Threading;
using static GeneralGommunication.Modbus_Transaction;

namespace GeneralGommunication
{
    public interface IModbusAsciiAsync : INotifyPropertyChanged
    {
        /// <summary>
        /// 通讯速度测量模块
        /// </summary>
        CommSpeedMeasuring Csm { get; }

        /// <summary>
        /// 包出错次数
        /// </summary>
        int ErrCnt { get; }

        /// <summary>
        /// 有数据需要发送
        /// </summary>
        event SendDataEventHandler SendMsgEvent;

        /// <summary>
        /// 设备连接状态改变
        /// </summary>
        event DeviceConnectEventHander DeviceConnectEvent;

        /// <summary>
        /// 通讯中
        /// </summary>
        bool IsBusy();

        /// <summary>
        /// 检查发生列表是否包含某条指令
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="desription"></param>
        /// <returns></returns>
        bool Contain(int deviceNo, string desription);

        /// <summary>
        /// 设备是否连接成功
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <returns></returns>
        bool IsConnected(byte deviceNo);

        /// <summary>
        /// 接收回调调用
        /// </summary>
        /// <param name="recBuf"></param>
        void RecMsg(byte[] recBuf);

        /// <summary>
        /// 复位全部状态，通常由于通讯模块检测到连接断开导致的
        /// </summary>
        void ResetMsg();

        /// <summary>
        /// 添加 通讯任务
        /// </summary>
        /// <param name="tran"></param>
        void AddTran(Modbus_Transaction tran);

        /// <summary>
        /// 读多个Holding REGs
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="desription"></param>
        /// <param name="parseU16FuncPack"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        /// <returns></returns>
        Modbus_Transaction Do_03(int deviceNo, int addr, int cnt,
            string desription,
           ParseU16FuncPackHandler parseU16FuncPack,
           CallBackHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 读多个Input REGs
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="desription"></param>
        /// <param name="parseU16FuncPack"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        /// <returns></returns>
        Modbus_Transaction Do_04(int deviceNo, int addr, int cnt,
            string desription,
           ParseU16FuncPackHandler parseU16FuncPack,
           CallBackHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 写单个 Holding REG
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="desription"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        /// <returns></returns>
        Modbus_Transaction Do_06(int deviceNo, int addr, UInt16 value,
            string desription,
           CallBackHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 写多个 Holding REG
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="addr"></param>
        /// <param name="cnt"></param>
        /// <param name="desription"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        /// <returns></returns>
        Modbus_Transaction Do_10(int deviceNo, int addr, IEnumerable<UInt16> datas,
           string desription,
           CallBackHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// <para>任务内部转为发送的字节</para>
        /// <para>用于自定义指令</para>
        /// </summary>
        /// <param name="tran"></param>
        void ToSendBuf(Modbus_Transaction tran);
    }
}
