// TestProgDlg.cpp : implementation file // #include "stdafx.h" #include "TestProg.h" #include "TestProgDlg.h" #include #include #include "I87123.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTestProgDlg dialog CTestProgDlg::CTestProgDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestProgDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestProgDlg) // 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 CTestProgDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestProgDlg) DDX_Control(pDX, IDC_COMBO_txrx, m_rxtx); DDX_Control(pDX, IDC_COMBO_CHANNEL, m_nthpdo); DDX_Control(pDX, IDC_EDIT_OBJbit, m_objbit); DDX_Control(pDX, IDC_EDIT_OBJIDX, m_objidx); DDX_Control(pDX, IDC_BUTTON_AUTOREC, m_autorec); DDX_Control(pDX, IDC_EDIT_RESPONSE, m_response); DDX_Control(pDX, IDC_EDIT_TXTYPE, m_txtype); DDX_Control(pDX, IDC_EDIT_SETCOBID, m_setcobid); DDX_Control(pDX, IDC_EDIT_IOCH, m_ioch); DDX_Control(pDX, IDC_COMBO_PDOMODE, m_pdomode); DDX_Control(pDX, IDC_EDIT_DLEN, m_dlen); DDX_Control(pDX, IDC_EDIT_OFFSET, m_offset); DDX_Control(pDX, IDC_EDIT_PDOTX, m_pdotx); DDX_Control(pDX, IDC_EDIT_PDORX, m_pdorx); DDX_Control(pDX, IDC_EDIT_COBID, m_cobid); DDX_Control(pDX, IDC_EDIT_SDORX, m_sdorx); DDX_Control(pDX, IDC_EDIT_SDOTX, m_sdotx); DDX_Control(pDX, IDC_EDIT_SUBINDEX, m_subindex); DDX_Control(pDX, IDC_EDIT_INDEX, m_index); DDX_Control(pDX, IDC_EDIT_SYNCTIMER, m_synctimer); DDX_Control(pDX, IDC_EDIT_SYNC, m_sync); DDX_Control(pDX, IDC_EDIT_LIFETIME, m_lifetime); DDX_Control(pDX, IDC_EDIT_GUARDTIME, m_guardtime); DDX_Control(pDX, IDC_COMBO_STATES, m_changestates); DDX_Control(pDX, IDC_BUTTON_SHUTDOWN, m_shutdown); DDX_Control(pDX, IDC_EDIT_STATES, m_states); DDX_Control(pDX, IDC_COMBO3, m_node); DDX_Control(pDX, IDC_BUTTON_CONFIG, m_config); DDX_Control(pDX, IDC_COMBO2, m_baud); DDX_Control(pDX, IDC_COMBO1, m_slot); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTestProgDlg, CDialog) //{{AFX_MSG_MAP(CTestProgDlg) ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig) ON_BN_CLICKED(IDC_BUTTON_ADDNODE, OnButtonAddnode) ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove) ON_WM_DESTROY() ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3) ON_BN_CLICKED(IDC_BUTTON_SHUTDOWN, OnButtonShutdown) ON_BN_CLICKED(IDC_BUTTON_STATES, OnButtonStates) ON_BN_CLICKED(IDC_BUTTON_GUARD, OnButtonGuard) ON_BN_CLICKED(IDC_BUTTON_SYNC, OnButtonSync) ON_BN_CLICKED(IDC_BUTTON_ABORT, OnButtonAbort) ON_BN_CLICKED(IDC_BUTTON_READSDO, OnButtonReadsdo) ON_BN_CLICKED(IDC_BUTTON_WRITESDO, OnButtonWritesdo) ON_BN_CLICKED(IDC_BUTTON_SENDPDO, OnButtonSendpdo) ON_BN_CLICKED(IDC_BUTTON_REMOTEPDO, OnButtonRemotepdo) ON_BN_CLICKED(IDC_BUTTON_PDOMODE, OnButtonPdomode) ON_BN_CLICKED(IDC_BUTTON_INSTALLPDO, OnButtonInstallpdo) ON_BN_CLICKED(IDC_BUTTON_REMOVEPDO, OnButtonRemovepdo) ON_BN_CLICKED(IDC_BUTTON_TXTYPE, OnButtonTxtype) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear) ON_BN_CLICKED(IDC_BUTTON_AUTOREC, OnButtonAutorec) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestProgDlg message handlers wchar_t wTempStr[100]; CString datastring; BYTE stopreceive=0; BYTE AsciiToChar[256]={0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10}; BOOL CTestProgDlg::OnInitDialog() { CString tital; 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 tital.Format(_T("I87123 Test Program, Library Ver %.2f"),I87123_GetVersion()); SetWindowText(tital); return TRUE; // return TRUE unless you set the focus to a control } void CTestProgDlg::OnDestroy() { int slot; CDialog::OnDestroy(); // TODO: Add your message handler code here slot = m_slot.GetCurSel() + 1; ChangeSlotTo87K(slot); I87123_ShutdownMaster(); } void CTestProgDlg::OnButtonConfig() { int ret; int slot,baud; // TODO: Add your control notification handler code here slot = m_slot.GetCurSel() + 1; baud = m_baud.GetCurSel(); ChangeSlotTo87K(slot); ret = I87123_Configure(baud); if(ret){ wsprintf(wTempStr,_T("Configure Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } else{ m_config.EnableWindow(FALSE); m_shutdown.EnableWindow(TRUE); m_slot.EnableWindow(FALSE); m_baud.EnableWindow(FALSE); SetTimer(123,5,NULL); } } void CTestProgDlg::OnButtonShutdown() { int ret,slot; // TODO: Add your control notification handler code here slot = m_slot.GetCurSel() + 1; ChangeSlotTo87K(slot); ret = I87123_ShutdownMaster(); if(ret){ wsprintf(wTempStr,_T("Shutdown Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } m_config.EnableWindow(TRUE); m_shutdown.EnableWindow(FALSE); m_slot.EnableWindow(TRUE); m_baud.EnableWindow(TRUE); KillTimer(123); } void CTestProgDlg::OnButtonAddnode() { int ret; int node; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); ret = I87123_AddNode(node); if(ret){ wsprintf(wTempStr,_T("Add node Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } else{ Sleep(20); OnSelchangeCombo3(); } } void CTestProgDlg::OnButtonRemove() { int ret; int node; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); ret = I87123_RemoveNode(node); if(ret){ wsprintf(wTempStr,_T("Remove node Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnSelchangeCombo3() { int ret; int node; unsigned char state; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); ret = I87123_GetState(node, &state); if(ret){ // To check the state of the node that has been selected m_states.SetWindowText(_T("Unknow State")); } else{ switch(state){ case 4: m_states.SetWindowText(_T("Stop State")); break; case 5: m_states.SetWindowText(_T("Operational State")); break; case 127: m_states.SetWindowText(_T("Pre-Operational State")); break; default: m_states.SetWindowText(_T("Unknow State")); break; } } } void CTestProgDlg::OnButtonStates() { int ret; int node; unsigned char state; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); switch(m_changestates.GetCurSel()){ case 0: state = 2; // Stop state break; case 1: state = 1; // Operational state break; case 2: state = 128; // Pre-Operational state break; case 3: state = 129; // Reset node break; } ret = I87123_ChangeState(node, state); if(ret){ wsprintf(wTempStr,_T("Change State Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } else{ if(state == 129) Sleep(1000); else Sleep(100); OnSelchangeCombo3(); } } void CTestProgDlg::OnButtonGuard() { int ret; int node; wchar_t wtemp[10]; char temp[10]; unsigned short guardtime; unsigned char lifetime; // TODO: Add your control notification handler code here m_guardtime.GetWindowText(wtemp,10); // Get Guarding time wcstombs(temp,wtemp,10); guardtime = (atoi(temp)); m_lifetime.GetWindowText(wtemp,10); // Get Lift time wcstombs(temp,wtemp,10); lifetime = (atoi(temp)); node = m_node.GetCurSel(); ret = I87123_Guarding(node, guardtime, lifetime); if(ret){ wsprintf(wTempStr,_T("Guarding Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnButtonSync() { int ret; wchar_t wtemp[10]; char temp[10],*endtemp; unsigned short syncid,timer; unsigned char cyclic; // TODO: Add your control notification handler code here m_sync.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); syncid = (unsigned short)strtol(temp,&endtemp,16); m_synctimer.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); timer = (atoi(temp)); if(timer){ // Cyclic cyclic = 1; // Send cyclic SYNC message ret = I87123_SendSYNC(syncid, cyclic, timer); if(ret){ wsprintf(wTempStr,_T("SYNC Send Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } else{ // Non-Cyclic cyclic = 1; // Stop cyclic SYNC message ret = I87123_SendSYNC(syncid, cyclic, timer); if(ret){ wsprintf(wTempStr,_T("SYNC Send Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } cyclic = 0; // Send one SYNC message ret = I87123_SendSYNC(syncid, cyclic, timer); } } void CTestProgDlg::OnButtonAbort() { int ret=0; wchar_t wtemp[10]; char temp[10],*endtemp; int node,subindex; unsigned short index; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); m_index.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); index = (unsigned short)strtol(temp,&endtemp,16); m_subindex.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); subindex = (unsigned short)strtol(temp,&endtemp,16); ret = I87123_AbortSDO(node,index,subindex); if(ret){ wsprintf(wTempStr,_T("Send abort Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnButtonReadsdo() { int ret=0,i; wchar_t wtemp[10],wsdodata[300]; char temp[10],*endtemp,sdodata[300]; int node,subindex; unsigned char len,rdata[300]; unsigned short index; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); m_index.GetWindowText(wtemp,10); // Set Index of dictionary wcstombs(temp,wtemp,10); index = (unsigned short)strtol(temp,&endtemp,16); m_subindex.GetWindowText(wtemp,10); // Set sub-Index of dictionary wcstombs(temp,wtemp,10); subindex = (unsigned short)strtol(temp,&endtemp,16); ret = I87123_ReadSDO(node,index,subindex,&len,rdata); if(ret){ //m_sdotx.SetWindowText(_T("Read Data Error")); wsprintf(wTempStr,_T("Read SDO Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } else{ sprintf(sdodata,"%02X",rdata[0]); for(i=1;i> 8) & 0xff); ret = I87123_InstallPDO(node, cobid, rxtxtype, channel, tdata); if(ret){ wsprintf(wTempStr,_T("PDO install Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnButtonRemovepdo() { int ret=0; int node,rxtxtype; wchar_t wtemp[10]; char temp[10],*endtemp; unsigned short cobid; unsigned char channel; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); m_setcobid.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); cobid = (unsigned short)strtol(temp,&endtemp,16); channel = m_nthpdo.GetCurSel(); rxtxtype = m_rxtx.GetCurSel(); ret = I87123_RemovePDO(node, cobid, rxtxtype, channel); if(ret){ wsprintf(wTempStr,_T("PDO remove Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnButtonTxtype() { int ret=0; int node; wchar_t wtemp[10]; char temp[10],*endtemp; unsigned char txtype; unsigned short cobid; // TODO: Add your control notification handler code here node = m_node.GetCurSel(); m_setcobid.GetWindowText(wtemp,10); wcstombs(temp,wtemp,10); cobid = (unsigned short)strtol(temp,&endtemp,16); m_txtype.GetWindowText(wtemp,10); // Set transsmission type wcstombs(temp,wtemp,10); txtype = (unsigned char)strtol(temp,&endtemp,16); ret = I87123_PDOTxType(node, cobid, txtype); if(ret){ wsprintf(wTempStr,_T("Set transmission type Error, Error Code=%d"),ret); MessageBox(wTempStr,_T("Error"),MB_OK); } } void CTestProgDlg::OnTimer(UINT nIDEvent) { int ret,i; unsigned short cobid; unsigned char node,len,rdata[40]; // TODO: Add your message handler code here and/or call default if(m_response.GetLineCount() >= 50){ datastring.Empty(); } ret = I87123_MsgResponse(&node, &cobid, &len, rdata); // receive response if(!stopreceive){ if(!ret){ datastring.Format(_T("%s%03X "),datastring,cobid); for(i=0;i