// WinPac_demo5Dlg.cpp : implementation file // #include "stdafx.h" #include "WinPac_demo5.h" #include "WinPac_demo5Dlg.h" #include #include #include "I87KCAN.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWinPac_demo5Dlg dialog CWinPac_demo5Dlg::CWinPac_demo5Dlg(CWnd* pParent /*=NULL*/) : CDialog(CWinPac_demo5Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CWinPac_demo5Dlg) // 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_demo5Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWinPac_demo5Dlg) DDX_Control(pDX, IDC_EDIT_SLOT, m_slot); DDX_Control(pDX, IDC_COMBO_BAUD, m_baud); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWinPac_demo5Dlg, CDialog) //{{AFX_MSG_MAP(CWinPac_demo5Dlg) ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig) ON_BN_CLICKED(IDC_BUTTON_SEND1, OnButtonSend1) ON_BN_CLICKED(IDC_BUTTON_SEND2, OnButtonSend2) ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWinPac_demo5Dlg message handlers #define comport 0 BOOL CWinPac_demo5Dlg::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_demo5Dlg::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_demo5Dlg::OnButtonSend1() { BYTE TempData[100]; // TODO: Add your control notification handler code here TempData[0] = '|'; // '|' = 0x7c TempData[1] = 0x0a; // data length (LSB) TempData[2] = 0x00; // data length (HSB) TempData[3] = 0x23; // id (LSB) TempData[4] = 0x01; // id (HSB) TempData[5] = 0x11; // data 0 TempData[6] = 0x22; // data 1 TempData[7] = 0x33; // data 2 TempData[8] = 0x44; // data 3 TempData[9] = 0x55; // data 4 TempData[10] = 0x66; // data 5 TempData[11] = 0x77; // data 6 TempData[12] = 0x88; // data 7 SendCmdBufn(0, (char*)TempData, 13); } void CWinPac_demo5Dlg::OnButtonSend2() { BYTE TempData[100]; // TODO: Add your control notification handler code here TempData[0] = '|'; // '|' = 0x7c TempData[1] = 0x0a; // data length (LSB) TempData[2] = 0x00; // data length (HSB) TempData[3] = 0x21; // id (LSB) TempData[4] = 0x03; // id (HSB) TempData[5] = 0x88; // data 0 TempData[6] = 0x77; // data 1 TempData[7] = 0x66; // data 2 TempData[8] = 0x55; // data 3 TempData[9] = 0x44; // data 4 TempData[10] = 0x33; // data 5 TempData[11] = 0x22; // data 6 TempData[12] = 0x11; // data 7 SendCmdBufn(0, (char*)TempData, 13); } void CWinPac_demo5Dlg::OnButtonExit() { // TODO: Add your control notification handler code here OnDestroy(); } void CWinPac_demo5Dlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here Close_Com(comport); }