﻿
// InternalSyncGeneratingSamplingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "InternalSyncGeneratingSampling.h"
#include "InternalSyncGeneratingSamplingDlg.h"
#include "afxdialogex.h"
#include "Caio.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CInternalSyncGeneratingSamplingDlg dialog



CInternalSyncGeneratingSamplingDlg::CInternalSyncGeneratingSamplingDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_INTERNALSYNCGENERATINGSAMPLING_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CInternalSyncGeneratingSamplingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_DEVICE_NAME, m_device_name);
	DDX_Control(pDX, IDC_COMBO_AO_RANGE_VALUE, m_ao_range);
	DDX_Control(pDX, IDC_EDIT_AO_CH_NUM, m_ao_channels);
	DDX_Control(pDX, IDC_EDIT_AO_GENERATING_CLOCK, m_ao_generating_clock);
	DDX_Control(pDX, IDC_EDIT_AO_GENERATING_TIMES, m_ao_generating_times);
	DDX_Control(pDX, IDC_EDIT_AO_GENERATING_COUNT, m_ao_generating_count);
	DDX_Control(pDX, IDC_EDIT_AO_STATUS, m_ao_status);
	DDX_Control(pDX, IDC_COMBO_AI_RANGE_VALUE, m_ai_range);
	DDX_Control(pDX, IDC_COMBO_AI_INP_METHOD, m_ai_input_method);
	DDX_Control(pDX, IDC_EDIT_AI_CH_NUM, m_ai_channels);
	DDX_Control(pDX, IDC_LIST_AI_SAMPLING_DATA, m_ai_sampling_data);
	DDX_Control(pDX, IDC_EDIT_AI_SAMPLING_COUNT, m_ai_sampling_count);
	DDX_Control(pDX, IDC_EDIT_AI_STATUS, m_ai_status);
	DDX_Control(pDX, IDC_EDIT_RETURN_CODE, m_return_code);
}

BEGIN_MESSAGE_MAP(CInternalSyncGeneratingSamplingDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_AIO_INIT, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioInit)
	ON_BN_CLICKED(IDC_BUTTON_AIO_RESET_DEV, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioResetDev)
	ON_BN_CLICKED(IDC_BUTTON_AI_AO_SETTING, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAiAoSetting)
	ON_BN_CLICKED(IDC_BUTTON_GENERATING_SAMPLING_SETTING, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingSetting)
	ON_BN_CLICKED(IDC_BUTTON_SYNC_SETTING, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonSyncSetting)
	ON_BN_CLICKED(IDC_BUTTON_OUTPUT_DATA_SETTINGS, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonOutputDataSettings)
	ON_BN_CLICKED(IDC_BUTTON_GENERATING_SAMPLING_START, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingStart)
	ON_BN_CLICKED(IDC_BUTTON_GET_STATUS, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGetStatus)
	ON_BN_CLICKED(IDC_BUTTON_GENERATING_SAMPLING_STOP, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingStop)
	ON_BN_CLICKED(IDC_BUTTON_OUTPUT_SAMPLING_DATA, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonOutputSamplingData)
	ON_BN_CLICKED(IDC_BUTTON_AIO_EXIT, &CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioExit)
	ON_BN_CLICKED(IDCLOSE, &CInternalSyncGeneratingSamplingDlg::OnBnClickedClose)
END_MESSAGE_MAP()

//----------------------------------------
// Macro definition
//----------------------------------------
#define MAX_AO_RANGE_NUM			31						// Maximum number of elements in analog output range array
#define MAX_AI_RANGE_NUM			32						// Maximum number of elements in analog input range array
#define DISPLAY_SAMPLING_COUNT		1000					// Maximum sampling count of sampling data displayed in listbox
//----------------------------------------
// Declaration of global variables
//----------------------------------------
short	g_id;												// ID for device access
TCHAR	g_file_name[] = _T("GeneratingData.csv");			// Generating data output file name
long	g_generating_count;									// Total generating count
float *	g_generating_data = NULL;							// Output data
short	g_ao_range[MAX_AO_RANGE_NUM] = {	PM10,			// +/-10V
											PM5,			// +/-5V
											PM25,			// +/-2.5V
											PM125,			// +/-1.25V
											PM1,			// +/-1V
											PM0625,			// +/-0.625V
											PM05,			// +/-0.5V
											PM03125,		// +/-0.3125V
											PM025,			// +/-0.25V
											PM0125,			// +/-0.125V
											PM01,			// +/-0.1V
											PM005,			// +/-0.05V
											PM0025,			// +/-0.025V
											PM00125,		// +/-0.0125V
											PM001,			// +/-0.01V
											P10,			// 0 ~ 10V
											P5,				// 0 ~ 5V
											P4095,			// 0 ~ 4.095V
											P25,			// 0 ~ 2.5V
											P125,			// 0 ~ 1.25V
											P1,				// 0 ~ 1V
											P05,			// 0 ~ 0.5V
											P025,			// 0 ~ 0.25V
											P01,			// 0 ~ 0.1V
											P005,			// 0 ~ 0.05V
											P0025,			// 0 ~ 0.025V
											P00125,			// 0 ~ 0.0125V
											P001,			// 0 ~ 0.01V
											P20MA,			// 0 ~ 20mA
											P4TO20MA,		// 4 ~ 20mA
											P1TO5 };		// 1 ~ 5V
long	g_sampling_count;									// Total sampling count
float *	g_sampling_data = NULL;								// Pointer to sampling data storage area
short	g_ai_range[MAX_AI_RANGE_NUM] = {	PM10,			// +/-10V
											PM5,			// +/-5V
											PM25,			// +/-2.5V
											PM125,			// +/-1.25V
											PM1,			// +/-1V
											PM0625,			// +/-0.625V
											PM05,			// +/-0.5V
											PM03125,		// +/-0.3125V
											PM025,			// +/-0.25V
											PM0125,			// +/-0.125V
											PM01,			// +/-0.1V
											PM005,			// +/-0.05V
											PM0025,			// +/-0.025V
											PM00125,		// +/-0.0125V
											PM001,			// +/-0.01V
											P10,			// 0 ~ 10V
											P5,				// 0 ~ 5V
											P4095,			// 0 ~ 4.095V
											P25,			// 0 ~ 2.5V
											P125,			// 0 ~ 1.25V
											P1,				// 0 ~ 1V
											P05,			// 0 ~ 0.5V
											P025,			// 0 ~ 0.25V
											P01,			// 0 ~ 0.1V
											P005,			// 0 ~ 0.05V
											P0025,			// 0 ~ 0.025V
											P00125,			// 0 ~ 0.0125V
											P001,			// 0 ~ 0.01V
											P20MA,			// 0 ~ 20mA
											P4TO20MA,		// 4 ~ 20mA
											PM20MA,			// +/-20mA
											P1TO5 };		// 1 ~ 5V

// CInternalSyncGeneratingSamplingDlg message handlers

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

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	//----------------------------------------
	// Update the initial display of device name
	//----------------------------------------
	m_device_name.SetWindowTextW(_T("AIO000"));
	//----------------------------------------
	// Update the initial display of number of channels for analog output
	//----------------------------------------
	m_ao_channels.SetWindowTextW(_T("1"));
	//----------------------------------------
	// Update the initial display of generating clock
	//----------------------------------------
	m_ao_generating_clock.SetWindowTextW(_T("1000"));
	//----------------------------------------
	// Update the initial display of output data generating times
	//----------------------------------------
	m_ao_generating_times.SetWindowTextW(_T("1000"));
	//----------------------------------------
	// Create the combobox for analog output range
	//----------------------------------------
	m_ao_range.AddString(_T("-10 - +10V"));
	m_ao_range.AddString(_T("-5 - +5V"));
	m_ao_range.AddString(_T("-2.5 - +2.5V"));
	m_ao_range.AddString(_T("-1.25 - +1.25V"));
	m_ao_range.AddString(_T("-1 - +1V"));
	m_ao_range.AddString(_T("-0.625 - +0.625V"));
	m_ao_range.AddString(_T("-0.5 - +0.5V"));
	m_ao_range.AddString(_T("-0.3125 - +0.3125V"));
	m_ao_range.AddString(_T("-0.25 - +0.25V"));
	m_ao_range.AddString(_T("-0.125 - +0.125V"));
	m_ao_range.AddString(_T("-0.1 - +0.1V"));
	m_ao_range.AddString(_T("-0.05 - +0.05V"));
	m_ao_range.AddString(_T("-0.025 - +0.025V"));
	m_ao_range.AddString(_T("-0.0125 - +0.0125V"));
	m_ao_range.AddString(_T("-0.01 - +0.01V"));
	m_ao_range.AddString(_T("0 - +10V"));
	m_ao_range.AddString(_T("0 - +5V"));
	m_ao_range.AddString(_T("0 - +4.095V"));
	m_ao_range.AddString(_T("0 - +2.5V"));
	m_ao_range.AddString(_T("0 - +1.25V"));
	m_ao_range.AddString(_T("0 - +1V"));
	m_ao_range.AddString(_T("0 - +0.5V"));
	m_ao_range.AddString(_T("0 - +0.25V"));
	m_ao_range.AddString(_T("0 - +0.1V"));
	m_ao_range.AddString(_T("0 - +0.05V"));
	m_ao_range.AddString(_T("0 - +0.025V"));
	m_ao_range.AddString(_T("0 - +0.0125V"));
	m_ao_range.AddString(_T("0 - +0.01V"));
	m_ao_range.AddString(_T("0 - +20mA"));
	m_ao_range.AddString(_T("4 - +20mA"));
	m_ao_range.AddString(_T("1 - +5V"));
	//----------------------------------------
	// Change the selection of analog output range combobox to 0
	//----------------------------------------
	m_ao_range.SetCurSel(0);
	//----------------------------------------
	// Update the initial display of number of channels for analog input
	//----------------------------------------
	m_ai_channels.SetWindowTextW(_T("1"));
	//----------------------------------------
	// Create the combobox for analog input method
	//----------------------------------------
	m_ai_input_method.AddString(_T("Single-end input"));
	m_ai_input_method.AddString(_T("Differential input"));
	//----------------------------------------
	// Change the selection of analog input method combobox to 0
	//----------------------------------------
	m_ai_input_method.SetCurSel(0);
	//----------------------------------------
	// Create the combobox for analog input range
	//----------------------------------------
	m_ai_range.AddString(_T("-10 - +10V"));
	m_ai_range.AddString(_T("-5 - +5V"));
	m_ai_range.AddString(_T("-2.5 - +2.5V"));
	m_ai_range.AddString(_T("-1.25 - +1.25V"));
	m_ai_range.AddString(_T("-1 - +1V"));
	m_ai_range.AddString(_T("-0.625 - +0.625V"));
	m_ai_range.AddString(_T("-0.5 - +0.5V"));
	m_ai_range.AddString(_T("-0.3125 - +0.3125V"));
	m_ai_range.AddString(_T("-0.25 - +0.25V"));
	m_ai_range.AddString(_T("-0.125 - +0.125V"));
	m_ai_range.AddString(_T("-0.1 - +0.1V"));
	m_ai_range.AddString(_T("-0.05 - +0.05V"));
	m_ai_range.AddString(_T("-0.025 - +0.025V"));
	m_ai_range.AddString(_T("-0.0125 - +0.0125V"));
	m_ai_range.AddString(_T("-0.01 - +0.01V"));
	m_ai_range.AddString(_T("0 - +10V"));
	m_ai_range.AddString(_T("0 - +5V"));
	m_ai_range.AddString(_T("0 - +4.095V"));
	m_ai_range.AddString(_T("0 - +2.5V"));
	m_ai_range.AddString(_T("0 - +1.25V"));
	m_ai_range.AddString(_T("0 - +1V"));
	m_ai_range.AddString(_T("0 - +0.5V"));
	m_ai_range.AddString(_T("0 - +0.25V"));
	m_ai_range.AddString(_T("0 - +0.1V"));
	m_ai_range.AddString(_T("0 - +0.05V"));
	m_ai_range.AddString(_T("0 - +0.025V"));
	m_ai_range.AddString(_T("0 - +0.0125V"));
	m_ai_range.AddString(_T("0 - +0.01V"));
	m_ai_range.AddString(_T("0 - +20mA"));
	m_ai_range.AddString(_T("4 - +20mA"));
	m_ai_range.AddString(_T("-20mA - +20mA"));
	m_ai_range.AddString(_T("1 - +5V"));
	//----------------------------------------
	// Change the selection of analog input range combobox to 0
	//----------------------------------------
	m_ai_range.SetCurSel(0);
	//----------------------------------------
	// Initialize global variables
	//----------------------------------------
	g_id				= 0;
	g_generating_count	= 0;
	g_sampling_count	= 0;

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CInternalSyncGeneratingSamplingDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CInternalSyncGeneratingSamplingDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


//================================================================================
// It is the process when the AioInit button is clicked
// Initialize the device
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioInit()
{
	TCHAR	text_temp[256];		// For temporary storage of text
	char	device_name[256];	// Device name
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	long	ret;				// For return code

	//----------------------------------------
	// Get device name from textbox
	//----------------------------------------
	m_device_name.GetWindowTextW(text_temp, _countof(text_temp));
	sprintf_s(device_name, "%S", text_temp);
	//----------------------------------------
	// Device initialization
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioInit(device_name, &g_id);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioInit = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the AioResetDevice button is clicked
// Reset the device
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioResetDev()
{
	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

	//----------------------------------------
	// Reset device
	//----------------------------------------
	ret	= AioResetDevice(g_id);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioResetDevice = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Analog I/O Set button is clicked
// Set the analog I/O settings
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAiAoSetting()
{
	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	input_method;		// Input method

	//----------------------------------------
	// Update GUI information
	//----------------------------------------
	UpdateData(TRUE);
	//----------------------------------------
	// Get the index of analog input range setting value from combobox
	//----------------------------------------
	index	= m_ai_range.GetCurSel();
	//----------------------------------------
	// Set the analog input range (all channels)
	//----------------------------------------
	ret	= AioSetAiRangeAll(g_id, g_ai_range[index]);
	//----------------------------------------
	// 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("Analog I/O Set: AioSetAiRangeAll = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get the index of input method setting value from combobox
	//----------------------------------------
	input_method	= m_ai_input_method.GetCurSel();
	//----------------------------------------
	// Set the analog input method
	//----------------------------------------
	ret	= AioSetAiInputMethod(g_id, input_method);
	//----------------------------------------
	// 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("Analog I/O Set: AioSetAiInputMethod = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get the index of analog output range setting value from combobox
	//----------------------------------------
	index	= m_ao_range.GetCurSel();
	//----------------------------------------
	// Set the analog output range (all channels)
	//----------------------------------------
	ret	= AioSetAoRangeAll(g_id, g_ao_range[index]);
	//----------------------------------------
	// 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("Analog I/O Set: AioSetAoRangeAll = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the message that analog input/output settings is completed
	//----------------------------------------
	text_string.Format(_T("Analog I/O Set: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Generating/Sampling Set button is clicked
// Set the generating/sampling settings
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingSetting()
{
	TCHAR	text_temp[256];		// For temporary storage of text
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	CString	text_string_temp;	// For temporary storage of textbox
	long	ret;				// For return code
	short	ai_channels;		// Number of analog input channels
	short	ao_channels;		// Number of analog output channels
	float	generating_clock;	// Internal clock conversion speed

	//----------------------------------------
	// Get the number of analog input channels from textbox
	//----------------------------------------
	m_ai_channels.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%hd"), &ai_channels);
	//----------------------------------------
	// Set the number of analog input channels used for conversion
	//----------------------------------------
	ret	= AioSetAiChannels(g_id, ai_channels);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiChannels = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the analog input conversion data transfer mode to device buffer mode
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiTransferMode(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiTransferMode = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the data storage memory type to FIFO
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiMemoryType(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiMemoryType = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the sampling start condition to Event controller output
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiStartTrigger(g_id, 10);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiStartTrigger = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the clock type to Event controller output
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiClockType(g_id, 10);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiClockType = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the sampling stop condition to Event controller output
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiStopTrigger(g_id, 10);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiStopTrigger = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the event factor to 'Event that AD conversion start', 'Event that device operation end', 'Event that overflow', 
	// 'Event that sampling clock error', and 'Event that AD conversion error'.
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAiEvent(g_id, m_hWnd, (AIE_START | AIE_END | AIE_OFERR | AIE_SCERR | AIE_ADERR));
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAiEvent = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	//  Get the number of analog output channels from textbox
	//----------------------------------------
	m_ao_channels.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%hd"), &ao_channels);
	//----------------------------------------
	// Set the number of analog output channels used for conversion
	//----------------------------------------
	ret	= AioSetAoChannels(g_id, ao_channels);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoChannels = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the analog output conversion data transfer mode to device buffer mode
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAoTransferMode(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoTransferMode = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the data storage memory type to FIFO
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAoMemoryType(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoMemoryType = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the generating start condition to Software
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAoStartTrigger(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoStartTrigger = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the clock type to Internal Clock
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAoClockType(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoClockType = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get the internal clock conversion speed from textbox
	//----------------------------------------
	m_ao_generating_clock.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%f"), &generating_clock);
	//----------------------------------------
	// Set the internal clock conversion speed
	//----------------------------------------
	ret	= AioSetAoSamplingClock(g_id, generating_clock);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoSamplingClock = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the generating stop condition to Stop conversion by the specified times
	// Caution for modify this function (if modified, the application may not work)
	//----------------------------------------
	ret	= AioSetAoStopTrigger(g_id, 0);
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoStopTrigger = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the event factor to 'Event that device operation end', 
	// 'Event that sampling clock error', and 'Event that DA conversion error'.
	// Caution for modify this function (if modified, the application may not work
	//----------------------------------------
	ret	= AioSetAoEvent(g_id, m_hWnd, (AOE_END | AOE_SCERR | AOE_DAERR));
	//----------------------------------------
	// 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("Generating/Sampling Set: AioSetAoEvent = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the message that generating/sampling settings is completed
	//----------------------------------------
	text_string.Format(_T("Generating/Sampling Set: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Sync Operation Set button is clicked
// Set the synchronous operation settings
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonSyncSetting()
{
	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

	//----------------------------------------
	// Event Controller Setting: Connect Analog output internal clock signal to Analog input sampling clock
	//----------------------------------------
	ret	= AioSetEcuSignal(g_id, AIOECU_DEST_AI_CLK, AIOECU_SRC_AO_CLK);
	//----------------------------------------
	// 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("Sync Operation Set: AioSetEcuSignal = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Event Controller Setting: Connect Ao software start signal to Analog input converting start signal
	//----------------------------------------
	ret	= AioSetEcuSignal(g_id, AIOECU_DEST_AI_START, AIOECU_SRC_START);
	//----------------------------------------
	// 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("Sync Operation Set: AioSetEcuSignal = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Event Controller Setting: Connect Analog output signal that data of the specified sampling times have been output (FIFO) to Analog input converting stop signal
	//----------------------------------------
	ret	= AioSetEcuSignal(g_id, AIOECU_DEST_AI_STOP, AIOECU_SRC_AO_STOP_FIFO);
	//----------------------------------------
	// 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("Sync Operation Set: AioSetEcuSignal = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the message that synchronous operation settings is completed
	//----------------------------------------
	text_string.Format(_T("Sync Operation Set: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Output Data Set button is clicked
// Set the output data
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonOutputDataSettings()
{
	TCHAR	text_temp[256];		// For temporary storage of text
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	CString	text_string_temp;	// For temporary storage of textbox
	FILE	*fp;				// File pointer
	long	i, j;				// Loop count
	long	ret;				// For return code
	errno_t	file_ret;			// For return code of the file operation function
	long	generating_times;	// Generating times of output data
	short	ao_channels;		// Number of channels
	short	ao_range;			// Range
	float	gain, offset;		// Coefficient of sine waveform

	//----------------------------------------
	// Get the number of channels
	//----------------------------------------
	ret	= AioGetAoChannels(g_id, &ao_channels);
	//----------------------------------------
	// 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("Output Data Set: AioGetAoChannels = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get range (channel 0 only)
	//----------------------------------------
	ret	= AioGetAoRange(g_id, 0, &ao_range);
	//----------------------------------------
	// 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("Output Data Set: AioGetAoRange = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get generating times from textbox
	//----------------------------------------
	m_ao_generating_times.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%ld"), &generating_times);
	//----------------------------------------
	// Output data process
	//----------------------------------------
	//--------------------
	// Allocate an array for data storage
	//--------------------
	if(g_generating_data != NULL){
		free(g_generating_data);
		g_generating_data	= NULL;
	}
	g_generating_data	= (float *)malloc(sizeof(float) * generating_times * ao_channels);
	if(g_generating_data == NULL){
		text_string.Format(_T("Output Data Set: Failed to allocate an array for storing data"));
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Create analog output data: sine waveform
	//----------------------------------------
	switch(ao_range){
	case PM10:
		gain	= 10;
		offset	= 0;
		break;
	case PM5:
		gain	= 5;
		offset	= 0;
		break;
	case PM25:
		gain	= 2.5f;
		offset	= 0;
		break;
	case PM125:
		gain	= 1.25f;
		offset	= 0;
		break;
	case PM1:
		gain	= 1;
		offset	= 0;
		break;
	case PM0625:
		gain	= 0.625f;
		offset	= 0;
		break;
	case PM05:
		gain	= 0.5f;
		offset	= 0;
		break;
	case PM03125:
		gain	= 0.3125f;
		offset	= 0;
		break;
	case PM025:
		gain	= 0.25f;
		offset	= 0;
		break;
	case PM0125:
		gain	= 0.125f;
		offset	= 0;
		break;
	case PM01:
		gain	= 0.1f;
		offset	= 0;
		break;
	case PM005:
		gain	= 0.05f;
		offset	= 0;
		break;
	case PM0025:
		gain	= 0.025f;
		offset	= 0;
		break;
	case PM00125:
		gain	= 0.0125f;
		offset	= 0;
		break;
	case PM001:
		gain	= 0.01f;
		offset	= 0;
		break;
	case P10:
		gain	= 5;
		offset	= 5;
		break;
	case P5:
		gain	= 2.5f;
		offset	= 2.5f;
		break;
	case P4095:
		gain	= 2.0475f;
		offset	= 2.0475f;
		break;
	case P25:
		gain	= 1.25f;
		offset	= 1.25f;
		break;
	case P125:
		gain	= 0.625f;
		offset	= 0.625f;
		break;
	case P1:
		gain	= 0.5f;
		offset	= 0.5f;
		break;
	case P05:
		gain	= 0.25f;
		offset	= 0.25f;
		break;
	case P025:
		gain	= 0.125f;
		offset	= 0.125f;
		break;
	case P01:
		gain	= 0.05f;
		offset	= 0.05f;
		break;
	case P005:
		gain	= 0.025f;
		offset	= 0.025f;
		break;
	case P0025:
		gain	= 0.0125f;
		offset	= 0.0125f;
		break;
	case P00125:
		gain	= 0.00625f;
		offset	= 0.00625f;
		break;
	case P001:
		gain	= 0.005f;
		offset	= 0.005f;
		break;
	case P20MA:
		gain	= 10;
		offset	= 10;
		break;
	case P4TO20MA:
		gain	= 8;
		offset	= 12;
		break;
	case P1TO5:
		gain	= 2;
		offset	= 3;
		break;
	default:
		gain	= 10;
		offset	= 0;
		break;
	}
	for(i = 0; i < generating_times; i++){
		for(j = 0; j < ao_channels; j++){
			g_generating_data[i * ao_channels + j]	= (float)(gain * sin(2 * 3.14159265358979 * i / generating_times + 3.14159265358979 / 2 * (j % 4)) + offset);
		}
	}
	//----------------------------------------
	// Set analog output data
	//----------------------------------------
	ret	= AioSetAoSamplingDataEx(g_id, generating_times, g_generating_data);
	//----------------------------------------
	// 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("Output Data Set: AioSetAoSamplingDataEx = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Open file
	//----------------------------------------
	file_ret	= _wfopen_s(&fp, g_file_name, _T("w"));
	if(file_ret != 0){
		text_string.Format(_T("Output Data Set: fopen = file open error."));
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Create file
	//----------------------------------------
	for(i = 0; i < generating_times; i++){
		text_string.Empty();
		//--------------------
		// Generate display string
		//--------------------
		text_string_temp.Format(_T("%5ld,"), (i + 1));
		text_string	+= text_string_temp;
		//--------------------
		// Repeat the process for the specified number of channels
		//--------------------
		for(j = 0; j < ao_channels; j++){
			text_string_temp.Format(_T(" %10.5f"), g_generating_data[i * ao_channels + j]);
			text_string	+= text_string_temp;
			//--------------------
			// Add newline character for the last channel
			//--------------------
			if(j == (ao_channels - 1)){
				text_string_temp.Format(_T("\n"));
				text_string	+= text_string_temp;
			//--------------------
			// Add comma for channels other than the last channel
			//--------------------
			}else{
				text_string_temp.Format(_T(","));
				text_string	+= text_string_temp;
			}
		}
		//----------------------------------------
		// Write data
		//----------------------------------------
		fputws(text_string, fp);
	}
	//----------------------------------------
	// Close file
	//----------------------------------------
	fclose(fp);
	//----------------------------------------
	// Display message
	//----------------------------------------
	m_return_code.SetWindowText(_T("Output Data Set: Successful completion"));
}

//================================================================================
// It is the process when the Generating/Sampling Start button is clicked
// After clearing the memory and status, start generating/sampling.
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingStart()
{
	TCHAR	text_temp[256];		// For temporary storage of text
	char	error_string[256];	// Error code string
	CString	text_string;		// For updating the textbox
	CString	text_string_temp;	// For temporary storage of textbox
	long	ai_status;			// Analog input status
	long	ao_status;			// Analog output status
	long	ret;				// For return code

	//----------------------------------------
	// Clear memory
	//----------------------------------------
	ret	= AioResetAiMemory(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioResetAiMemory = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Clear status
	//----------------------------------------
	ret	= AioResetAiStatus(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioResetAiStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Initialize the total sampling count
	//----------------------------------------
	g_sampling_count	= 0;
	//----------------------------------------
	// Start sampling
	//----------------------------------------
	ret	= AioStartAi(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioStartAi = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get status
	//----------------------------------------
	ret	= AioGetAiStatus(g_id, &ai_status);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioGetAiStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display status
	//----------------------------------------
	text_string.Format(_T("%08xH ("), ai_status);
	//--------------------
	// When status 'Device is running' is ON
	//--------------------
	if((ai_status & AIS_BUSY) == AIS_BUSY){
		text_string_temp.Format(_T("Operating"));
		text_string	+= text_string_temp;
	//--------------------
	// When status 'Device is running' is OFF
	//--------------------
	}else{
		text_string_temp.Format(_T("Stop"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Wait the start trigger' is ON
	//--------------------
	if((ai_status & AIS_START_TRG) == AIS_START_TRG){
		text_string_temp.Format(_T(", Wait the start trigger"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'The specified number of data are stored' is ON
	//--------------------
	if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
		text_string_temp.Format(_T(", The specified number of data are stored"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Overflow' is ON
	//--------------------
	if((ai_status & AIS_OFERR) == AIS_OFERR){
		text_string_temp.Format(_T(", Overflow"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Sampling clock error' is ON
	//--------------------
	if((ai_status & AIS_SCERR) == AIS_SCERR){
		text_string_temp.Format(_T(", Sampling clock error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'AD conversion error' is ON
	//--------------------
	if((ai_status & AIS_AIERR) == AIS_AIERR){
		text_string_temp.Format(_T(", AD conversion error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Driver spec error' is ON
	//--------------------
	if((ai_status & AIS_DRVERR) == AIS_DRVERR){
		text_string_temp.Format(_T(", Driver spec error"));
		text_string	+= text_string_temp;
	}
	text_string_temp.Format(_T(")"));
	text_string	+= text_string_temp;
	m_ai_status.SetWindowText(text_string);
	//----------------------------------------
	// Update the sampling count
	//----------------------------------------
	text_string.Format(_T("0"));
	m_ai_sampling_count.SetWindowText(text_string);
	//----------------------------------------
	// Clear the listbox for sampling data display
	//----------------------------------------
	m_ai_sampling_data.ResetContent();
	//----------------------------------------
	// Reset the analog output status
	//----------------------------------------
	ret	= AioResetAoStatus(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioResetAoStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Initialize the total generating count
	//----------------------------------------
	g_generating_count	= 0;
	//----------------------------------------
	// Start generating
	//----------------------------------------
	ret	= AioStartAo(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioStartAo = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get status
	//----------------------------------------
	ret	= AioGetAoStatus(g_id, &ao_status);
	//----------------------------------------
	// 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("Generating/Sampling Start: AioGetAoStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display status
	//----------------------------------------
	text_string.Format(_T("%08xH ("), ao_status);
	//--------------------
	// When status 'Device is running' is ON
	//--------------------
	if((ao_status & AOS_BUSY) == AOS_BUSY){
		text_string_temp.Format(_T("Operating"));
	//--------------------
	// When status 'Device is running' is OFF
	//--------------------
	}else{
		text_string_temp.Format(_T("Stop"));
	}
	text_string	+= text_string_temp;
	//--------------------
	// When status 'Wait the start trigger' is ON
	//--------------------
	if((ao_status & AOS_START_TRG) == AOS_START_TRG){
		text_string_temp.Format(_T(", Wait the start trigger"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'The specified number of data are output' is ON
	//--------------------
	if((ao_status & AOS_DATA_NUM) == AOS_DATA_NUM){
		text_string_temp.Format(_T(", The specified number of data are output"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Sampling clock error' is ON
	//--------------------
	if((ao_status & AOS_SCERR) == AOS_SCERR){
		text_string_temp.Format(_T(", Sampling clock error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'DA conversion error' is ON
	//--------------------
	if((ao_status & AOS_AOERR) == AOS_AOERR){
		text_string_temp.Format(_T(", DA conversion error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Driver spec error' is ON
	//--------------------
	if((ao_status & AOS_DRVERR) == AOS_DRVERR){
		text_string_temp.Format(_T(", Driver spec error"));
		text_string	+= text_string_temp;
	}
	text_string_temp.Format(_T(")"));
	text_string	+= text_string_temp;
	m_ao_status.SetWindowText(text_string);
	//----------------------------------------
	// Update generating count
	//----------------------------------------
	text_string.Format(_T("0"));
	m_ao_generating_count.SetWindowText(text_string);
	//----------------------------------------
	// Display the message that generating/sampling start is completed
	//----------------------------------------
	text_string.Format(_T("Generating/Sampling Start: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Get Status button is clicked
// Get the count and status of generating/sampling and display it on the dialog
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGetStatus()
{
	TCHAR	text_temp[256];			// For temporary storage of text
	char	error_string[256];		// Error code string
	CString	text_string;			// For updating the textbox
	CString	text_string_temp;		// For temporary storage of textbox
	long	ai_sampling_count;		// Sampling count
	long	ai_status;				// Sampling status
	long	ao_generating_count;	// Generating count
	long	ao_status;				// Generating status
	long	ret;					// For return code

	//----------------------------------------
	// Get the sampling count
	//----------------------------------------
	ret	= AioGetAiSamplingCount(g_id, &ai_sampling_count);
	//----------------------------------------
	// 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("Get Status: AioGetAiSamplingCount = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display sampling count
	//----------------------------------------
	text_string.Format(_T("%d"), ai_sampling_count);
	m_ai_sampling_count.SetWindowText(text_string);
	//----------------------------------------
	// Get sampling status
	//----------------------------------------
	ret	= AioGetAiStatus(g_id, &ai_status);
	//----------------------------------------
	// 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("Get Status: AioGetAiStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display status
	//----------------------------------------
	text_string.Format(_T("%08xH ("), ai_status);
	//--------------------
	// When status 'Device is running' is ON
	//--------------------
	if((ai_status & AIS_BUSY) == AIS_BUSY){
		text_string_temp.Format(_T("Operating"));
	//--------------------
	// When status 'Device is running' is OFF
	//--------------------
	}else{
		text_string_temp.Format(_T("Stop"));
	}
	text_string	+= text_string_temp;
	//--------------------
	// When status 'Wait the start trigger' is ON
	//--------------------
	if((ai_status & AIS_START_TRG) == AIS_START_TRG){
		text_string_temp.Format(_T(", Wait the start trigger"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'The specified number of data are stored' is ON
	//--------------------
	if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
		text_string_temp.Format(_T(", The specified number of data are stored"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Overflow' is ON
	//--------------------
	if((ai_status & AIS_OFERR) == AIS_OFERR){
		text_string_temp.Format(_T(", Overflow"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Sampling clock error' is ON
	//--------------------
	if((ai_status & AIS_SCERR) == AIS_SCERR){
		text_string_temp.Format(_T(", Sampling clock error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'AD conversion error' is ON
	//--------------------
	if((ai_status & AIS_AIERR) == AIS_AIERR){
		text_string_temp.Format(_T(", AD conversion error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Driver spec error' is ON
	//--------------------
	if((ai_status & AIS_DRVERR) == AIS_DRVERR){
		text_string_temp.Format(_T(", Driver spec error"));
		text_string	+= text_string_temp;
	}
	text_string_temp.Format(_T(")"));
	text_string	+= text_string_temp;
	m_ai_status.SetWindowText(text_string);
	//----------------------------------------
	// Get generating count
	//----------------------------------------
	ret	= AioGetAoSamplingCount(g_id, &ao_generating_count);
	//----------------------------------------
	// 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("Get Status: AioGetAoSamplingCount = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Update the generating count
	//----------------------------------------
	text_string.Format(_T("%d"), ao_generating_count);
	m_ao_generating_count.SetWindowText(text_string);
	//----------------------------------------
	// Get generating status
	//----------------------------------------
	ret	= AioGetAoStatus(g_id, &ao_status);
	//----------------------------------------
	// 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("Get Status: AioGetAoStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display status
	//----------------------------------------
	text_string.Format(_T("%08xH ("), ao_status);
	//--------------------
	// When status 'Device is running' is ON
	//--------------------
	if((ao_status & AOS_BUSY) == AOS_BUSY){
		text_string_temp.Format(_T("Operating"));
	//--------------------
	// When status 'Device is running' is OFF
	//--------------------
	}else{
		text_string_temp.Format(_T("Stop"));
	}
	text_string	+= text_string_temp;
	//--------------------
	// When status 'Wait the start trigger' is ON
	//--------------------
	if((ao_status & AOS_START_TRG) == AOS_START_TRG){
		text_string_temp.Format(_T(", Wait the start trigger"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'The specified number of data are output' is ON
	//--------------------
	if((ao_status & AOS_DATA_NUM) == AOS_DATA_NUM){
		text_string_temp.Format(_T(", The specified number of data are output"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Sampling clock error' is ON
	//--------------------
	if((ao_status & AOS_SCERR) == AOS_SCERR){
		text_string_temp.Format(_T(", Sampling clock error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'DA conversion error' is ON
	//--------------------
	if((ao_status & AOS_AOERR) == AOS_AOERR){
		text_string_temp.Format(_T(", DA conversion error"));
		text_string	+= text_string_temp;
	}
	//--------------------
	// When status 'Driver spec error' is ON
	//--------------------
	if((ao_status & AOS_DRVERR) == AOS_DRVERR){
		text_string_temp.Format(_T(", Driver spec error"));
		text_string	+= text_string_temp;
	}
	text_string_temp.Format(_T(")"));
	text_string	+= text_string_temp;
	m_ao_status.SetWindowText(text_string);
	//----------------------------------------
	// Display the message that get status is completed
	//----------------------------------------
	text_string.Format(_T("Get Status: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Generating/Sampling Stop button is clicked
// Stop generating/sampling
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonGeneratingSamplingStop()
{
	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

	//----------------------------------------
	// Stop generating
	//----------------------------------------
	ret	= AioStopAo(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Stop: AioStopAo = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Stop sampling
	//----------------------------------------
	ret	= AioStopAi(g_id);
	//----------------------------------------
	// 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("Generating/Sampling Stop: AioStopAi = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the message that generating/sampling stop is completed
	//----------------------------------------
	text_string.Format(_T("Generating/Sampling Stop: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Output Acquired Data to File button is clicked
// Output the globally held sampling data to a CSV file
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonOutputSamplingData()
{
	TCHAR	text_temp[256];							// For temporary storage of text
	char	error_string[256];						// Error code string
	TCHAR	file_name[] = _T("SamplingData.csv");	// Sampling data output file name
	CString	text_string;							// For updating the textbox
	CString	text_string_temp;						// For temporary storage of textbox
	FILE	*fp;									// File pointer
	long	i, j;									// Loop count
	long	ret;									// For return code
	errno_t	file_ret;								// For return code of the file operation function
	short	ai_channels;							// Number of channels

	//----------------------------------------
	// Open file
	//----------------------------------------
	file_ret	= _wfopen_s(&fp, file_name, _T("w"));
	if(file_ret != 0){
		text_string.Format(_T("Output Acquired Data to File: fopen = file open error."));
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get the number of channels
	//----------------------------------------
	ret	= AioGetAiChannels(g_id, &ai_channels);
	//----------------------------------------
	// 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("Output Acquired Data to File: AioGetAiChannels = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		//----------------------------------------
		// Close file
		//----------------------------------------
		fclose(fp);
		return;
	}
	//----------------------------------------
	// Create sampling data for file output
	//----------------------------------------
	//--------------------
	// If the total sampling count is 1 or more and pointer to sampling data storage area is not NULL, output the file
	//--------------------
	if((g_sampling_count > 0) && (g_sampling_data != NULL)){
		//--------------------
		// Repeat the process up to the total sampling count
		//--------------------
		for(i = 0; i < g_sampling_count; i++){
			text_string.Empty();
			//--------------------
			// Generate display string
			//--------------------
			text_string_temp.Format(_T("%5d,"), (i + 1));
			text_string	+= text_string_temp;
			//--------------------
			// Repeat the process for the specified number of channels
			//--------------------
			for(j = 0; j < ai_channels; j++){
				text_string_temp.Format(_T(" % 10.5f"), g_sampling_data[i * ai_channels + j]);
				text_string	+= text_string_temp;
				//--------------------
				// Add newline character for the last channel
				//--------------------
				if(j == (ai_channels - 1)){
					text_string_temp.Format(_T("\n"));
					text_string	+= text_string_temp;
				//--------------------
				// Add comma for channels other than the last channel
				//--------------------
				}else{
					text_string_temp.Format(_T(","));
					text_string	+= text_string_temp;
				}
			}
			//----------------------------------------
			// Write data
			//----------------------------------------
			fputws(text_string, fp);
		}
	}
	//----------------------------------------
	// Close file
	//----------------------------------------
	fclose(fp);
	//----------------------------------------
	// Display the message that file output is completed
	//----------------------------------------
	text_string.Format(_T("Output Acquired Data to File: Save data to \"%s\"."), file_name);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the AioExit button is clicked
// Perform the exit process of device
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedButtonAioExit()
{
	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

	//----------------------------------------
	// Release the array for storing AD conversion data
	//----------------------------------------
	if(g_sampling_data != NULL){
		free(g_sampling_data);
		g_sampling_data = NULL;
	}
	//----------------------------------------
	// Release the output data buffer
	//----------------------------------------
	if(g_generating_data != NULL){
		free(g_generating_data);
		g_generating_data	= NULL;
	}
	//----------------------------------------
	// Exit process
	//----------------------------------------
	ret	= AioExit(g_id);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioExit = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Close button is clicked
// Perform the exit process of device and terminate the application
//================================================================================
void CInternalSyncGeneratingSamplingDlg::OnBnClickedClose()
{
	//----------------------------------------
	// Release the array for storing AD conversion data
	//----------------------------------------
	if(g_sampling_data != NULL){
		free(g_sampling_data);
		g_sampling_data = NULL;
	}
	//----------------------------------------
	// Release the output data buffer
	//----------------------------------------
	if(g_generating_data != NULL){
		free(g_generating_data);
		g_generating_data	= NULL;
	}
	//----------------------------------------
	// Exit process
	//----------------------------------------
	AioExit(g_id);
	//----------------------------------------
	// Close dialog
	//----------------------------------------
	CDialog::OnOK();
}

//================================================================================
// Operation when event occurred
// Process for each event occurred
//================================================================================
LRESULT CInternalSyncGeneratingSamplingDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	TCHAR			text_temp[256];			// For temporary storage of text
	char			error_string[256];		// Error code string
	CString			text_string;			// For updating the textbox
	CString			text_string_temp;		// For temporary storage of textbox
	CDC				*device_context;		// Device context of ListBox for sampling data display
	CFont			*old_font;				// Font settings of ListBox for sampling data display
	unsigned long	string_length;			// String width of ListBox for sampling data display
	unsigned long	max_string_length;		// Maximum string width of ListBox for displaying sampling data
	long			ai_sampling_count;		// Sampling count
	long			ai_status;				// Sampling Status
	long			ao_generating_count;	// Generating count
	long			ao_status;				// Generating Status
	long			ret;					// For return code
	long			i, j;					// Loop count
	long			loop_max_count;			// Maximum loop count
	long			top_address;			// Top address of buffer for sampling data display
	short			ai_channels;			// Number of channels

	//----------------------------------------
	// [Sampling]
	// Event that AD conversion start
	// Display the status
	//----------------------------------------
	if(message == AIOM_AIE_START){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAiStatus(g_id, &ai_status);
		//----------------------------------------
		// 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("Event that AD conversion start Process: AioGetAiStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ai_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ai_status & AIS_BUSY) == AIS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ai_status & AIS_START_TRG) == AIS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are stored' is ON
		//--------------------
		if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are stored"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Overflow' is ON
		//--------------------
		if((ai_status & AIS_OFERR) == AIS_OFERR){
			text_string_temp.Format(_T(", Overflow"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ai_status & AIS_SCERR) == AIS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'AD conversion error' is ON
		//--------------------
		if((ai_status & AIS_AIERR) == AIS_AIERR){
			text_string_temp.Format(_T(", AD conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ai_status & AIS_DRVERR) == AIS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ai_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Event that AD conversion start Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Sampling]
	// Event that device operation end
	// Acquire and display data
	//----------------------------------------
	if(message == AIOM_AIE_END){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAiStatus(g_id, &ai_status);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAiStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ai_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ai_status & AIS_BUSY) == AIS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ai_status & AIS_START_TRG) == AIS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are stored' is ON
		//--------------------
		if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are stored"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Overflow' is ON
		//--------------------
		if((ai_status & AIS_OFERR) == AIS_OFERR){
			text_string_temp.Format(_T(", Overflow"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ai_status & AIS_SCERR) == AIS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'AD conversion error' is ON
		//--------------------
		if((ai_status & AIS_AIERR) == AIS_AIERR){
			text_string_temp.Format(_T(", AD conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ai_status & AIS_DRVERR) == AIS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ai_status.SetWindowText(text_string);
		//----------------------------------------
		// Get the current sampling count
		//----------------------------------------
		ret	= AioGetAiSamplingCount(g_id, &ai_sampling_count);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAiSamplingCount = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display sampling count
		//----------------------------------------
		text_string.Format(_T("%d"), ai_sampling_count);
		m_ai_sampling_count.SetWindowText(text_string);
		//----------------------------------------
		// Get the number of channels
		//----------------------------------------
		ret	= AioGetAiChannels(g_id, &ai_channels);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAiChannels = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Get sampling data process
		//----------------------------------------
		//--------------------
		// Allocate an array for storing data
		//--------------------
		if(g_sampling_data != NULL){
			free(g_sampling_data);
			g_sampling_data = NULL;
		}
		g_sampling_data	= (float *)malloc(sizeof(float) * ai_sampling_count * ai_channels);
		if(g_sampling_data == NULL){
			text_string.Format(_T("Device Operation End Event Process: Failed to allocate an array for storing data"));
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Get sampling data
		//----------------------------------------
		ret	= AioGetAiSamplingDataEx(g_id, &ai_sampling_count, g_sampling_data);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAiSamplingDataEx = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Update the total sampling count
		//----------------------------------------
		g_sampling_count	= ai_sampling_count;
		//----------------------------------------
		// Set the loop count for the sampling data display loop
		//----------------------------------------
		//--------------------
		// When the sampling count of the data acquired this time exceeds the maximum sampling number of data display
		//--------------------
		if(ai_sampling_count > DISPLAY_SAMPLING_COUNT){
			//--------------------
			// Limit the maximum number of loops to the data display maximum sampling count
			//--------------------
			loop_max_count	= DISPLAY_SAMPLING_COUNT;
			//--------------------
			// Set the top address of the buffer to be referenced to the address 
			// before the maximum sampling count for data display from the end of the acquired data
			//--------------------
			top_address		= ai_sampling_count - DISPLAY_SAMPLING_COUNT;
		//--------------------
		// When the sampling count of the data acquired this time is less than or equal to the maximum sampling number of data display
		//--------------------
		}else{
			//--------------------
			// Set the number of total sampling data to the maximum loop number
			//--------------------
			loop_max_count	= ai_sampling_count;
			//--------------------
			// Set the top address of the referenced buffer to 0
			//--------------------
			top_address		= 0;
		}
		//----------------------------------------
		// Display sampling data
		// (Display from the end of acquired data to the maximum number of data display sampling count)
		//----------------------------------------
		//--------------------
		// When the sampling count of the data acquired this time is 1 or more
		//--------------------
		if(ai_sampling_count > 0){
			//--------------------
			// Get device context for listbox
			//--------------------
			device_context		= m_ai_sampling_data.GetDC();
			old_font			= device_context->SelectObject(m_ai_sampling_data.GetFont());
			max_string_length	= 0;
			string_length		= 0;
			//--------------------
			// Clear the listbox for sampling data display
			//--------------------
			m_ai_sampling_data.ResetContent();
			//--------------------
			// Repeat the process up to the maximum sampling count of the display data
			//--------------------
			for(i = top_address; i < (loop_max_count + top_address); i++){
				//--------------------
				// Clear display string storage variable
				//--------------------
				text_string.Empty();
				//--------------------
				// Generate display string
				//--------------------
				text_string_temp.Format(_T("%5d:  "), (i + 1));
				text_string	+= text_string_temp;
				//--------------------
				// Repeat the process for the specified number of channels
				//--------------------
				for(j = 0; j < ai_channels; j++){
					text_string_temp.Format(_T(" % 10.5f"), g_sampling_data[i * ai_channels + j]);
					text_string	+= text_string_temp;
				}
				//----------------------------------------
				// Adjust horizontal width of listbox
				//----------------------------------------
				string_length	= device_context->GetTextExtent(text_string).cx;
				//--------------------
				// If the horizontal width of the string to be added is greater than the current maximum
				//--------------------
				if(string_length > max_string_length){
					//--------------------
					// Set horizontal width
					//--------------------
					m_ai_sampling_data.SetHorizontalExtent(string_length);
					//--------------------
					// Update maximum horizontal width
					//--------------------
					max_string_length	= string_length;
				}
				//----------------------------------------
				// Display sampling start data
				//----------------------------------------
				m_ai_sampling_data.AddString(text_string);
			}
			//--------------------
			// Release device context of listbox
			//--------------------
			device_context->SelectObject(old_font);
			ReleaseDC(device_context);
		}
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Device Operation End Event Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Sampling]
	// Event that overflow
	// Display the status
	//----------------------------------------
	if(message == AIOM_AIE_OFERR){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAiStatus(g_id, &ai_status);
		//----------------------------------------
		// 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("Overflow Occurrence Process: AioGetAiStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ai_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ai_status & AIS_BUSY) == AIS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ai_status & AIS_START_TRG) == AIS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are stored' is ON
		//--------------------
		if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are stored"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Overflow' is ON
		//--------------------
		if((ai_status & AIS_OFERR) == AIS_OFERR){
			text_string_temp.Format(_T(", Overflow"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ai_status & AIS_SCERR) == AIS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'AD conversion error' is ON
		//--------------------
		if((ai_status & AIS_AIERR) == AIS_AIERR){
			text_string_temp.Format(_T(", AD conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ai_status & AIS_DRVERR) == AIS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ai_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Overflow Occurrence Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Sampling]
	// Event that sampling clock error
	// Display the status
	//----------------------------------------
	if(message == AIOM_AIE_SCERR){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAiStatus(g_id, &ai_status);
		//----------------------------------------
		// 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("Sampling Clock Error Occurrence Process: AioGetAiStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ai_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ai_status & AIS_BUSY) == AIS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ai_status & AIS_START_TRG) == AIS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are stored' is ON
		//--------------------
		if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are stored"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Overflow' is ON
		//--------------------
		if((ai_status & AIS_OFERR) == AIS_OFERR){
			text_string_temp.Format(_T(", Overflow"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ai_status & AIS_SCERR) == AIS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'AD conversion error' is ON
		//--------------------
		if((ai_status & AIS_AIERR) == AIS_AIERR){
			text_string_temp.Format(_T(", AD conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ai_status & AIS_DRVERR) == AIS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ai_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Sampling Clock Error Occurrence Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Sampling]
	// Event that AD conversion error
	// Display the status
	//----------------------------------------
	if(message == AIOM_AIE_ADERR){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAiStatus(g_id, &ai_status);
		//----------------------------------------
		// 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("AD Conversion Error Occurrence Process: AioGetAiStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ai_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ai_status & AIS_BUSY) == AIS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ai_status & AIS_START_TRG) == AIS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are stored' is ON
		//--------------------
		if((ai_status & AIS_DATA_NUM) == AIS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are stored"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Overflow' is ON
		//--------------------
		if((ai_status & AIS_OFERR) == AIS_OFERR){
			text_string_temp.Format(_T(", Overflow"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ai_status & AIS_SCERR) == AIS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'AD conversion error' is ON
		//--------------------
		if((ai_status & AIS_AIERR) == AIS_AIERR){
			text_string_temp.Format(_T(", AD conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ai_status & AIS_DRVERR) == AIS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ai_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("AD Conversion Error Occurrence Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Generating]
	// Event that device operation end
	// Acquire and display data
	//----------------------------------------
	if(message == AIOM_AOE_END){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAoStatus(g_id, &ao_status);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAoStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ao_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ao_status & AOS_BUSY) == AOS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ao_status & AOS_START_TRG) == AOS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are output' is ON
		//--------------------
		if((ao_status & AOS_DATA_NUM) == AOS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are output"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ao_status & AOS_SCERR) == AOS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'DA conversion error' is ON
		//--------------------
		if((ao_status & AOS_AOERR) == AOS_AOERR){
			text_string_temp.Format(_T(", DA conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ao_status & AOS_DRVERR) == AOS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ao_status.SetWindowText(text_string);
		//----------------------------------------
		// Get the current generating count
		//----------------------------------------
		ret	= AioGetAoSamplingCount(g_id, &ao_generating_count);
		//----------------------------------------
		// 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("Device Operation End Event Process: AioGetAoSamplingCount = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display generating count
		//----------------------------------------
		text_string.Format(_T("%d"), ao_generating_count);
		m_ao_generating_count.SetWindowText(text_string);
		//----------------------------------------
		// Update the total generating count
		//----------------------------------------
		g_generating_count	= ao_generating_count;
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Device Operation End Event Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Generating]
	// Event that sampling clock error
	// Display the status
	//----------------------------------------
	if(message == AIOM_AOE_SCERR){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAoStatus(g_id, &ao_status);
		//----------------------------------------
		// 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("Sampling Clock Error Occurrence Process: AioGetAoStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ao_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ao_status & AOS_BUSY) == AOS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ao_status & AOS_START_TRG) == AOS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are output' is ON
		//--------------------
		if((ao_status & AOS_DATA_NUM) == AOS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are output"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ao_status & AOS_SCERR) == AOS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'DA conversion error' is ON
		//--------------------
		if((ao_status & AOS_AOERR) == AOS_AOERR){
			text_string_temp.Format(_T(", DA conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ao_status & AOS_DRVERR) == AOS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ao_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Sampling Clock Error Occurrence Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// [Generating]
	// Event that DA conversion error
	// Display the status
	//----------------------------------------
	if(message == AIOM_AOE_DAERR){
		//----------------------------------------
		// Get status
		//----------------------------------------
		ret	= AioGetAoStatus(g_id, &ao_status);
		//----------------------------------------
		// 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("DA Conversion Error Occurrence Process: AioGetAoStatus = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display status
		//----------------------------------------
		text_string.Format(_T("%08xH ("), ao_status);
		//--------------------
		// When status 'Device is running' is ON
		//--------------------
		if((ao_status & AOS_BUSY) == AOS_BUSY){
			text_string_temp.Format(_T("Operating"));
		//--------------------
		// When status 'Device is running' is OFF
		//--------------------
		}else{
			text_string_temp.Format(_T("Stop"));
		}
		text_string	+= text_string_temp;
		//--------------------
		// When status 'Wait the start trigger' is ON
		//--------------------
		if((ao_status & AOS_START_TRG) == AOS_START_TRG){
			text_string_temp.Format(_T(", Wait the start trigger"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'The specified number of data are output' is ON
		//--------------------
		if((ao_status & AOS_DATA_NUM) == AOS_DATA_NUM){
			text_string_temp.Format(_T(", The specified number of data are output"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Sampling clock error' is ON
		//--------------------
		if((ao_status & AOS_SCERR) == AOS_SCERR){
			text_string_temp.Format(_T(", Sampling clock error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'DA conversion error' is ON
		//--------------------
		if((ao_status & AOS_AOERR) == AOS_AOERR){
			text_string_temp.Format(_T(", DA conversion error"));
			text_string	+= text_string_temp;
		}
		//--------------------
		// When status 'Driver spec error' is ON
		//--------------------
		if((ao_status & AOS_DRVERR) == AOS_DRVERR){
			text_string_temp.Format(_T(", Driver spec error"));
			text_string	+= text_string_temp;
		}
		text_string_temp.Format(_T(")"));
		text_string	+= text_string_temp;
		m_ao_status.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("DA Conversion Error Occurrence Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}

	return CDialogEx::DefWindowProc(message, wParam, lParam);
}
