// WinPac_demo3Dlg.cpp : implementation file // #include "stdafx.h" #include "WinPac_demo3.h" #include "WinPac_demo3Dlg.h" #include #include #include "I87KCAN.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWinPac_demo3Dlg dialog CWinPac_demo3Dlg::CWinPac_demo3Dlg(CWnd* pParent /*=NULL*/) : CDialog(CWinPac_demo3Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CWinPac_demo3Dlg) // 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 CWinPac_demo3Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWinPac_demo3Dlg) DDX_Control(pDX, IDC_EDIT_RECEIVEDATA, m_recedata); DDX_Control(pDX, IDC_EDIT_SLOT, m_slot); DDX_Control(pDX, IDC_COMBO_BAUD, m_baud); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWinPac_demo3Dlg, CDialog) //{{AFX_MSG_MAP(CWinPac_demo3Dlg) ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig) ON_WM_DESTROY() ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart) ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop) ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWinPac_demo3Dlg message handlers #define comport 0 BOOL CWinPac_demo3Dlg::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 return TRUE; // return TRUE unless you set the focus to a control } void CWinPac_demo3Dlg::OnButtonConfig() { int Ret; unsigned long baud; wchar_t wTempValue[10]; wchar_t wTempStr[100]; char TempValue[10]; // TODO: Add your control notification handler code here Ret=Open_Com(comport,115200UL,8,0,0); // For WinPac communicate with slot module if (Ret){ Ret = Close_Com(comport); if(Ret){ MessageBox(_T("Close com Err"),NULL,NULL); return; } Ret=Open_Com(comport,115200UL,8,0,0); if (Ret){ wsprintf(wTempStr,_T("Open Com Error, Error Code=%d"),Ret); MessageBox(wTempStr,_T("Error"),MB_OK); return; } } m_slot.GetWindowText(wTempValue,10); wcstombs(TempValue,wTempValue,10); ChangeSlotTo87K((BYTE)(atoi(TempValue))); // Change slot to I-87120 switch(m_baud.GetCurSel()){ // Set CAN port baud rate case 0: baud = 10000L; break; case 1: baud = 20000L; break; case 2: baud = 50000L; break; case 3: baud = 125000L; break; case 4: baud = 250000L; break; case 5: baud = 500000L; break; case 6: baud = 800000L; break; case 7: baud = 1000000L; break; } Ret=I87KCANInit(baud,0,0,0x00000000L,0xffffffffL,0,0); // Configure CAN port if (Ret){ wsprintf(wTempStr,_T("I87KCAN Initialize Error, Error Code=%d"),Ret); MessageBox(wTempStr,_T("Error"),MB_OK); Ret = Close_Com(comport); if(Ret) MessageBox(_T("Close com Err"),NULL,NULL); return; } } void CWinPac_demo3Dlg::OnButtonStart() { // TODO: Add your control notification handler code here SetTimer(123,5,NULL); } void CWinPac_demo3Dlg::OnButtonStop() { // TODO: Add your control notification handler code here KillTimer(123); } void CWinPac_demo3Dlg::OnButtonExit() { // TODO: Add your control notification handler code here OnDestroy(); } void CWinPac_demo3Dlg::OnTimer(UINT nIDEvent) { int Ret; char RecBuf[50]; wchar_t wRecBuf[100]; WORD m_WT; CString strtemp; // TODO: Add your message handler code here and/or call default Ret=Receive_Cmd(comport,RecBuf,200,0,&m_WT); if(!Ret){ mbstowcs(wRecBuf,RecBuf,100); m_recedata.SetWindowText(wRecBuf); } CDialog::OnTimer(nIDEvent); } void CWinPac_demo3Dlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here KillTimer(123); Close_Com(comport); }