﻿// ConditionDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AiSamplingInfiniteUser.h"
#include "ConditionDlg.h"
#include "afxdialogex.h"
#include "Caio.h"


// CConditionDlg dialog

IMPLEMENT_DYNAMIC(CConditionDlg, CDialogEx)

CConditionDlg::CConditionDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_CONDITION_DIALOG, pParent)
{

}

CConditionDlg::~CConditionDlg()
{
}

void CConditionDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_START_CONDITION, m_ai_start_condition);
	DDX_Control(pDX, IDC_EDIT_START_LEVEL_CH_NO, m_ai_start_level_ch_no);
	DDX_Control(pDX, IDC_EDIT_START_LEVEL_COMPARISON_VALUE, m_ai_start_level_comparison_value);
	DDX_Control(pDX, IDC_COMBO_START_LEVEL_COMPARISON_DIRECTION, m_ai_start_level_comparison_direction);
	DDX_Control(pDX, IDC_EDIT_START_RANGE_CH_NO, m_ai_start_range_ch_no);
	DDX_Control(pDX, IDC_EDIT_START_RANGE_UPPER_LIMIT_VALUE, m_ai_start_range_upper_limit_value);
	DDX_Control(pDX, IDC_EDIT_START_RANGE_LOWER_LIMIT_VALUE, m_ai_start_range_lower_limit_value);
	DDX_Control(pDX, IDC_EDIT_START_RANGE_STATE_TIMES, m_ai_start_range_state_times);
	DDX_Control(pDX, IDC_COMBO_CLOCK_TYPE, m_ai_clock_type);
	DDX_Control(pDX, IDC_EDIT_SAMPLING_CLOCK, m_ai_sampling_clock);
	DDX_Control(pDX, IDC_COMBO_EXTERNAL_CLOCK_INPUT_TIMING, m_ai_clock_edge);
	DDX_Control(pDX, IDC_EDIT_SCAN_CLOCK, m_ai_scan_clock);
	DDX_Control(pDX, IDC_COMBO_STOP_CONDITION, m_ai_stop_condition);
	DDX_Control(pDX, IDC_EDIT_STOP_LEVEL_CH_NO, m_ai_stop_level_ch_no);
	DDX_Control(pDX, IDC_EDIT_STOP_LEVEL_COMPARISON_VALUE, m_ai_stop_level_comparison_value);
	DDX_Control(pDX, IDC_COMBO_STOP_LEVEL_COMPARISON_DIRECTION, m_ai_stop_level_comparison_direction);
	DDX_Control(pDX, IDC_EDIT_STOP_RANGE_CH_NO, m_ai_stop_range_ch_no);
	DDX_Control(pDX, IDC_EDIT_STOP_RANGE_UPPER_LIMIT_VALUE, m_ai_stop_range_upper_limit_value);
	DDX_Control(pDX, IDC_EDIT_STOP_RANGE_LOWER_LIMIT_VALUE, m_ai_stop_range_lower_limit_value);
	DDX_Control(pDX, IDC_EDIT_STOP_RANGE_STATE_TIMES, m_ai_stop_range_state_times);
	DDX_Control(pDX, IDC_EDIT_TRANSFER_SIZE, m_ai_transfer_size);
}


BEGIN_MESSAGE_MAP(CConditionDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_COMBO_START_CONDITION, &CConditionDlg::OnCbnSelchangeComboStartCondition)
	ON_CBN_SELCHANGE(IDC_COMBO_CLOCK_TYPE, &CConditionDlg::OnCbnSelchangeComboClockType)
	ON_CBN_SELCHANGE(IDC_COMBO_STOP_CONDITION, &CConditionDlg::OnCbnSelchangeComboStopCondition)
	ON_BN_CLICKED(IDC_BUTTON_OK, &CConditionDlg::OnBnClickedButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, &CConditionDlg::OnBnClickedButtonCancel)
END_MESSAGE_MAP()

//----------------------------------------
// Declaration of global variables
//----------------------------------------
extern	short	g_id;						// ID for device access
short	g_start_trigger[] = {	0,			// Software
								1,			// External trigger rising edge
								2,			// External trigger falling edge
								3,			// Level comparison
								4,			// In Range comparison
								5 };		// Out Range comparison
short	g_clock_type[] = {		0,			// Internal clock
								1 };		// External clock
short	g_clock_edge[] = {		0,			// External input falling edge
								1 };		// External input rising edge
short	g_stop_trigger[] = {	1,			// External trigger rising edge
								2,			// External trigger falling edge
								3,			// Level comparison
								4,			// Command (AioStopAi)
								5,			// In Range comparison
								6 };		// Out Range comparison

// CConditionDlg message handlers


BOOL CConditionDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	TCHAR	text_temp[256];		// For temporary storage of text
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	CString	message_string;		// For displaying message
	long	ret;				// For return code
	short	index;				// Index of combobox
	short	ai_start_trigger;	// Conversion start condition
	short	ai_stop_trigger;	// Conversion stop condition
	float	ai_level;			// Level comparison data
	short	ai_direction;		// Level comparison direction
	float	ai_range_level1;	// Upper limit data of In Range / Out Range comparison
	float	ai_range_level2;	// Lower limit data of In Range / Out Range comparison
	long	ai_state_times;		// Sampling times of the state-holding
	short	ai_clock_type;		// Clock type
	float	ai_sampling_clock;	// Sampling clock
	short	ai_clock_edge;		// Input timing of the external clock
	short	ai_auto_mode;		// Set mode of transfer size
	long	ai_transfer_size;	// Transfer size
	float	ai_scan_clock;		// Conversion speed
	short	err_flag;			// Function execution error flag

	//----------------------------------------
	// Initialize parameters
	//----------------------------------------
	err_flag	= 0;
	//----------------------------------------
	// Create the combobox for analog input conversion start condition
	//----------------------------------------
	m_ai_start_condition.AddString(_T("Software"));
	m_ai_start_condition.AddString(_T("External trigger rising edge"));
	m_ai_start_condition.AddString(_T("External trigger falling edge"));
	m_ai_start_condition.AddString(_T("Level comparison"));
	m_ai_start_condition.AddString(_T("In Range comparison"));
	m_ai_start_condition.AddString(_T("Out Range comparison"));
	//----------------------------------------
	// Get the conversion start condition
	//----------------------------------------
	ret	= AioGetAiStartTrigger(g_id, &ai_start_trigger);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiStartTrigger = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_start_condition.EnableWindow(FALSE);
		}
		//--------------------
		// Change the selection of analog input conversion start condition combobox to 0
		//--------------------
		m_ai_start_condition.SetCurSel(0);
		OnCbnSelchangeComboStartCondition();
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Convert from conversion start condition to index
		//--------------------
		index	= 0;
		switch(ai_start_trigger){
		case 0:
			index	= 0;
			break;
		case 1:
			index	= 1;
			break;
		case 2:
			index	= 2;
			break;
		case 3:
			index	= 3;
			break;
		case 4:
			index	= 4;
			break;
		case 5:
			index	= 5;
			break;
		default:
			index	= 0;
			break;
		}
		//--------------------
		// Change the selection of the analog input conversion start condition combobox
		//--------------------
		m_ai_start_condition.SetCurSel(index);
		OnCbnSelchangeComboStartCondition();
	}
	//----------------------------------------
	// Update the initial display of channel No.
	//----------------------------------------
	m_ai_start_level_ch_no.SetWindowTextW(_T("0"));
	//----------------------------------------
	// Create the combobox for level comparison direction
	//----------------------------------------
	m_ai_start_level_comparison_direction.AddString(_T("Both edges"));
	m_ai_start_level_comparison_direction.AddString(_T("Rising edge"));
	m_ai_start_level_comparison_direction.AddString(_T("Falling edge"));
	//----------------------------------------
	// For Level comparison
	//----------------------------------------
	if(ai_start_trigger == 3){
		//----------------------------------------
		// Get the level when the level comparison is started
		//----------------------------------------
		ret	= AioGetAiStartLevelEx(g_id, 0, &ai_level, &ai_direction);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStartLevelEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_start_level_ch_no.EnableWindow(FALSE);
				m_ai_start_level_comparison_value.EnableWindow(FALSE);
				m_ai_start_level_comparison_direction.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of comparison value
			//--------------------
			m_ai_start_level_comparison_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Change the selection of the level comparison direction combobox to 0
			//--------------------
			m_ai_start_level_comparison_direction.SetCurSel(0);
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update comparison value
			//--------------------
			text_string.Format(_T("%.1f"), ai_level);
			m_ai_start_level_comparison_value.SetWindowTextW(text_string);
			//--------------------
			// Convert from level comparison direction to index
			//--------------------
			index	= 0;
			switch(ai_direction){
			case 0:
				index	= 0;
				break;
			case 1:
				index	= 1;
				break;
			case 2:
				index	= 2;
				break;
			default:
				index	= 0;
				break;
			}
			//--------------------
			// Change the selection of the level comparison direction combobox
			//--------------------
			m_ai_start_level_comparison_direction.SetCurSel(index);
		}
	//----------------------------------------
	// Other than Level comparison
	//----------------------------------------
	}else{
		//--------------------
		// Update the initial display of comparison value
		//--------------------
		m_ai_start_level_comparison_value.SetWindowTextW(_T("1.0"));
		//--------------------
		// Change the selection of the level comparison direction combobox to 0
		//--------------------
		m_ai_start_level_comparison_direction.SetCurSel(0);
	}
	//----------------------------------------
	// Update the initial display of channel No.
	//----------------------------------------
	m_ai_start_range_ch_no.SetWindowTextW(_T("0"));
	//----------------------------------------
	// For In Range comparison
	//----------------------------------------
	if(ai_start_trigger == 4){
		//----------------------------------------
		// Get the settings of In Range comparison start condition
		//----------------------------------------
		ret	= AioGetAiStartInRangeEx(g_id, 0, &ai_range_level1, &ai_range_level2, &ai_state_times);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStartInRangeEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_start_range_ch_no.EnableWindow(FALSE);
				m_ai_start_range_upper_limit_value.EnableWindow(FALSE);
				m_ai_start_range_lower_limit_value.EnableWindow(FALSE);
				m_ai_start_range_state_times.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of upper limit
			//--------------------
			m_ai_start_range_upper_limit_value.SetWindowTextW(_T("10.0"));
			//--------------------
			// Update the initial display of lower limit
			//--------------------
			m_ai_start_range_lower_limit_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Update the initial display of state-holding times
			//--------------------
			m_ai_start_range_state_times.SetWindowTextW(_T("1"));
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update upper limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level1);
			m_ai_start_range_upper_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update lower limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level2);
			m_ai_start_range_lower_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update state-holding times
			//--------------------
			text_string.Format(_T("%d"), ai_state_times);
			m_ai_start_range_state_times.SetWindowTextW(text_string);
		}
	//----------------------------------------
	// For Out Range comparison
	//----------------------------------------
	}else if(ai_start_trigger == 5){
		//----------------------------------------
		// Get the settings of Out Range comparison start condition
		//----------------------------------------
		ret	= AioGetAiStartOutRangeEx(g_id, 0, &ai_range_level1, &ai_range_level2, &ai_state_times);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStartOutRangeEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_start_range_ch_no.EnableWindow(FALSE);
				m_ai_start_range_upper_limit_value.EnableWindow(FALSE);
				m_ai_start_range_lower_limit_value.EnableWindow(FALSE);
				m_ai_start_range_state_times.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of upper limit
			//--------------------
			m_ai_start_range_upper_limit_value.SetWindowTextW(_T("10.0"));
			//--------------------
			// Update the initial display of lower limit
			//--------------------
			m_ai_start_range_lower_limit_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Update the initial display of state-holding times
			//--------------------
			m_ai_start_range_state_times.SetWindowTextW(_T("1"));
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update upper limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level1);
			m_ai_start_range_upper_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update lower limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level2);
			m_ai_start_range_lower_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update state-holding times
			//--------------------
			text_string.Format(_T("%d"), ai_state_times);
			m_ai_start_range_state_times.SetWindowTextW(text_string);
		}
	//----------------------------------------
	// Other than In Range comparison / Out Range comparison
	//----------------------------------------
	}else{
		//--------------------
		// Update the initial display of upper limit
		//--------------------
		m_ai_start_range_upper_limit_value.SetWindowTextW(_T("10.0"));
		//--------------------
		// Update the initial display of lower limit
		//--------------------
		m_ai_start_range_lower_limit_value.SetWindowTextW(_T("1.0"));
		//--------------------
		// Update the initial display of state-holding times
		//--------------------
		m_ai_start_range_state_times.SetWindowTextW(_T("1"));
	}
	//----------------------------------------
	// Create the combobox for analog input clock type
	//----------------------------------------
	m_ai_clock_type.AddString(_T("Internal clock"));
	m_ai_clock_type.AddString(_T("External clock"));
	//----------------------------------------
	// Get clock type
	//----------------------------------------
	ret	= AioGetAiClockType(g_id, &ai_clock_type);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiClockType = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_clock_type.EnableWindow(FALSE);
		}
		//--------------------
		// Change the selection of the analog input clock type combobox to 0
		//--------------------
		m_ai_clock_type.SetCurSel(0);
		OnCbnSelchangeComboClockType();
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Convert from clock type to index
		//--------------------
		index	= 0;
		switch(ai_clock_type){
		case 0:
			index	= 0;
			break;
		case 1:
			index	= 1;
			break;
		default:
			index	= 0;
			break;
		}
		//--------------------
		// Change the selection of the analog input clock type combobox
		//--------------------
		m_ai_clock_type.SetCurSel(index);
		OnCbnSelchangeComboClockType();
	}
	//----------------------------------------
	// Get sampling clock
	//----------------------------------------
	ret	= AioGetAiSamplingClock(g_id, &ai_sampling_clock);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiSamplingClock = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_sampling_clock.EnableWindow(FALSE);
		}
		//--------------------
		// Update the initial display of sampling clock
		//--------------------
		m_ai_sampling_clock.SetWindowTextW(_T("1000"));
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Update sampling clock
		//--------------------
		text_string.Format(_T("%f"), ai_sampling_clock);
		m_ai_sampling_clock.SetWindowTextW(text_string);
	}
	//----------------------------------------
	// Create the combobox for analog input external clock input timing
	//----------------------------------------
	m_ai_clock_edge.AddString(_T("External input falling edge"));
	m_ai_clock_edge.AddString(_T("External input rising edge"));
	//----------------------------------------
	// For External clock
	//----------------------------------------
	if(ai_clock_type == 1){
		//----------------------------------------
		// Get the timing of external clock input.
		//----------------------------------------
		ret	= AioGetAiClockEdge(g_id, &ai_clock_edge);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiClockEdge = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_clock_edge.EnableWindow(FALSE);
			}
			//----------------------------------------
			// Change the selection of the analog input external clock input timing combobox to 0
			//----------------------------------------
			m_ai_clock_edge.SetCurSel(0);
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Convert from input timing to index
			//--------------------
			index	= 0;
			switch(ai_clock_edge){
			case 0:
				index	= 0;
				break;
			case 1:
				index	= 1;
				break;
			default:
				index	= 0;
				break;
			}
			//----------------------------------------
			// Change the selection of the analog input external clock input timing combobox
			//----------------------------------------
			m_ai_clock_edge.SetCurSel(index);
		}
	//----------------------------------------
	// Other than External clock
	//----------------------------------------
	}else{
		//----------------------------------------
		// Change the selection of the analog input external clock input timing combobox to 0
		//----------------------------------------
		m_ai_clock_edge.SetCurSel(0);
	}
	//----------------------------------------
	// Get transfer size
	//----------------------------------------
	ret	= AioGetAiTransferSize(g_id, &ai_auto_mode, &ai_transfer_size);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiTransferSize = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_transfer_size.EnableWindow(FALSE);
		}
		//--------------------
		// Update the initial display of transfer size
		//--------------------
		m_ai_transfer_size.SetWindowTextW(_T("0"));
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Update transfer size
		//--------------------
		text_string.Format(_T("%ld"), ai_transfer_size);
		m_ai_transfer_size.SetWindowTextW(text_string);
	}
	//----------------------------------------
	// Get conversion speed
	//----------------------------------------
	ret	= AioGetAiScanClock(g_id, &ai_scan_clock);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiScanClock = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_scan_clock.EnableWindow(FALSE);
		}
		//--------------------
		// Update the initial display of conversion speed
		//--------------------
		m_ai_scan_clock.SetWindowTextW(_T("10"));
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Update conversion speed
		//--------------------
		text_string.Format(_T("%f"), ai_scan_clock);
		m_ai_scan_clock.SetWindowTextW(text_string);
	}
	//----------------------------------------
	// Create the combobox for analog input conversion stop condition
	//----------------------------------------
	m_ai_stop_condition.AddString(_T("External trigger rising edge"));
	m_ai_stop_condition.AddString(_T("External trigger falling edge"));
	m_ai_stop_condition.AddString(_T("Level comparison"));
	m_ai_stop_condition.AddString(_T("Command (AioStopAi)"));
	m_ai_stop_condition.AddString(_T("In Range comparison"));
	m_ai_stop_condition.AddString(_T("Out Range comparison"));
	//----------------------------------------
	// Get the conversion stop condition
	//----------------------------------------
	ret	= AioGetAiStopTrigger(g_id, &ai_stop_trigger);
	//----------------------------------------
	// Abnormal termination process
	//----------------------------------------
	if(ret != 0){
		if(ret != 20001){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			message_string.Format(_T("AioGetAiStopTrigger = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
			err_flag	= 1;
		}else{
			//--------------------
			// Disable control
			//--------------------
			m_ai_stop_condition.EnableWindow(FALSE);
		}
		//--------------------
		// Change the selection in the analog input conversion stop condition combobox to 3
		//--------------------
		m_ai_stop_condition.SetCurSel(3);
		OnCbnSelchangeComboStopCondition();
	//----------------------------------------
	// Normal termination process
	//----------------------------------------
	}else{
		//--------------------
		// Convert from conversion stop condition to index
		//--------------------
		index	= 0;
		switch(ai_stop_trigger){
		case 0:
			index	= 3;
			break;
		case 1:
			index	= 0;
			break;
		case 2:
			index	= 1;
			break;
		case 3:
			index	= 2;
			break;
		case 4:
			index	= 3;
			break;
		case 5:
			index	= 4;
			break;
		case 6:
			index	= 5;
			break;
		default:
			index	= 3;
			break;
		}
		//--------------------
		// Change the selection in the analog input conversion stop condition combobox
		//--------------------
		m_ai_stop_condition.SetCurSel(index);
		OnCbnSelchangeComboStopCondition();
	}
	//----------------------------------------
	// Update the initial display of channel No.
	//----------------------------------------
	m_ai_stop_level_ch_no.SetWindowTextW(_T("0"));
	//----------------------------------------
	// Create the combobox for level comparison direction
	//----------------------------------------
	m_ai_stop_level_comparison_direction.AddString(_T("Both edges"));
	m_ai_stop_level_comparison_direction.AddString(_T("Rising edge"));
	m_ai_stop_level_comparison_direction.AddString(_T("Falling edge"));
	//----------------------------------------
	// For Level comparison
	//----------------------------------------
	if(ai_stop_trigger == 3){
		//----------------------------------------
		// Get the level when the level comparison is stopped
		//----------------------------------------
		ret	= AioGetAiStopLevelEx(g_id, 0, &ai_level, &ai_direction);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStopLevelEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_stop_level_ch_no.EnableWindow(FALSE);
				m_ai_stop_level_comparison_value.EnableWindow(FALSE);
				m_ai_stop_level_comparison_direction.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of comparison value
			//--------------------
			m_ai_stop_level_comparison_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Change the selection of the level comparison direction combobox to 0
			//--------------------
			m_ai_stop_level_comparison_direction.SetCurSel(0);
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update comparison value
			//--------------------
			text_string.Format(_T("%.1f"), ai_level);
			m_ai_stop_level_comparison_value.SetWindowTextW(text_string);
			//--------------------
			// Convert from level comparison direction to index
			//--------------------
			index	= 0;
			switch(ai_direction){
			case 0:
				index	= 0;
				break;
			case 1:
				index	= 1;
				break;
			case 2:
				index	= 2;
				break;
			default:
				index	= 0;
				break;
			}
			//--------------------
			// Change the selection of the level comparison direction combobox
			//--------------------
			m_ai_stop_level_comparison_direction.SetCurSel(index);
		}
	//----------------------------------------
	// Other than Level comparison
	//----------------------------------------
	}else{
		//--------------------
		// Update the initial display of comparison value
		//--------------------
		m_ai_stop_level_comparison_value.SetWindowTextW(_T("1.0"));
		//--------------------
		// Change the selection of the level comparison direction combobox to 0
		//--------------------
		m_ai_stop_level_comparison_direction.SetCurSel(0);
	}
	//----------------------------------------
	// Update the initial display of channel No.
	//----------------------------------------
	m_ai_stop_range_ch_no.SetWindowTextW(_T("0"));
	//----------------------------------------
	// For In Range comparison
	//----------------------------------------
	if(ai_stop_trigger == 5){
		//----------------------------------------
		// Get the settings of In Range comparison stop condition
		//----------------------------------------
		ret	= AioGetAiStopInRangeEx(g_id, 0, &ai_range_level1, &ai_range_level2, &ai_state_times);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStopInRangeEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_stop_range_ch_no.EnableWindow(FALSE);
				m_ai_stop_range_upper_limit_value.EnableWindow(FALSE);
				m_ai_stop_range_lower_limit_value.EnableWindow(FALSE);
				m_ai_stop_range_state_times.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of upper limit
			//--------------------
			m_ai_stop_range_upper_limit_value.SetWindowTextW(_T("10.0"));
			//--------------------
			// Update the initial display of lower limit
			//--------------------
			m_ai_stop_range_lower_limit_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Update the initial display of state-holding times
			//--------------------
			m_ai_stop_range_state_times.SetWindowTextW(_T("1"));
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update upper limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level1);
			m_ai_stop_range_upper_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update lower limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level2);
			m_ai_stop_range_lower_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update state-holding times
			//--------------------
			text_string.Format(_T("%d"), ai_state_times);
			m_ai_stop_range_state_times.SetWindowTextW(text_string);
		}
	//----------------------------------------
	// For Out Range comparison
	//----------------------------------------
	}else if(ai_stop_trigger == 6){
		//----------------------------------------
		// Get the settings of Out Range comparison stop condition
		//----------------------------------------
		ret	= AioGetAiStopOutRangeEx(g_id, 0, &ai_range_level1, &ai_range_level2, &ai_state_times);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			if(ret != 20001){
				//--------------------
				// Get error string
				//--------------------
				AioGetErrorString(ret, error_string);
				//--------------------
				// Display message
				//--------------------
				wsprintf(text_temp, _T("%S"), error_string);
				message_string.Format(_T("AioGetAiStopOutRangeEx = %d : %s\n\n*The display could not be updated since an error occurred."), ret, text_temp);
				err_flag	= 1;
			}else{
				//--------------------
				// Disable control
				//--------------------
				m_ai_stop_range_ch_no.EnableWindow(FALSE);
				m_ai_stop_range_upper_limit_value.EnableWindow(FALSE);
				m_ai_stop_range_lower_limit_value.EnableWindow(FALSE);
				m_ai_stop_range_state_times.EnableWindow(FALSE);
			}
			//--------------------
			// Update the initial display of upper limit
			//--------------------
			m_ai_stop_range_upper_limit_value.SetWindowTextW(_T("10.0"));
			//--------------------
			// Update the initial display of lower limit
			//--------------------
			m_ai_stop_range_lower_limit_value.SetWindowTextW(_T("1.0"));
			//--------------------
			// Update the initial display of state-holding times
			//--------------------
			m_ai_stop_range_state_times.SetWindowTextW(_T("1"));
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			//--------------------
			// Update upper limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level1);
			m_ai_stop_range_upper_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update lower limit
			//--------------------
			text_string.Format(_T("%.1f"), ai_range_level2);
			m_ai_stop_range_lower_limit_value.SetWindowTextW(text_string);
			//--------------------
			// Update state-holding times
			//--------------------
			text_string.Format(_T("%d"), ai_state_times);
			m_ai_stop_range_state_times.SetWindowTextW(text_string);
		}
	//----------------------------------------
	// Other than In Range comparison / Out Range comparison
	//----------------------------------------
	}else{
		//--------------------
		// Update the initial display of upper limit
		//--------------------
		m_ai_stop_range_upper_limit_value.SetWindowTextW(_T("10.0"));
		//--------------------
		// Update the initial display of lower limit
		//--------------------
		m_ai_stop_range_lower_limit_value.SetWindowTextW(_T("1.0"));
		//--------------------
		// Update the initial display of state-holding times
		//--------------------
		m_ai_stop_range_state_times.SetWindowTextW(_T("1"));
	}
	//----------------------------------------
	// Display message if an error occurs
	//----------------------------------------
	if(err_flag != 0){
		MessageBox(message_string, _T("Error"), MB_OK);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}

//================================================================================
// It is the process when the Start Condition combobox is changed
// Update available controls
//================================================================================
void CConditionDlg::OnCbnSelchangeComboStartCondition()
{
	short	index;				// Index of combobox

	//----------------------------------------
	// Get the index of start condition from combobox
	//----------------------------------------
	index	= m_ai_start_condition.GetCurSel();
	//----------------------------------------
	// Branch processing by start condition
	//----------------------------------------
	switch(g_start_trigger[index]){
	case 0:		// Software
	case 1:		// External trigger rising edge
	case 2:		// External trigger falling edge
		m_ai_start_level_ch_no.EnableWindow(FALSE);
		m_ai_start_level_comparison_value.EnableWindow(FALSE);
		m_ai_start_level_comparison_direction.EnableWindow(FALSE);
		m_ai_start_range_ch_no.EnableWindow(FALSE);
		m_ai_start_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_start_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_start_range_state_times.EnableWindow(FALSE);
		break;
	case 3:		// Level comparison
		m_ai_start_level_ch_no.EnableWindow(TRUE);
		m_ai_start_level_comparison_value.EnableWindow(TRUE);
		m_ai_start_level_comparison_direction.EnableWindow(TRUE);
		m_ai_start_range_ch_no.EnableWindow(FALSE);
		m_ai_start_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_start_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_start_range_state_times.EnableWindow(FALSE);
		break;
	case 4:		// In Range comparison
	case 5:		// Out Range comparison
		m_ai_start_level_ch_no.EnableWindow(FALSE);
		m_ai_start_level_comparison_value.EnableWindow(FALSE);
		m_ai_start_level_comparison_direction.EnableWindow(FALSE);
		m_ai_start_range_ch_no.EnableWindow(TRUE);
		m_ai_start_range_upper_limit_value.EnableWindow(TRUE);
		m_ai_start_range_lower_limit_value.EnableWindow(TRUE);
		m_ai_start_range_state_times.EnableWindow(TRUE);
		break;
	default:
		m_ai_start_level_ch_no.EnableWindow(FALSE);
		m_ai_start_level_comparison_value.EnableWindow(FALSE);
		m_ai_start_level_comparison_direction.EnableWindow(FALSE);
		m_ai_start_range_ch_no.EnableWindow(FALSE);
		m_ai_start_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_start_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_start_range_state_times.EnableWindow(FALSE);
		break;
	}
}

//================================================================================
// It is the process when the Clock Type combobox is changed
// Update available controls
//================================================================================
void CConditionDlg::OnCbnSelchangeComboClockType()
{
	short	index;			// Index of combobox
	long	ret;			// For return code
	short	auto_mode;		// Set mode of transfer size
	long	transfer_size;	// Transfer Size

	//----------------------------------------
	// Get the index of clock type from combobox
	//----------------------------------------
	index	= m_ai_clock_type.GetCurSel();
	//----------------------------------------
	// Branch processing by clock type
	//----------------------------------------
	switch(g_clock_type[index]){
	case 0:		// Internal clock
		m_ai_sampling_clock.EnableWindow(TRUE);
		m_ai_clock_edge.EnableWindow(FALSE);
		m_ai_transfer_size.EnableWindow(FALSE);
		break;
	case 1:		// External clock
		m_ai_sampling_clock.EnableWindow(FALSE);
		m_ai_clock_edge.EnableWindow(TRUE);
		//----------------------------------------
		// Get transfer size
		//----------------------------------------
		ret	= AioGetAiTransferSize(g_id, &auto_mode, &transfer_size);
		//----------------------------------------
		// Abnormal termination process
		//----------------------------------------
		if(ret != 0){
			m_ai_transfer_size.EnableWindow(FALSE);
		//----------------------------------------
		// Normal termination process
		//----------------------------------------
		}else{
			m_ai_transfer_size.EnableWindow(TRUE);
		}
		break;
	default:
		m_ai_sampling_clock.EnableWindow(TRUE);
		m_ai_clock_edge.EnableWindow(FALSE);
		m_ai_transfer_size.EnableWindow(FALSE);
		break;
	}
}

//================================================================================
// It is the process when the Stop Condition combobox is changed
// Update available controls
//================================================================================
void CConditionDlg::OnCbnSelchangeComboStopCondition()
{
	short	index;				// Index of combobox

	//----------------------------------------
	// Get the index of stop condition from combobox
	//----------------------------------------
	index	= m_ai_stop_condition.GetCurSel();
	//----------------------------------------
	// Branch processing by stop condition
	//----------------------------------------
	switch(g_stop_trigger[index]){
	case 1:		// External trigger rising edge
	case 2:		// External trigger falling edge
	case 4:		// Command (AioStopAi)
		m_ai_stop_level_ch_no.EnableWindow(FALSE);
		m_ai_stop_level_comparison_value.EnableWindow(FALSE);
		m_ai_stop_level_comparison_direction.EnableWindow(FALSE);
		m_ai_stop_range_ch_no.EnableWindow(FALSE);
		m_ai_stop_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_state_times.EnableWindow(FALSE);
		break;
	case 3:		// Level comparison
		m_ai_stop_level_ch_no.EnableWindow(TRUE);
		m_ai_stop_level_comparison_value.EnableWindow(TRUE);
		m_ai_stop_level_comparison_direction.EnableWindow(TRUE);
		m_ai_stop_range_ch_no.EnableWindow(FALSE);
		m_ai_stop_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_state_times.EnableWindow(FALSE);
		break;
	case 5:		// In Range comparison
	case 6:		// Out Range comparison
		m_ai_stop_level_ch_no.EnableWindow(FALSE);
		m_ai_stop_level_comparison_value.EnableWindow(FALSE);
		m_ai_stop_level_comparison_direction.EnableWindow(FALSE);
		m_ai_stop_range_ch_no.EnableWindow(TRUE);
		m_ai_stop_range_upper_limit_value.EnableWindow(TRUE);
		m_ai_stop_range_lower_limit_value.EnableWindow(TRUE);
		m_ai_stop_range_state_times.EnableWindow(TRUE);
		break;
	default:
		m_ai_stop_level_ch_no.EnableWindow(FALSE);
		m_ai_stop_level_comparison_value.EnableWindow(FALSE);
		m_ai_stop_level_comparison_direction.EnableWindow(FALSE);
		m_ai_stop_range_ch_no.EnableWindow(FALSE);
		m_ai_stop_range_upper_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_lower_limit_value.EnableWindow(FALSE);
		m_ai_stop_range_state_times.EnableWindow(FALSE);
		break;
	}
}

//================================================================================
// It is the process when the OK button is clicked
// Set sampling condition
//================================================================================
void CConditionDlg::OnBnClickedButtonOk()
{
	TCHAR	text_temp[256];		// For temporary storage of text
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	long	ret;				// For return code
	short	index;				// Index of combobox
	short	ai_level_channel;	// Level comparison channel
	float	ai_level;			// Level comparison data
	short	ai_direction;		// Level comparison direction
	short	ai_range_channel;	// Channel of In Range / Out Range comparison
	float	ai_range_level1;	// Upper limit data of In Range / Out Range comparison
	float	ai_range_level2;	// Lower limit data of In Range / Out Range comparison
	long	ai_state_times;		// Sampling times of the state-holding
	float	ai_sampling_clock;	// Sampling clock
	float	ai_scan_clock;		// Conversion speed
	long	ai_transfer_size;	// Transfer size

	//----------------------------------------
	// Set the data storage memory type to Overwrite the memory
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiMemoryType(g_id, 1);
	//----------------------------------------
	// Error process
	//----------------------------------------
	if(ret != 0){
		//--------------------
		// Get error string
		//--------------------
		AioGetErrorString(ret, error_string);
		//--------------------
		// Display message
		//--------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("AioSetAiMemoryType = %d : %s"), ret, text_temp);
		MessageBox(text_string, _T("Error"), MB_OK);
		return;
	}
	//----------------------------------------
	// Get the index of the conversion start condition setting value from combobox
	//----------------------------------------
	index	= m_ai_start_condition.GetCurSel();
	//----------------------------------------
	// Set analog input conversion start condition
	//----------------------------------------
	ret	= AioSetAiStartTrigger(g_id, g_start_trigger[index]);
	//----------------------------------------
	// Error process
	//----------------------------------------
	//--------------------
	// Exit the process if not completed successfully
	//--------------------
	if(ret != 0){
		//--------------------
		// Get error string
		//--------------------
		AioGetErrorString(ret, error_string);
		//--------------------
		// Display message
		//--------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("AioSetAiStartTrigger = %d : %s"), ret, text_temp);
		MessageBox(text_string, _T("Error"), MB_OK);
		return;
	}
	//----------------------------------------
	// For Level comparison
	//----------------------------------------
	if(g_start_trigger[index] == 3){
		//----------------------------------------
		// Get the Level comparison channel from textbox
		//----------------------------------------
		m_ai_start_level_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_level_channel);
		//----------------------------------------
		// Get the Level comparison data from textbox
		//----------------------------------------
		m_ai_start_level_comparison_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_level);
		//----------------------------------------
		// Get the Level comparison direction from textbox
		//----------------------------------------
		ai_direction	= m_ai_start_level_comparison_direction.GetCurSel();
		//----------------------------------------
		// Set the level at start of level comparison
		//----------------------------------------
		ret	= AioSetAiStartLevelEx(g_id, ai_level_channel, ai_level, ai_direction);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStartLevelEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	//----------------------------------------
	// For In Range comparison
	//----------------------------------------
	}else if(g_start_trigger[index] == 4){
		//----------------------------------------
		// Get the channel of In Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_range_channel);
		//----------------------------------------
		// Get the upper limit data of In Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_upper_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level1);
		//----------------------------------------
		// Get the lower limit data of In Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_lower_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level2);
		//----------------------------------------
		// Get the state-holding times from textbox
		//----------------------------------------
		m_ai_start_range_state_times.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%ld"), &ai_state_times);
		//----------------------------------------
		// Set In Range comparison start condition
		//----------------------------------------
		ret	= AioSetAiStartInRangeEx(g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStartInRangeEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	//----------------------------------------
	// For Out Range comparison
	//----------------------------------------
	}else if(g_start_trigger[index] == 5){
		//----------------------------------------
		// Get the channel of Out Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_range_channel);
		//----------------------------------------
		// Get the upper limit data of Out Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_upper_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level1);
		//----------------------------------------
		// Get the lower limit data of Out Range comparison from textbox
		//----------------------------------------
		m_ai_start_range_lower_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level2);
		//----------------------------------------
		// Get the state-holding times from textbox
		//----------------------------------------
		m_ai_start_range_state_times.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%ld"), &ai_state_times);
		//----------------------------------------
		// Set Out Range comparison start condition
		//----------------------------------------
		ret	= AioSetAiStartOutRangeEx(g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStartOutRangeEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	}
	//----------------------------------------
	// Get the index of the clock type setting value from combobox
	//----------------------------------------
	index	= m_ai_clock_type.GetCurSel();
	//----------------------------------------
	// Set analog input clock type
	//----------------------------------------
	ret	= AioSetAiClockType(g_id, g_clock_type[index]);
	//----------------------------------------
	// Error process
	//----------------------------------------
	//--------------------
	// Exit the process if not completed successfully
	//--------------------
	if(ret != 0){
		//--------------------
		// Get error string
		//--------------------
		AioGetErrorString(ret, error_string);
		//--------------------
		// Display message
		//--------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("AioSetAiClockType = %d : %s"), ret, text_temp);
		MessageBox(text_string, _T("Error"), MB_OK);
		return;
	}
	//----------------------------------------
	// For Internal clock
	//----------------------------------------
	if(g_clock_type[index] == 0){
		//----------------------------------------
		// Get the sampling clock from textbox
		//----------------------------------------
		m_ai_sampling_clock.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_sampling_clock);
		//----------------------------------------
		// Set analog input sampling clock
		//----------------------------------------
		ret	= AioSetAiSamplingClock(g_id, ai_sampling_clock);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiSamplingClock = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
		//----------------------------------------
		// Set analog input transfer size
		//----------------------------------------
		ret	= AioSetAiTransferSize(g_id, AI_TRANSFERSIZE_AUTO, 0);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if((ret != 0) && (ret != 20001)){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiTransferSize = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	//----------------------------------------
	// For External clock
	//----------------------------------------
	}else if(g_clock_type[index] == 1){
		//----------------------------------------
		// Get the index of the external clock input timing setting value from combobox
		//----------------------------------------
		index	= m_ai_clock_edge.GetCurSel();
		//----------------------------------------
		// Set the timing of external clock input
		//----------------------------------------
		ret	= AioSetAiClockEdge(g_id, g_clock_edge[index]);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if((ret != 0) && (ret != 20001)){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiClockEdge = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
		//----------------------------------------
		// Get the transfer size from textbox
		//----------------------------------------
		m_ai_transfer_size.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%ld"), &ai_transfer_size);
		//----------------------------------------
		// Set analog input transfer size
		//----------------------------------------
		ret	= AioSetAiTransferSize(g_id, AI_TRANSFERSIZE_MANUAL, ai_transfer_size);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if((ret != 0) && (ret != 20001)){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiTransferSize = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	}
	//----------------------------------------
	// When conversion speed function is available
	//----------------------------------------
	if(m_ai_scan_clock.IsWindowEnabled() != 0){
		//----------------------------------------
		// Get the conversion speed from textbox
		//----------------------------------------
		m_ai_scan_clock.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_scan_clock);
		//----------------------------------------
		// Set analog input conversion speed
		//----------------------------------------
		ret	= AioSetAiScanClock(g_id, ai_scan_clock);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiScanClock = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	}
	//----------------------------------------
	// Get the index of the conversion stop condition setting value from combobox
	//----------------------------------------
	index	= m_ai_stop_condition.GetCurSel();
	//----------------------------------------
	// Set analog input conversion stop condition
	//----------------------------------------
	ret	= AioSetAiStopTrigger(g_id, g_stop_trigger[index]);
	//----------------------------------------
	// Error process
	//----------------------------------------
	//--------------------
	// Exit the process if not completed successfully
	//--------------------
	if(ret != 0){
		//--------------------
		// Get error string
		//--------------------
		AioGetErrorString(ret, error_string);
		//--------------------
		// Display message
		//--------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("AioSetAiStopTrigger  = %d : %s"), ret, text_temp);
		MessageBox(text_string, _T("Error"), MB_OK);
		return;
	}
	//----------------------------------------
	// For Level comparison
	//----------------------------------------
	if(g_stop_trigger[index] == 3){
		//----------------------------------------
		// Get the Level comparison channel from textbox
		//----------------------------------------
		m_ai_stop_level_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_level_channel);
		//----------------------------------------
		// Get the Level comparison data from textbox
		//----------------------------------------
		m_ai_stop_level_comparison_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_level);
		//----------------------------------------
		// Get the Level comparison direction from textbox
		//----------------------------------------
		ai_direction	= m_ai_stop_level_comparison_direction.GetCurSel();
		//----------------------------------------
		// Set the level at stop of level comparison
		//----------------------------------------
		ret	= AioSetAiStopLevelEx(g_id, ai_level_channel, ai_level, ai_direction);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStopLevelEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	//----------------------------------------
	// For In Range comparison
	//----------------------------------------
	}else if(g_stop_trigger[index] == 5){
		//----------------------------------------
		// Get the channel of In Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_range_channel);
		//----------------------------------------
		// Get the upper limit data of In Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_upper_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level1);
		//----------------------------------------
		// Get the lower limit data of In Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_lower_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level2);
		//----------------------------------------
		// Get the state-holding times from textbox
		//----------------------------------------
		m_ai_stop_range_state_times.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%ld"), &ai_state_times);
		//----------------------------------------
		// Set In Range comparison stop condition
		//----------------------------------------
		ret	= AioSetAiStopInRangeEx(g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStopInRangeEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	//----------------------------------------
	// For Out Range comparison
	//----------------------------------------
	}else if(g_stop_trigger[index] == 6){
		//----------------------------------------
		// Get the channel of Out Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_ch_no.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%hd"), &ai_range_channel);
		//----------------------------------------
		// Get the upper limit data of Out Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_upper_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level1);
		//----------------------------------------
		// Get the lower limit data of Out Range comparison from textbox
		//----------------------------------------
		m_ai_stop_range_lower_limit_value.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%f"), &ai_range_level2);
		//----------------------------------------
		// Get the state-holding times from textbox
		//----------------------------------------
		m_ai_stop_range_state_times.GetWindowTextW(text_temp, _countof(text_temp));
		_stscanf_s(text_temp, _T("%ld"), &ai_state_times);
		//----------------------------------------
		// Set Out Range comparison stop condition
		//----------------------------------------
		ret	= AioSetAiStopOutRangeEx(g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times);
		//----------------------------------------
		// Error process
		//----------------------------------------
		//--------------------
		// Exit the process if not completed successfully
		//--------------------
		if(ret != 0){
			//--------------------
			// Get error string
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("AioSetAiStopOutRangeEx = %d : %s"), ret, text_temp);
			MessageBox(text_string, _T("Error"), MB_OK);
			return;
		}
	}
	//----------------------------------------
	// OK process
	//----------------------------------------
	CDialogEx::OnOK();
}

//================================================================================
// It is the process when the Close button is clicked
// Terminate the dialog
//================================================================================
void CConditionDlg::OnBnClickedButtonCancel()
{
	//----------------------------------------
	// Cancel process
	//----------------------------------------
	CDialogEx::OnCancel();
}
