robotView.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:21k
- // robotView.cpp : implementation of the CRobotView class
- //
- #include "stdafx.h"
- #include "robot.h"
- #include"Label.h"
- #include "robotDoc.h"
- #include "robotView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CRobotView
- IMPLEMENT_DYNCREATE(CRobotView, CFormView)
- BEGIN_MESSAGE_MAP(CRobotView, CFormView)
- //{{AFX_MSG_MAP(CRobotView)
- ON_WM_CTLCOLOR()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_COMMNOTIFY, OnCommNotify)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRobotView construction/destruction
- CRobotView::CRobotView()
- : CFormView(CRobotView::IDD)
- {
- //{{AFX_DATA_INIT(CRobotView)
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- m_ncomand1=10;
- m_bflag=0;
- m_nsudu=1;
- m_ngzq=0;
- m_nguanjie;
- m_nfangxiang;
- m_nmsg[0]=0;
- m_njishu=0;
- m_nmsg[1]=0;
- m_nmsg[2]=0;
- m_nmsg[3]=0;
- m_nmsg[4]=0;
- m_nsum=0;
- m_ndelay=0;
- nLength=0;
- m_recflag=1;
- m_failflag=1;
- m_brush.CreateSolidBrush(RGB(40,98,122)); // 生成一绿色刷子
- }
- CRobotView::~CRobotView()
- {
- }
- void CRobotView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRobotView)
- //DDX_Control(pDX, IDC_EDIT1, m_edit1);
- DDX_Control(pDX, IDC_STATIC_LINK, m_link);
- DDX_Control(pDX, IDC_STATIC_1, m_ml);
- DDX_Control(pDX, IDC_STATIC_4, m_workpart);
- DDX_Control(pDX, IDC_STATIC_COMMAND, m_command);
- DDX_Control(pDX, IDC_STATIC_STATUS, m_static);
- DDX_Control(pDX, IDC_STATIC_BUCHANG, m_buchangshu);
- DDX_Control(pDX, IDC_STATIC_5, m_buchang);
- DDX_Control(pDX, IDC_STATIC_3, m_sudu);
- DDX_Control(pDX, IDC_STATIC_2, m_zhuangtai);
- //}}AFX_DATA_MAP
- }
- BOOL CRobotView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFormView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CRobotView diagnostics
- #ifdef _DEBUG
- void CRobotView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CRobotView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CRobotDoc* CRobotView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRobotDoc)));
- return (CRobotDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CRobotView message handlers
- void CRobotView::OnDraw(CDC* pDC)
- {
- // TODO: Add your specialized code here and/or call the base class
- SuduDisplay(m_nsudu);
- GzqDisplay(m_ngzq);
- }
- void CRobotView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- // TODO: Add your specialized code here and/or call the base class
- m_link.SetLink(TRUE)
- .SetTextColor(RGB(0,0,255))
- .SetFontUnderline(TRUE)
- .SetLinkCursor(AfxGetApp()->LoadCursor(IDC_ICON1));
- m_command.SetFontSize(24)
- .SetFontName("Terminal")
- .SetTextColor(RGB(240,240,40));
- m_static.SetFontSize(24)
- .SetTextColor(RGB(240,240,40));
- m_workpart.SetFontSize(24)
- .SetFontBold(TRUE)
- .SetTextColor(RGB(0,240,0));
- m_buchangshu.SetFontSize(24)
- .SetTextColor(RGB(240,240,40));
- m_buchang.SetFontSize(24)
- .SetFontBold(TRUE)
- .SetTextColor(RGB(0,240,0));
- m_sudu.SetFontSize(24)
- .SetFontBold(TRUE)
- .SetTextColor(RGB(0,240,0));
- m_zhuangtai.SetFontSize(24)
- .SetFontBold(TRUE)
- .SetTextColor(RGB(0,240,0));
- m_ml.SetFontSize(24)
- .SetLinkCursor(AfxGetApp()->LoadCursor(IDC_ICON1))
- .SetFontBold(TRUE)
- .SetTextColor(RGB(0,240,0));
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- }
- LRESULT CRobotView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(message == (WM_USER + 1002))
- ProcessMessage(wParam, lParam);
- else if(message==(WM_USER+1003))
- ProcessMyMessage();
- return CFormView::WindowProc(message, wParam, lParam);
- }
- void CRobotView::ProcessMessage(WPARAM wParam, LPARAM lParam)
- {
-
- CRobotDoc* pDoc=GetDocument();
- char* l[57] = {"零","一","二",///012
- "三","四","五","六","七","八","九","执行","各关节归零","大臂正转",///12
- "大臂反转","小臂正转","小臂反转","手腕正转","手腕反转","手爪张开","手爪闭合","上升","下降","大臂运行",///13--22
- "大臂负运行","小臂运行","小臂负运行","手腕运行","手腕负运行","手爪运行","手爪负运行","升降运行",////23---30
- "升降负运行","大臂归零","小臂归零","手腕归零","手爪归零","升降归零","速度加","原点记忆",///31---38
- "系统复位","示教盒","","","回原点","速度减","区号加","区号减","单步再现","周期再现",///39---48
- "连续再现","返回","继续","数据记忆","读取数据","设置串口","打开串口","关闭串口"};
- CString strcomand;
- CString strstatus;
- m_recflag=1;
- if(!pDoc->m_bConnected)
- {
- KillTimer(1);
- MessageBox("请先打开串口");
- return;
- }
- if(wParam==100)
- {
- KillTimer(1);
- if(!m_failflag)
- {
- CWnd* pWnd=GetDlgItem(IDC_STATIC_5);
- pWnd->SetWindowText("");
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText("");
- pWnd=GetDlgItem(IDC_STATIC_COMMAND);
- pWnd->SetWindowText("请输入新的命令");
- pWnd=GetDlgItem(IDC_STATIC_STATUS);
- pWnd->SetWindowText("执行完毕");
- m_ncomand1=0;
-
- }
- else
- MessageBox("请检查连线是否正确或下位机是否打开","通信失败",MB_ICONWARNING);
- }
- else if(wParam>=11&&wParam<=56)
- {
- m_bflag=0;
- m_ncomand1=wParam;
- strcomand=l[m_ncomand1];
- CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
- pWnd->SetWindowText(strcomand);
- pWnd=GetDlgItem(IDC_STATIC_STATUS);
- pWnd->SetWindowText("");
- pWnd=GetDlgItem(IDC_STATIC_5);
- pWnd->SetWindowText("");
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText("");
- m_nsum=0;
- m_njishu=0;
- }
- else if(wParam>=0&&wParam<=9)
- {
- if(m_ncomand1>=12&&m_ncomand1<=21)
- {
- m_bflag=1;
- m_nmsg[m_njishu]=wParam;
- //pWnd=GetDlgItem(IDC_STATIC_COMMAND);
- //pWnd->SetWindowText(strcomand);
- CWnd* pWnd=GetDlgItem(IDC_STATIC_5);
- pWnd->SetWindowText("步长:");
- ++m_njishu;
- if(m_njishu==1)
- {
- CString m_stemp;
- m_nsum=m_nmsg[0];
- m_stemp.Format("%d",m_nsum);
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText(m_stemp);
- }
- if(m_njishu==2)
- {
- CString m_stemp;
- m_nsum=m_nmsg[0]*10+m_nmsg[1];
- m_stemp.Format("%d",m_nsum);
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText(m_stemp);
- }
- if(m_njishu==3)
- {
- CString m_stemp;
- m_nsum=m_nmsg[0]*100+m_nmsg[1]*10+m_nmsg[2];
- //m_nmsg[0]=0;
- //m_nmsg[1]=0
- // m_nmsg[2]=0;
- // m_njishu=0;
- m_stemp.Format("%d",m_nsum);
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText(m_stemp);
- }
- if(m_njishu==4)
- {
- CString m_stemp;
- m_nsum=m_nmsg[0]*1000+m_nmsg[1]*100+m_nmsg[2]*10+m_nmsg[3];
- m_stemp.Format("%d",m_nsum);
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText(m_stemp);
- }
- if(m_njishu>4)
- {
- m_njishu=1;
- m_nmsg[0]=m_nmsg[4];
- CString m_stemp;
- m_nsum=m_nmsg[0];
- m_stemp.Format("%d",m_nsum);
- pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
- pWnd->SetWindowText(m_stemp);
- m_nmsg[1]=0;
- m_nmsg[2]=0;
- m_nmsg[3]=0;
- }
- }
- else
- ; //MessageBox("清先输入运动步数命令");
- }
- else if(wParam=10)
- { SetTimer(1,500,NULL);
- if(m_ncomand1>=11&&m_ncomand1<=56)
- {
- if(!m_bflag)
- {
- strstatus="正在执行命令,请稍后.....";
- CWnd* pWnd=GetDlgItem(IDC_STATIC_STATUS);
- pWnd->SetWindowText(strstatus);
- Execute(m_ncomand1);
-
- }
- else //if(m_ncomand1>=12&&m_ncomand1<=21)
- {
- unsigned char m_uhi,m_ulo;
- m_nmsg[0]=0;
- m_nmsg[1]=0;
- m_nmsg[2]=0;
- m_nmsg[3]=0;
- m_njishu=0;
- /// CWnd* pWnd=GetDlgItem(IDC_STATIC_STATUS);
- /// pWnd->SetWindowText("正在执行命令,请稍后.....");
- switch(m_ncomand1)
- {
- case(12):
- m_nguanjie=01;
- m_nfangxiang=00;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(13):
- m_nguanjie=0x01;
- m_nfangxiang=0xff;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(14):
- m_nguanjie=0x02;
- m_nfangxiang=0x00;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum)/(m_nsudu*3);
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(15):
- m_nguanjie=0x02;
- m_nfangxiang=0xff;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum)/(m_nsudu*3);
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(16):
- m_nguanjie=0x04;
- m_nfangxiang=0x00;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(17):
- m_nguanjie=0x04;
- m_nfangxiang=0xff;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(18):
- m_nguanjie=0x05;
- m_nfangxiang=0x00;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(19):
- m_nguanjie=0x05;
- m_nfangxiang=0xff;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/m_nsudu;
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(20):
- m_nguanjie=0x03;
- m_nfangxiang=0x00;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/(m_nsudu*2);
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- case(21):
- m_nguanjie=0x03;
- m_nfangxiang=0xff;
- m_uhi=(unsigned char)(m_nsum/256);
- m_ulo=(unsigned char)(m_nsum-m_uhi*256);
- m_ndelay=(m_nsum+500)/(m_nsudu*2);
- Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
- break;
- }
-
- }
- m_failflag=1;}
- else
- MessageBox("清先输入命令");
- }
- else
- MessageBox("不能识别,请重新输入命令");
- }
- void CRobotView::ProcessMyMessage()
- {
- CDC *PDc=GetDC();
- m_failflag=0;
- switch(m_ncomand1)
- {
- case(37):
- {
- m_nsudu++;
- if(m_nsudu==6)
- m_nsudu=1;
- OnDraw(PDc);
- }
- break;
- case(44):
- {
- m_nsudu--;
- if(m_nsudu==0)
- m_nsudu=5;
- OnDraw(PDc);
- }
- break;
- case(45):
- {
- m_ngzq++;
- if(m_ngzq==8)
- m_ngzq=0;
- OnDraw(PDc);
- }
- break;
- case(46):
- {
- m_ngzq--;
- if(m_ngzq==-1)
- m_ngzq=7;
- OnDraw(PDc);
- }
- break;
- }
- CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
- pWnd->SetWindowText("请输入新的命令");
- pWnd=GetDlgItem(IDC_STATIC_STATUS);
- pWnd->SetWindowText("执行完毕");
- m_ncomand1=0;
- //}
- //else
- // MessageBox("请检查连线是否正确或下位机是否打开","通信失败",MB_ICONWARNING);
- }
- void CRobotView::SuduDisplay(int n)
- {
- CWnd* pWnd=GetDlgItem(IDC_STATIC_SUDU);
- CDC* pControlDC=pWnd->GetDC();
- pWnd->Invalidate();
- pWnd->UpdateWindow();
- pControlDC->SelectStockObject(BLACK_BRUSH);
- CBitmap mBit;
- CDC MemDC;
- MemDC.CreateCompatibleDC(NULL);
- switch(n)
- {
- case 0:
- mBit.LoadBitmap(IDB_BMP10);
- break;
- case 1:
- mBit.LoadBitmap(IDB_BMP11);
- break;
- case 2:
- mBit.LoadBitmap(IDB_BMP12);
- break;
- case 3:
- mBit.LoadBitmap(IDB_BMP13);
- break;
- case 4:
- mBit.LoadBitmap(IDB_BMP14);
- break;
- case 5:
- mBit.LoadBitmap(IDB_BMP15);
- break;
- default:
- //mBit.LoadBitmap(IDB_BMP0);
- MessageBox("error");
- }
- CBitmap *pOldBit=MemDC.SelectObject(&mBit);
- pControlDC->BitBlt(0,0,900,700,&MemDC,0,0,SRCCOPY);
- MemDC.SelectObject(pOldBit);
- }
- void CRobotView::GzqDisplay(int n)
- {
- CWnd* pWnd=GetDlgItem(IDC_STATIC_GONGZUOQU);
- CDC* pControlDC=pWnd->GetDC();
- pWnd->Invalidate();
- pWnd->UpdateWindow();
- pControlDC->SelectStockObject(BLACK_BRUSH);
- CBitmap mBit;
- CDC MemDC;
- MemDC.CreateCompatibleDC(NULL);
- switch(n)
- {
- case 0:
- mBit.LoadBitmap(IDB_BMP10);
- break;
- case 1:
- mBit.LoadBitmap(IDB_BMP11);
- break;
- case 2:
- mBit.LoadBitmap(IDB_BMP12);
- break;
- case 3:
- mBit.LoadBitmap(IDB_BMP13);
- break;
- case 4:
- mBit.LoadBitmap(IDB_BMP14);
- break;
- case 5:
- mBit.LoadBitmap(IDB_BMP15);
- break;
- case 6:
- mBit.LoadBitmap(IDB_BMP16);
- break;
- case 7:
- mBit.LoadBitmap(IDB_BMP17);
- break;
- default:
- //mBit.LoadBitmap(IDB_BMP0);
- MessageBox("error");
- }
- CBitmap *pOldBit=MemDC.SelectObject(&mBit);
- pControlDC->BitBlt(0,0,900,700,&MemDC,0,0,SRCCOPY);
- MemDC.SelectObject(pOldBit);
- }
- void CRobotView::Execute(int n)
- {
- CRobotDoc* pDoc=GetDocument();
- unsigned char send1;
- switch(n)
- {
- case(11):
- home();
- break;
- case(12):
- {//大臂正传
- unsigned char send[6]={0x53,0x01,0x00,0x00,0x07,0x18};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000/m_nsudu);
- break;
- }
- case(13):
- {
- unsigned char send[6]={0x53,0x01,0xff,0x00,0x07,0x18};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- // pDoc->ReadComm(&buf,1);
- // if(nLength)
- //// {
- // str.Format("%d",buf);
- // m_edit1.SetSel(-1, 0);
- // m_edit1.ReplaceSel(str); // 向编辑视图中插入收到的字符
- // }
- // else
- // MessageBox("fjdklfjsdklgjsdfkl");
- Sleep(2000/m_nsudu);
- break;
- }
- case(14)://xiaobizhengzhuan
- {
- unsigned char send[6]={0x53,0x02,0x00,0x00,0x0f,0xe3};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000/m_nsudu);
- break;
- }
-
- case(15)://小臂反转
- {
- unsigned char send[6]={0x53,0x02,0xff,0x00,0x0f,0xe3};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000/m_nsudu);
- break;
- }
- case(16)://手腕正转
- {
- unsigned char send[6]={0x53,0x04,0x00,0x00,0x00,0xff};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(1000/m_nsudu);
- break;
- }
- case(17)://shouwanfanzhuan
- {
- unsigned char send[6]={0x53,0x04,0xff,0x00,0x00,0xff};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(1000/m_nsudu);
- }
- break;
- case(18)://shouzhuazhangkai
- {
- unsigned char send[6]={0x53,0x05,0x00,0x00,0x00,0x43};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000/m_nsudu);
- }
- break;
- case(19):
- {
- unsigned char send[6]={0x53,0x05,0xff,0x00,0x00,0xf3};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000/m_nsudu);
- }
- break;
- case(20)://shangsheng
- {
- unsigned char send[6]={0x53,0x03,0x00,0x00,0x02,0xe3};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(1000/m_nsudu);
- }
- break;
- case(21):
- {
- unsigned char send[6]={0x53,0x03,0xff,0x00,0x02,0xe3};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(1000/m_nsudu);
- }
- break;
- /* case(22)://dabiyunxing
- {
- unsigned char send[3]={0x63,0x01,0x00};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(23):
- {
- unsigned char send[3]={0x63,0x01,0xff};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(24)://xiaobiyunxing
- {
- unsigned char send[3]={0x63,0x02,0x00};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(25):
- {
- unsigned char send[3]={0x63,0x02,0xff};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(26)://shouwanyunxing
- {
- unsigned char send[3]={0x63,0x04,0x00};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(27):
- {
- unsigned char send[3]={0x63,0x04,0xff};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(28)://shouzhuayunxing
- {
- unsigned char send[3]={0x63,0x05,0x00};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(29):
- {
- unsigned char send[3]={0x63,0x05,0xff};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(30)://shengjiangyunxing
- {
- unsigned char send[3]={0x63,0x03,0x00};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- case(31):
- {
- unsigned char send[3]={0x63,0x05,0xff};
- for(int i=0;i<=2;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(2000);
- }
- break;
- */
- case(32)://dabiguiling
- {
- unsigned char send[2]={0xa3,0x01};
- for(int i=0;i<=1;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(18000);
- }
- break;
- case(33)://xiaobiguiling
- {
- unsigned char send[2]={0xa3,0x02};
- for(int i=0;i<=1;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(15000);
- }
- break;
- case(34)://shouwanguiling
- {
- unsigned char send[2]={0xa3,0x04};
- for(int i=0;i<=1;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(6000);
- }
- break;
- case(35)://shouzhuaguiling
- {
- unsigned char send[2]={0xa3,0x05};
- for(int i=0;i<=1;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(6000);
- }
- break;
- case(36)://shengjiangguiling
- {
- unsigned char send[2]={0xa3,0x03};
- for(int i=0;i<=1;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(10000);
- }
- break;
- case(37)://sudujia
- {
- send1=0xb3;
- pDoc->WriteComm(&send1,1);
- }
- Sleep(1000);
- break;
- case(38)://yuandianjiyi
- send1=0x73;
- pDoc->WriteComm(&send1,1);
- break;
- case(39):
- send1=0xc3;
- pDoc->WriteComm(&send1,1);
- break;
- case(40):
- send1=0xf6;
- pDoc->WriteComm(&send1,1);
- break;
- case(41):
- send1=0x83;
- pDoc->WriteComm(&send1,1);
- break;
- case(42):
- send1=0x93;
- pDoc->WriteComm(&send1,1);
- break;
- case(43):
- // {
- // unsigned char send[2]={0x86,0x03};
- // for(int i=0;i<=1;i++)
- // pDoc->WriteComm(&send[i],1);
- // Sleep(4000);
- // }
- send1=0x86;
- pDoc->WriteComm(&send1,1);
- break;
- case(44)://sudujian
- {
- send1=0xe3;
- pDoc->WriteComm(&send1,1);
- }
- break;
- case(45):
- {
- send1=0x12;
- pDoc->WriteComm(&send1,1);
- }
- break;
- case(46):
- {
- send1=0x22;
- pDoc->WriteComm(&send1,1);
- }
- break;
- case(47): //danbuzaixian
- send1=0x13;
- pDoc->WriteComm(&send1,1);
- Sleep(4000);
- break;
- case(48): //zhouqizaixian
- send1=0x23;
- pDoc->WriteComm(&send1,1);
- Sleep(8000);
- break;
- case(49): //lianxuzaixian
- send1=0x33;
- pDoc->WriteComm(&send1,1);
- break;
- case(50):
- //send1=0x32;
- //pDoc->WriteComm(&send1,1);
- break;
- case(51):
- break;
- case(52):
- send1=0x43;
- pDoc->WriteComm(&send1,1);
- break;
- case(53):
- break;
- case(54):
- pDoc->OnSetupcomm();
- break;
- case(55):
- pDoc->OnOpencomm();
- break;
- default:
- pDoc->OnClosecomm();
- break;
- }
- }
- //void CRobotView::OnButton3()
- //{
- // TODO: Add your control notification handler code here
- // SendMessage(WM_USER + 1002,10,0);
- //}
- void CRobotView::Execute_1(unsigned char a,unsigned char b,unsigned char c,unsigned char d,int e)
- {
- CRobotDoc* pDoc=GetDocument();
- unsigned char send[6]={0x53,a,b,0x00,c,d};
- for(int i=0;i<=5;i++)
- pDoc->WriteComm(&send[i],1);
- Sleep(m_ndelay);
- }
- HBRUSH CRobotView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
-
- // TODO: Change any attributes of the DC here
- switch(nCtlColor)
- {
- case CTLCOLOR_DLG:
- {
- //pDC->SetBkMode(TRANSPARENT);
- return m_brush; //返加绿色刷子
- }
- case CTLCOLOR_STATIC:
- {
- //返加绿色刷子
- // pDC->SetBkMode(TRANSPARENT);
- return m_brush;
- }
- }
- // TODO: Return a different brush if the default is not desired
- return hbr;
- }
- void CRobotView::home()
- {
- SendMessage(WM_USER+1002,32,0);
- SendMessage(WM_USER+1002,10,0);
- Sleep(1000);
- SendMessage(WM_USER+1002,33,0);
- SendMessage(WM_USER+1002,10,0);
- Sleep(1000);
- SendMessage(WM_USER+1002,34,0);
- SendMessage(WM_USER+1002,10,0);
- Sleep(1000);
- SendMessage(WM_USER+1002,35,0);
- SendMessage(WM_USER+1002,10,0);
- Sleep(1000);
- SendMessage(WM_USER+1002,36,0);
- SendMessage(WM_USER+1002,10,0);
- Sleep(1000);
- }
- LRESULT CRobotView::OnCommNotify(WPARAM wParam, LPARAM lParam)
- {
- unsigned char buf;
- CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
- CString str1,str2;
- CRobotDoc* pDoc=GetDocument();
- m_recflag=0;
- if(!pDoc->m_bConnected ||
- (wParam & EV_RXCHAR)!=EV_RXCHAR) // 是否是EV_RXCHAR事件?
- {
- SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
- return 0L;
- }
- nLength=pDoc->ReadComm(&buf,1);
- if(nLength)
- {
- // str1.Format("%d",buf);
- //m_edit1.SetSel(-1, 0);
- // m_edit1.ReplaceSel(str1); // 向编辑视图中插入收到的字符
- str2="正在执行命令,请稍后.....";
- pWnd->SetWindowText(str2);
- SendMessage(WM_USER+1003);
- }
- SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
- return 0L;
- }
- void CRobotView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- SendMessage(WM_USER+1002,100);
- CFormView::OnTimer(nIDEvent);
- }