// vc_DCON_DIODlg.cpp : implementation file // #include "stdafx.h" #include "vc_DCON_DIO.h" #include "vc_DCON_DIODlg.h" #include "uart.h" #include "DCON_FUN.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif long useTimeout = 500; ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVc_DCON_DIODlg dialog CVc_DCON_DIODlg::CVc_DCON_DIODlg(CWnd* pParent /*=NULL*/) : CDialog(CVc_DCON_DIODlg::IDD, pParent) { //{{AFX_DATA_INIT(CVc_DCON_DIODlg) m_address = 1; m_baudrate = 115200; m_checksum = 0; m_dival = 0; m_dich = 6; m_doval = 0; m_doout = 0x7f; m_doch = 7; m_port = 3; m_slot = -1; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CVc_DCON_DIODlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CVc_DCON_DIODlg) DDX_Text(pDX, IDC_ADDRESS, m_address); DDX_Text(pDX, IDC_BAUDRATE, m_baudrate); DDX_Text(pDX, IDC_CHECKSUM, m_checksum); DDX_Text(pDX, IDC_DI, m_dival); DDX_Text(pDX, IDC_DICH, m_dich); DDX_Text(pDX, IDC_DO, m_doval); DDX_Text(pDX, IDC_DOOUT, m_doout); DDX_Text(pDX, IDC_DOCH, m_doch); DDX_Text(pDX, IDC_PORT, m_port); DDX_Text(pDX, IDC_SLOT, m_slot); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CVc_DCON_DIODlg, CDialog) //{{AFX_MSG_MAP(CVc_DCON_DIODlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_OPEN, OnOpen) ON_BN_CLICKED(IDC_Close, OnClose) ON_BN_CLICKED(IDC_DOOUTPUT, OnDooutput) ON_BN_CLICKED(IDC_DIO, OnDio) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVc_DCON_DIODlg message handlers BOOL CVc_DCON_DIODlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CVc_DCON_DIODlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 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 CVc_DCON_DIODlg::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 CVc_DCON_DIODlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CVc_DCON_DIODlg::OnOpen() { // TODO: Add your control notification handler code here char str[128]; // m_port = GetDlgItemInt(IDC_PORT,NULL,FALSE); m_baudrate = GetDlgItemInt(IDC_BAUDRATE,NULL,FALSE); m_checksum = GetDlgItemInt(IDC_CHECKSUM,NULL,FALSE); m_address = GetDlgItemInt(IDC_ADDRESS,NULL,FALSE); m_slot = GetDlgItemInt(IDC_SLOT,NULL,TRUE); m_dich = GetDlgItemInt(IDC_DICH,NULL,FALSE); m_doch = GetDlgItemInt(IDC_DOCH,NULL,FALSE); int ret=Open_Com(m_port,m_baudrate,8,0,0); if(ret) { sprintf(str,"Open COM %d Failed ! Error code %d",m_port,ret); MessageBox(str,"Error",MB_OK); } } void CVc_DCON_DIODlg::OnClose() { // TODO: Add your control notification handler code here Close_Com(m_port); } void CVc_DCON_DIODlg::OnDooutput() { // TODO: Add your control notification handler code here char str[128]; int ret; // TODO: Add your control notification handler code here m_doout = GetDlgItemInt(IDC_DOOUT,NULL,FALSE); ret= DCON_Write_DO(m_port, m_address,m_slot,m_doch,m_doout,m_checksum,useTimeout); if(ret) { sprintf(str,"DO Output Failed ! Error code %d",ret); MessageBox(str,"Error",MB_OK); } } void CVc_DCON_DIODlg::OnDio() { // TODO: Add your control notification handler code here char str[128],DI_BitArr[256],DO_BitArr[256]; int ret; // TODO: Add your control notification handler code here ret=DCON_Read_DIO(m_port,m_address,m_slot,m_dich, m_doch,m_checksum, useTimeout,&m_dival,&m_doval, DI_BitArr,DO_BitArr); if(ret) { sprintf(str,"ReadBack DIO Failed ! Error code %d",ret); MessageBox(str,"Error",MB_OK); } else { sprintf(str,"%08lX",m_dival); SetDlgItemText(IDC_DI, str); sprintf(str,"%08lX",m_doval); SetDlgItemText(IDC_DO, str); } }