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

namespace Pti4
{
	/// <summary>
	/// Ccappt ̊Tv̐łB
	/// </summary>
	public class Ccappt
	{
		public Ccappt()
		{
			// 
			// TODO: RXgN^ WbNɒǉĂB
			//
		}
		//======================================================================
		//======================================================================
		//	API-CAP(W32)
		//	CCAPPT.CS											CONTEC.CO.,LTD.
		//======================================================================
		//======================================================================

		//-----------------------------------------------------
		// `l
		//-----------------------------------------------------
		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;		//ωȂ
		public const short	AVE_NUMBER		=	1;		//񐔕
		public const short	AVE_TIME		=	2;		//ԕ

		public const short	LINEAR_TEMP		=	0;		//xԂ܂B
		public const short	LINEAR_OHM		=	1;		//RlԂ܂B

		public const short	ADJ_CONTEC		=	0;		//o׌̍Zlgp
		public const short	ADJ_USER		=	1;		//[U[ݒgp

		public const short	DIPSW_LINE		=	0;		//3A4
		public const short	DIPSW_PT_JPT	=	1;		//JPT100APT100

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

		//-----------------------------------------------------
		// ߂l
		//-----------------------------------------------------
		public const short	PT_ERR_SUCCESS				=	0;		//I 
		public const short	PT_ERR_INI_MEMORY			=	3;		//̊蓖ĂɎs܂B 
		public const short	PT_ERR_INI_REGISTRY			=	4;		//WXg̃ANZXɎs܂B 
		public const short	PT_ERR_DLL_DEVICE_NAME		=	10000;	//WXgɓo^ĂȂfoCXw肳܂B 
		public const short	PT_ERR_DLL_INVALID_ID		=	10001;	//IDw肳܂B 
		public const short	PT_ERR_START				=	10002;	//W[NɃG[܂B
		public const short	PT_ERR_DLL_CREATE_FILE		=	10003;	//nh̎擾ɍ쐬Ɏs܂B 
		public const short	PT_ERR_DLL_CLOSE_FILE		=	10004;	//nh̃N[YɎs܂B
		public const short	PT_ERR_ACCESS_RIGHT			=	10005;	//ANZXG[łB
		public const short	PT_ERR_DLL_TIMEOUT			=	10006;	//ʐM^CAEg܂B
		public const short	PT_ERR_INFO_INVALID_DEVICE	=	10050;	//w肵foCX̂܂BXymFĂB 
		public const short	PT_ERR_INFO_NOT_FIND_DEVICE	=	10051;	//p\ȃfoCX܂B  
		public const short	PT_ERR_DLL_BUFF_ADDRESS		=	10100;	//f[^obt@AhXsłB 
		public const short	PT_ERR_CH_NO				=	20100;	//`lԍw\͈͂𒴂Ă܂B 
		public const short	PT_ERR_VALUE				=	20101;	//lw\͈͂zĂ܂B
		public const short	PT_ERR_OVER_RANGE			=	20102;	//肵xv\Ȕ͈͂zĂ܂B
		public const short	PT_ERR_NOT_START			=	20103;	//foCX͂܂NĂ܂B
		
			//-----------------------------------------------------
		// vg^Cv
		//-----------------------------------------------------
		[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);
	}
}
