//
//		TEXIO USB488 Access Lib  Ver 1.00
//
//*     Copyright(c) 2012  TEXIO TECHNOLOGY CORPORATION 

#include "stdafx.h"
#include  "TMI_API.h"


TMI_API::TMI_API()
{
	
	m_TMI_HandleOpen		= NULL;
	m_TMI_HandleClose		= NULL;
	m_TMI_TimeOut			= NULL;
	m_TMI_Refresh			= NULL;
	m_TMI_ModelNameQ		= NULL;
	m_TMI_Voltage			= NULL;
	m_TMI_VoltageQ			= NULL;
	m_TMI_Current			= NULL;
	m_TMI_CurrentQ			= NULL;
	m_TMI_MainOutput		= NULL;
	m_TMI_MainOutputQ		= NULL;
	m_TMI_Delay				= NULL;
	m_TMI_DelayQ			= NULL;
	m_TMI_OutputSel			= NULL;
	m_TMI_OutputSelQ		= NULL;
	m_TMI_TrackingOnOff		= NULL;
	m_TMI_TrackingOnOffQ	= NULL;
	m_TMI_TrackingMode		= NULL;
	m_TMI_TrackingModeQ		= NULL;
	m_TMI_TrackingGroup		= NULL;
	m_TMI_TrackingGroupQ	= NULL;
	m_TMI_TrackingData		= NULL;
	m_TMI_TrackingDataQ		= NULL;
	m_TMI_DelayTime			= NULL;
	m_TMI_DelayTimeQ		= NULL;
	m_TMI_Display			= NULL;
	m_TMI_DisplayQ			= NULL;
	m_TMI_Preset			= NULL;
	m_TMI_PresetQ			= NULL;
	m_TMI_MoniDataQ			= NULL;
	m_TMI_AdrQ				= NULL;
	m_TMI_RemoteLocal		= NULL;
	m_TMI_LocalLockOut		= NULL;
	m_TMI_DataBackUp		= NULL;
	m_TMI_SRQEnable			= NULL;
	m_TMI_AllPresetQ		= NULL;
	m_TMI_AllPresetQS		= NULL;
	m_TMI_Out				= NULL;
	m_TMI_In				= NULL;
	
}

TMI_API::~TMI_API()
{
	if(m_TMI_APIDll != NULL)
		FreeLibrary(m_TMI_APIDll);
}

//////////////////////////////////////////////////
// 関数名 :	IFInitialize						//
// 機能   : USB IF の初期化、					//
//			ライブラリ及び関数のハンドルの取得	//
// 引数	  : なし								//
// 戻り値 : TRUE	正常終了					//
//		    FAULSE	異常終了					//
//////////////////////////////////////////////////

BOOL TMI_API::IFInitialize()
{
	m_TMI_APIDll=LoadLibrary((LPCSTR)"TMI_API.dll");
	if( m_TMI_APIDll == NULL )
		return FALSE;

	m_TMI_HandleOpen = (int  ( __stdcall*  )( char * , char * )) GetProcAddress(m_TMI_APIDll , "TMI_HandleOpen");
	if( m_TMI_HandleOpen == NULL )
		return FALSE;

	m_TMI_HandleClose = (int  ( __stdcall*  )( int )) GetProcAddress(m_TMI_APIDll , "TMI_HandleClose");
	if( m_TMI_HandleClose == NULL )
		return FALSE;

	m_TMI_TimeOut = (int  ( __stdcall*  )( int , int )) GetProcAddress(m_TMI_APIDll , "TMI_TimeOut");
	if( m_TMI_TimeOut == NULL )
		return FALSE;

	m_TMI_Refresh = (int  ( __stdcall*  )( int )) GetProcAddress(m_TMI_APIDll , "TMI_Refresh");
	if( m_TMI_Refresh == NULL )
		return FALSE;

	m_TMI_ModelNameQ = (int  ( __stdcall*  )( int , char * )) GetProcAddress(m_TMI_APIDll , "TMI_ModelNameQ");
	if( m_TMI_ModelNameQ == NULL )
		return FALSE;

	m_TMI_Voltage = (int  ( __stdcall*  )( int , unsigned char , unsigned char , double )) GetProcAddress(m_TMI_APIDll , "TMI_Voltage");
	if( m_TMI_Voltage == NULL )
		return FALSE;

	m_TMI_VoltageQ = (int  ( __stdcall*  )( int , unsigned char , unsigned char , double * )) GetProcAddress(m_TMI_APIDll , "TMI_VoltageQ");
	if( m_TMI_VoltageQ == NULL )
		return FALSE;

	m_TMI_Current = (int  ( __stdcall*  )(int , unsigned char , unsigned char , double )) GetProcAddress(m_TMI_APIDll , "TMI_Current");
	if( m_TMI_Current == NULL )
		return FALSE;

	m_TMI_CurrentQ = (int  ( __stdcall*  )(int , unsigned char , unsigned char , double * )) GetProcAddress(m_TMI_APIDll , "TMI_CurrentQ");
	if( m_TMI_CurrentQ == NULL )
		return FALSE;

	m_TMI_MainOutput = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_MainOutput");
	if( m_TMI_MainOutput == NULL )
		return FALSE;

	m_TMI_MainOutputQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_MainOutputQ");
	if( m_TMI_MainOutputQ == NULL )
		return FALSE;

	m_TMI_Delay = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_Delay");
	if( m_TMI_Delay == NULL )
		return FALSE;

	m_TMI_DelayQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_DelayQ");
	if( m_TMI_DelayQ == NULL )
		return FALSE;

	m_TMI_OutputSel = (int  ( __stdcall*  )(int , unsigned char , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_OutputSel");
	if( m_TMI_OutputSel == NULL )
		return FALSE;

	m_TMI_OutputSelQ = (int  ( __stdcall*  )(int , unsigned char , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_OutputSelQ");
	if( m_TMI_OutputSelQ == NULL )
		return FALSE;

	m_TMI_TrackingOnOff = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingOnOff");
	if( m_TMI_TrackingOnOff == NULL )
		return FALSE;

	m_TMI_TrackingOnOffQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingOnOffQ");
	if( m_TMI_TrackingOnOffQ == NULL )
		return FALSE;

	m_TMI_TrackingMode = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingMode");
	if( m_TMI_TrackingMode == NULL )
		return FALSE;

	m_TMI_TrackingModeQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingModeQ");
	if( m_TMI_TrackingModeQ == NULL )
		return FALSE;

	m_TMI_TrackingGroup = (int  ( __stdcall*  )(int , unsigned char , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingGroup");
	if( m_TMI_TrackingGroup == NULL )
		return FALSE;

	m_TMI_TrackingGroupQ = (int  ( __stdcall*  )(int , unsigned char , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingGroupQ");
	if( m_TMI_TrackingGroupQ == NULL )
		return FALSE;

	m_TMI_TrackingData = (int  ( __stdcall*  )(int , unsigned char , unsigned char , double )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingData");
	if( m_TMI_TrackingData == NULL )
		return FALSE;

	m_TMI_TrackingDataQ = (int  ( __stdcall*  )(int , unsigned char , unsigned char , double * )) GetProcAddress(m_TMI_APIDll , "TMI_TrackingDataQ");
	if( m_TMI_TrackingDataQ == NULL )
		return FALSE;

	m_TMI_DelayTime = (int  ( __stdcall*  )(int , unsigned char , double )) GetProcAddress(m_TMI_APIDll , "TMI_DelayTime");
	if( m_TMI_DelayTime == NULL )
		return FALSE;

	m_TMI_DelayTimeQ = (int  ( __stdcall*  )(int , unsigned char , double * )) GetProcAddress(m_TMI_APIDll , "TMI_DelayTimeQ");
	if( m_TMI_DelayTimeQ == NULL )
		return FALSE;

	m_TMI_Display = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_Display");
	if( m_TMI_Display == NULL )
		return FALSE;

	m_TMI_DisplayQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_DisplayQ");
	if( m_TMI_DisplayQ == NULL )
		return FALSE;

	m_TMI_Preset = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_Preset");
	if( m_TMI_Preset == NULL )
		return FALSE;

	m_TMI_PresetQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_PresetQ");
	if( m_TMI_PresetQ == NULL )
		return FALSE;

	m_TMI_MoniDataQ = (int  ( __stdcall*  )(int , unsigned char , double * , double * , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_MoniDataQ");
	if( m_TMI_MoniDataQ == NULL )
		return FALSE;

	m_TMI_AdrQ = (int  ( __stdcall*  )(int , unsigned char * )) GetProcAddress(m_TMI_APIDll , "TMI_AdrQ");
	if( m_TMI_AdrQ == NULL )
		return FALSE;

	m_TMI_RemoteLocal = (int  ( __stdcall*  )(int )) GetProcAddress(m_TMI_APIDll , "TMI_RemoteLocal");
	if( m_TMI_RemoteLocal == NULL )
		return FALSE;

	m_TMI_LocalLockOut = (int  ( __stdcall*  )(int )) GetProcAddress(m_TMI_APIDll , "TMI_LocalLockOut");
	if( m_TMI_LocalLockOut == NULL )
		return FALSE;

	m_TMI_DataBackUp = (int  ( __stdcall*  )(int )) GetProcAddress(m_TMI_APIDll , "TMI_DataBackUp");
	if( m_TMI_DataBackUp == NULL )
		return FALSE;

	m_TMI_SRQEnable = (int  ( __stdcall*  )(int , unsigned char )) GetProcAddress(m_TMI_APIDll , "TMI_SRQEnable");
	if( m_TMI_SRQEnable == NULL )
		return FALSE;

	m_TMI_AllPresetQ = (int  ( __stdcall*  )(int , double * )) GetProcAddress(m_TMI_APIDll , "TMI_AllPresetQ");
	if( m_TMI_AllPresetQ == NULL )
		return FALSE;

	m_TMI_AllPresetQS = (int  ( __stdcall*  )(int , char * )) GetProcAddress(m_TMI_APIDll , "TMI_AllPresetQS");
	if( m_TMI_AllPresetQS == NULL )
		return FALSE;

	m_TMI_Out = (int  ( __stdcall*  )(int , char * )) GetProcAddress(m_TMI_APIDll , "TMI_Out");
	if( m_TMI_Out == NULL )
		return FALSE;

	m_TMI_In = (int  ( __stdcall*  )(int , char * )) GetProcAddress(m_TMI_APIDll , "TMI_In");
	if( m_TMI_In == NULL )
		return FALSE;

	return TRUE;
} 


// デバイスのオープン
int TMI_API::TMI_HandleOpen(char *Str_Renamed, char *Ptr)
{
	if (m_TMI_HandleOpen == NULL)
		return DLL_ERROR;
	
	return m_TMI_HandleOpen(Str_Renamed, Ptr);
}
// デバイスのクローズ
int TMI_API::TMI_HandleClose(int hID)
{
	if (m_TMI_HandleClose == NULL)
		return DLL_ERROR;
	
	return m_TMI_HandleClose(hID);
}
// タイムアウト時間設定
int TMI_API::TMI_TimeOut(int hID, int time)
{
	if (m_TMI_TimeOut == NULL)
		return DLL_ERROR;
	
	return m_TMI_TimeOut(hID, time);
}
// リフレッシュ動作
int TMI_API::TMI_Refresh(int hID)
{
	if (m_TMI_Refresh == NULL)
		return DLL_ERROR;
	
	return m_TMI_Refresh(hID);
}
// モデル名の取得
int TMI_API::TMI_ModelNameQ(int hID, char *Model)
{
	if (m_TMI_ModelNameQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_ModelNameQ(hID, Model);
}
// 出力位置とプリセット位置を指定して電圧値を設定する
int TMI_API::TMI_Voltage(int hID, unsigned char ch, unsigned char  preset, double Data)
{
	if (m_TMI_Voltage == NULL)
		return DLL_ERROR;
	
	return m_TMI_Voltage(hID, ch, preset, Data);
}
// 出力位置とプリセット位置を指定して電圧値を取得する
int TMI_API::TMI_VoltageQ(int hID, unsigned char ch, unsigned char preset,  double *Voltage)
{
	if (m_TMI_VoltageQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_VoltageQ(hID, ch, preset,  Voltage);
}
// 出力位置とプリセット位置を指定して電流値を設定する
int TMI_API::TMI_Current(int hID, unsigned char ch, unsigned char preset, double Data)
{
	if (m_TMI_Current == NULL)
		return DLL_ERROR;
	
	return m_TMI_Current(hID, ch, preset, Data);
}
// 出力位置とプリセット位置を指定して電流値を取得する
int TMI_API::TMI_CurrentQ(int hID, unsigned char ch, unsigned char preset, double *Current)
{
	if (m_TMI_CurrentQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_CurrentQ(hID, ch, preset, Current);
}
// MainOutputのON OFFを行う
int TMI_API::TMI_MainOutput(int hID, unsigned char onoff)
{
	if (m_TMI_MainOutput == NULL)
		return DLL_ERROR;
	
	return m_TMI_MainOutput(hID, onoff);
}
// MainOutputの状態を取得する
int TMI_API::TMI_MainOutputQ(int hID, unsigned char *Ans)
{
	if (m_TMI_MainOutputQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_MainOutputQ(hID, Ans);
}
// Delay のON OFFを行う
int TMI_API::TMI_Delay(int hID, unsigned char onoff)
{
	if (m_TMI_Delay == NULL)
		return DLL_ERROR;
	
	return m_TMI_Delay(hID, onoff);
}
// Delayの状態を取得する
int TMI_API::TMI_DelayQ(int hID, unsigned char *Ans)
{
	if (m_TMI_DelayQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_DelayQ(hID, Ans);
}
// OutputSelectの出力別ON OFFを行う
int TMI_API::TMI_OutputSel(int hID, unsigned char ch, unsigned char onoff)
{
	if (m_TMI_OutputSel == NULL)
		return DLL_ERROR;
	
	return m_TMI_OutputSel(hID, ch, onoff);
}
// OutputSelectの出力別の状態を取得する
int TMI_API::TMI_OutputSelQ(int hID, unsigned char ch, unsigned char *Ans)
{
	if (m_TMI_OutputSelQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_OutputSelQ(hID, ch, Ans);
}
// TrackingのON OFFを行う
int TMI_API::TMI_TrackingOnOff(int hID, unsigned char onoff)
{
	if (m_TMI_TrackingOnOff == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingOnOff(hID, onoff);
}
// Trackingの状態を取得する
int TMI_API::TMI_TrackingOnOffQ(int hID, unsigned char *Ans)
{
	if (m_TMI_TrackingOnOffQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingOnOffQ(hID, Ans);
}
// TrackingModeを設定する
int TMI_API::TMI_TrackingMode(int hID, unsigned char mode)
{
	if (m_TMI_TrackingMode == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingMode(hID, mode);
}
// TrackingModeの状態を取得する
int TMI_API::TMI_TrackingModeQ(int hID, unsigned char *Ans)
{
	if (m_TMI_TrackingModeQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingModeQ(hID, Ans);
}
// TrackingGroupを出力別に設定する
int TMI_API::TMI_TrackingGroup(int hID, unsigned char ch, unsigned char Tracking_Set)
{
	if (m_TMI_TrackingGroup == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingGroup(hID, ch, Tracking_Set);
}
// TrackingGroupの出力別設定状態を取得する
int TMI_API::TMI_TrackingGroupQ(int hID, unsigned char ch, unsigned char *Ans)
{
	if (m_TMI_TrackingGroupQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingGroupQ(hID, ch, Ans);
}
// TrackingGroupの電圧・電流値を出力別に増減させる
int TMI_API::TMI_TrackingData(int hID, unsigned char ch, unsigned char va, double Data)
{
	if (m_TMI_TrackingData == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingData(hID, ch, va, Data);
}
// TrackingGroupの電圧・電流値を出力別に取得する
int TMI_API::TMI_TrackingDataQ(int hID, unsigned char ch, unsigned char va, double *Data)
{
	if (m_TMI_TrackingDataQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_TrackingDataQ(hID, ch, va, Data);
}
// DELAY時間を出力別に設定する
int TMI_API::TMI_DelayTime(int hID, unsigned char ch, double Data)
{
	if (m_TMI_DelayTime == NULL)
		return DLL_ERROR;
	
	return m_TMI_DelayTime(hID, ch, Data);
}
// DELAY時間を出力別に取得する
int TMI_API::TMI_DelayTimeQ(int hID, unsigned char ch, double *Data)
{
	if (m_TMI_DelayTimeQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_DelayTimeQ(hID, ch, Data);
}
// Display表示位置を設定する
int TMI_API::TMI_Display(int hID, unsigned char ch)
{
	if (m_TMI_Display == NULL)
		return DLL_ERROR;
	
	return m_TMI_Display(hID, ch);
}
// Display表示位置を取得する
int TMI_API::TMI_DisplayQ(int hID, unsigned char *Ans)
{
	if (m_TMI_DisplayQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_DisplayQ(hID, Ans);
}
// Preset番号を設定する
int TMI_API::TMI_Preset(int hID, unsigned char preset)
{
	if (m_TMI_Preset == NULL)
		return DLL_ERROR;
	
	return m_TMI_Preset(hID, preset);
}
// Preset番号を取得する
int TMI_API::TMI_PresetQ(int hID, unsigned char *Ans)
{
	if (m_TMI_PresetQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_PresetQ(hID, Ans);
}
// 指定した出力の電圧・電流モニタ値とCV/CC状態を取得する
int TMI_API::TMI_MoniDataQ(int hID, unsigned char ch, double *Voltage, double *Current, unsigned char *cv_cc)
{
	if (m_TMI_MoniDataQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_MoniDataQ(hID, ch, Voltage, Current, cv_cc);
}
// システムアドレスを取得する
int TMI_API::TMI_AdrQ(int hID, unsigned char *Adr)
{
	if (m_TMI_AdrQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_AdrQ(hID, Adr);
}
// リモートからローカルへ切り替える
int TMI_API::TMI_RemoteLocal(int hID)
{
	if (m_TMI_RemoteLocal == NULL)
		return DLL_ERROR;
	
	return m_TMI_RemoteLocal(hID);
}
// ローカルロックアウト状態へ移行する
int TMI_API::TMI_LocalLockOut(int hID)
{
	if (m_TMI_LocalLockOut == NULL)
		return DLL_ERROR;
	
	return m_TMI_LocalLockOut(hID);
}
// データのバックアップを行う
int TMI_API::TMI_DataBackUp(int hID)
{
	if (m_TMI_DataBackUp == NULL)
		return DLL_ERROR;
	
	return m_TMI_DataBackUp(hID);
}
// サービスリクエストの禁止・許可の設定をする
int TMI_API::TMI_SRQEnable(int hID, unsigned char ch)
{
	if (m_TMI_SRQEnable == NULL)
		return DLL_ERROR;
	
	return m_TMI_SRQEnable(hID, ch);
}
// 全出力のPRESET値の取得
int TMI_API::TMI_AllPresetQ(int hID, double *PresetMem)
{
	if (m_TMI_AllPresetQ == NULL)
		return DLL_ERROR;
	
	return m_TMI_AllPresetQ(hID, PresetMem);
}
// 全出力のPRESET値の取得
int TMI_API::TMI_AllPresetQS(int hID, char *PresetMem)
{
	if (m_TMI_AllPresetQS == NULL)
		return DLL_ERROR;
	
	return m_TMI_AllPresetQS(hID, PresetMem);
}
// コントロール関数：コマンド送信
int TMI_API::TMI_Out(int hID, char *Str_Renamed)
{
	if (m_TMI_Out == NULL)
		return DLL_ERROR;
	
	return m_TMI_Out(hID, Str_Renamed);
}
// コントロール関数：コマンド受信
int TMI_API::TMI_In(int hID, char *strbuf)
{
	if (m_TMI_In == NULL)
		return DLL_ERROR;
	
	return m_TMI_In(hID, strbuf);
}

