// I8124W_QuickStartDlg.cpp : implementation file // #include "stdafx.h" #include "I8124W_QuickStart.h" #include "I8124W_QuickStartDlg.h" #include "I8124API_eVC.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CI8124W_QuickStartDlg dialog CI8124W_QuickStartDlg::CI8124W_QuickStartDlg(CWnd* pParent /*=NULL*/) : CDialog(CI8124W_QuickStartDlg::IDD, pParent) { //{{AFX_DATA_INIT(CI8124W_QuickStartDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CI8124W_QuickStartDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CI8124W_QuickStartDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CI8124W_QuickStartDlg, CDialog) //{{AFX_MSG_MAP(CI8124W_QuickStartDlg) ON_BN_CLICKED(IDC_BUTTON_ACTIVE, OnButtonActive) ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear) ON_BN_CLICKED(IDC_BUTTON_ADD_DEVICE, OnButtonAddDevice) ON_BN_CLICKED(IDC_BUTTON_ADDPOLL, OnButtonAddpoll) ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart) ON_BN_CLICKED(IDC_BUTTON_READIO, OnButtonReadio) ON_BN_CLICKED(IDC_BUTTON_WRITEIO, OnButtonWriteio) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CI8124W_QuickStartDlg message handlers BYTE TotalModule,SlotNo[8]; CString Str; BOOL CI8124W_QuickStartDlg::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 CenterWindow(GetDesktopWindow()); // center to the hpc screen // TODO: Add extra initialization here I8124_TotalI8124Module(&TotalModule,SlotNo); Str.Format(_T("Total Module : %d"),TotalModule); SetDlgItemText(IDC_STATIC_TOTAL_MODULE,LPCTSTR(Str)); Str.Format(_T("Slot No. : %d"),SlotNo[0]); SetDlgItemText(IDC_STATIC_SLOT_NO,LPCTSTR(Str)); SetDlgItemText(IDC_EDIT_WRITEIO,_T("00")); return TRUE; // return TRUE unless you set the focus to a control } void CI8124W_QuickStartDlg::OnButtonActive() { // TODO: Add your control notification handler code here DWORD Ret; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_ActiveModule(SlotNo[0]); Str.Format(_T("Return : %d"),Ret); SetDlgItemText(IDC_STATIC_ACTIVE,Str); } void CI8124W_QuickStartDlg::OnButtonClear() { // TODO: Add your control notification handler code here DWORD Ret; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_ClearAllConfig(SlotNo[0]); Str.Format(_T("Return : %d"),Ret); SetDlgItemText(IDC_STATIC_CLEAR,Str); } void CI8124W_QuickStartDlg::OnButtonAddDevice() { // TODO: Add your control notification handler code here DWORD Ret; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_AddDevice(SlotNo[0],12,1000); Str.Format(_T("Return : %d"),Ret); SetDlgItemText(IDC_STATIC_ADD_DEVICE,Str); } void CI8124W_QuickStartDlg::OnButtonAddpoll() { // TODO: Add your control notification handler code here DWORD Ret; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_AddIOConnection(SlotNo[0],12,ConType_Poll,1,1,10); Str.Format(_T("Return : %d"),Ret); SetDlgItemText(IDC_STATIC_ADD_IO,Str); } void CI8124W_QuickStartDlg::OnButtonStart() { // TODO: Add your control notification handler code here DWORD Ret; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_StartDevice(SlotNo[0],12); Str.Format(_T("Return : %d"),Ret); SetDlgItemText(IDC_STATIC_START,Str); } void CI8124W_QuickStartDlg::OnButtonReadio() { // TODO: Add your control notification handler code here DWORD Ret; WORD IOLen; BYTE IODATA[512]; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } Ret = I8124_ReadInputData(SlotNo[0],12,ConType_Poll,&IOLen,IODATA); if(Ret) Str.Format(_T("Return : %d"),Ret); else Str.Format(_T("Data : 0x%02X"),IODATA[0]); SetDlgItemText(IDC_STATIC_READIO,Str); } void CI8124W_QuickStartDlg::OnButtonWriteio() { // TODO: Add your control notification handler code here DWORD Ret; WORD IOLen; BYTE IODATA[512]; if(TotalModule == 0) { Str.Format(_T("There is no any I-8124W module exists.")); AfxMessageBox(Str); return; } GetDlgItemText(IDC_EDIT_WRITEIO,Str); if((Str[0] >= '0') && (Str[0] <= '9')) IODATA[0] = (Str[0] - '0')*16; else if((Str[0] >= 'A') && (Str[0] <= 'F')) IODATA[0] = (Str[0] - 'A'+10)*16; else { AfxMessageBox(_T("IO Data Error")); return; } if((Str[1] >= '0') && (Str[1] <= '9')) IODATA[0] += (Str[1] - '0'); else if((Str[1] >= 'A') && (Str[1] <= 'F')) IODATA[0] += (Str[1] - 'A'+10); else { AfxMessageBox(_T("IO Data Error")); return; } IOLen = 1; Ret = I8124_WriteOutputData(SlotNo[0],12,ConType_Poll,IOLen,IODATA); Str.Format(_T("Return : %d"),Ret); AfxMessageBox(Str); }