// SendMsgDlg.cpp : implementation file // #include "stdafx.h" #include "SendMsg.h" #include "SendMsgDlg.h" #include "..\..\I8120Lib\ver_100\I8120.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSendMsgDlg dialog CSendMsgDlg::CSendMsgDlg(CWnd* pParent /*=NULL*/) : CDialog(CSendMsgDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSendMsgDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSendMsgDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSendMsgDlg) DDX_Control(pDX, IDC_DATALEN_EDIT, m_DataLen); DDX_Control(pDX, IDC_11BIT_RADIO, m_11bit); DDX_Control(pDX, IDC_SLOT_COMBO, m_Slot); DDX_Control(pDX, IDC_SEND_BUTTON, m_Send); DDX_Control(pDX, IDC_RTR_CHECK, m_RTR); DDX_Control(pDX, IDC_RESET_BUTTON, m_Reset); DDX_Control(pDX, IDC_INIT_BUTTON, m_Init); DDX_Control(pDX, IDC_ID_EDIT, m_ID); DDX_Control(pDX, IDC_DATA_EDIT, m_Data); DDX_Control(pDX, IDC_BAUD_COMBO, m_Baud); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSendMsgDlg, CDialog) //{{AFX_MSG_MAP(CSendMsgDlg) ON_CBN_SELENDOK(IDC_SLOT_COMBO, OnSelendokSlotCombo) ON_BN_CLICKED(IDC_INIT_BUTTON, OnInitButton) ON_BN_CLICKED(IDC_RESET_BUTTON, OnResetButton) ON_BN_CLICKED(IDC_SEND_BUTTON, OnSendButton) ON_BN_CLICKED(IDC_29BIT_RADIO, On29bitRadio) ON_BN_CLICKED(IDC_11BIT_RADIO, On11bitRadio) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSendMsgDlg message handlers WORD OldSlotSelect; void CSendMsgDlg::FormInit(void){ //Initiate all objects and parameters used in the dialog m_Reset.EnableWindow(FALSE); m_11bit.EnableWindow(FALSE); m_29bit.EnableWindow(FALSE); m_ID.EnableWindow(FALSE); m_RTR.EnableWindow(FALSE); m_DataLen.EnableWindow(FALSE); m_Data.EnableWindow(FALSE); m_Send.EnableWindow(FALSE); } BOOL CSendMsgDlg::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 //initial button FormInit(); //parameter initialize m_Slot.SetCurSel(0); OldSlotSelect=0; m_11bit.SetCheck(BST_CHECKED); m_Baud.SetCurSel(11); m_DataLen.LimitText(1); m_DataLen.SetWindowText(_T("8")); m_Data.LimitText(23); m_Data.SetWindowText(_T("FF FF FF FF FF FF FF FF")); m_ID.LimitText(3); m_ID.SetWindowText(_T("3FF")); m_11bit.SetCheck(TRUE); return TRUE; // return TRUE unless you set the focus to a control } void CSendMsgDlg::OnSelendokSlotCombo() { //Check if the slot combo box is changed or not, and do something for different situation if (m_Slot.GetCurSel()!=OldSlotSelect){ FormInit(); OldSlotSelect=m_Slot.GetCurSel(); return; } } void CSendMsgDlg::OnInitButton() { wchar_t wTempStr[100]; WORD Ret; CString TempStr; DWORD BaudMap[]={5000UL,10000UL,20000UL,25000UL,50000UL,100000UL,125000UL, 20000UL,250000UL,500000UL,800000UL,1000000UL}; OldSlotSelect=m_Slot.GetCurSel(); //configue the I-8120 setting and initiate the I-87KCAN Ret=I8120Init(OldSlotSelect+1,BaudMap[m_Baud.GetCurSel()],0,0,0x00000000UL,0xffffffffUL); if (Ret){ wsprintf(wTempStr,_T("Initiate I-8120 Error, Error Code=%d"),Ret); MessageBox(wTempStr,_T("Error"),MB_OK); return; } //start the objects and parameters used in the dialog m_Reset.EnableWindow(TRUE); m_11bit.EnableWindow(TRUE); m_29bit.EnableWindow(TRUE); m_ID.EnableWindow(TRUE); m_RTR.EnableWindow(TRUE); m_DataLen.EnableWindow(TRUE); m_Data.EnableWindow(TRUE); m_Send.EnableWindow(TRUE); } void CSendMsgDlg::OnResetButton() { //Send command to reset the I-8120 module WORD Ret; wchar_t wTempStr[200]; Ret=ResetI8120(OldSlotSelect+1); if (Ret){ FormInit(); wsprintf(wTempStr,_T("Get Status Error, Error Code=%d"),Ret); MessageBox(wTempStr,_T("Error"),MB_OK); return; } } void CSendMsgDlg::OnSendButton() { wchar_t wTempStr[100],*wendptr; char TempStr[100],*ptr1,*ptr2,*endptr; BYTE Mode,RTR,DataLen,Data[8]; WORD i,Ret; DWORD ID; //configue the transmit CAN message m_ID.GetWindowText(wTempStr,16); ID=_tcstoul(wTempStr,&wendptr,16); if (m_11bit.GetCheck()){ Mode=0; } else{ Mode=1; } if (m_RTR.GetCheck()){ RTR=1; } else{ RTR=0; } m_DataLen.GetWindowText(wTempStr,2); DataLen=(BYTE)(_tcstoul(wTempStr,&wendptr,10)&0xff); if (DataLen>8) DataLen=8; m_Data.GetWindowText(wTempStr,46); wcstombs(TempStr,wTempStr,46); sprintf(TempStr,"%s ",TempStr); i=0; ptr1=TempStr; ptr2=strchr(TempStr,' '); while(ptr2){ *ptr2=0; if (i>7) break; Data[i]=(BYTE)(strtoul(ptr1, &endptr,16)&0xff); i++; ptr1=ptr2+1; ptr2=strchr(ptr1,' '); } while(i