// PI_API_TestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PI_API_Test.h"
#include "PI_API_TestDlg.h"
#include "..\..\..\Includes\ICPDAS_USBIO.h"
#include <SSTREAM>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

ICPDAS_USBIO USBIO;
BYTE m_byDITotal;
BYTE m_byDOTotal;
BYTE m_byAITotal;
BYTE m_byAOTotal;
BYTE m_byPITotal;
BYTE m_byPOTotal;

/////////////////////////////////////////////////////////////////////////////
// CPI_API_TestDlg dialog

CPI_API_TestDlg::CPI_API_TestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPI_API_TestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPI_API_TestDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPI_API_TestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPI_API_TestDlg)
	DDX_Control(pDX, IDC_TXTCHISOLATED, m_txtChIsolated);
	DDX_Control(pDX, IDC_TXTLPFWIDTHCH, m_txtLPFWidthCh);
	DDX_Control(pDX, IDC_TXTLPFWIDTH, m_txtLPFWidth);
	DDX_Control(pDX, IDC_TXTLPFENABLE, m_txtLPFEnable);
	DDX_Control(pDX, IDC_TXTCHTOSET, m_txtChToSet);
	DDX_Control(pDX, IDC_TXTTRIGGERMODE, m_txtTriggerMode);
	DDX_Control(pDX, IDC_TXTCHCLEARMASK, m_txtChClrMask);
	DDX_Control(pDX, IDC_TXTCH, m_txtSetTypeCodeChannel);
	DDX_Control(pDX, IDC_TXTTYPECODE, m_txtTypeCode);
	DDX_Control(pDX, IDC_TXTBOARDID, m_txtUserDefinedBID);
	DDX_Control(pDX, IDC_TXTTIMEOUT, m_txtWDTTimeout);
	DDX_Control(pDX, IDC_TXTNICKNAME, m_txtNickname);
	DDX_Control(pDX, IDC_LBMODULEINFO, m_lbModuleInfo);
	DDX_Control(pDX, IDC_TXTBID, m_txtBID);
	DDX_Control(pDX, IDC_CBXDID, m_cbxDID);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPI_API_TestDlg, CDialog)
	//{{AFX_MSG_MAP(CPI_API_TestDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOPEN, OnOpenDevice)
	ON_BN_CLICKED(IDCLOSE, OnCloseDevice)
	ON_BN_CLICKED(IDLOADDEFAULT, OnLoadDefault)
	ON_BN_CLICKED(IDREFRESHINFO, OnRefreshInfo)
	ON_BN_CLICKED(IDSETNICKNAME, OnSetNickname)
	ON_BN_CLICKED(IDSETWDTTIMEOUT, OnSetWDTTimeout)
	ON_BN_CLICKED(IDSETBOARDID, OnSetBoardID)
	ON_BN_CLICKED(IDGETSUPTYPECODE, OnGetSupTypeCode)
	ON_BN_CLICKED(IDGETTYPECODE, OnGetChTypeCode)
	ON_BN_CLICKED(IDGETTRIGGERMODE, OnGetTriggerMode)
	ON_BN_CLICKED(IDGETLPFENABLE, OnGetLPFEnable)
	ON_BN_CLICKED(IDGETLPFWIDTH, OnGetLPFWidth)
	ON_BN_CLICKED(IDSETTYPECODE, OnSetTypeCode)
	ON_BN_CLICKED(IDCHCLEAR, OnClearCh)
	ON_BN_CLICKED(IDSETTRIGGERMODE, OnSetTriggerMode)
	ON_BN_CLICKED(IDEXIT, OnExit)
	ON_BN_CLICKED(IDSETLPFENABLE, OnSetLPFEnable)
	ON_BN_CLICKED(IDSETLPFWIDTH, OnSetLPFWidth)
	ON_BN_CLICKED(IDGETCHISOLATED, OnGetChIsolated)
	ON_BN_CLICKED(IDCHISOLATED, OnSetChIsolated)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPI_API_TestDlg message handlers

BOOL CPI_API_TestDlg::OnInitDialog()
{
	CDialog::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

  m_txtBID.SetWindowText("1");
  m_cbxDID.SetCurSel(0);
	
	// TODO: Add extra initialization here
	
	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 CPI_API_TestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (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
	{
		CDialog::OnPaint();
	}
}

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

void CPI_API_TestDlg::OnOpenDevice() 
{
  CString szBID;
  DWORD dwBID;
  int iSelIdx;
  int iErrCode;
  
  m_txtBID.GetWindowText(szBID);
  dwBID = _tcstoul(szBID, NULL, 10);
  
  iSelIdx = m_cbxDID.GetCurSel();
  
  USBIO.SetCommTimeout(500);
  if(ERR_NO_ERR != (iErrCode = USBIO.OpenDevice(USBIO_MINPID+iSelIdx+84, (BYTE)dwBID)))
  {
    char szMessage[10];
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    char szItemString[200];
    DWORD dwSoftWDTTimeout;
    WORD wFWVer;
    BYTE byDeviceSN[USBIO_SN_LENGTH];
    BYTE byDeviceNickName[USBIO_NICKNAME_LENGTH];
    BYTE bySupIOMask;
    int iIdx;
    
    USBIO.GetSoftWDTTimeout(&dwSoftWDTTimeout);
    sprintf(szItemString, "SoftWDT: %d", dwSoftWDTTimeout);
    m_lbModuleInfo.AddString(szItemString);
    
    USBIO.GetFwVer(&wFWVer);
    sprintf(szItemString, "Version: %d", wFWVer);
    m_lbModuleInfo.AddString(szItemString);
    
    USBIO.GetDeviceNickName(byDeviceNickName);
    sprintf(szItemString, "Description: ");
    for(iIdx = 0; iIdx < USBIO_NICKNAME_LENGTH; iIdx++)
      sprintf(szItemString + strlen(szItemString), "%c", byDeviceNickName[iIdx]);
    m_lbModuleInfo.AddString(szItemString);
    
    USBIO.GetDeviceSN(byDeviceSN);
    sprintf(szItemString, "SN: ");
    for(iIdx = 0; iIdx < USBIO_SN_LENGTH; iIdx++)
      sprintf(szItemString + strlen(szItemString), "%C", byDeviceSN[iIdx]);
    m_lbModuleInfo.AddString(szItemString);
    
    USBIO.GetSupportIOMask(&bySupIOMask);
    sprintf(szItemString, "Support IO Mask: 0x%02X", bySupIOMask);
    m_lbModuleInfo.AddString(szItemString);
    
    if(SUPPORT_DI(bySupIOMask))
    {
      USBIO.GetDITotal(&m_byDITotal);
      sprintf(szItemString, "DI channels: %d", m_byDITotal);
      m_lbModuleInfo.AddString(szItemString);
    }
    
    if(SUPPORT_DO(bySupIOMask))
    {
      USBIO.GetDITotal(&m_byDOTotal);
      sprintf(szItemString, "DO channels: %d", m_byDOTotal);
      m_lbModuleInfo.AddString(szItemString);
    }
    
    if(SUPPORT_AI(bySupIOMask))
    {
      USBIO.GetAITotal(&m_byAITotal);
      sprintf(szItemString, "AI channels: %d", m_byAITotal);
      m_lbModuleInfo.AddString(szItemString);
    }
    
    if(SUPPORT_AO(bySupIOMask))
    {
      USBIO.GetAOTotal(&m_byAOTotal);
      sprintf(szItemString, "AO channels: %d", m_byAOTotal);
      m_lbModuleInfo.AddString(szItemString);
    }
    
    if(SUPPORT_PI(bySupIOMask))
    {
      USBIO.GetPITotal(&m_byPITotal);
      sprintf(szItemString, "PI channels: %d", m_byPITotal);
      m_lbModuleInfo.AddString(szItemString);
    }
    
    if(SUPPORT_PO(bySupIOMask))
    {
      USBIO.GetPOTotal(&m_byPOTotal);
      sprintf(szItemString, "PO channels: %d", m_byPOTotal);
      m_lbModuleInfo.AddString(szItemString);
    }
  }
}

void CPI_API_TestDlg::OnCloseDevice() 
{
  int iErrCode;
  
  m_lbModuleInfo.ResetContent();
  
  if(ERR_NO_ERR != (iErrCode = USBIO.CloseDevice()))
  {
    char szMessage[10];
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnLoadDefault() 
{
  int iErrCode;
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.LoadDefault()))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnRefreshInfo() 
{
  int iErrCode;
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.RefreshDeviceInfo()))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetNickname() 
{
  int iErrCode;
  char szMessage[300];
  BYTE byNickname[USBIO_NICKNAME_LENGTH];
  CString szNickname;
  
  m_txtNickname.GetWindowText(szNickname);
  memset(byNickname, 32, USBIO_NICKNAME_LENGTH);
  sscanf(szNickname, "%s", byNickname);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.SetDeviceNickName(byNickname)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetWDTTimeout() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwWDTTimeout;
  CString szWDTTimeout;
  
  m_txtWDTTimeout.GetWindowText(szWDTTimeout);
  dwWDTTimeout = _tcstoul(szWDTTimeout, NULL, 10);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.SetSoftWDTTimeout(dwWDTTimeout)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetBoardID() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwBoardID;
  CString szBoardID;
  
  m_txtUserDefinedBID.GetWindowText(szBoardID);
  dwBoardID = _tcstoul(szBoardID, NULL, 10);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.SetUserDefinedBoardID(dwBoardID)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetSupTypeCode() 
{
  BYTE byTotalSupType;
  BYTE bySupTypeCode[USBIO_MAX_SUPPORT_TYPE];
  char szMessage[300];
  int iErrCode;
  BOOL bRet = true;
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetTotalSupportType(&byTotalSupType)))
  {
    bRet = false;
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetSupportTypeCode(bySupTypeCode)))
  {
    bRet = false;
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  
  if(bRet)
  {
    sprintf(szMessage, "%d supported types for this module.\n", byTotalSupType);
    if(byTotalSupType > 0)
    {
      sprintf(szMessage + strlen(szMessage), "Support types is:\n");
      for(int iIdx = 0; iIdx < byTotalSupType; iIdx++)
        sprintf(szMessage + strlen(szMessage), "0x%02X\n", bySupTypeCode[iIdx]);
    }
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetChTypeCode() 
{
  int iErrCode;
  BYTE byChTypeCode[USBIO_PI_MAX_CHANNEL];
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetTypeCode(byChTypeCode)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    sprintf(szMessage, "Module current channel type:\n");
    for(int iIdx = 0; iIdx < m_byPITotal; iIdx++)
      sprintf(szMessage + strlen(szMessage), "Ch%d: 0x%02X\n", iIdx, byChTypeCode[iIdx]);
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetTriggerMode() 
{
  int iErrCode;
  BYTE byTriggerMode[USBIO_PI_MAX_CHANNEL];;
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetTriggerMode(byTriggerMode)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    sprintf(szMessage, "Module current trigger mode:");
    for(int iIdx = 0; iIdx < m_byPITotal; iIdx++)
      sprintf(szMessage + strlen(szMessage), "\nCh%d: %d", iIdx, byTriggerMode[iIdx]);
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetLPFEnable() 
{
  int iErrCode;
  BYTE byLPFilterEnable[(USBIO_PI_MAX_CHANNEL + 7) / 8];
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetLPFilterEnable(byLPFilterEnable)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    sprintf(szMessage, "Module LP filter enable mask: 0x");
    for(int iIdx = 0; iIdx < ((m_byPITotal + 7) / 8); iIdx++)
      sprintf(szMessage + strlen(szMessage), "%02X", byLPFilterEnable[iIdx]);
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetLPFWidth() 
{
  int iErrCode;
  USHORT byLPFilterWidth[USBIO_PI_MAX_CHANNEL];
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetLPFilterWidth(byLPFilterWidth)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    sprintf(szMessage, "Module current LP filter width:");
    for(int iIdx = 0; iIdx < m_byPITotal; iIdx++)
      sprintf(szMessage + strlen(szMessage), "\nCh%d: %d", iIdx, byLPFilterWidth[iIdx]);
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetTypeCode() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwChToSet;
  DWORD dwTypeCode;
  CString szChToSet, szTypeCode;
  
  m_txtTypeCode.GetWindowText(szTypeCode);
  dwTypeCode = _tcstoul(szTypeCode, NULL, 16);
  
  m_txtSetTypeCodeChannel.GetWindowText(szChToSet);
  dwChToSet = _tcstoul(szChToSet, NULL, 10);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_SetTypeCode((BYTE)dwChToSet, (BYTE)dwTypeCode)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnClearCh() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwChClrMask;
  CString szChClrMask;
  BYTE byClrMask[(USBIO_PI_MAX_CHANNEL + 7) / 8];
  int iIdx;
  
  m_txtChClrMask.GetWindowText(szChClrMask);
  dwChClrMask = _tcstoul(szChClrMask, NULL, 16);
  
  for(iIdx = 0; iIdx < (USBIO_PI_MAX_CHANNEL + 7) / 8; iIdx++)
    byClrMask[iIdx] = (BYTE)((dwChClrMask >> (iIdx * 8)) & 0xFF);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_ClearChCount(byClrMask)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetTriggerMode() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwChToSet;
  DWORD dwTriggerMode;
  CString szChToSet, szTriggerMode;
  
  m_txtTriggerMode.GetWindowText(szTriggerMode);
  dwTriggerMode = _tcstoul(szTriggerMode, NULL, 10);
  
  m_txtChToSet.GetWindowText(szChToSet);
  dwChToSet = _tcstoul(szChToSet, NULL, 10);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_SetTriggerMode((BYTE)dwChToSet, (BYTE)dwTriggerMode)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnExit() 
{
  USBIO.CloseDevice();
  
  CDialog::OnCancel();
}

void CPI_API_TestDlg::OnSetLPFEnable() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwLPFEnable;
  CString szLPFEnable;
  BYTE byLPFEnable[(USBIO_PI_MAX_CHANNEL + 7) / 8];
  int iIdx;
  
  m_txtLPFEnable.GetWindowText(szLPFEnable);
  dwLPFEnable = _tcstoul(szLPFEnable, NULL, 16);
  
  for(iIdx = 0; iIdx < (USBIO_PI_MAX_CHANNEL + 7) / 8; iIdx++)
    byLPFEnable[iIdx] = (BYTE)((dwLPFEnable >> (iIdx * 8)) & 0xFF);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_SetLPFilterEnable(byLPFEnable)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetLPFWidth() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwChToSet;
  DWORD dwLPFWidth;
  CString szChToSet, szLPFWidth;
  
  m_txtLPFWidth.GetWindowText(szLPFWidth);
  dwLPFWidth = _tcstoul(szLPFWidth, NULL, 10);
  
  m_txtLPFWidthCh.GetWindowText(szChToSet);
  dwChToSet = _tcstoul(szChToSet, NULL, 10);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_SetLPFilterWidth((BYTE)dwChToSet, (WORD)dwLPFWidth)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnGetChIsolated() 
{
  int iErrCode;
  BYTE byChIsolatedFlag[(USBIO_PI_MAX_CHANNEL + 7) / 8];
  char szMessage[300];
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_GetChIsolatedFlag(byChIsolatedFlag)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    sprintf(szMessage, "Module channel isolated flag: 0x");
    for(int iIdx = 0; iIdx < ((m_byPITotal + 7) / 8); iIdx++)
      sprintf(szMessage + strlen(szMessage), "%02X", byChIsolatedFlag[iIdx]);
    
    MessageBox(szMessage, "Information", MB_ICONINFORMATION | MB_OK);
  }
}

void CPI_API_TestDlg::OnSetChIsolated() 
{
  int iErrCode;
  char szMessage[300];
  DWORD dwChIsolated;
  CString szChIsolated;
  BYTE byChIsolated[(USBIO_PI_MAX_CHANNEL + 7) / 8];
  int iIdx;
  
  m_txtChIsolated.GetWindowText(szChIsolated);
  dwChIsolated = _tcstoul(szChIsolated, NULL, 16);
  
  for(iIdx = 0; iIdx < (USBIO_PI_MAX_CHANNEL + 7) / 8; iIdx++)
    byChIsolated[iIdx] = (BYTE)((dwChIsolated >> (iIdx * 8)) & 0xFF);
  
  if(ERR_NO_ERR != (iErrCode = USBIO.PI_SetChIsolatedFlag(byChIsolated)))
  {
    sprintf(szMessage, "[%d]", iErrCode);
    
    MessageBox(szMessage, "Error", MB_ICONERROR | MB_OK);
  }
  else
  {
    MessageBox("Success.", "Error", MB_ICONINFORMATION | MB_OK);
  }
}
