
// CollectionConditionsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CollectionConditions.h"
#include "CollectionConditionsDlg.h"
#include "afxdialogex.h"
#include "clogger_api.h"
#include "ChannelSettigDlg.h"
#include "ClockSettingDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CCollectionConditionsDlg dialog



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

void CCollectionConditionsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_FILETYPE, m_combo_filetype);
	DDX_Control(pDX, IDC_COMBO_OPENMODE, m_combo_openmode);
	DDX_Control(pDX, IDC_EDIT_DEVICENAME, m_edit_devicename);
	DDX_Control(pDX, IDC_EDIT_MEMORYSIZE, m_edit_memorysize);
	DDX_Control(pDX, IDC_EDIT_RETURNNUM, m_edit_returnnum);
	DDX_Control(pDX, IDC_EDIT_STATUS, m_edit_status);
	DDX_Control(pDX, IDC_MFCEDITBROWSE_DATAFILE, m_edit_datafile);
	DDX_Control(pDX, IDC_MFCEDITBROWSE_IMPORTFILE, m_edit_importfile);
	DDX_Control(pDX, IDC_EDIT_SAMPLINGCOUNT, m_edit_samplingcount);
}

BEGIN_MESSAGE_MAP(CCollectionConditionsDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_LOGGEROPENAPPLICATION, &CCollectionConditionsDlg::OnBnClickedButtonLoggeropenapplication)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETDEVICENAME, &CCollectionConditionsDlg::OnBnClickedButtonLoggersetdevicename)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERGETDEVICENAME, &CCollectionConditionsDlg::OnBnClickedButtonLoggergetdevicename)
	ON_BN_CLICKED(IDC_BUTTON_CHANNEL, &CCollectionConditionsDlg::OnBnClickedButtonChannel)
	ON_BN_CLICKED(IDC_BUTTON_CLOCK, &CCollectionConditionsDlg::OnBnClickedButtonClock)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETMEMORYOPTION, &CCollectionConditionsDlg::OnBnClickedButtonLoggersetmemoryoption)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETAUTOSAVE, &CCollectionConditionsDlg::OnBnClickedButtonLoggersetautosave)
	ON_BN_CLICKED(IDC_BUTTON_LOGGEREXPORTSETTINGFILE, &CCollectionConditionsDlg::OnBnClickedButtonLoggerexportsettingfile)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERIMPORTSETTINGFILE, &CCollectionConditionsDlg::OnBnClickedButtonLoggerimportsettingfile)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSTARTOPERATION, &CCollectionConditionsDlg::OnBnClickedButtonLoggerstartoperation)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERGETAPPLICATIONSTATUS, &CCollectionConditionsDlg::OnBnClickedButtonLoggergetapplicationstatus)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSTOPOPERATION, &CCollectionConditionsDlg::OnBnClickedButtonLoggerstopoperation)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERCLOSEAPPLICATION, &CCollectionConditionsDlg::OnBnClickedButtonLoggercloseapplication)
	ON_BN_CLICKED(IDCCLOSE, &CCollectionConditionsDlg::OnBnClickedCclose)
	ON_WM_TIMER()
END_MESSAGE_MAP()

//----------------------------------------
// Macro definition
//----------------------------------------
#define TIMERID_SAMPLING_COUNT				1				// Timer event ID for updating sampling count
#define TIMERINTERVAL_SAMPLING_COUNT		1000			// Sampling count update interval [ms]

//----------------------------------------
// Declaration of global variables
//----------------------------------------
short	g_appid;											// ID for application access

// CCollectionConditionsDlg message handlers
//================================================================================
// Initial settings
//================================================================================
BOOL CCollectionConditionsDlg::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_edit_devicename.SetWindowTextW(_T("AIO000"));
	//----------------------------------------
	// Create the combobox for screen size
	//----------------------------------------
	m_combo_openmode.AddString(_T("Minimize"));
	m_combo_openmode.AddString(_T("Normal"));
	m_combo_openmode.AddString(_T("Maximize"));
	//----------------------------------------
	// Change the selection of screen size combobox to Minimize
	//----------------------------------------
	m_combo_openmode.SetCurSel(LOGGER_PARAM_WINDOW_OFF);
	//----------------------------------------
	// Update the initial display of memory size
	//----------------------------------------
	m_edit_memorysize.SetWindowTextW(_T("10"));
	//----------------------------------------
	// Create the combobox for file type
	//----------------------------------------
	m_combo_filetype.AddString(_T("None"));
	m_combo_filetype.AddString(_T("clb"));
	m_combo_filetype.AddString(_T("csv"));
	//----------------------------------------
	// Create the combobox for file type
	//----------------------------------------
	m_combo_filetype.SetCurSel(LOGGER_PARAM_SAVE_NONE);
	//----------------------------------------
	// Initialize the timer ID
	//----------------------------------------
	m_TimerID = 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 CCollectionConditionsDlg::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 CCollectionConditionsDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

//================================================================================
// It is the process when the LoggerOpenApplication button is clicked
// Launch the app and enable access
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggeropenapplication()
{
	TCHAR			text_temp[256];				// For temporary text storage
	char			device_name[256];			// Device name
	char			error_string[256];			// Error code string
	unsigned short	openmode;					// Screen size
	long			ret;						// For return code
	CString			text_string;				// For updating textbox

	//----------------------------------------
	// Get device name from textbox
	//----------------------------------------
	m_edit_devicename.GetWindowText(text_temp, _countof(text_temp));
	sprintf_s(device_name, "%S", text_temp);
	//----------------------------------------
	// Get screen size from combobox
	//----------------------------------------
	openmode = m_combo_openmode.GetCurSel();
	//----------------------------------------
	// Initialize the application
	//----------------------------------------
	ret = LoggerOpenApplication(device_name, &g_appid, openmode);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerOpenApplication = %d : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

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

	//----------------------------------------
	// Get device name from textbox
	//----------------------------------------
	m_edit_devicename.GetWindowText(text_temp, _countof(text_temp));
	sprintf_s(device_name, "%S", text_temp);
	//----------------------------------------
	// Set the device name
	//----------------------------------------
	ret = LoggerSetDeviceName(g_appid, device_name);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetDeviceName = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

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

	//----------------------------------------
	// Get the device name
	//----------------------------------------
	ret = LoggerGetDeviceName(g_appid, device_name);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerGetDeviceName = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	//----------------------------------------
    // If the device name acquisition function is completed successfully
    //----------------------------------------
	if(ret == 0){
		//----------------------------------------
		// Display device name
		//----------------------------------------
		text_string.Format(_T("%S"), device_name);
		m_edit_devicename.SetWindowText(text_string);
	}
	return;
}

//================================================================================
// It is the process when the Channel Settings... button is clicked
// Display the channel setting dialog
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonChannel()
{
	ChannelSettigDlg	channelsettingdlg;		// Channel settings dialog
	TCHAR				text_temp[256];			// For temporary text storage
	char				error_string[256];		// Error code string
	long				ret;					// For return code
	CString				text_string;			// For updating textbox	
	CHANNEL_SETTING		channel_setting;		// Channel setting structure
	int					i;						// Loop count

	//----------------------------------------
	// Set the initial value
	//----------------------------------------
	channel_setting.InputType = LOGGER_PARAM_SINGLEENDED;
	channel_setting.AiChannels = SEQUENCE_NUM;
	for(i = 0; i < SEQUENCE_NUM; i++){
		channel_setting.ChannelNo[i]	= 0;
		channel_setting.ChName[i][0]	= '\0';
		channel_setting.Range[i]		= PM10;
		channel_setting.ScaleEnable[i]	= LOGGER_PARAM_DISABLE;
		channel_setting.MinData[i]		= -10;
		channel_setting.MaxData[i]		= 10;
		channel_setting.MinScale[i]		= -10;
		channel_setting.MaxScale[i]		= 10;
	}

	//----------------------------------------
	// Get channel settings
	//----------------------------------------
	ret = LoggerGetChannelSetting(	g_appid,
									&channel_setting.InputType,
									&channel_setting.AiChannels,
									&channel_setting.ChannelNo[0],
									channel_setting.ChName[0],
									&channel_setting.Range[0]);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetChannelSetting = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get scale conversion setting
	//----------------------------------------
	for(i = 0; i < SEQUENCE_NUM; i++){
		if(channel_setting.AiChannels < i + 1){
			break;
		}
		ret = LoggerGetScaleConversion(	g_appid,
										i,
										&channel_setting.ScaleEnable[i],
										&channel_setting.MinData[i],
										&channel_setting.MaxData[i],
										&channel_setting.MinScale[i],
										&channel_setting.MaxScale[i]);
		if(ret != 0){
			break;
		}
	}
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetScaleConversion = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Data transfer
	//----------------------------------------
	channelsettingdlg.channel_data(&channel_setting);
	//----------------------------------------
	// If OK is pressed, the process is performed
	//----------------------------------------
	if(channelsettingdlg.DoModal() == IDOK){
		//----------------------------------------
		// Set the channel
		//----------------------------------------
		ret = LoggerSetChannelSetting(	g_appid,
										channel_setting.InputType,
										channel_setting.AiChannels,
										channel_setting.ChannelNo,
										channel_setting.ChName[0],
										channel_setting.Range);
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerSetChannelSetting = %ld : %s"), ret, text_temp);
			m_edit_returnnum.SetWindowText(text_string);
			return;
		}
		//----------------------------------------
		// Set the scale conversion
		//----------------------------------------
		for(i = 0; i < channel_setting.AiChannels; i++){
			ret = LoggerSetScaleConversion(	g_appid,
											i,
											channel_setting.ScaleEnable[i],
											channel_setting.MinData[i],
											channel_setting.MaxData[i],
											channel_setting.MinScale[i],
											channel_setting.MaxScale[i]);
			if(ret != 0){
				break;
			}
		}
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerSetScaleConversion = %d : %s"), ret, text_temp);
			m_edit_returnnum.SetWindowText(text_string);
			return;
		}
		//----------------------------------------
		// Display the message that channel setting is completed
		//----------------------------------------
		text_string.Format(_T("Channel settings : Successful completion"));
		m_edit_returnnum.SetWindowText(text_string);
	}
	return;
}

//================================================================================
// It is the process when the Clock Settings... button is clicked
// Display the clock setting dialog
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonClock()
{
	ClockSettingDlg		clocksettingdlg;		// Clock settings dialog
	TCHAR				text_temp[256];			// For temporary text storage
	char				error_string[256];		// Error code string
	long				ret;					// For return code
	CString				text_string;			// For updating textbox
	double				value_temp;				// For temporary storage of setting values
	CLOCK_SETTING		clock_setting;			// Clock setting structure
	unsigned short		value_time_type;		// For temporary storage of setting values
	unsigned long		value_time1;			// For temporary storage of setting values
	unsigned long		value_time2;			// For temporary storage of setting values
	unsigned long		value_time3;			// For temporary storage of setting values

	//----------------------------------------
	// Set the initial value
	//----------------------------------------
	clock_setting.sampling_clock_unit				= LOGGER_PARAM_FREQUNIT_USEC;
	clock_setting.sampling_clock					= 0;
	clock_setting.external_clock					= 0;

	//----------------------------------------
	// Get sampling clock conditions
	//----------------------------------------
	value_temp = 0;
	ret = LoggerGetSamplingClock(	g_appid,
									&clock_setting.clock_type,
									clock_setting.sampling_clock_unit,			// Unit specification
									&value_temp);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetSamplingClock = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the acquired value to the sampling clock in the case of internal clock setting
	//----------------------------------------
	if(clock_setting.clock_type == LOGGER_PARAM_CLOCK_INTERNAL){
		clock_setting.sampling_clock = value_temp;
	//----------------------------------------
	// Set the acquired value to the external clock in the case of external clock setting
	//----------------------------------------
	}else{
		clock_setting.external_clock = value_temp;
	}
	//----------------------------------------
	// Get sampling times, conversion speed and repeat times
	//----------------------------------------
	ret = LoggerGetSamplingSetting(	g_appid,
									&clock_setting.sampling_times,
									&clock_setting.scan_clock,
									&clock_setting.repeat_times,
									&clock_setting.start_trigger_type,
									&clock_setting.stop_trigger_type,
									&clock_setting.delay_time);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetSamplingSetting = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get start trigger analog level
	//----------------------------------------
	ret = LoggerGetAnalogLevelTrigger(	g_appid,
										LOGGER_PARAM_STARTTRIGGER,
										&clock_setting.start_level_trigger_edge,
										&clock_setting.start_level_sequence_no,
										&clock_setting.start_level_border_value);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetAnalogLevelTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get start trigger analog in-range/out-range
	//----------------------------------------
	ret = LoggerGetAnalogRangeTrigger(	g_appid,
										LOGGER_PARAM_STARTTRIGGER,
										&clock_setting.start_range_sequence_no,
										&clock_setting.start_range_upper_border_value,
										&clock_setting.start_range_lower_border_value,
										&clock_setting.start_range_state_times);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetAnalogRangeTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get start trigger Time/Moment
	//----------------------------------------
	ret = LoggerGetTimeTrigger(	g_appid,
								LOGGER_PARAM_STARTTRIGGER,
								&value_time_type,
								&value_time1,
								&value_time2,
								&value_time3);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetTimeTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// For Time, assign the acquired value to the time
	//----------------------------------------
	if(value_time_type == LOGGER_PARAM_TIMETYPE_ELAPSED){
		clock_setting.start_time_time	= value_time1;
		clock_setting.start_time_hour	= 0;
		clock_setting.start_time_minute = 0;
		clock_setting.start_time_second = 0;
	//----------------------------------------
	// For Moment, assign the acquired value to the moment
	//----------------------------------------
	}else{
		clock_setting.start_time_time	= 60;
		clock_setting.start_time_hour	= value_time1;
		clock_setting.start_time_minute = value_time2;
		clock_setting.start_time_second = value_time3;
	}
	//----------------------------------------
	// Get stop trigger analog level
	//----------------------------------------
	ret = LoggerGetAnalogLevelTrigger(	g_appid,
										LOGGER_PARAM_STOPTRIGGER,
										&clock_setting.stop_level_trigger_edge,
										&clock_setting.stop_level_sequence_no,
										&clock_setting.stop_level_border_value);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetAnalogLevelTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get stop trigger analog in-range/out-range
	//----------------------------------------
	ret = LoggerGetAnalogRangeTrigger(	g_appid,
										LOGGER_PARAM_STOPTRIGGER,
										&clock_setting.stop_range_sequence_no,
										&clock_setting.stop_range_upper_border_value,
										&clock_setting.stop_range_lower_border_value,
										&clock_setting.stop_range_state_times);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetAnalogRangeTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get stop trigger Time/Moment
	//----------------------------------------
	ret = LoggerGetTimeTrigger(	g_appid,
								LOGGER_PARAM_STOPTRIGGER,
								&value_time_type,
								&value_time1,
								&value_time2,
								&value_time3);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetTimeTrigger = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// For Time, assign the acquired value to the time
	//----------------------------------------
	if(value_time_type == LOGGER_PARAM_TIMETYPE_ELAPSED){
		clock_setting.stop_time_time	= value_time1;
		clock_setting.stop_time_hour	= 0;
		clock_setting.stop_time_minute	= 0;
		clock_setting.stop_time_second	= 0;
	//----------------------------------------
	// For Moment, assign the acquired value to the moment
	//----------------------------------------
	}else{
		clock_setting.stop_time_time	= 60;
		clock_setting.stop_time_hour	= value_time1;
		clock_setting.stop_time_minute	= value_time2;
		clock_setting.stop_time_second	= value_time3;
	}
	//----------------------------------------
	// Data transfer
	//----------------------------------------
	clocksettingdlg.clock_data(&clock_setting);
	//----------------------------------------
	// If OK is pressed, the process is performed
	//----------------------------------------
	if(clocksettingdlg.DoModal() == IDOK){
		//----------------------------------------
		// For internal clock, specify the sampling clock period (frequency)
		//----------------------------------------
		if(clock_setting.clock_type == LOGGER_PARAM_CLOCK_INTERNAL){
			value_temp = clock_setting.sampling_clock;
		//----------------------------------------
		// For external clock, specify the external clock update interval
		//----------------------------------------
		}else{
			value_temp = clock_setting.external_clock;
		}
		//----------------------------------------
		// Set the sampling clock condition
		//----------------------------------------
		ret = LoggerSetSamplingClock(	g_appid,
										clock_setting.clock_type,
										clock_setting.sampling_clock_unit,
										value_temp);
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerSetSamplingClock = %ld : %s"), ret, text_temp);
			m_edit_returnnum.SetWindowText(text_string);
			return;
		}
		//----------------------------------------
		// Set the sampling times, conversion speed and repeat times
		//----------------------------------------
		ret = LoggerSetSamplingSetting(	g_appid,
										clock_setting.sampling_times,
										clock_setting.scan_clock,
										clock_setting.repeat_times,
										clock_setting.start_trigger_type,
										clock_setting.stop_trigger_type,
										clock_setting.delay_time);
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerSetSamplingSetting = %ld : %s"), ret, text_temp);
			m_edit_returnnum.SetWindowText(text_string);
			return;
		}
		if(clock_setting.start_trigger_type == LOGGER_PARAM_TRIGGER_LEVEL){
			//----------------------------------------
			// Set start trigger analog level
			//----------------------------------------
			ret = LoggerSetAnalogLevelTrigger(	g_appid,
												LOGGER_PARAM_STARTTRIGGER,
												clock_setting.start_level_trigger_edge,
												clock_setting.start_level_sequence_no,
												clock_setting.start_level_border_value);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetAnalogLevelTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.start_trigger_type == LOGGER_PARAM_TRIGGER_INRANGE) || (clock_setting.start_trigger_type == LOGGER_PARAM_TRIGGER_OUTRANGE)){
			//----------------------------------------
			// Set start trigger analog in-range/out-range
			//----------------------------------------
			ret = LoggerSetAnalogRangeTrigger(	g_appid,
												LOGGER_PARAM_STARTTRIGGER,
												clock_setting.start_range_sequence_no,
												clock_setting.start_range_upper_border_value,
												clock_setting.start_range_lower_border_value,
												clock_setting.start_range_state_times);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetAnalogRangeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.start_trigger_type == LOGGER_PARAM_TRIGGER_ELAPSED_TIME)){
			//----------------------------------------
			// Set start trigger Time
			//----------------------------------------
			ret = LoggerSetTimeTrigger(	g_appid,
										LOGGER_PARAM_STARTTRIGGER,
										LOGGER_PARAM_TIMETYPE_ELAPSED,
										clock_setting.start_time_time,
										0,
										0);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetTimeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.start_trigger_type == LOGGER_PARAM_TRIGGER_CURRENT_TIME)){
			//----------------------------------------
			// Set start trigger Moment
			//----------------------------------------
			ret = LoggerSetTimeTrigger(	g_appid,
										LOGGER_PARAM_STARTTRIGGER,
										LOGGER_PARAM_TIMETYPE_CURRENT,
										clock_setting.start_time_hour,
										clock_setting.start_time_minute,
										clock_setting.start_time_second);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetTimeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if(clock_setting.stop_trigger_type == LOGGER_PARAM_TRIGGER_LEVEL){
			//----------------------------------------
			// Set stop trigger analog level
			//----------------------------------------
			ret = LoggerSetAnalogLevelTrigger(	g_appid,
												LOGGER_PARAM_STOPTRIGGER,
												clock_setting.stop_level_trigger_edge,
												clock_setting.stop_level_sequence_no,
												clock_setting.stop_level_border_value);						
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetAnalogLevelTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.stop_trigger_type == LOGGER_PARAM_TRIGGER_INRANGE) || (clock_setting.stop_trigger_type == LOGGER_PARAM_TRIGGER_OUTRANGE)){
			//----------------------------------------
			// Set stop trigger analog in-range/out-range
			//----------------------------------------
			ret = LoggerSetAnalogRangeTrigger(	g_appid,
												LOGGER_PARAM_STOPTRIGGER,
												clock_setting.stop_range_sequence_no,
												clock_setting.stop_range_upper_border_value,
												clock_setting.stop_range_lower_border_value,
												clock_setting.stop_range_state_times);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetAnalogRangeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.stop_trigger_type == LOGGER_PARAM_TRIGGER_ELAPSED_TIME)){
			//----------------------------------------
			// Set stop trigger Time
			//----------------------------------------
			ret = LoggerSetTimeTrigger(	g_appid,
										LOGGER_PARAM_STOPTRIGGER,
										LOGGER_PARAM_TIMETYPE_ELAPSED,
										clock_setting.stop_time_time,
										0,
										0);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetTimeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		if((clock_setting.stop_trigger_type == LOGGER_PARAM_TRIGGER_CURRENT_TIME)){
			//----------------------------------------
			// Set stop trigger Moment
			//----------------------------------------
			ret = LoggerSetTimeTrigger(	g_appid,
										LOGGER_PARAM_STOPTRIGGER,
										LOGGER_PARAM_TIMETYPE_CURRENT,
										clock_setting.stop_time_hour,
										clock_setting.stop_time_minute,
										clock_setting.stop_time_second);
			if(ret != 0){
				//----------------------------------------
				// Get error string
				//----------------------------------------
				LoggerGetErrorString(ret, error_string);
				//----------------------------------------
				// Display error code and message
				//----------------------------------------
				wsprintf(text_temp, _T("%S"), error_string);
				text_string.Format(_T("LoggerSetTimeTrigger = %ld : %s"), ret, text_temp);
				m_edit_returnnum.SetWindowText(text_string);
				return;
			}
		}
		//----------------------------------------
		// Display the message that clock setting is completed
		//----------------------------------------
		text_string.Format(_T("Clock settings: Successful completion"));
		m_edit_returnnum.SetWindowText(text_string);
	}
	return;
}

//================================================================================
// It is the process when the LoggerSetMemoryOption button is clicked
// Set memory options
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggersetmemoryoption()
{
	TCHAR			text_temp[256];			// For temporary text storage
	char			error_string[256];		// Error code string
	long			ret;					// For return code
	CString			text_string;			// For updating textbox
	unsigned short	memorysize;				// For memory size storage

	//----------------------------------------
	// Get memory size from textbox
	//----------------------------------------
	m_edit_memorysize.GetWindowText(text_temp, _countof(text_temp));
	memorysize = (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// Set memory options
	//----------------------------------------
	ret = LoggerSetMemoryOption(g_appid, memorysize);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetMemoryOption = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// It is the process when the LoggerSetAutoSave button is clicked
// Set the autosave
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggersetautosave()
{
	TCHAR		text_temp[256];				// For temporary text storage
	char		filepath[256];				// File path
	char		error_string[256];			// Error code string
	long		ret;						// For return code
	CString		text_string;				// For error code display
	int			auto_save_type;				// For autosave type storage

	//----------------------------------------
	// Get save file path from the textbox
	//----------------------------------------
	m_edit_datafile.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &filepath[0], 256, NULL, NULL);
	//----------------------------------------
	// Get autosave type from combobox
	//----------------------------------------
	auto_save_type = m_combo_filetype.GetCurSel();
	//----------------------------------------
	// Set the autosave
	//----------------------------------------
	ret = LoggerSetAutoSave(g_appid, 0, auto_save_type, filepath);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetAutoSave = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// It is the process when the LoggerExportSettingFile button is clicked
// Export the setting file
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggerexportsettingfile()
{
	TCHAR		text_temp[256];			// For temporary text storage
	char		filepath[256];			// File path
	char		error_string[256];		// Error code string
	long		ret;					// For return code
	CString		text_string;			// For error code display

	//----------------------------------------
	// Get setting file path from the textbox
	//----------------------------------------
	m_edit_importfile.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &filepath[0], 256, NULL, NULL);
	//----------------------------------------
	// Export the setting file
	//----------------------------------------
	ret = LoggerExportSettingFile(g_appid, filepath);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerExportSettingFile= %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerImportSettingFile button
// Import the settings file
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggerimportsettingfile()
{
	TCHAR				text_temp[256];			// For temporary text storage
	char				filepath[256];			// File path
	char				error_string[256];		// Error code string
	long				ret;					// For return code
	CString				text_string;			// For error code display
	unsigned long long	status;					// For status storage

	//----------------------------------------
	// Get setting file path from the textbox
	//----------------------------------------
	m_edit_importfile.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &filepath[0], 256, NULL, NULL);
	//----------------------------------------
	// Import the settings file
	//----------------------------------------
	ret = LoggerImportSettingFile(g_appid, filepath, &status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerImportSettingFile = %ld : %s\r\nstatus=0x%016x"), ret, text_temp, status);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// It is the process when the Start Collecting button is clicked
// Start the application input and output
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggerstartoperation()
{
	TCHAR	text_temp[256];				// For temporary text storage
	char	error_string[256];			// Error code string
	long	ret;						// For return code
	CString	text_string;				// For updating textbox
	unsigned long status;				// For status storage
	unsigned long event_setting;		// For event settings storage

	//----------------------------------------
	// Close file
	//----------------------------------------
	ret = LoggerGraphWindowOperation(	g_appid,
										LOGGER_PARAM_GRAPH_CLOSE,
										LOGGER_PARAM_FILE,
										0);							// Reserved
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGraphWindowOperation = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Specify the buffer mode (basic mode)
	//----------------------------------------
	ret = LoggerSetAcquiredMode(g_appid, LOGGER_PARAM_MODE_BASIC);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerSetAcquiredMode = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Set the event
	//----------------------------------------
	event_setting =	LOGGER_PARAM_EVENT_START |
					LOGGER_PARAM_EVENT_RPTEND |
					LOGGER_PARAM_EVENT_END |
					LOGGER_PARAM_EVENT_OFERR |
					LOGGER_PARAM_EVENT_SCERR;
	ret = LoggerSetNotifyEvent(g_appid, CallBackProc, event_setting, this);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerSetNotifyEvent = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Start the application input and output
	//----------------------------------------
	ret = LoggerStartOperation(g_appid, &status);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerStartOperation = %ld : %s\r\nstatus=%ld"), ret, text_temp, status);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Start timer
	//----------------------------------------
	if(m_TimerID == 0){
		m_TimerID = SetTimer(TIMERID_SAMPLING_COUNT, TIMERINTERVAL_SAMPLING_COUNT, NULL);
	}
	return;
}

//================================================================================
// It is the process when the LoggerGetApplicationStatus button is clicked
// Get the device status
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggergetapplicationstatus()
{
	TCHAR			text_temp[256];								// For temporary text storage
	TCHAR			status_string[256];							// Status string
	char			error_string[256];							// Error code string
	long			ret;										// For return code
	CString			text_string;								// For updating textbox
	unsigned long	status;										// For status storage

	//----------------------------------------
	// Get the device status
	//----------------------------------------
	ret = LoggerGetApplicationStatus(g_appid, &status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerGetApplicationStatus = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	//----------------------------------------
	// If the status acquisition function is completed successfully
	//----------------------------------------
	if(ret == 0){
		//----------------------------------------
		// Get status string
		//----------------------------------------
		switch (status) {
		case LOGGER_STATUS_STOP:
			wsprintf(status_string, _T("Stop"));
			break;
		case LOGGER_STATUS_START_TRG:
			wsprintf(status_string, _T("Wait the start trigger"));
			break;
		case LOGGER_STATUS_BUSY:
			wsprintf(status_string, _T("Operating"));
			break;
		default:
			wsprintf(status_string, _T("Unknown status"));
			break;
		}
		//----------------------------------------
		// Display the status
		//----------------------------------------
		text_string.Format(_T("%lu (%s)"), status, status_string);
		m_edit_status.SetWindowText(text_string);
	}
	return;
}

//================================================================================
// It is the process when the Stop Collecting button is clicked
// Stop the application input and output
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggerstopoperation()
{
	TCHAR				text_temp[256];				// For temporary text storage
	char				error_string[256];			// Error code string
	long				ret;						// For return code
	CString				text_string;				// For updating textbox
	unsigned long long	total_sampling_count;		// For total sampling count storage

	//----------------------------------------
	// Stop timer
	//----------------------------------------
	if(m_TimerID != 0){
		KillTimer(m_TimerID);
		m_TimerID = 0;
	}
	//----------------------------------------
	// Stop the application input and output
	//----------------------------------------
	ret = LoggerStopOperation(g_appid);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerStopOperation = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get total sampling count
	//----------------------------------------
	total_sampling_count = 0;
	ret = LoggerGetTotalSamplingCount(g_appid, &total_sampling_count);
	if(ret != 0){
		//----------------------------------------
		// Get error string
		//----------------------------------------
		LoggerGetErrorString(ret, error_string);
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerGetTotalSamplingCount = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Display the total sampling count
	//----------------------------------------
	text_string.Format(_T("%lld"), total_sampling_count);
	m_edit_samplingcount.SetWindowText(text_string);
	return;
}

//================================================================================
// It is the process when the C-LOGGER Exit button is clicked
// Stop the app and disable access
//================================================================================
void CCollectionConditionsDlg::OnBnClickedButtonLoggercloseapplication()
{
	TCHAR			text_temp[256];										// For temporary text storage
	TCHAR			status_string[256];									// Status string
	char			error_string[256];									// Error code string
	long			ret;												// For return code
	CString			text_string;										// For updating textbox
	unsigned long	status;												// For status storage

	//----------------------------------------
	// Close the file(Considering that C-LOGGER may have exited, do not check the result)
	//----------------------------------------
	ret = LoggerGraphWindowOperation(	g_appid,
										LOGGER_PARAM_GRAPH_CLOSE,
										LOGGER_PARAM_FILE,
										0);							// Reserved
	//----------------------------------------
	// Stop the application and disable access
	//----------------------------------------
	ret = LoggerCloseApplication(g_appid, &status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	if (ret != 0) {
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerCloseApplication = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get status string
	//----------------------------------------
	switch(status){
	case LOGGER_STATUS_SUCCESS:
		wsprintf(status_string, _T("Successful completion"));
		break;
	case LOGGER_STATUS_FAILURE:
		wsprintf(status_string, _T("C-LOGGER exit error"));
		break;
	default:
		wsprintf(status_string, _T("Unknown status"));
		break;
	}
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerCloseApplication = %ld : %s\r\nstatus=%ld : %s"), ret, text_temp, status, status_string);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// It is the process when the Close button is clicked
// 
//================================================================================
void CCollectionConditionsDlg::OnBnClickedCclose()
{
	unsigned long	status				= LOGGER_STATUS_SUCCESS;		// For status storage

	//----------------------------------------
	// Close the file(Considering that C-LOGGER may have exited, do not check the result)
	//----------------------------------------
	LoggerGraphWindowOperation(	g_appid,
								LOGGER_PARAM_GRAPH_CLOSE,
								LOGGER_PARAM_FILE,
								0);							// Reserved
	//----------------------------------------
	// Stop the application and disable access
	//----------------------------------------
	LoggerCloseApplication(g_appid, &status);
	//----------------------------------------
	// Exit the dialog
	//----------------------------------------
	CDialog::OnOK();
}

//================================================================================
// Callback routine
// 
//================================================================================
long CCollectionConditionsDlg::CallBackProc(short Id, long AiEvent, WPARAM wParam, LPARAM lParam, void *Param)
{
	TCHAR				text_temp[256];				// For temporary text storage
	char				error_string[256];			// Error code string
	long				ret;						// For return code
	unsigned long long	total_sampling_count;		// For total sampling count storage
	CString				text_string;				// For updating textbox
	CCollectionConditionsDlg *dlg;					// Caller dialog
	//----------------------------------------
	// Create the class object
	//----------------------------------------
	dlg = (CCollectionConditionsDlg *)Param;

	switch (AiEvent){
	case LOGGER_PARAM_EVENT_START:
		text_string.Format(_T("Event that start"));
		dlg->m_edit_returnnum.SetWindowText(text_string);
		break;
	case LOGGER_PARAM_EVENT_RPTEND:
		text_string.Format(_T("Event that repeat end"));
		dlg->m_edit_returnnum.SetWindowText(text_string);
		break;
	case LOGGER_PARAM_EVENT_END:
	case LOGGER_PARAM_EVENT_OFERR:
	case LOGGER_PARAM_EVENT_SCERR:
		if(AiEvent == LOGGER_PARAM_EVENT_END){
			text_string.Format(_T("Event that device operation end"));
		}else if(AiEvent == LOGGER_PARAM_EVENT_OFERR){
			text_string.Format(_T("Event that overflow"));
		}else if(AiEvent == LOGGER_PARAM_EVENT_SCERR){
			text_string.Format(_T("Event that sampling clock period error"));
		}
		dlg->m_edit_returnnum.SetWindowText(text_string);
		//----------------------------------------
		// Stop timer
		//----------------------------------------
		if(dlg->m_TimerID != 0){
			dlg->KillTimer(dlg->m_TimerID);
			dlg->m_TimerID = 0;
		}
		//----------------------------------------
		// Get total sampling count
		//----------------------------------------
		total_sampling_count = 0;
		ret = LoggerGetTotalSamplingCount(g_appid, &total_sampling_count);
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerGetTotalSamplingCount = %ld : %s"), ret, text_temp);
			dlg->m_edit_returnnum.SetWindowText(text_string);
			break;
		}
		//----------------------------------------
		// Display the total sampling count
		//----------------------------------------
		text_string.Format(_T("%lld"), total_sampling_count);
		dlg->m_edit_samplingcount.SetWindowText(text_string);
		break;
	case LOGGER_PARAM_EVENT_DATANUM:
		text_string.Format(_T("Event that the specified number of data are stored"));
		dlg->m_edit_returnnum.SetWindowText(text_string);
		break;
	default:
		text_string.Format(_T("Unknown event"));
		dlg->m_edit_returnnum.SetWindowText(text_string);
		break;
	}
	return 0;
}

//================================================================================
// Timer event
// 
//================================================================================
void CCollectionConditionsDlg::OnTimer(UINT_PTR nIDEvent)
{
	TCHAR				text_temp[256];				// For temporary text storage
	char				error_string[256];			// Error code string
	long				ret;						// For return code
	CString				text_string;				// For updating textbox
	unsigned long long	total_sampling_count;		// For total sampling count storage

	//----------------------------------------
	// For updating sampling times
	//----------------------------------------
	if(nIDEvent == TIMERID_SAMPLING_COUNT){
		//----------------------------------------
		// Get total sampling count
		//----------------------------------------
		total_sampling_count = 0;
		ret = LoggerGetTotalSamplingCount(g_appid, &total_sampling_count);
		if(ret != 0){
			//----------------------------------------
			// Get error string
			//----------------------------------------
			LoggerGetErrorString(ret, error_string);
			//----------------------------------------
			// Display error code and message
			//----------------------------------------
			wsprintf(text_temp, _T("%S"), error_string);
			text_string.Format(_T("LoggerGetTotalSamplingCount = %ld : %s"), ret, text_temp);
			m_edit_returnnum.SetWindowText(text_string);
		}
		//----------------------------------------
		// Display the total sampling count
		//----------------------------------------
		text_string.Format(_T("%lld"), total_sampling_count);
		m_edit_samplingcount.SetWindowText(text_string);
	}
	CDialogEx::OnTimer(nIDEvent);
}

