﻿
// AoGeneratingInfiniteDevDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AoGeneratingInfiniteDev.h"
#include "AoGeneratingInfiniteDevDlg.h"
#include "ConditionDlg.h"
#include "afxdialogex.h"
#include "Caio.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAoGeneratingInfiniteDevDlg dialog



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

void CAoGeneratingInfiniteDevDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_DEVICE_NAME, m_device_name);
	DDX_Control(pDX, IDC_COMBO_RANGE_VALUE, m_ao_range);
	DDX_Control(pDX, IDC_EDIT_CH_NUM, m_ao_channels);
	DDX_Control(pDX, IDC_EDIT_GENERATING_TIMES, m_ao_generating_times);
	DDX_Control(pDX, IDC_EDIT_EVENT_GENERATING_TIMES, m_ao_event_generating_times);
	DDX_Control(pDX, IDC_EDIT_TOTAL_GENERATING_COUNT, m_total_generating_count);
	DDX_Control(pDX, IDC_EDIT_SETTING_GENERATING_COUNT, m_setting_generating_count);
	DDX_Control(pDX, IDC_EDIT_STATUS, m_ao_status);
	DDX_Control(pDX, IDC_EDIT_RETURN_CODE, m_return_code);
}

BEGIN_MESSAGE_MAP(CAoGeneratingInfiniteDevDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_AIO_INIT, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonAioInit)
	ON_BN_CLICKED(IDC_BUTTON_RESET_DEVICE, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonResetDevice)
	ON_BN_CLICKED(IDC_BUTTON_SET_AO_RANGE_ALL, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoRangeAll)
	ON_BN_CLICKED(IDC_BUTTON_SET_AO_CHANNELS, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoChannels)
	ON_BN_CLICKED(IDC_BUTTON_CONDITION_SETTINGS, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonConditionSettings)
	ON_BN_CLICKED(IDC_BUTTON_OUTPUT_DATA_GENERATE, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonOutputDataGenerate)
	ON_BN_CLICKED(IDC_BUTTON_SET_AO_EVENT_SAMPLING_TIMES, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoEventSamplingTimes)
	ON_BN_CLICKED(IDC_BUTTON_GENERATING_START, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGeneratingStart)
	ON_BN_CLICKED(IDC_BUTTON_GET_AO_SAMPLING_COUNT, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoSamplingCount)
	ON_BN_CLICKED(IDC_BUTTON_GET_AO_SAMPLING_TIMES, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoSamplingTimes)
	ON_BN_CLICKED(IDC_BUTTON_GET_AO_STATUS, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoStatus)
	ON_BN_CLICKED(IDC_BUTTON_GENERATING_STOP, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGeneratingStop)
	ON_BN_CLICKED(IDC_BUTTON_AIO_EXIT, &CAoGeneratingInfiniteDevDlg::OnBnClickedButtonAioExit)
	ON_BN_CLICKED(IDCLOSE, &CAoGeneratingInfiniteDevDlg::OnBnClickedClose)
END_MESSAGE_MAP()

//----------------------------------------
// Macro definition
//----------------------------------------
#define MAX_AO_RANGE_NUM	31								// Maximum number of elements in analog output range array
//----------------------------------------
// 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_times;									// Generating times
float *	g_generating_data;									// 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

// CAoGeneratingInfiniteDevDlg message handlers

BOOL CAoGeneratingInfiniteDevDlg::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 output data generating times
	//----------------------------------------
	m_ao_generating_times.SetWindowTextW(_T("1000"));
	//----------------------------------------
	// Update the initial display of the generating times when "Event that the specified number of data are output" is used
	//----------------------------------------
	m_ao_event_generating_times.SetWindowTextW(_T("500"));
	//----------------------------------------
	// 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);
	//----------------------------------------
	// Initialize global variables
	//----------------------------------------
	g_id	= 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 CAoGeneratingInfiniteDevDlg::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 CAoGeneratingInfiniteDevDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


//================================================================================
// It is the process when the AioInit button is clicked
// Initialize the device
//================================================================================
void CAoGeneratingInfiniteDevDlg::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 CAoGeneratingInfiniteDevDlg::OnBnClickedButtonResetDevice()
{
	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 AioSetAoRangeAll button is clicked
// Set the output range of analog output
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoRangeAll()
{
	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

	//----------------------------------------
	// Update GUI information
	//----------------------------------------
	UpdateData(TRUE);
	//----------------------------------------
	// Get the index of 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]);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioSetAoRangeAll = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the AioSetAoChannels button is clicked
// Set the number of analog output channels used for generating
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoChannels()
{
	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	ao_channels;		// Number of channels

	//----------------------------------------
	// Get the number of 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);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioSetAoChannels = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Condition Set button is clicked
// Open the condition setting dialog
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonConditionSettings()
{
	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

	//----------------------------------------
	// Open the condition setting dialog
	//----------------------------------------
	CConditionDlg	dlg;
	if(dlg.DoModal() == IDOK){
		//----------------------------------------
		// Set the event factor to 'Event that device operation end', 'Event that the specified number of data are output', 
		// '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_DATA_NUM | AOE_SCERR | AOE_DAERR));
		//----------------------------------------
		// Error process
		//----------------------------------------
		if(ret != 0){
			//--------------------
			// Display message
			//--------------------
			AioGetErrorString(ret, error_string);
			//--------------------
			// Display message
			//--------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("Condition Set: AioSetAoEvent = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return;
		}
		//----------------------------------------
		// Display the message that condition setting is completed
		//----------------------------------------
		text_string.Format(_T("Condition Set: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
}

//================================================================================
// It is the process when the Generate Output Data button is clicked
// Generate output data file
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonOutputDataGenerate()
{
	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
	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("Generate Output Data: 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("Generate Output Data: 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"), &g_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) * g_generating_times * ao_channels);
	if(g_generating_data == NULL){
		text_string.Format(_T("Generate Output Data: 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 < g_generating_times; i++){
		for(j = 0; j < ao_channels; j++){
			g_generating_data[i * ao_channels + j]	= (float)(gain * sin(2 * 3.14159265358979 * i / g_generating_times + 3.14159265358979 / 2 * (j % 4)) + offset);
		}
	}
	//----------------------------------------
	// Open file
	//----------------------------------------
	file_ret	= _wfopen_s(&fp, g_file_name, _T("w"));
	if(file_ret != 0){
		text_string.Format(_T("Generate Output Data: fopen = file open error."));
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Create file
	//----------------------------------------
	for(i = 0; i < g_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("Generate Output Data: Successful completion"));
}

//================================================================================
// It is the process when the AioSetAoEventSamplingTimes button is clicked
// Set the generating times when "Event that the specified number of data are output" is used
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonSetAoEventSamplingTimes()
{
	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
	long	generating_times;	// Generating times

	//----------------------------------------
	// Get the generating times from textbox
	//----------------------------------------
	m_ao_event_generating_times.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%ld"), &generating_times);
	//----------------------------------------
	// Set the generating times when "Event that the specified number of data are output" is used
	//----------------------------------------
	ret	= AioSetAoEventSamplingTimes(g_id, generating_times);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioSetAoEventSamplingTimes = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the Generating Start button is clicked
// After clearing the memory and status, start generating.
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGeneratingStart()
{
	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			ao_status;			// Analog output status
	long			i, j;				// Loop count
	long			ret;				// For return code
	HANDLE			h_find;				// For the return code of the file search function
	WIN32_FIND_DATA	find_file_data;		// File information
	short			ao_channels;		// Number of channels
	short			ao_range;			// Range
	float			gain, offset;		// Coefficient of sine waveform


	//----------------------------------------
	// Reset driver memory
	//----------------------------------------
	ret	= AioResetAoMemory(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 Start: AioResetAoMemory = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// 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 Start: AioResetAoStatus = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get the generating times from textbox
	//----------------------------------------
	m_ao_generating_times.GetWindowTextW(text_temp, _countof(text_temp));
	_stscanf_s(text_temp, _T("%ld"), &g_generating_times);
	//----------------------------------------
	// If the output data file does not exist
	//----------------------------------------
	if((h_find = FindFirstFile(g_file_name, &find_file_data)) == INVALID_HANDLE_VALUE){
		//----------------------------------------
		// 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("Generating Start: 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("Generating Start: AioGetAoRange = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return;
		}
		//----------------------------------------
		// 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) * g_generating_times * ao_channels);
		if(g_generating_data == NULL){
			text_string.Format(_T("Generating Start: 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 < g_generating_times; i++){
			for(j = 0; j < ao_channels; j++){
				g_generating_data[i * ao_channels + j]	= (float)(gain * sin(2 * 3.14159265358979 * i / g_generating_times + 3.14159265358979 / 2 * (j % 4)) + offset);
			}
		}
	}else{
		//----------------------------------------
		// Close file search handle
		//----------------------------------------
		FindClose(h_find);
	}
	//----------------------------------------
	// Set analog output data
	//----------------------------------------
	ret	= AioSetAoSamplingDataEx(g_id, g_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("Generating Start: AioSetAoSamplingDataEx = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// 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 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 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 the total generating count
	//----------------------------------------
	text_string.Format(_T("0"));
	m_total_generating_count.SetWindowText(text_string);
	//----------------------------------------
	// Update the setting generating count
	//----------------------------------------
	text_string.Format(_T("0"));
	m_setting_generating_count.SetWindowText(text_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	m_return_code.SetWindowText(_T("Generating Start: Successful completion"));
}

//================================================================================
// It is the process when the AioGetAoSamplingCount button is clicked
// Get the generating count and display it on the dialog
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoSamplingCount()
{
	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
	long	ao_generating_count;	// Generating count

	//----------------------------------------
	// Get generating count
	//----------------------------------------
	ret	= AioGetAoSamplingCount(g_id, &ao_generating_count);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioGetAoSamplingCount = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
	//----------------------------------------
	// When the generating count acquisition function is completed successfully
	//----------------------------------------
	if(ret == 0){
		//--------------------
		// Update the generating count
		//--------------------
		text_string.Format(_T("%d"), ao_generating_count);
		m_total_generating_count.SetWindowText(text_string);
	}
}

//================================================================================
// It is the process when the AioGetAoSamplingTimes button is clicked
// Acquire the remaining output data amount by the generating count and display it on the dialog
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoSamplingTimes()
{
	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
	long	ao_generating_times;	// Generating count

	//----------------------------------------
	// Get generating count
	//----------------------------------------
	ret	= AioGetAoSamplingTimes(g_id, &ao_generating_times);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioGetAoSamplingTimes = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
	//----------------------------------------
	// When the generating count acquisition function is completed successfully
	//----------------------------------------
	if(ret == 0){
		//--------------------
		// Update the generating count
		//--------------------
		text_string.Format(_T("%d"), ao_generating_times);
		m_setting_generating_count.SetWindowText(text_string);
	}
}

//================================================================================
// It is the process when the AioGetAoStatus button is clicked
// Get the analog output status and display it on the dialog
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGetAoStatus()
{
	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	ao_status;				// Analog output status
	long	ret;					// For return code

	//----------------------------------------
	// Get status
	//----------------------------------------
	ret	= AioGetAoStatus(g_id, &ao_status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	AioGetErrorString(ret, error_string);
	//----------------------------------------
	// Display message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("AioGetAoStatus = %d : %s"), ret, text_temp);
	m_return_code.SetWindowText(text_string);
	//----------------------------------------
	// When the status acquisition function is completed successfully
	//----------------------------------------
	if(ret == 0){
		//----------------------------------------
		// 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);
	}
}

//================================================================================
// It is the process when the Generating Stop button is clicked
// Stop generating
//================================================================================
void CAoGeneratingInfiniteDevDlg::OnBnClickedButtonGeneratingStop()
{
	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 Stop: AioStopAo = %d : %s"), ret, text_temp);
		m_return_code.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the message that generating stop is completed
	//----------------------------------------
	text_string.Format(_T("Generating Stop: Successful completion"));
	m_return_code.SetWindowText(text_string);
}

//================================================================================
// It is the process when the AioExit button is clicked
// Perform the exit process of device
//================================================================================
void CAoGeneratingInfiniteDevDlg::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 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 CAoGeneratingInfiniteDevDlg::OnBnClickedClose()
{
	//----------------------------------------
	// 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 CAoGeneratingInfiniteDevDlg::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
	long	ao_generating_count;	// Generating count
	long	ao_generating_times;	// Generating times
	long	ao_status;				// Status
	long	ret;					// For return code

	//----------------------------------------
	// Event that the specified number of data are output
	// Acquire and display data
	//----------------------------------------
	if(message == AIOM_AOE_DATA_NUM){
		//----------------------------------------
		// 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("Event that the specified number of data are output 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);
		//----------------------------------------
		// Set analog output data
		//----------------------------------------
		ret	= AioSetAoSamplingDataEx(g_id, g_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("Event that the specified number of data are output Process: AioSetAoSamplingDataEx = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// 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("Event that the specified number of data are output Process: AioGetAoSamplingCount = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display the total generating count
		//----------------------------------------
		text_string.Format(_T("%d"), ao_generating_count);
		m_total_generating_count.SetWindowText(text_string);
		//----------------------------------------
		// Get the current generating count
		//----------------------------------------
		ret	= AioGetAoSamplingTimes(g_id, &ao_generating_times);
		//----------------------------------------
		// 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 the specified number of data are output Process: AioGetAoSamplingTimes = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display the setting generating count
		//----------------------------------------
		text_string.Format(_T("%d"), ao_generating_times);
		m_setting_generating_count.SetWindowText(text_string);
		//----------------------------------------
		// Display the message that event processing is completed
		//----------------------------------------
		text_string.Format(_T("Event that the specified number of data are output Process: Successful completion"));
		m_return_code.SetWindowText(text_string);
	}
	//----------------------------------------
	// 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 the total generating count
		//----------------------------------------
		text_string.Format(_T("%d"), ao_generating_count);
		m_total_generating_count.SetWindowText(text_string);
		//----------------------------------------
		// Get the current generating count
		//----------------------------------------
		ret	= AioGetAoSamplingTimes(g_id, &ao_generating_times);
		//----------------------------------------
		// 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: AioGetAoSamplingTimes = %d : %s"), ret, text_temp);
			m_return_code.SetWindowText(text_string);
			return TRUE;
		}
		//----------------------------------------
		// Display the setting generating count
		//----------------------------------------
		text_string.Format(_T("%d"), ao_generating_times);
		m_setting_generating_count.SetWindowText(text_string);
		//----------------------------------------
		// 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);
	}
	//----------------------------------------
	// 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);
	}
	//----------------------------------------
	// 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);
}
