using System.Collections.Generic;
using System;
using System.Drawing;
using System.Diagnostics;
using System.Data;
using System.Collections;
using System.Windows.Forms;
using System.Threading.Tasks;

namespace vmsnet
{
	//###########################################################################################
	//##
	//##   작성자 : tindevil(tindevil@nate.com , tindevil@jdtek.co.kr)
	//##   소유자 : 작성자 , JDTEK
	//##   최초작성일 : 2011-11-16
	//##   설명 : DA100사용시 미리 정의한 함수목록
	//##
	//###########################################################################################
	
	
	/// <summary>
	/// 측정된 정보가 들어있는곳.. 센서의 갯수만큼이 배열로 존재한다. 내부 time,temp 는 같은배열크기를 가진다.
	/// </summary>
	/// <remarks></remarks>
	public class Mcdata
	{
		
		
		private List<double> dtime = new List<double>(0);
		private List<double> dtemp = new List<double>(0);
		public Mcdata()
		{
			dtime = new List<double>(0);
			dtemp = new List<double>(0);
		}
		
		
		
		/// <summary>
		/// 자료의 시간이 저장됨
		/// </summary>
		/// <value></value>
		/// <returns></returns>
		/// <remarks></remarks>
		public List<double> DataTime
		{
			get
			{
				return this.dtime;
			}
			set
			{
				this.dtime = value;
			}
		}
		
		/// <summary>
		/// 자료의 온도가 저장됨
		/// </summary>
		/// <value></value>
		/// <returns></returns>
		/// <remarks></remarks>
		public List<double> DataTemp
		{
			get
			{
				return this.dtemp;
			}
			set
			{
				this.dtemp = value;
			}
		}
	}
	
	
	/// <summary>
	/// 각장치마다 별도의 클래스가 될수있으므로 반드시 재정의 되어야한다.
	/// </summary>
	/// <remarks></remarks>
	public abstract class CMachine
    {
        public bool DoRequest = false; ////현재 진행중이라는 뜻
        public string IP; ////Ip Address
		public int PORT;
		public bool isOn; ////Connect  접속가능여부
		public bool isBusy; ////Busy 사용중인가
		public bool isLock; ////사용불가 플래그
		public short idx = (short) 0;
		public string Name;
		public bool Disable = true;
		public DateTime ConnectTry;
		public UInt16 ConnTryCount = 0;
		
		public enum ESENDMSGRESULT
		{
			SUC = 1,
			FAIL = 0,
			DISC = 2
		}
		
		/// <summary>
		/// 반환시 사용되는 데이터값
		/// </summary>
		/// <remarks></remarks>
		public struct ReturnData
		{
			/// <summary>
			/// yyyy-MM-dd HH:mm:ss
			/// </summary>
			public string time;
			public int value;
			public bool err;
			public short unit;
			public short ch;
			public bool timeerror;
			public bool dataerror;
		}
		
		public CMachine(string p_ip,int port, string name)
		{
			this.IP = p_ip;
			this.PORT = port;
			this.isOn = false;
			this.isBusy = false;
			this.isLock = false;
			this.Name = name;
		}

		/// <summary>
		/// 연결을시도합니다. 연결완료를 반환합니다.
		/// </summary>
		/// <returns></returns>
		/// <remarks></remarks>
		abstract public  Task<bool> Connect();

        /// <summary>
        /// 연결을 종료합니다.
        /// </summary>
        /// <remarks></remarks>
        abstract public void Disconnect();
		
		/// <summary>
		/// 데이터를 반환합니다.
		/// </summary>
		/// <param name="unitchs">시작유닛+채널번호입니다.(001 ~ 560)</param>
		/// <param name="unitche">종료유닛+채널번호입니다.(001 ~ 560)</param>
		/// <returns>반환데이터</returns>
		/// <remarks></remarks>
		abstract public ReturnData[] GetDataBinary(string unitchs, string unitche);
        abstract public ReturnData[] GetDataBinary(int unitchs, int unitche);

        abstract public bool SyncDate();
		abstract public bool SetInit();
		
		
	}
	
}
