星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LuoBoPenUtil.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. using Common.system;
  2. using RobotpenGateway;
  3. using System;
  4. using System.Threading;
  5. using XHWK.WKTool.Utils.pen;
  6. namespace XHWK.WKTool.Utils.luobo
  7. {
  8. class LuoBoPenUtil
  9. {
  10. #region 罗博智慧笔
  11. #region 值初始化
  12. PenEventI penEvent = null;
  13. [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  14. public static extern void OutputDebugString(string message);
  15. public robotpenController.returnPointData Date { get => date; set => date = value; }
  16. public bool usbIsConnected = false;
  17. private eDeviceType deviceType = eDeviceType.Unknow;
  18. private int m_nDeviceW = 22600;
  19. private int m_nDeviceH = 16650;
  20. private robotpenController.returnPointData date = null;
  21. public bool isOpen = true;
  22. /// <summary>
  23. /// 是否为笔模式
  24. /// </summary>
  25. private bool IsPen = false;
  26. private bool IsT8 = true;
  27. #endregion 值初始化
  28. public LuoBoPenUtil(PenEventI penEvent) {
  29. this.penEvent = penEvent;
  30. }
  31. /// <summary>
  32. /// 笔模式
  33. /// </summary>
  34. public void lb_device_hand()
  35. {
  36. IsPen = true;
  37. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ || deviceType == eDeviceType.T8C)
  38. {
  39. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND);
  40. }
  41. else
  42. {
  43. //获取当前设备模式,根据模式切换鼠标和笔
  44. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  45. }
  46. }
  47. /// <summary>
  48. /// 鼠标模式
  49. /// </summary>
  50. public void lb_device_mouse()
  51. {
  52. IsPen = false;
  53. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ || deviceType == eDeviceType.T8C)
  54. {
  55. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE);
  56. }
  57. else
  58. {
  59. //获取当前设备模式,根据模式切换鼠标和笔
  60. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  61. }
  62. }
  63. private void luobo_searchModeEvt(int modeType)
  64. {
  65. if (APP.IsOutputInfoLog)
  66. {
  67. if (modeType == 1)
  68. {
  69. LogHelper.WriteInfoLog("当前为笔模式");
  70. }
  71. else
  72. {
  73. LogHelper.WriteInfoLog("当前为鼠标模式");
  74. }
  75. }
  76. }
  77. // 子节点设备状态改变事件
  78. private void luobo_nodeStatusEvt(NODE_STATUS ns)
  79. {
  80. string strStatus = string.Empty;
  81. switch (ns)
  82. {
  83. case NODE_STATUS.DEVICE_POWER_OFF:
  84. {
  85. strStatus = "DEVICE_POWER_OFF";
  86. }
  87. break;
  88. case NODE_STATUS.DEVICE_STANDBY:
  89. {
  90. strStatus = "DEVICE_STANDBY";
  91. }
  92. break;
  93. case NODE_STATUS.DEVICE_INIT_BTN:
  94. {
  95. strStatus = "DEVICE_INIT_BTN";
  96. }
  97. break;
  98. case NODE_STATUS.DEVICE_OFFLINE:
  99. {
  100. strStatus = "DEVICE_OFFLINE";
  101. }
  102. break;
  103. case NODE_STATUS.DEVICE_ACTIVE:
  104. {
  105. strStatus = "DEVICE_ACTIVE";
  106. //deviceHand();
  107. }
  108. break;
  109. case NODE_STATUS.DEVICE_LOW_POWER_ACTIVE:
  110. {
  111. strStatus = "DEVICE_LOW_POWER_ACTIVE";
  112. }
  113. break;
  114. case NODE_STATUS.DEVICE_OTA_MODE:
  115. {
  116. strStatus = "DEVICE_OTA_MODE";
  117. }
  118. break;
  119. case NODE_STATUS.DEVICE_OTA_WAIT_SWITCH:
  120. {
  121. strStatus = "DEVICE_OTA_WAIT_SWITCH";
  122. }
  123. break;
  124. case NODE_STATUS.DEVICE_DFU_MODE:
  125. {
  126. strStatus = "DEVICE_DFU_MODE";
  127. }
  128. break;
  129. case NODE_STATUS.DEVICE_TRYING_POWER_OFF:
  130. {
  131. strStatus = "DEVICE_TRYING_POWER_OFF";
  132. }
  133. break;
  134. case NODE_STATUS.DEVICE_FINISHED_PRODUCT_TEST:
  135. {
  136. strStatus = "DEVICE_FINISHED_PRODUCT_TEST";
  137. }
  138. break;
  139. case NODE_STATUS.DEVICE_SYNC_MODE:
  140. {
  141. strStatus = "DEVICE_SYNC_MODE";
  142. }
  143. break;
  144. default:
  145. {
  146. strStatus = "UNKNOW";
  147. }
  148. break;
  149. }
  150. }
  151. private void luobo_switchModeEvt(int modeType)
  152. {
  153. if (modeType == 1)
  154. {
  155. if (APP.IsOutputInfoLog)
  156. {
  157. LogHelper.WriteInfoLog("当前为笔模式");
  158. }
  159. if (!IsPen)
  160. {
  161. lb_device_mouse();
  162. }
  163. }
  164. else
  165. {
  166. if (APP.IsOutputInfoLog)
  167. {
  168. LogHelper.WriteInfoLog("当前为鼠标模式");
  169. }
  170. if (IsPen)
  171. {
  172. lb_device_hand();
  173. }
  174. }
  175. }
  176. //初始化笔服务
  177. public void InitlbPen()
  178. {
  179. try
  180. {
  181. robotpenController.GetInstance()._ConnectInitialize(eDeviceType.Gateway, IntPtr.Zero);
  182. robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(luobo_deviceChangeEvt);
  183. robotpenController.GetInstance().searchModeEvt += luobo_searchModeEvt;
  184. robotpenController.GetInstance().nodeStatusEvt += luobo_nodeStatusEvt;
  185. robotpenController.GetInstance().switchModeEvt += luobo_switchModeEvt;
  186. robotpenController.GetInstance().keyPressEvt += new robotpenController.KeyPress(luobo_keyPressEvt);
  187. robotpenController.returnPointData datad = new robotpenController.returnPointData(luobo_bigDataReportEvt1);
  188. robotpenController.GetInstance().initDeletgate(ref datad);
  189. CheckUsbConnect();
  190. }
  191. catch (Exception ex)
  192. {
  193. LogHelper.WriteErrLog("设备初始化失败:" + ex.Message, ex);
  194. }
  195. }
  196. /// <summary>
  197. /// 设备插拔消息,更新listview
  198. /// </summary>
  199. /// <param name="bStatus">
  200. /// </param>
  201. /// <param name="uPid">
  202. /// </param>
  203. private void luobo_deviceChangeEvt(bool bStatus, ushort uPid)
  204. {
  205. //throw new NotImplementedException();
  206. Console.WriteLine("luobo_deviceChangeEvt");
  207. try
  208. {
  209. if (APP.IsOutputInfoLog)
  210. {
  211. LogHelper.WriteInfoLog(string.Format("设备状态{0} PID = {1}", bStatus, uPid));
  212. }
  213. }
  214. catch (Exception)
  215. {
  216. }
  217. CheckUsbConnect();
  218. }
  219. /// <summary>
  220. /// 书写
  221. /// </summary>
  222. /// ///
  223. /// <param name="bIndex">
  224. /// </param>
  225. /// <param name="bPenStatus">
  226. /// </param>
  227. /// <param name="bx">
  228. /// </param>
  229. /// <param name="by">
  230. /// </param>
  231. /// <param name="bPress">
  232. /// </param>
  233. private void luobo_bigDataReportEvt1(byte bIndex, byte bPenStatus, short bx, short by, short bPress)
  234. {
  235. if (bx == 0 && by == 0 && bPenStatus == 0 && bPress == 0)
  236. {
  237. return;
  238. }
  239. if (penEvent != null)
  240. {
  241. penEvent.penPointEvent(bIndex, bPenStatus, bx, by, bPress, m_nDeviceW, m_nDeviceH);
  242. }
  243. }
  244. /// <summary>
  245. /// 判断是否有设备连接
  246. /// </summary>
  247. public void CheckUsbConnect()
  248. {
  249. usbIsConnected = false;
  250. Thread.Sleep(200);
  251. int nDeviceCount = robotpenController.GetInstance()._GetDeviceCount();
  252. if (APP.IsOutputInfoLog)
  253. {
  254. LogHelper.WriteInfoLog(string.Format("当前有 {0} 个设备", nDeviceCount));
  255. }
  256. if (nDeviceCount > 0)
  257. {
  258. for (int i = 0; i < nDeviceCount; ++i)
  259. {
  260. ushort npid = 0;
  261. ushort nvid = 0;
  262. string strDeviceName = string.Empty;
  263. eDeviceType dtype = eDeviceType.Unknow;
  264. if (robotpenController.GetInstance()._GetAvailableDevice(i, ref npid, ref nvid, ref strDeviceName, ref dtype))
  265. {
  266. if (!usbIsConnected)
  267. {
  268. usbIsConnected = true;
  269. deviceType = dtype;
  270. robotpenController.GetInstance()._ConnectInitialize(deviceType, IntPtr.Zero);
  271. int nRes = robotpenController.GetInstance()._ConnectOpen();
  272. if (nRes != 0)
  273. {
  274. //LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
  275. LogHelper.WriteErrLog("设备自动连接失败,请重新插拔设备或尝试手动连接!", null);
  276. usbIsConnected = false;
  277. break;
  278. }
  279. robotpenController.GetInstance()._Send(cmdId.GetConfig);
  280. APP.BoardStatus = true;
  281. try
  282. {
  283. int banWidth = robotpenController.GetInstance().getWidth();
  284. int banHeight = robotpenController.GetInstance().getHeight();
  285. if (banWidth > 0 && banHeight > 0)
  286. {
  287. if (banWidth > banHeight)
  288. {
  289. m_nDeviceW = banWidth;
  290. m_nDeviceH = banHeight;
  291. }
  292. else
  293. {
  294. m_nDeviceW = banHeight;
  295. m_nDeviceH = banWidth;
  296. }
  297. }
  298. if (APP.IsOutputInfoLog)
  299. {
  300. LogHelper.WriteInfoLog(string.Format("手写板宽度为:{0} 高度为:{1}", m_nDeviceW, m_nDeviceH));
  301. }
  302. }
  303. catch (Exception ex)
  304. {
  305. LogHelper.WriteErrLog("手写板大小获取失败:" + ex.Message, ex);
  306. }
  307. UpdateDevStatus();
  308. if (APP.IsOutputInfoLog)
  309. {
  310. LogHelper.WriteInfoLog(string.Format("设备类型:{0}", deviceType.ToString()));
  311. }
  312. new Thread(new ThreadStart(new Action(() =>
  313. {
  314. Thread.Sleep(500);
  315. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  316. }))).Start();
  317. }
  318. }
  319. }
  320. }
  321. else
  322. {
  323. APP.BoardStatus = false;
  324. UpdateDevStatus();
  325. }
  326. }
  327. /// <summary>
  328. /// 按键回调函数
  329. /// </summary>
  330. /// <param name="Value">
  331. /// </param>
  332. private void luobo_keyPressEvt(eKeyPress Value)
  333. {
  334. switch (Value)
  335. {
  336. case eKeyPress.CLICK:
  337. break;
  338. case eKeyPress.DBCLICK:
  339. break;
  340. case eKeyPress.PAGEUP:
  341. //last_button_Click(null, null);
  342. break;
  343. case eKeyPress.PAGEDOWN:
  344. //next_btn_Click(null, null);
  345. break;
  346. case eKeyPress.CREATEPAGE://关机键
  347. break;
  348. case eKeyPress.KEY_A:
  349. break;
  350. case eKeyPress.KEY_B:
  351. break;
  352. case eKeyPress.KEY_C:
  353. break;
  354. case eKeyPress.KEY_D:
  355. break;
  356. case eKeyPress.KEY_E:
  357. break;
  358. case eKeyPress.KEY_F:
  359. break;
  360. case eKeyPress.KEY_UP:
  361. //last_button_Click(null, null);
  362. break;
  363. case eKeyPress.KEY_DOWN:
  364. //next_btn_Click(null, null);
  365. break;
  366. case eKeyPress.KEY_YES:
  367. break;
  368. case eKeyPress.KEY_NO:
  369. break;
  370. case eKeyPress.KEY_CANCEL:
  371. break;
  372. case eKeyPress.KEY_OK:
  373. break;
  374. case eKeyPress.PAGEUPCLICK://上一页
  375. //last_button_Click(null, null);
  376. break;
  377. case eKeyPress.PAGEUPDBCLICK://双击上一页
  378. break;
  379. case eKeyPress.PAGEUPPRESS://长按上一页
  380. break;
  381. case eKeyPress.PAGEDOWNCLICK://下一页
  382. //next_btn_Click(null, null);
  383. break;
  384. case eKeyPress.PAGEDOWNDBCLICK://双击下一页
  385. break;
  386. case eKeyPress.PAGEDOWNPRESS://长按下一页
  387. break;
  388. }
  389. }
  390. /// <summary>
  391. /// 更新设备状态显示
  392. /// </summary>
  393. public void UpdateDevStatus()
  394. {
  395. if (penEvent != null)
  396. {
  397. penEvent.penStatusEvent();
  398. }
  399. }
  400. #endregion 罗博智慧笔
  401. }
  402. }