?? sdudemodlg.cpp
字號:
// sduDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sduDemo.h"
#include "sduDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSduDemoDlg dialog
CSduDemoDlg::CSduDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSduDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSduDemoDlg)
m_Info = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
TempState = false;
bStart=false;
bTimer = false;
m_State = NULL;
bChange = false;
m_pRobot = NULL;
m_pMotion = NULL;
m_pImageCap = NULL;
numOfModules = 0;
m_pImageProcess = NULL;
m_pImage=NULL;
m_iRefreshCount = 0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSduDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSduDemoDlg)
DDX_Control(pDX, IDC_LISTSEQ, m_ListSeq);
DDX_Text(pDX, IDC_EDITINFO, m_Info);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSduDemoDlg, CDialog)
//{{AFX_MSG_MAP(CSduDemoDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_MOVE, OnMove)
ON_BN_CLICKED(IDC_HOMEALL, OnHomeall)
ON_BN_CLICKED(IDC_HOME, OnHome)
ON_BN_CLICKED(IDC_SCAN, OnScan)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_INITASR, OnInitasr)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSduDemoDlg message handlers
BOOL CSduDemoDlg::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
// TODO: Add extra initialization here
m_ListSeq.InsertColumn(0,"SEQUENCE",LVCFMT_CENTER,80);
m_ListSeq.InsertColumn(1,"ID",LVCFMT_LEFT,50);
m_ListSeq.InsertColumn(2,"SerialNo",LVCFMT_LEFT,80);
m_ListSeq.InsertColumn(3,"Module_State",LVCFMT_LEFT,250);
SetDlgItemText(IDC_EDITINFO,"準備工作");
GetDlgItem(IDC_START)->EnableWindow(false);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CSduDemoDlg::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 CSduDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSduDemoDlg::OnMove()
{
// TODO: Add your control notification handler code here
int index=-1;
index=m_ListSeq.GetNextItem(-1,LVNI_SELECTED);
if(!TempState||numOfModules==0||index==-1)
{
return;
}
PCube_setRampAcc(DeviceID,LogicIdMap[index],0.1);
//PCube_moveVel(DeviceID,LogicIdMap[index],0.15);
PCube_moveStep( DeviceID, LogicIdMap[index], 0.17, 1000);
}
void CSduDemoDlg::OnHomeall()
{
// TODO: Add your control notification handler code here
if(!TempState||numOfModules==0)
{
return;
}
PCube_homeAll(DeviceID);
}
void CSduDemoDlg::OnHome()
{
// TODO: Add your control notification handler code here
int index=-1;
index=m_ListSeq.GetNextItem(-1,LVNI_SELECTED);
if(!TempState||numOfModules==0||index==-1)
{
return;
}
PCube_homeModule(DeviceID,LogicIdMap[index]);
}
void CSduDemoDlg::OnScan()
{
// TODO: Add your control notification handler code here
TempState = true;
int ret;
CString m_strInitString;
m_strInitString =_T("ESD:0,250");
PCube_closeDevices();
ret = PCube_openDevice( &DeviceID, m_strInitString.GetBuffer(0) );//open the CAN
ShowErrorMessage(ret);
if(ret)
{
TempState = false;
return;
}
if(!TempState)
{
return;
}
m_ListSeq.DeleteAllItems();
CString strtemp;
numOfModules = PCube_getModuleCount( DeviceID );
if(numOfModules==0)
{
AfxMessageBox("No Hardware");
//PCube_closeDevice(DeviceID);
return;
}
ShowErrorMessage(numOfModules);
PCube_getModuleIdMap( DeviceID, aiIdMap );
for(int i =0; i<numOfModules;i++ )
{
PCube_getModuleState( DeviceID, aiIdMap[i], &puiState[i] );
PCube_getModuleSerialNo( DeviceID,aiIdMap[i],&puiValue[i] );
LogicIdMap[i]=aiIdMap[i];
LogicValue[i]=puiValue[i];
LogicState[i]=puiState[i];
ShowModuleState(puiState[i],i);
strtemp.Format("%d",i);
m_ListSeq.InsertItem(i,strtemp);
strtemp.Format("%d",aiIdMap[i]);
m_ListSeq.SetItemText(i,1,strtemp);
strtemp.Format("%d",puiValue[i]);
m_ListSeq.SetItemText(i,2,strtemp);
m_ListSeq.SetItemText(i,3,pucState[i]);
//m_ListSeq.GetDlgItemText();
}
if(bTimer)
{
KillTimer(1);
}
bTimer=true;
SetTimer(1,200,NULL);
}
void CSduDemoDlg::ShowErrorMessage(int ErrorMessage)
{
if (ErrorMessage == ERRID_DEV)
{
AfxMessageBox("ERRID_DEV");
}
else if (ErrorMessage == ERRID_DEV_FUNCTIONNOTAVAILABLE )
{
AfxMessageBox("ERRID_DEV_FUNCTIONNOTAVAILABLE ");
}
else if (ErrorMessage == ERRID_DEV_NOINITSTRING )
{
AfxMessageBox("ERRID_DEV_NOINITSTRING ");
}
else if (ErrorMessage == ERRID_DEV_NODEVICENAME )
{
AfxMessageBox("ERRID_DEV_NODEVICENAME ");
}
else if (ErrorMessage == ERRID_DEV_BADINITSTRING )
{
AfxMessageBox("ERRID_DEV_BADINITSTRING ");
}
else if (ErrorMessage == ERRID_DEV_INITERROR )
{
AfxMessageBox("ERRID_DEV_INITERROR ");
}
else if (ErrorMessage == ERRID_DEV_NOTINITIALIZED )
{
AfxMessageBox("ERRID_DEV_NOTINITIALIZED ");
}
else if (ErrorMessage == ERRID_DEV_WRITEERROR )
{
AfxMessageBox("ERRID_DEV_WRITEERROR ");
}
else if (ErrorMessage == ERRID_DEV_READERROR )
{
AfxMessageBox("ERRID_DEV_READERROR ");
}
else if (ErrorMessage == ERRID_DEV_READTIMEOUT )
{
AfxMessageBox("ERRID_DEV_READTIMEOUT ");
}
else if (ErrorMessage == ERRID_DEV_WRONGMESSAGEID )
{
AfxMessageBox("ERRID_DEV_WRONGMESSAGEID ");
}
else if (ErrorMessage == ERRID_DEV_WRONGCOMMANDID )
{
AfxMessageBox("ERRID_DEV_WRONGCOMMANDID ");
}
else if (ErrorMessage == ERRID_DEV_WRONGPARAMETERID )
{
AfxMessageBox("ERRID_DEV_WRONGPARAMETERID ");
}
else if (ErrorMessage == ERRID_DEV_EXITERROR )
{
AfxMessageBox("ERRID_DEV_EXITERROR ");
}
else if (ErrorMessage == ERRID_DEV_NOMODULES )
{
AfxMessageBox("ERRID_DEV_NOMODULES ");
}
else if (ErrorMessage == ERRID_DEV_WRONGDEVICEID )
{
AfxMessageBox("ERRID_DEV_WRONGDEVICEID ");
}
else if (ErrorMessage == ERRID_DEV_NOLIBRARY )
{
AfxMessageBox("ERRID_DEV_NOLIBRARY ");
}
else if (ErrorMessage == ERRID_DEV_ISINITIALIZED )
{
AfxMessageBox("ERRID_DEV_ISINITIALIZED ");
}
else if (ErrorMessage == ERRID_DEV_WRONGEMSMODULEID )
{
AfxMessageBox("ERRID_DEV_WRONGEMSMODULEID ");
}
else if (ErrorMessage == ERRID_DEV_EMSNOTINITIALIZED )
{
AfxMessageBox("ERRID_DEV_EMSNOTINITIALIZED ");
}
else if (ErrorMessage == ERRID_DEV_EMSMAXNUMBER )
{
AfxMessageBox("ERRID_DEV_EMSMAXNUMBER ");
}
else if (ErrorMessage == ERRID_DEV_EMSINITERROR )
{
AfxMessageBox("ERRID_DEV_EMSINITERROR ");
}
else if (ErrorMessage == ERRID_DEV_WRONGEMSTYPE )
{
AfxMessageBox("ERRID_DEV_WRONGEMSTYPE ");
}
else if (ErrorMessage == ERRID_DEV_WRONGEMSCHANNELID )
{
AfxMessageBox("ERRID_DEV_WRONGEMSCHANNELID ");
}
else if (ErrorMessage == ERRID_DEV_WRONGMP55MODULEID )
{
AfxMessageBox("ERRERRID_DEV_WRONGMP55MODULEID ");
}
else if (ErrorMessage == ERRID_DEV_WRONGSCHUNKMODULEID )
{
AfxMessageBox("ERRID_DEV_WRONGSCHUNKMODULEID ");
}
else if (ErrorMessage == ERRID_DEV_WRONGMODULEID )
{
AfxMessageBox("ERRID_DEV_WRONGMODULEID ");
}
else if (ErrorMessage == ERRID_DEV_MODULEERROR )
{
AfxMessageBox("ERRID_DEV_MODULEERROR ");
}
else if (ErrorMessage == ERRID_DEV_WAITTIMEOUT )
{
AfxMessageBox("ERRID_DEV_WAITTIMEOUT ");
}
else if (ErrorMessage == ERRID_DEV_OPENINIFILE )
{
AfxMessageBox("ERRID_DEV_OPENINIFILE ");
}
return;
}
void CSduDemoDlg::ShowModuleState (unsigned long StateMessage,int i)
{
pucState[i]="_";
//#define STATEID_MOD_BEYOND_SOFT 0x04000000L
if(StateMessage&STATEID_MOD_BEYOND_SOFT )
{
//AfxMessageBox("STATEID_MOD_BEYOND_SOFT ");
pucState[i]="SOFT_";
}
//#define STATEID_MOD_BEYOND_HARD 0x02000000L
if(StateMessage&STATEID_MOD_BEYOND_HARD )
{
//AfxMessageBox("STATEID_MOD_BEYOND_HARD ");
pucState[i]="HARD_"+pucState[i];
}
//#define STATEID_MOD_CPU_OVERLOAD 0x01000000L
if(StateMessage&STATEID_MOD_CPU_OVERLOAD )
{
//AfxMessageBox("STATEID_MOD_CPU_OVERLOAD ");
pucState[i]="OVERLOAD_"+pucState[i];
}
//#define STATEID_MOD_POW_INTEGRALERR 0x00800000L
if(StateMessage&STATEID_MOD_POW_INTEGRALERR)
{
//AfxMessageBox("STATEID_MOD_POW_INTEGRALERR ");
pucState[i]="INT_"+pucState[i];
}
//#define STATEID_MOD_POW_HALLERR 0x00400000L
if(StateMessage&STATEID_MOD_POW_HALLERR )
{
//AfxMessageBox("STATEID_MOD_POW_HALLERR ");
pucState[i]="HERR_"+pucState[i];
}
//#define STATEID_MOD_POW_SHORTCUR 0x00200000L
if(StateMessage&STATEID_MOD_POW_SHORTCUR )
{
//AfxMessageBox("STATEID_MOD_POW_SHORTCUR ");
pucState[i]="SHORTCUR_"+pucState[i];
}
//#define STATEID_MOD_POW_WDG_TEMP 0x00100000L
if(StateMessage&STATEID_MOD_POW_WDG_TEMP )
{
//AfxMessageBox("STATEID_MOD_POW_WDG_TEMP ");
pucState[i]="WTEMP_"+pucState[i];
}
//#define STATEID_MOD_POW_FET_TEMP 0x00080000L
if(StateMessage&STATEID_MOD_POW_FET_TEMP)
{
//AfxMessageBox("STATEID_MOD_POW_FET_TEMP ");
pucState[i]="FTEMP_"+pucState[i];
}
//#define STATEID_MOD_POW_VOLT_ERR 0x00040000L
if(StateMessage&STATEID_MOD_POW_VOLT_ERR )
{
//AfxMessageBox("STATEID_MOD_POW_VOLT_ERR ");
pucState[i]="VERR_"+pucState[i];
}
//#define STATEID_MOD_FULLBUFFER 0x00020000
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -