using System;
using System.Text;
using System.Runtime.InteropServices;

namespace Pti4
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class Ccappt
	{
		public Ccappt()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		//======================================================================
		//======================================================================
		//	API-CAP(W32)
		//	CCAPPT.CS											CONTEC.CO.,LTD.
		//======================================================================
		//======================================================================

		//-----------------------------------------------------
		// Defination
		//-----------------------------------------------------
		public const int	SPEED_150MS		=	150000;		//150ms
		public const int	SPEED_40MS		=	40000;		//40ms
		public const int	SPEED_5MS		=	5000;		//5ms
		public const int	SPEED_1P5MS		=	1500;		//1.5ms

		public const short	AVE_NO_AVE		=	0;		//Not averaging
		public const short	AVE_NUMBER		=	1;		//Average on times
		public const short	AVE_TIME		=	2;		//Average on time

		public const short	LINEAR_TEMP		=	0;		//Return the temperature value
		public const short	LINEAR_OHM		=	1;		//Return the resistance capacity

		public const short	ADJ_CONTEC		=	0;		//Use the calibrated value in shipment inspection
		public const short	ADJ_USER		=	1;		//Use the user setting

		public const short	DIPSW_LINE		=	0;		//3-Lines, 4-Lines
		public const short	DIPSW_PT_JPT	=	1;		//JPT100, PT100

		public const short	DIPSW_LINE_4	=	0;		//4-Lines
		public const short	DIPSW_LINE_3	=	1;		//3-Lines
		public const short	DIPSW_JPT100	=	0;		//JPT100
		public const short	DIPSW_PT100		=	1;		//PT100

		//-----------------------------------------------------
		// Return value
		//-----------------------------------------------------
		public const short	PT_ERR_SUCCESS				=	0;		//Successed.
		public const short	PT_ERR_INI_MEMORY			=	3;		//Cannot allocate memory.
		public const short	PT_ERR_INI_REGISTRY			=	4;		//Cannot acceess registory.
		public const short	PT_ERR_DLL_DEVICE_NAME		=	10000;	//Used DeviceName unwritten in registory.
		public const short	PT_ERR_DLL_INVALID_ID		=	10001;	//Invalid Id.
		public const short	PT_ERR_START				=	10002;	//Start error.
		public const short	PT_ERR_DLL_CREATE_FILE		=	10003;	//Cannot open.
		public const short	PT_ERR_DLL_CLOSE_FILE		=	10004;	//Close error.
		public const short	PT_ERR_ACCESS_RIGHT			=	10005;	//Access rights error.
		public const short	PT_ERR_DLL_TIMEOUT			=	10006;	//Timeout.
		public const short	PT_ERR_INFO_INVALID_DEVICE	=	10050;	//Invalid device.
		public const short	PT_ERR_INFO_NOT_FIND_DEVICE	=	10051;	//Not find device.
		public const short	PT_ERR_DLL_BUFF_ADDRESS		=	10100;	//Buffer address error.
		public const short	PT_ERR_CH_NO				=	20100;	//Invalid channel number.
		public const short	PT_ERR_VALUE				=	20101;	//Invalid value.
		public const short	PT_ERR_OVER_RANGE			=	20102;	//Input data is out of measurement possible range.
		public const short	PT_ERR_NOT_START			=	20103;	//Device is not start.
		
		//-----------------------------------------------------
		// Prototype
		//-----------------------------------------------------
		[DllImport("CCAPPT.DLL")]
		public static extern int PtInit(StringBuilder DeviceName, ref short Id);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtExit(short Id);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetErrorString(int Err, StringBuilder ErrMsg);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtQueryDeviceName(short Index, ref short GroupID, ref short UnitID, ref short DeviceID, StringBuilder DeviceName, StringBuilder Device);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetAccessRight(ref byte AccsRight);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetDirectMode(short Id, short DirectMode);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetIOInterval(int Interval);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtStartIO(short Id, short Start);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetRemoteStatus(short Id, ref byte Start, ref byte Status);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetUpdateTiming(short Id, int Speed);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetUpdateTiming(short Id, ref int Speed);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetAverage(short Id, short Type, int Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetAverage(short Id, ref short Type, ref int Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetAlarm(short Id, short ChNo, short Enable, int UpperUpper, int UpperLower, int LowerUpper, int LowerLower);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetAlarm(short Id, short ChNo, ref short Enable, ref int UpperUpper, ref int UpperLower, ref int LowerUpper, ref int LowerLower);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetLinearise(short Id, short Linearise);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetLinearise(short Id, ref short Linearise);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetAdjustmentData(short Id, short ChNum, short IsUser, ref int Offset, ref int Gain);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetAdjustmentData(short Id, short ChNum, ref short IsUser, ref int Offset, ref int Gain);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSingleInput(short Id, short ChNo, ref int Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSingleInputEx(short Id, short ChNo, ref float Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtMultiInput(short Id, short ChNum, [MarshalAs(UnmanagedType.LPArray)]int Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtMultiInputEx(short Id, short ChNum, [MarshalAs(UnmanagedType.LPArray)]float[] Data);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetCurrentAlarmStatus(short Id, ref int UpperStatus, ref int LowerStatus);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetLatchedAlarmStatus(short Id, ref int UpperStatus, ref int LowerStatus);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtResetLatchedAlarmStatus(short Id, int UpperStatus, int LowerStatus);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetDisconnectStatus(short Id, ref int Status);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetSWStatus(short Id, short Type, ref short Status);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtSetChannelDisable(short Id, int Disable);
		[DllImport("CCAPPT.DLL")]
		public static extern int PtGetChannelDisable(short Id, ref int Disable);
	}
}
