robotView.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:21k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. // robotView.cpp : implementation of the CRobotView class
  2. //
  3. #include "stdafx.h"
  4. #include "robot.h"
  5. #include"Label.h"
  6. #include "robotDoc.h"
  7. #include "robotView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CRobotView
  15. IMPLEMENT_DYNCREATE(CRobotView, CFormView)
  16. BEGIN_MESSAGE_MAP(CRobotView, CFormView)
  17. //{{AFX_MSG_MAP(CRobotView)
  18. ON_WM_CTLCOLOR()
  19. ON_WM_TIMER()
  20. //}}AFX_MSG_MAP
  21. ON_MESSAGE(WM_COMMNOTIFY, OnCommNotify)
  22. END_MESSAGE_MAP()
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CRobotView construction/destruction
  25. CRobotView::CRobotView()
  26. : CFormView(CRobotView::IDD)
  27. {
  28. //{{AFX_DATA_INIT(CRobotView)
  29. //}}AFX_DATA_INIT
  30. // TODO: add construction code here
  31. m_ncomand1=10;
  32. m_bflag=0;
  33. m_nsudu=1;
  34. m_ngzq=0;
  35. m_nguanjie;
  36. m_nfangxiang;
  37. m_nmsg[0]=0;
  38. m_njishu=0;
  39. m_nmsg[1]=0;
  40. m_nmsg[2]=0;
  41. m_nmsg[3]=0;
  42. m_nmsg[4]=0;
  43. m_nsum=0;
  44. m_ndelay=0;
  45. nLength=0;
  46. m_recflag=1;
  47. m_failflag=1;
  48. m_brush.CreateSolidBrush(RGB(40,98,122)); // 生成一绿色刷子 
  49. }
  50. CRobotView::~CRobotView()
  51. {
  52. }
  53. void CRobotView::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CFormView::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(CRobotView)
  57. //DDX_Control(pDX, IDC_EDIT1, m_edit1);
  58. DDX_Control(pDX, IDC_STATIC_LINK, m_link);
  59. DDX_Control(pDX, IDC_STATIC_1, m_ml);
  60. DDX_Control(pDX, IDC_STATIC_4, m_workpart);
  61. DDX_Control(pDX, IDC_STATIC_COMMAND, m_command);
  62. DDX_Control(pDX, IDC_STATIC_STATUS, m_static);
  63. DDX_Control(pDX, IDC_STATIC_BUCHANG, m_buchangshu);
  64. DDX_Control(pDX, IDC_STATIC_5, m_buchang);
  65. DDX_Control(pDX, IDC_STATIC_3, m_sudu);
  66. DDX_Control(pDX, IDC_STATIC_2, m_zhuangtai);
  67. //}}AFX_DATA_MAP
  68. }
  69. BOOL CRobotView::PreCreateWindow(CREATESTRUCT& cs)
  70. {
  71. // TODO: Modify the Window class or styles here by modifying
  72. //  the CREATESTRUCT cs
  73. return CFormView::PreCreateWindow(cs);
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CRobotView diagnostics
  77. #ifdef _DEBUG
  78. void CRobotView::AssertValid() const
  79. {
  80. CFormView::AssertValid();
  81. }
  82. void CRobotView::Dump(CDumpContext& dc) const
  83. {
  84. CFormView::Dump(dc);
  85. }
  86. CRobotDoc* CRobotView::GetDocument() // non-debug version is inline
  87. {
  88. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRobotDoc)));
  89. return (CRobotDoc*)m_pDocument;
  90. }
  91. #endif //_DEBUG
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CRobotView message handlers
  94. void CRobotView::OnDraw(CDC* pDC) 
  95. {
  96. // TODO: Add your specialized code here and/or call the base class
  97. SuduDisplay(m_nsudu);
  98. GzqDisplay(m_ngzq);
  99. }
  100. void CRobotView::OnInitialUpdate() 
  101. {
  102. CFormView::OnInitialUpdate();
  103. // TODO: Add your specialized code here and/or call the base class
  104. m_link.SetLink(TRUE)
  105. .SetTextColor(RGB(0,0,255))
  106. .SetFontUnderline(TRUE)
  107. .SetLinkCursor(AfxGetApp()->LoadCursor(IDC_ICON1));
  108. m_command.SetFontSize(24)
  109. .SetFontName("Terminal")
  110.   .SetTextColor(RGB(240,240,40));
  111. m_static.SetFontSize(24)
  112.   .SetTextColor(RGB(240,240,40));
  113. m_workpart.SetFontSize(24)
  114. .SetFontBold(TRUE)
  115.   .SetTextColor(RGB(0,240,0));
  116. m_buchangshu.SetFontSize(24)
  117.   .SetTextColor(RGB(240,240,40));
  118. m_buchang.SetFontSize(24)
  119. .SetFontBold(TRUE)
  120.   .SetTextColor(RGB(0,240,0));
  121. m_sudu.SetFontSize(24)
  122. .SetFontBold(TRUE)
  123.   .SetTextColor(RGB(0,240,0));
  124. m_zhuangtai.SetFontSize(24)
  125. .SetFontBold(TRUE)
  126.   .SetTextColor(RGB(0,240,0));
  127. m_ml.SetFontSize(24)
  128. .SetLinkCursor(AfxGetApp()->LoadCursor(IDC_ICON1))
  129. .SetFontBold(TRUE)
  130.  .SetTextColor(RGB(0,240,0));
  131. GetParentFrame()->RecalcLayout();
  132. ResizeParentToFit();
  133. }
  134. LRESULT CRobotView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  135. {
  136. // TODO: Add your specialized code here and/or call the base class
  137. if(message == (WM_USER + 1002))
  138. ProcessMessage(wParam, lParam);
  139. else if(message==(WM_USER+1003))
  140. ProcessMyMessage();
  141. return CFormView::WindowProc(message, wParam, lParam);
  142. }
  143. void CRobotView::ProcessMessage(WPARAM wParam, LPARAM lParam)
  144. {
  145. CRobotDoc* pDoc=GetDocument();
  146. char* l[57] = {"零","一","二",///012
  147. "三","四","五","六","七","八","九","执行","各关节归零","大臂正转",///12
  148. "大臂反转","小臂正转","小臂反转","手腕正转","手腕反转","手爪张开","手爪闭合","上升","下降","大臂运行",///13--22
  149. "大臂负运行","小臂运行","小臂负运行","手腕运行","手腕负运行","手爪运行","手爪负运行","升降运行",////23---30
  150. "升降负运行","大臂归零","小臂归零","手腕归零","手爪归零","升降归零","速度加","原点记忆",///31---38
  151. "系统复位","示教盒","","","回原点","速度减","区号加","区号减","单步再现","周期再现",///39---48
  152. "连续再现","返回","继续","数据记忆","读取数据","设置串口","打开串口","关闭串口"};
  153. CString    strcomand;
  154. CString    strstatus;
  155. m_recflag=1;
  156. if(!pDoc->m_bConnected)
  157. {
  158. KillTimer(1);
  159. MessageBox("请先打开串口");
  160. return;
  161. }
  162. if(wParam==100)
  163. {
  164. KillTimer(1);
  165. if(!m_failflag)
  166. {
  167. CWnd* pWnd=GetDlgItem(IDC_STATIC_5);
  168. pWnd->SetWindowText("");
  169.         pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  170.             pWnd->SetWindowText("");
  171.         pWnd=GetDlgItem(IDC_STATIC_COMMAND);
  172.         pWnd->SetWindowText("请输入新的命令");
  173.         pWnd=GetDlgItem(IDC_STATIC_STATUS);
  174.         pWnd->SetWindowText("执行完毕");
  175.         m_ncomand1=0;
  176. }
  177. else
  178. MessageBox("请检查连线是否正确或下位机是否打开","通信失败",MB_ICONWARNING);
  179. }
  180. else if(wParam>=11&&wParam<=56)
  181. {
  182. m_bflag=0;
  183. m_ncomand1=wParam;
  184. strcomand=l[m_ncomand1];
  185. CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
  186. pWnd->SetWindowText(strcomand);
  187. pWnd=GetDlgItem(IDC_STATIC_STATUS);
  188. pWnd->SetWindowText("");
  189. pWnd=GetDlgItem(IDC_STATIC_5);
  190. pWnd->SetWindowText("");
  191. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  192. pWnd->SetWindowText("");
  193. m_nsum=0;
  194. m_njishu=0;
  195. }
  196. else if(wParam>=0&&wParam<=9)
  197. {
  198. if(m_ncomand1>=12&&m_ncomand1<=21)
  199. {
  200. m_bflag=1;
  201. m_nmsg[m_njishu]=wParam;
  202.    //pWnd=GetDlgItem(IDC_STATIC_COMMAND);
  203.         //pWnd->SetWindowText(strcomand);
  204. CWnd* pWnd=GetDlgItem(IDC_STATIC_5);
  205. pWnd->SetWindowText("步长:");
  206. ++m_njishu;
  207. if(m_njishu==1)
  208. {
  209. CString m_stemp;
  210. m_nsum=m_nmsg[0];
  211. m_stemp.Format("%d",m_nsum);
  212. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  213. pWnd->SetWindowText(m_stemp);
  214. }
  215. if(m_njishu==2)
  216. {
  217. CString m_stemp;
  218. m_nsum=m_nmsg[0]*10+m_nmsg[1];
  219. m_stemp.Format("%d",m_nsum);
  220. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  221. pWnd->SetWindowText(m_stemp);
  222. }
  223. if(m_njishu==3)
  224. {
  225. CString m_stemp;
  226. m_nsum=m_nmsg[0]*100+m_nmsg[1]*10+m_nmsg[2];
  227. //m_nmsg[0]=0;
  228. //m_nmsg[1]=0
  229. // m_nmsg[2]=0;
  230. // m_njishu=0;
  231. m_stemp.Format("%d",m_nsum);
  232. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  233. pWnd->SetWindowText(m_stemp);
  234. }
  235. if(m_njishu==4)
  236. {
  237. CString m_stemp;
  238. m_nsum=m_nmsg[0]*1000+m_nmsg[1]*100+m_nmsg[2]*10+m_nmsg[3];
  239. m_stemp.Format("%d",m_nsum);
  240. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  241. pWnd->SetWindowText(m_stemp);
  242. }
  243. if(m_njishu>4)
  244. {
  245. m_njishu=1;
  246. m_nmsg[0]=m_nmsg[4];
  247. CString m_stemp;
  248. m_nsum=m_nmsg[0];
  249. m_stemp.Format("%d",m_nsum);
  250. pWnd=GetDlgItem(IDC_STATIC_BUCHANG);
  251. pWnd->SetWindowText(m_stemp);
  252. m_nmsg[1]=0;
  253. m_nmsg[2]=0;
  254. m_nmsg[3]=0;
  255. }
  256. }
  257. else
  258. ; //MessageBox("清先输入运动步数命令");
  259. }
  260. else if(wParam=10)
  261. {    SetTimer(1,500,NULL);
  262. if(m_ncomand1>=11&&m_ncomand1<=56)
  263. {
  264. if(!m_bflag)
  265. {
  266. strstatus="正在执行命令,请稍后.....";
  267. CWnd* pWnd=GetDlgItem(IDC_STATIC_STATUS);
  268. pWnd->SetWindowText(strstatus);
  269. Execute(m_ncomand1);
  270. }
  271. else //if(m_ncomand1>=12&&m_ncomand1<=21)
  272. {
  273. unsigned char m_uhi,m_ulo;
  274. m_nmsg[0]=0;
  275.          m_nmsg[1]=0;
  276. m_nmsg[2]=0;
  277. m_nmsg[3]=0;
  278. m_njishu=0;
  279. /// CWnd* pWnd=GetDlgItem(IDC_STATIC_STATUS);
  280.    /// pWnd->SetWindowText("正在执行命令,请稍后.....");
  281. switch(m_ncomand1)
  282. {
  283. case(12):
  284. m_nguanjie=01;
  285. m_nfangxiang=00;
  286. m_uhi=(unsigned char)(m_nsum/256);
  287. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  288. m_ndelay=(m_nsum+500)/m_nsudu;
  289. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  290. break;
  291. case(13):
  292. m_nguanjie=0x01;
  293. m_nfangxiang=0xff;
  294. m_uhi=(unsigned char)(m_nsum/256);
  295. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  296. m_ndelay=(m_nsum+500)/m_nsudu;
  297. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  298. break;
  299. case(14):
  300. m_nguanjie=0x02;
  301. m_nfangxiang=0x00;
  302. m_uhi=(unsigned char)(m_nsum/256);
  303. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  304. m_ndelay=(m_nsum)/(m_nsudu*3);
  305. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  306. break;
  307. case(15):
  308. m_nguanjie=0x02;
  309. m_nfangxiang=0xff;
  310. m_uhi=(unsigned char)(m_nsum/256);
  311. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  312. m_ndelay=(m_nsum)/(m_nsudu*3);
  313. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  314. break;
  315. case(16):
  316. m_nguanjie=0x04;
  317. m_nfangxiang=0x00;
  318. m_uhi=(unsigned char)(m_nsum/256);
  319. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  320. m_ndelay=(m_nsum+500)/m_nsudu;
  321. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  322. break;
  323. case(17):
  324. m_nguanjie=0x04;
  325. m_nfangxiang=0xff;
  326. m_uhi=(unsigned char)(m_nsum/256);
  327. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  328. m_ndelay=(m_nsum+500)/m_nsudu;
  329. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  330. break;
  331. case(18):
  332. m_nguanjie=0x05;
  333. m_nfangxiang=0x00;
  334. m_uhi=(unsigned char)(m_nsum/256);
  335. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  336. m_ndelay=(m_nsum+500)/m_nsudu;
  337. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  338. break;
  339. case(19):
  340. m_nguanjie=0x05;
  341. m_nfangxiang=0xff;
  342. m_uhi=(unsigned char)(m_nsum/256);
  343. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  344. m_ndelay=(m_nsum+500)/m_nsudu;
  345. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  346. break;
  347. case(20):
  348. m_nguanjie=0x03;
  349. m_nfangxiang=0x00;
  350. m_uhi=(unsigned char)(m_nsum/256);
  351. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  352. m_ndelay=(m_nsum+500)/(m_nsudu*2);
  353. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  354. break;
  355. case(21):
  356. m_nguanjie=0x03;
  357. m_nfangxiang=0xff;
  358. m_uhi=(unsigned char)(m_nsum/256);
  359. m_ulo=(unsigned char)(m_nsum-m_uhi*256);
  360. m_ndelay=(m_nsum+500)/(m_nsudu*2);
  361. Execute_1(m_nguanjie,m_nfangxiang,m_uhi,m_ulo,m_ndelay);
  362. break;
  363. }
  364.            }
  365. m_failflag=1;}
  366.    else
  367.    MessageBox("清先输入命令");
  368.      }
  369.  else
  370.  MessageBox("不能识别,请重新输入命令");
  371. }
  372. void CRobotView::ProcessMyMessage()
  373. {
  374. CDC *PDc=GetDC();
  375. m_failflag=0;
  376. switch(m_ncomand1)
  377. {
  378. case(37):
  379. {
  380. m_nsudu++;
  381. if(m_nsudu==6)
  382. m_nsudu=1;
  383. OnDraw(PDc);
  384. }
  385. break;
  386. case(44):
  387. {
  388. m_nsudu--;
  389. if(m_nsudu==0)
  390. m_nsudu=5;
  391. OnDraw(PDc);
  392. }
  393. break;
  394. case(45):
  395. {
  396. m_ngzq++;
  397. if(m_ngzq==8)
  398. m_ngzq=0;
  399. OnDraw(PDc);
  400. }
  401. break;
  402. case(46):
  403. {
  404. m_ngzq--;
  405. if(m_ngzq==-1)
  406. m_ngzq=7;
  407. OnDraw(PDc);
  408. }
  409. break;
  410. }
  411. CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
  412. pWnd->SetWindowText("请输入新的命令");
  413. pWnd=GetDlgItem(IDC_STATIC_STATUS);
  414. pWnd->SetWindowText("执行完毕");
  415. m_ncomand1=0;
  416. //}
  417. //else
  418. // MessageBox("请检查连线是否正确或下位机是否打开","通信失败",MB_ICONWARNING);
  419. }
  420. void CRobotView::SuduDisplay(int n)
  421. {
  422. CWnd* pWnd=GetDlgItem(IDC_STATIC_SUDU);
  423. CDC* pControlDC=pWnd->GetDC();
  424. pWnd->Invalidate();
  425. pWnd->UpdateWindow();
  426. pControlDC->SelectStockObject(BLACK_BRUSH);
  427. CBitmap mBit;
  428. CDC MemDC;
  429. MemDC.CreateCompatibleDC(NULL);
  430. switch(n)
  431. {
  432. case 0:
  433. mBit.LoadBitmap(IDB_BMP10);
  434. break;
  435. case 1:
  436. mBit.LoadBitmap(IDB_BMP11);
  437. break;
  438. case 2:
  439. mBit.LoadBitmap(IDB_BMP12);
  440. break;
  441. case 3:
  442. mBit.LoadBitmap(IDB_BMP13);
  443. break;
  444. case 4:
  445. mBit.LoadBitmap(IDB_BMP14);
  446. break;
  447. case 5:
  448. mBit.LoadBitmap(IDB_BMP15);
  449. break;
  450. default:
  451. //mBit.LoadBitmap(IDB_BMP0);
  452. MessageBox("error");
  453. }
  454. CBitmap *pOldBit=MemDC.SelectObject(&mBit);
  455. pControlDC->BitBlt(0,0,900,700,&MemDC,0,0,SRCCOPY);
  456. MemDC.SelectObject(pOldBit);
  457. }
  458. void CRobotView::GzqDisplay(int n)
  459. {
  460. CWnd* pWnd=GetDlgItem(IDC_STATIC_GONGZUOQU);
  461. CDC* pControlDC=pWnd->GetDC();
  462. pWnd->Invalidate();
  463. pWnd->UpdateWindow();
  464. pControlDC->SelectStockObject(BLACK_BRUSH);
  465. CBitmap mBit;
  466. CDC MemDC;
  467. MemDC.CreateCompatibleDC(NULL);
  468. switch(n)
  469. {
  470. case 0:
  471. mBit.LoadBitmap(IDB_BMP10);
  472. break;
  473. case 1:
  474. mBit.LoadBitmap(IDB_BMP11);
  475. break;
  476. case 2:
  477. mBit.LoadBitmap(IDB_BMP12);
  478. break;
  479. case 3:
  480. mBit.LoadBitmap(IDB_BMP13);
  481. break;
  482. case 4:
  483. mBit.LoadBitmap(IDB_BMP14);
  484. break;
  485. case 5:
  486. mBit.LoadBitmap(IDB_BMP15);
  487. break;
  488. case 6:
  489. mBit.LoadBitmap(IDB_BMP16);
  490. break;
  491. case 7:
  492. mBit.LoadBitmap(IDB_BMP17);
  493. break;
  494. default:
  495. //mBit.LoadBitmap(IDB_BMP0);
  496. MessageBox("error");
  497. }
  498. CBitmap *pOldBit=MemDC.SelectObject(&mBit);
  499. pControlDC->BitBlt(0,0,900,700,&MemDC,0,0,SRCCOPY);
  500. MemDC.SelectObject(pOldBit);
  501. }
  502. void CRobotView::Execute(int n)
  503. {
  504. CRobotDoc* pDoc=GetDocument();
  505. unsigned char send1;
  506. switch(n)
  507. {
  508. case(11):
  509. home();
  510. break;
  511. case(12):
  512. {//大臂正传
  513. unsigned char send[6]={0x53,0x01,0x00,0x00,0x07,0x18};
  514. for(int i=0;i<=5;i++)
  515. pDoc->WriteComm(&send[i],1);
  516. Sleep(2000/m_nsudu);
  517. break;
  518. }
  519. case(13):
  520. {
  521. unsigned char send[6]={0x53,0x01,0xff,0x00,0x07,0x18};
  522. for(int i=0;i<=5;i++)
  523. pDoc->WriteComm(&send[i],1);
  524. // pDoc->ReadComm(&buf,1);
  525. // if(nLength)
  526. //// {
  527. // str.Format("%d",buf);
  528. // m_edit1.SetSel(-1, 0);
  529. // m_edit1.ReplaceSel(str); // 向编辑视图中插入收到的字符
  530. // }
  531. // else
  532. // MessageBox("fjdklfjsdklgjsdfkl");
  533. Sleep(2000/m_nsudu);
  534. break;
  535. }
  536. case(14)://xiaobizhengzhuan
  537. {
  538. unsigned char send[6]={0x53,0x02,0x00,0x00,0x0f,0xe3};
  539. for(int i=0;i<=5;i++)
  540. pDoc->WriteComm(&send[i],1);
  541. Sleep(2000/m_nsudu);
  542. break;
  543. }
  544. case(15)://小臂反转
  545. {
  546. unsigned char send[6]={0x53,0x02,0xff,0x00,0x0f,0xe3};
  547. for(int i=0;i<=5;i++)
  548. pDoc->WriteComm(&send[i],1);
  549. Sleep(2000/m_nsudu);
  550. break;
  551. }
  552. case(16)://手腕正转
  553. {
  554. unsigned char send[6]={0x53,0x04,0x00,0x00,0x00,0xff};
  555. for(int i=0;i<=5;i++)
  556. pDoc->WriteComm(&send[i],1);
  557. Sleep(1000/m_nsudu);
  558. break;
  559. }
  560. case(17)://shouwanfanzhuan
  561. {
  562. unsigned char send[6]={0x53,0x04,0xff,0x00,0x00,0xff};
  563. for(int i=0;i<=5;i++)
  564. pDoc->WriteComm(&send[i],1);
  565. Sleep(1000/m_nsudu);
  566. }
  567. break;
  568. case(18)://shouzhuazhangkai
  569. {
  570. unsigned char send[6]={0x53,0x05,0x00,0x00,0x00,0x43};
  571. for(int i=0;i<=5;i++)
  572. pDoc->WriteComm(&send[i],1);
  573. Sleep(2000/m_nsudu);
  574. }
  575. break;
  576. case(19):
  577. {
  578. unsigned char send[6]={0x53,0x05,0xff,0x00,0x00,0xf3};
  579. for(int i=0;i<=5;i++)
  580. pDoc->WriteComm(&send[i],1);
  581. Sleep(2000/m_nsudu);
  582. }
  583. break;
  584. case(20)://shangsheng
  585. {
  586. unsigned char send[6]={0x53,0x03,0x00,0x00,0x02,0xe3};
  587. for(int i=0;i<=5;i++)
  588. pDoc->WriteComm(&send[i],1);
  589. Sleep(1000/m_nsudu);
  590. }
  591. break;
  592. case(21):
  593. {
  594. unsigned char send[6]={0x53,0x03,0xff,0x00,0x02,0xe3};
  595. for(int i=0;i<=5;i++)
  596. pDoc->WriteComm(&send[i],1);
  597. Sleep(1000/m_nsudu);
  598. }
  599. break;
  600. /* case(22)://dabiyunxing
  601. {
  602. unsigned char send[3]={0x63,0x01,0x00};
  603. for(int i=0;i<=2;i++)
  604. pDoc->WriteComm(&send[i],1);
  605. Sleep(2000);
  606. }
  607. break;
  608. case(23):
  609. {
  610. unsigned char send[3]={0x63,0x01,0xff};
  611. for(int i=0;i<=2;i++)
  612. pDoc->WriteComm(&send[i],1);
  613. Sleep(2000);
  614. }
  615. break;
  616. case(24)://xiaobiyunxing
  617. {
  618. unsigned char send[3]={0x63,0x02,0x00};
  619. for(int i=0;i<=2;i++)
  620. pDoc->WriteComm(&send[i],1);
  621. Sleep(2000);
  622. }
  623. break;
  624. case(25):
  625. {
  626. unsigned char send[3]={0x63,0x02,0xff};
  627. for(int i=0;i<=2;i++)
  628. pDoc->WriteComm(&send[i],1);
  629. Sleep(2000);
  630. }
  631. break;
  632. case(26)://shouwanyunxing
  633. {
  634. unsigned char send[3]={0x63,0x04,0x00};
  635. for(int i=0;i<=2;i++)
  636. pDoc->WriteComm(&send[i],1);
  637. Sleep(2000);
  638. }
  639. break;
  640. case(27):
  641. {
  642. unsigned char send[3]={0x63,0x04,0xff};
  643. for(int i=0;i<=2;i++)
  644. pDoc->WriteComm(&send[i],1);
  645. Sleep(2000);
  646. }
  647. break;
  648. case(28)://shouzhuayunxing
  649. {
  650. unsigned char send[3]={0x63,0x05,0x00};
  651. for(int i=0;i<=2;i++)
  652. pDoc->WriteComm(&send[i],1);
  653. Sleep(2000);
  654. }
  655. break;
  656. case(29):
  657. {
  658. unsigned char send[3]={0x63,0x05,0xff};
  659. for(int i=0;i<=2;i++)
  660. pDoc->WriteComm(&send[i],1);
  661. Sleep(2000);
  662. }
  663. break;
  664. case(30)://shengjiangyunxing
  665. {
  666. unsigned char send[3]={0x63,0x03,0x00};
  667. for(int i=0;i<=2;i++)
  668. pDoc->WriteComm(&send[i],1);
  669. Sleep(2000);
  670. }
  671. break;
  672. case(31):
  673. {
  674. unsigned char send[3]={0x63,0x05,0xff};
  675. for(int i=0;i<=2;i++)
  676. pDoc->WriteComm(&send[i],1);
  677. Sleep(2000);
  678. }
  679. break;
  680. */
  681. case(32)://dabiguiling
  682. {
  683. unsigned char send[2]={0xa3,0x01};
  684. for(int i=0;i<=1;i++)
  685. pDoc->WriteComm(&send[i],1);
  686. Sleep(18000);
  687. }
  688. break;
  689. case(33)://xiaobiguiling
  690. {
  691. unsigned char send[2]={0xa3,0x02};
  692. for(int i=0;i<=1;i++)
  693. pDoc->WriteComm(&send[i],1);
  694. Sleep(15000);
  695. }
  696. break;
  697. case(34)://shouwanguiling
  698. {
  699. unsigned char send[2]={0xa3,0x04};
  700. for(int i=0;i<=1;i++)
  701. pDoc->WriteComm(&send[i],1);
  702. Sleep(6000);
  703. }
  704. break;
  705. case(35)://shouzhuaguiling
  706. {
  707. unsigned char send[2]={0xa3,0x05};
  708. for(int i=0;i<=1;i++)
  709. pDoc->WriteComm(&send[i],1);
  710. Sleep(6000);
  711. }
  712. break;
  713. case(36)://shengjiangguiling
  714. {
  715. unsigned char send[2]={0xa3,0x03};
  716. for(int i=0;i<=1;i++)
  717. pDoc->WriteComm(&send[i],1);
  718. Sleep(10000);
  719. }
  720. break;
  721. case(37)://sudujia
  722. {
  723. send1=0xb3;
  724. pDoc->WriteComm(&send1,1);
  725. }
  726. Sleep(1000);
  727. break;
  728. case(38)://yuandianjiyi
  729. send1=0x73;
  730. pDoc->WriteComm(&send1,1);
  731. break;
  732. case(39):
  733. send1=0xc3;
  734. pDoc->WriteComm(&send1,1);
  735. break;
  736. case(40):
  737. send1=0xf6;
  738. pDoc->WriteComm(&send1,1);
  739. break;
  740. case(41):
  741. send1=0x83;
  742. pDoc->WriteComm(&send1,1);
  743. break;
  744. case(42):
  745. send1=0x93;
  746. pDoc->WriteComm(&send1,1);
  747. break;
  748. case(43):
  749. // {
  750. // unsigned char send[2]={0x86,0x03};
  751. // for(int i=0;i<=1;i++)
  752. // pDoc->WriteComm(&send[i],1);
  753. // Sleep(4000);
  754. // }
  755. send1=0x86;
  756. pDoc->WriteComm(&send1,1);
  757. break;
  758. case(44)://sudujian
  759. {
  760. send1=0xe3;
  761. pDoc->WriteComm(&send1,1);
  762. }
  763. break;
  764. case(45):
  765. {
  766. send1=0x12;
  767. pDoc->WriteComm(&send1,1);
  768. }
  769. break;
  770. case(46):
  771. {
  772. send1=0x22;
  773. pDoc->WriteComm(&send1,1);
  774. }
  775. break;
  776. case(47): //danbuzaixian
  777. send1=0x13;
  778. pDoc->WriteComm(&send1,1);
  779. Sleep(4000);
  780. break;
  781. case(48): //zhouqizaixian
  782. send1=0x23;
  783. pDoc->WriteComm(&send1,1);
  784. Sleep(8000);
  785. break;
  786. case(49): //lianxuzaixian
  787. send1=0x33;
  788. pDoc->WriteComm(&send1,1);
  789. break;
  790. case(50):
  791. //send1=0x32;
  792. //pDoc->WriteComm(&send1,1);
  793. break;
  794. case(51):
  795. break;
  796. case(52):
  797. send1=0x43;
  798. pDoc->WriteComm(&send1,1);
  799. break;
  800. case(53):
  801. break;
  802. case(54):
  803. pDoc->OnSetupcomm();
  804. break;
  805. case(55):
  806. pDoc->OnOpencomm();
  807. break;
  808. default:
  809. pDoc->OnClosecomm();
  810. break;
  811. }
  812. }
  813. //void CRobotView::OnButton3() 
  814. //{
  815. // TODO: Add your control notification handler code here
  816. // SendMessage(WM_USER + 1002,10,0);
  817. //}
  818. void CRobotView::Execute_1(unsigned char a,unsigned char b,unsigned char c,unsigned char d,int e)
  819. {
  820. CRobotDoc* pDoc=GetDocument();
  821. unsigned char send[6]={0x53,a,b,0x00,c,d};
  822. for(int i=0;i<=5;i++)
  823. pDoc->WriteComm(&send[i],1);
  824. Sleep(m_ndelay);
  825. }
  826. HBRUSH CRobotView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  827. {
  828. HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
  829. // TODO: Change any attributes of the DC here
  830. switch(nCtlColor)
  831. {
  832. case CTLCOLOR_DLG:
  833. {
  834. //pDC->SetBkMode(TRANSPARENT);
  835. return m_brush;   //返加绿色刷子
  836. }
  837. case CTLCOLOR_STATIC:
  838. {
  839.    //返加绿色刷子
  840. // pDC->SetBkMode(TRANSPARENT);
  841. return m_brush;
  842. }
  843. }
  844. // TODO: Return a different brush if the default is not desired
  845. return hbr;
  846. }
  847. void CRobotView::home() 
  848. {
  849. SendMessage(WM_USER+1002,32,0);
  850. SendMessage(WM_USER+1002,10,0);
  851. Sleep(1000);
  852. SendMessage(WM_USER+1002,33,0);
  853. SendMessage(WM_USER+1002,10,0);
  854. Sleep(1000);
  855.     SendMessage(WM_USER+1002,34,0);
  856. SendMessage(WM_USER+1002,10,0);
  857. Sleep(1000);
  858. SendMessage(WM_USER+1002,35,0);
  859. SendMessage(WM_USER+1002,10,0);
  860. Sleep(1000);
  861. SendMessage(WM_USER+1002,36,0);
  862. SendMessage(WM_USER+1002,10,0);
  863. Sleep(1000);
  864. }
  865. LRESULT CRobotView::OnCommNotify(WPARAM wParam, LPARAM lParam)
  866. {
  867. unsigned char buf;
  868. CWnd* pWnd=GetDlgItem(IDC_STATIC_COMMAND);
  869. CString str1,str2;
  870. CRobotDoc* pDoc=GetDocument();
  871. m_recflag=0;
  872. if(!pDoc->m_bConnected || 
  873. (wParam & EV_RXCHAR)!=EV_RXCHAR) // 是否是EV_RXCHAR事件?
  874. {
  875. SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
  876. return 0L;
  877. }
  878. nLength=pDoc->ReadComm(&buf,1);
  879. if(nLength)
  880. {
  881. // str1.Format("%d",buf);
  882. //m_edit1.SetSel(-1, 0);
  883. // m_edit1.ReplaceSel(str1); // 向编辑视图中插入收到的字符
  884. str2="正在执行命令,请稍后.....";
  885. pWnd->SetWindowText(str2);
  886. SendMessage(WM_USER+1003);
  887. }
  888. SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
  889. return 0L;
  890. }
  891. void CRobotView::OnTimer(UINT nIDEvent) 
  892. {
  893. // TODO: Add your message handler code here and/or call default
  894. SendMessage(WM_USER+1002,100);
  895. CFormView::OnTimer(nIDEvent);
  896. }