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

namespace GeneralGommunication
{
    /// <summary>
    /// 通用通讯接口
    /// general communication
    /// </summary>
    public interface IGeneralComm : INotifyPropertyChanged
    {
        /// <summary>
        /// IP 地址 and 端口号
        /// </summary>
        string Addr { get; set; }

        /// <summary>
        /// 是否异常
        /// </summary>
        bool IsError { get; }

        /// <summary>
        /// 异常信息
        /// </summary>
        string ErrMsg { get; }

        /// <summary>
        /// 连接成功
        /// </summary>
        bool IsConnected { get; }


        /// <summary>
        /// 运行中
        /// </summary>
        bool IsRunning { get; }

        /// <summary>
        /// 开始
        /// </summary>
        void Start();

        /// <summary>
        /// 结束
        /// </summary>
        void Stop();

        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="buf"></param>
        void Write(byte[] buf);


        /// <summary>
        /// 接收数据
        /// </summary>
        event IGeneralCommDataReceivedHandler DataReceived;

        /// <summary>
        /// 清空输入缓存
        /// </summary>
        void DiscardInBuffer();
    }

    public delegate void IGeneralCommDataReceivedHandler(IGeneralComm sender, byte[] buf);
}
