Commander.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. using IvfTl.Control.Entity;
  2. namespace ivf_tl_SerialHelper.Util
  3. {
  4. public static class Commander
  5. {
  6. //public static int MachineModel { get; set; }
  7. /// <summary>
  8. /// 求累加和校验
  9. /// </summary>
  10. /// <param name="bytes"></param>
  11. /// <returns></returns>
  12. public static byte[] CreateORC(byte[] bytes)
  13. {
  14. byte orcByte = 0x00;
  15. for (int i = 0; i < bytes.Length - 1; i++)
  16. {
  17. orcByte += bytes[i];
  18. }
  19. bytes[bytes.Length - 1] = orcByte;
  20. return bytes;
  21. }
  22. /// <summary>
  23. /// 判断校验
  24. /// </summary>
  25. /// <param name="bytes"></param>
  26. /// <returns></returns>
  27. public static bool CheckORC(byte[] bytes)
  28. {
  29. byte orcByte = 0x00;
  30. for (int i = 0; i < bytes.Length - 1; i++)
  31. {
  32. orcByte += bytes[i];
  33. }
  34. return bytes[bytes.Length - 1] == orcByte;
  35. }
  36. public static void CustomProtocolLength(CustomProtocol custom)
  37. {
  38. custom.lenght = 6;
  39. custom.WaitTime = 0;
  40. switch (custom.sendBuffer[1])
  41. {
  42. case 0x01://握手指令
  43. custom.lenght = 6;
  44. break;
  45. case 0x02://自检指令
  46. custom.lenght = 6;
  47. break;
  48. case 0x04://设置目标温度
  49. custom.lenght = 7;
  50. break;
  51. case 0x05://电机控制指令
  52. custom.lenght = 6;
  53. break;
  54. case 0x06://读传感器信号
  55. custom.lenght = 9;
  56. break;
  57. case 0x08://读传感器AD
  58. custom.lenght = 9;
  59. break;
  60. case 0x09://设置IO
  61. custom.lenght = 6;
  62. break;
  63. case 0x10://获取IO
  64. custom.lenght = 7;
  65. break;
  66. case 0x11://读E方
  67. custom.lenght = 10;
  68. break;
  69. case 0x12://写E方
  70. custom.lenght = 6;
  71. break;
  72. case 0x18://读电机位置
  73. custom.lenght = 10;
  74. break;
  75. case 0x19://缓冲瓶补气
  76. custom.lenght = 6;
  77. break;
  78. case 0x20://读缓冲瓶数据
  79. custom.lenght = 12;
  80. break;
  81. }
  82. }
  83. #region 操作
  84. /// <summary>
  85. /// 握手 64
  86. /// </summary>
  87. /// <returns></returns>
  88. public static void CreateHandCommand(this CustomProtocol custom)
  89. {
  90. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x01, 0x00, 0x05, 0x00 });
  91. CustomProtocolLength(custom);
  92. }
  93. /// <summary>
  94. /// 打开CCD补光LED,长度7
  95. /// </summary>
  96. /// <returns></returns>
  97. public static void CreateOpenLEDCommand(this CustomProtocol custom)
  98. {
  99. custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x01, 0x6F };
  100. CustomProtocolLength(custom);
  101. }
  102. /// <summary>
  103. /// 关闭CCD补光LED,长度7
  104. /// </summary>
  105. /// <returns></returns>
  106. public static void CreateCloseLEDCommand(this CustomProtocol custom)
  107. {
  108. custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x00, 0x6E };
  109. CustomProtocolLength(custom);
  110. }
  111. /// <summary>
  112. /// 打开进气阀
  113. /// </summary>
  114. /// <returns></returns>
  115. public static void CreateOpenIntakeValveCommand(this CustomProtocol custom)
  116. {
  117. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });
  118. CustomProtocolLength(custom);
  119. }
  120. /// <summary>
  121. /// 关闭进气阀
  122. /// </summary>
  123. /// <returns></returns>
  124. public static void CreateCloseIntakeValveCommand(this CustomProtocol custom)
  125. {
  126. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });
  127. CustomProtocolLength(custom);
  128. }
  129. /// <summary>
  130. /// 打开排气阀
  131. /// </summary>
  132. /// <returns></returns>
  133. public static void CreateOpenExhaustValveCommand(this CustomProtocol custom)
  134. {
  135. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 });
  136. CustomProtocolLength(custom);
  137. }
  138. /// <summary>
  139. /// 关闭排气阀
  140. /// </summary>
  141. /// <returns></returns>
  142. public static void CreateCloseExhaustValveCommand(this CustomProtocol custom)
  143. {
  144. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 });
  145. CustomProtocolLength(custom);
  146. }
  147. /// <summary>
  148. /// 缓冲瓶补气 7C
  149. /// </summary>
  150. /// <returns></returns>
  151. public static void CreateBufferBottleAerationCommand(this CustomProtocol custom)
  152. {
  153. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x19, 0x00, 0x05, 0x00 });
  154. CustomProtocolLength(custom);
  155. }
  156. /// <summary>
  157. /// 仓室补气 72
  158. /// </summary>
  159. /// <returns></returns>
  160. public static void CreateHouseAerationCommand(this CustomProtocol custom)
  161. {
  162. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x04, 0x01, 0x00 });
  163. CustomProtocolLength(custom);
  164. }
  165. /// <summary>
  166. /// 舱室排气
  167. /// </summary>
  168. /// <returns></returns>
  169. public static void CreateHouseVentCommand(this CustomProtocol custom)
  170. {
  171. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x05, 0x01, 0x00 });
  172. CustomProtocolLength(custom);
  173. }
  174. /// <summary>
  175. /// 读垂直电机位置
  176. /// </summary>
  177. /// <returns></returns>
  178. public static void CreateReadVerticalMotorCommand(this CustomProtocol custom)
  179. {
  180. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x02, 0x00 });
  181. CustomProtocolLength(custom);
  182. }
  183. /// <summary>
  184. /// 读水平电机位置
  185. /// </summary>
  186. /// <returns></returns>
  187. public static void CreateReadHorizontalMotorCommand(this CustomProtocol custom)
  188. {
  189. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x01, 0x00 });
  190. CustomProtocolLength(custom);
  191. }
  192. /// <summary>
  193. /// 读E方 仪器编号
  194. /// </summary>
  195. /// <returns></returns>
  196. public static void CreateReadTLNumCommand(this CustomProtocol custom)
  197. {
  198. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x08, 0x04, 0x00 });
  199. CustomProtocolLength(custom);
  200. }
  201. #endregion
  202. #region 温度、压力、仓门状态
  203. /// <summary>
  204. /// 温度 6b(下盖板温度)
  205. /// </summary>
  206. /// <param name="wayNum"></param>
  207. /// <returns></returns>
  208. public static void CreateReadTemperatureCommand(this CustomProtocol custom)
  209. {
  210. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x00, 0x00 });
  211. CustomProtocolLength(custom);
  212. }
  213. /// <summary>
  214. /// 获取上盖板温度
  215. /// </summary>
  216. /// <returns></returns>
  217. public static void CreateReadShangTemperatureCommand(this CustomProtocol custom)
  218. {
  219. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x01, 0x00 });
  220. CustomProtocolLength(custom);
  221. }
  222. /// <summary>
  223. /// 获取玻璃片下方温度
  224. /// </summary>
  225. /// <returns></returns>
  226. public static void CreateReadBoLiTemperatureCommand(this CustomProtocol custom)
  227. {
  228. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x02, 0x00 });
  229. CustomProtocolLength(custom);
  230. }
  231. /// <summary>
  232. /// 压力
  233. /// </summary>
  234. /// <param name="wayNum"></param>
  235. /// <returns></returns>
  236. public static void CreateReadPressureCommand(this CustomProtocol custom)
  237. {
  238. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x03, 0x00 });
  239. CustomProtocolLength(custom);
  240. }
  241. /// <summary>
  242. /// 获取缓冲瓶气压 83
  243. /// </summary>
  244. /// <returns></returns>
  245. public static void CreateBufferBottlePressureCommand(this CustomProtocol custom)
  246. {
  247. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x20, 0x00, 0x05, 0x00 });
  248. CustomProtocolLength(custom);
  249. }
  250. /// <summary>
  251. /// 门
  252. /// </summary>
  253. /// <returns>5E 0A 00 06 02 71</returns>
  254. public static void CreateReadDoorCommand(this CustomProtocol custom)
  255. {
  256. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x10, 0x00, 0x06, 0x02, 0x00 });
  257. CustomProtocolLength(custom);
  258. }
  259. #endregion
  260. /// <summary>
  261. /// 读EEPROM->水平电机Well位置,返回长度10个字节
  262. /// </summary>
  263. /// <param name="wellNum"></param>
  264. /// <returns></returns>
  265. public static void CreateReadEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum)
  266. {
  267. List<byte> command = new List<byte>();
  268. command.Add(0x5E);
  269. command.Add(0x11);
  270. command.Add(0x00);
  271. command.Add(0x09);
  272. switch (wellNum)
  273. {
  274. case 1:
  275. command.Add(0x00);
  276. command.Add(0x04);
  277. command.Add(0x00);
  278. break;
  279. case 2:
  280. command.Add(0x00);
  281. command.Add(0x04);
  282. command.Add(0x50);
  283. break;
  284. case 3:
  285. command.Add(0x00);
  286. command.Add(0x04);
  287. command.Add(0x54);
  288. break;
  289. case 4:
  290. command.Add(0x00);
  291. command.Add(0x04);
  292. command.Add(0x58);
  293. break;
  294. case 5:
  295. command.Add(0x00);
  296. command.Add(0x04);
  297. command.Add(0x5C);
  298. break;
  299. case 6:
  300. command.Add(0x00);
  301. command.Add(0x04);
  302. command.Add(0x60);
  303. break;
  304. case 7:
  305. command.Add(0x00);
  306. command.Add(0x04);
  307. command.Add(0x64);
  308. break;
  309. case 8:
  310. command.Add(0x00);
  311. command.Add(0x04);
  312. command.Add(0x68);
  313. break;
  314. case 9:
  315. command.Add(0x00);
  316. command.Add(0x04);
  317. command.Add(0x6C);
  318. break;
  319. case 10:
  320. command.Add(0x00);
  321. command.Add(0x04);
  322. command.Add(0x70);
  323. break;
  324. case 11:
  325. command.Add(0x00);
  326. command.Add(0x04);
  327. command.Add(0x74);
  328. break;
  329. case 12:
  330. command.Add(0x00);
  331. command.Add(0x04);
  332. command.Add(0x78);
  333. break;
  334. case 13:
  335. command.Add(0x00);
  336. command.Add(0x04);
  337. command.Add(0x7C);
  338. break;
  339. case 14:
  340. command.Add(0x00);
  341. command.Add(0x04);
  342. command.Add(0x80);
  343. break;
  344. case 15:
  345. command.Add(0x00);
  346. command.Add(0x04);
  347. command.Add(0x84);
  348. break;
  349. case 16:
  350. command.Add(0x00);
  351. command.Add(0x04);
  352. command.Add(0x04);
  353. break;
  354. default:
  355. break;
  356. }
  357. command.Add(0x04);
  358. command.Add(0x00);
  359. custom.sendBuffer = CreateORC(command.ToArray());
  360. CustomProtocolLength(custom);
  361. }
  362. /// <summary>
  363. /// 写EEPROM->水平电机Well位置,返回长度10个字节
  364. /// </summary>
  365. /// <param name="wellNum"></param>
  366. /// <returns></returns>
  367. public static void CreateWriteEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum, int newValue)
  368. {
  369. byte[] pulses = BitConverter.GetBytes(newValue);
  370. List<byte> command = new List<byte>();
  371. command.Add(0x5E);//帧头
  372. command.Add(0x12);//WRITE_EEPROM
  373. command.Add(0x00);//CMDNO
  374. command.Add(0x0C);//LTH
  375. switch (wellNum)
  376. {
  377. case 1:
  378. command.Add(0x00);
  379. command.Add(0x04);
  380. command.Add(0x00);
  381. break;
  382. case 2:
  383. command.Add(0x00);
  384. command.Add(0x04);
  385. command.Add(0x50);
  386. break;
  387. case 3:
  388. command.Add(0x00);
  389. command.Add(0x04);
  390. command.Add(0x54);
  391. break;
  392. case 4:
  393. command.Add(0x00);
  394. command.Add(0x04);
  395. command.Add(0x58);
  396. break;
  397. case 5:
  398. command.Add(0x00);
  399. command.Add(0x04);
  400. command.Add(0x5C);
  401. break;
  402. case 6:
  403. command.Add(0x00);
  404. command.Add(0x04);
  405. command.Add(0x60);
  406. break;
  407. case 7:
  408. command.Add(0x00);
  409. command.Add(0x04);
  410. command.Add(0x64);
  411. break;
  412. case 8:
  413. command.Add(0x00);
  414. command.Add(0x04);
  415. command.Add(0x68);
  416. break;
  417. case 9:
  418. command.Add(0x00);
  419. command.Add(0x04);
  420. command.Add(0x6C);
  421. break;
  422. case 10:
  423. command.Add(0x00);
  424. command.Add(0x04);
  425. command.Add(0x70);
  426. break;
  427. case 11:
  428. command.Add(0x00);
  429. command.Add(0x04);
  430. command.Add(0x74);
  431. break;
  432. case 12:
  433. command.Add(0x00);
  434. command.Add(0x04);
  435. command.Add(0x78);
  436. break;
  437. case 13:
  438. command.Add(0x00);
  439. command.Add(0x04);
  440. command.Add(0x7C);
  441. break;
  442. case 14:
  443. command.Add(0x00);
  444. command.Add(0x04);
  445. command.Add(0x80);
  446. break;
  447. case 15:
  448. command.Add(0x00);
  449. command.Add(0x04);
  450. command.Add(0x84);
  451. break;
  452. case 16:
  453. command.Add(0x00);
  454. command.Add(0x04);
  455. command.Add(0x04);
  456. break;
  457. default:
  458. break;
  459. }
  460. if (BitConverter.IsLittleEndian)
  461. {
  462. command.Add(pulses[0]);//参数1(低)
  463. command.Add(pulses[1]);//参数2
  464. command.Add(pulses[2]);//参数3
  465. command.Add(pulses[3]);//参数4(高)
  466. }
  467. else
  468. {
  469. command.Add(pulses[3]);//参数1(低)
  470. command.Add(pulses[2]);//参数2
  471. command.Add(pulses[1]);//参数3
  472. command.Add(pulses[0]);//参数4 (高)
  473. }
  474. command.Add(0x00);//校验和CRC
  475. custom.sendBuffer = CreateORC(command.ToArray());
  476. CustomProtocolLength(custom);
  477. }
  478. /// <summary>
  479. /// 读EEPROM->下加热板目标温度
  480. /// </summary>
  481. /// <param name="wellNum"></param>
  482. /// <returns></returns>
  483. public static void CreateReadTargetTemp(this CustomProtocol custom)
  484. {
  485. List<byte> command = new List<byte>();
  486. command.Add(0x5E);
  487. command.Add(0x11);
  488. command.Add(0x00);
  489. command.Add(0x09);
  490. command.Add(0x00);
  491. command.Add(0x02);
  492. command.Add(0x38);
  493. command.Add(0x04);
  494. command.Add(0x00);
  495. custom.sendBuffer = CreateORC(command.ToArray());
  496. CustomProtocolLength(custom);
  497. }
  498. /// <summary>
  499. /// 读EEPROM->垂直电机焦准脉冲数(零点),返回长度10个字节
  500. /// </summary>
  501. /// <returns></returns>
  502. public static void CreateReadEEPROMvertMtStartPulse(this CustomProtocol custom,int i)
  503. {
  504. List<byte> command = new List<byte>();
  505. command.Add(0x5E);
  506. command.Add(0x11);
  507. command.Add(0x00);
  508. command.Add(0x09);
  509. switch (i)
  510. {
  511. case 1:
  512. command.Add(0x00);
  513. command.Add(0x04);
  514. command.Add(0x08);
  515. break;
  516. case 2:
  517. command.Add(0x00);
  518. command.Add(0x04);
  519. command.Add(0x0C);
  520. break;
  521. case 3:
  522. command.Add(0x00);
  523. command.Add(0x04);
  524. command.Add(0x10);
  525. break;
  526. case 4:
  527. command.Add(0x00);
  528. command.Add(0x04);
  529. command.Add(0x14);
  530. break;
  531. case 5:
  532. command.Add(0x00);
  533. command.Add(0x04);
  534. command.Add(0x18);
  535. break;
  536. case 6:
  537. command.Add(0x00);
  538. command.Add(0x04);
  539. command.Add(0x1C);
  540. break;
  541. case 7:
  542. command.Add(0x00);
  543. command.Add(0x04);
  544. command.Add(0x20);
  545. break;
  546. case 8:
  547. command.Add(0x00);
  548. command.Add(0x04);
  549. command.Add(0x24);
  550. break;
  551. case 9:
  552. command.Add(0x00);
  553. command.Add(0x04);
  554. command.Add(0x28);
  555. break;
  556. case 10:
  557. command.Add(0x00);
  558. command.Add(0x04);
  559. command.Add(0x2C);
  560. break;
  561. case 11:
  562. command.Add(0x00);
  563. command.Add(0x04);
  564. command.Add(0x30);
  565. break;
  566. case 12:
  567. command.Add(0x00);
  568. command.Add(0x04);
  569. command.Add(0x34);
  570. break;
  571. case 13:
  572. command.Add(0x00);
  573. command.Add(0x04);
  574. command.Add(0x38);
  575. break;
  576. case 14:
  577. command.Add(0x00);
  578. command.Add(0x04);
  579. command.Add(0x3C);
  580. break;
  581. case 15:
  582. command.Add(0x00);
  583. command.Add(0x04);
  584. command.Add(0x40);
  585. break;
  586. case 16:
  587. command.Add(0x00);
  588. command.Add(0x04);
  589. command.Add(0x44);
  590. break;
  591. default:
  592. break;
  593. }
  594. command.Add(0x04);
  595. command.Add(0x00);
  596. custom.sendBuffer = CreateORC(command.ToArray());
  597. CustomProtocolLength(custom);
  598. }
  599. /// <summary>
  600. /// 写入EEPROM->垂直电机焦准脉冲数(零点),返回长度6个字节
  601. /// </summary>
  602. /// <returns></returns>
  603. public static void CreateWriteEEPROMvertMtStartPulse(this CustomProtocol custom, int pulse)
  604. {
  605. byte[] pulses = BitConverter.GetBytes(pulse);
  606. List<byte> command = new List<byte>();
  607. command.Add(0x5E);//帧头
  608. command.Add(0x12);//WRITE_EEPROM
  609. command.Add(0x00);//CMDNO
  610. command.Add(0x0C);//LTH
  611. command.Add(0x00);//地址(高)
  612. command.Add(0x03);//地址(中)
  613. command.Add(0x1C);//地址(低)
  614. if (BitConverter.IsLittleEndian)
  615. {
  616. command.Add(pulses[0]);//参数1(低)
  617. command.Add(pulses[1]);//参数2
  618. command.Add(pulses[2]);//参数3
  619. command.Add(pulses[3]);//参数4(高)
  620. }
  621. else
  622. {
  623. command.Add(pulses[3]);//参数1(低)
  624. command.Add(pulses[2]);//参数2
  625. command.Add(pulses[1]);//参数3
  626. command.Add(pulses[0]);//参数4 (高)
  627. }
  628. command.Add(0x00);//校验和CRC
  629. custom.sendBuffer = CreateORC(command.ToArray());
  630. CustomProtocolLength(custom);
  631. }
  632. /// <summary>
  633. /// 读EEPROM->垂直电机扫描间隔脉冲,返回长度10个字节
  634. /// </summary>
  635. /// <returns></returns>
  636. public static void CreateReadEEPROMvertMtScanPluse(this CustomProtocol custom)
  637. {
  638. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x04, 0x48, 0x04, 0x00 });
  639. CustomProtocolLength(custom);
  640. }
  641. /// <summary>
  642. /// 写入EEPROM->垂直电机扫描间隔脉冲,返回长度6个字节
  643. /// </summary>
  644. /// <returns></returns>
  645. public static void CreateWriteEEPROMvertMtScanPluse(this CustomProtocol custom,int pulse)
  646. {
  647. byte[] pulses = BitConverter.GetBytes(pulse);
  648. List<byte> command = new List<byte>();
  649. command.Add(0x5E);//帧头
  650. command.Add(0x12);//WRITE_EEPROM
  651. command.Add(0x00);//CMDNO
  652. command.Add(0x0C);//LTH
  653. command.Add(0x00);//地址(高)
  654. command.Add(0x04);//地址(中)
  655. command.Add(0x48);//地址(低)
  656. if (BitConverter.IsLittleEndian)
  657. {
  658. command.Add(pulses[0]);//参数1(低)
  659. command.Add(pulses[1]);//参数2
  660. command.Add(pulses[2]);//参数3
  661. command.Add(pulses[3]);//参数4(高)
  662. }
  663. else
  664. {
  665. command.Add(pulses[3]);//参数1(低)
  666. command.Add(pulses[2]);//参数2
  667. command.Add(pulses[1]);//参数3
  668. command.Add(pulses[0]);//参数4(高)
  669. }
  670. command.Add(0x00);//校验和CRC
  671. custom.sendBuffer = CreateORC(command.ToArray());
  672. CustomProtocolLength(custom);
  673. }
  674. /// <summary>
  675. /// 读EEPROM->仓室进气阀打开时间
  676. /// </summary>
  677. /// <returns></returns>
  678. public static void CreateReadEEPROOpenIntakeTimeCommand(this CustomProtocol custom)
  679. {
  680. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x0c, 0x04, 0x00 });
  681. CustomProtocolLength(custom);
  682. }
  683. /// <summary>
  684. /// 写EEPROM->仓室进气阀打开时间
  685. /// </summary>
  686. /// <param name="wellNum"></param>
  687. /// <returns></returns>
  688. public static void CreateWriteEEPROOpenIntakeTimeCommand(this CustomProtocol custom,int newValue)
  689. {
  690. byte[] pulses = BitConverter.GetBytes(newValue);
  691. List<byte> command = new List<byte>();
  692. command.Add(0x5E);//帧头
  693. command.Add(0x12);//WRITE_EEPROM
  694. command.Add(0x00);//CMDNO
  695. command.Add(0x0C);//LTH
  696. command.Add(0x00);
  697. command.Add(0x03);
  698. command.Add(0x0c);
  699. if (BitConverter.IsLittleEndian)
  700. {
  701. command.Add(pulses[0]);//参数1(低)
  702. command.Add(pulses[1]);//参数2
  703. command.Add(pulses[2]);//参数3
  704. command.Add(pulses[3]);//参数4(高)
  705. }
  706. else
  707. {
  708. command.Add(pulses[3]);//参数1(低)
  709. command.Add(pulses[2]);//参数2
  710. command.Add(pulses[1]);//参数3
  711. command.Add(pulses[0]);//参数4(高)
  712. }
  713. command.Add(0x00);//校验和CRC
  714. custom.sendBuffer = CreateORC(command.ToArray());
  715. CustomProtocolLength(custom);
  716. }
  717. /// <summary>
  718. /// 读EEPROM->缓冲瓶气阀打开时间
  719. /// </summary>
  720. /// <returns></returns>
  721. public static void CreateReadEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom)
  722. {
  723. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x05, 0x0c, 0x04, 0x00 });
  724. CustomProtocolLength(custom);
  725. }
  726. /// <summary>
  727. /// 写EEPROM->缓冲瓶进气阀打开时间
  728. /// </summary>
  729. /// <param name="wellNum"></param>
  730. /// <returns></returns>
  731. public static void CreateWriteEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom,int newValue)
  732. {
  733. byte[] pulses = BitConverter.GetBytes(newValue);
  734. List<byte> command = new List<byte>();
  735. command.Add(0x5E);//帧头
  736. command.Add(0x12);//WRITE_EEPROM
  737. command.Add(0x00);//CMDNO
  738. command.Add(0x0C);//LTH
  739. command.Add(0x00);
  740. command.Add(0x05);
  741. command.Add(0x0c);
  742. if (BitConverter.IsLittleEndian)
  743. {
  744. command.Add(pulses[0]);//参数1(低)
  745. command.Add(pulses[1]);//参数2
  746. command.Add(pulses[2]);//参数3
  747. command.Add(pulses[3]);//参数4(高)
  748. }
  749. else
  750. {
  751. command.Add(pulses[3]);//参数1(低)
  752. command.Add(pulses[2]);//参数2
  753. command.Add(pulses[1]);//参数3
  754. command.Add(pulses[0]);//参数4(高)
  755. }
  756. command.Add(0x00);//校验和CRC
  757. custom.sendBuffer = CreateORC(command.ToArray());
  758. CustomProtocolLength(custom);
  759. }
  760. /// <summary>
  761. /// 读E方 -->灯光亮度
  762. /// </summary>
  763. /// <param name="num"></param>
  764. /// <returns></returns>
  765. public static void CreateReadEEPROMLightNum(this CustomProtocol custom)
  766. {
  767. var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x05, 0x34, 0x04, 0x00 };
  768. custom.sendBuffer = CreateORC(array);
  769. CustomProtocolLength(custom);
  770. }
  771. /// <summary>
  772. /// 读EEPROM->CCDSN
  773. /// </summary>
  774. /// <returns></returns>
  775. public static void CreateGetModuleCommand(this CustomProtocol custom)
  776. {
  777. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x10, 0x04, 0x00 });
  778. CustomProtocolLength(custom);
  779. }
  780. /// <summary>
  781. /// 写EEPROM
  782. /// </summary>
  783. /// <param name="address">地址</param>
  784. /// <param name="value">值</param>
  785. /// <returns></returns>
  786. public static void CreateWriteEEPROM(this CustomProtocol custom,int address, double value)
  787. {
  788. byte[] byteAddress = BitConverter.GetBytes(address);
  789. byte[] byteValue = BitConverter.GetBytes(value);
  790. List<byte> command = new List<byte>();
  791. command.Add(0x5E);//帧头
  792. command.Add(0x12);//WRITE_EEPROM
  793. command.Add(0x00);//CMDNO
  794. command.Add(0x0C);//LTH
  795. if (BitConverter.IsLittleEndian)
  796. {
  797. command.Add(byteAddress[2]);//地址(高)
  798. command.Add(byteAddress[1]);//地址(中)
  799. command.Add(byteAddress[0]);//地址(低)
  800. command.Add(byteValue[0]);//参数1(低)
  801. command.Add(byteValue[1]);//参数2
  802. command.Add(byteValue[2]);//参数3
  803. command.Add(byteValue[3]);//参数4(高)
  804. }
  805. else
  806. {
  807. command.Add(byteAddress[0]);//地址(高)
  808. command.Add(byteAddress[1]);//地址(中)
  809. command.Add(byteAddress[2]);//地址(低)
  810. command.Add(byteValue[3]);//参数1(低)
  811. command.Add(byteValue[2]);//参数2
  812. command.Add(byteValue[1]);//参数3
  813. command.Add(byteValue[0]);//参数4(高)
  814. }
  815. command.Add(0x00);//校验和CRC
  816. custom.sendBuffer = CreateORC(command.ToArray());
  817. CustomProtocolLength(custom);
  818. }
  819. #region 电机运动
  820. /// <summary>
  821. /// 水平电机复位运动,长度11
  822. /// </summary>
  823. /// <returns></returns>
  824. public static void CreateHorizontalMotorResetCommand(this CustomProtocol custom)
  825. {
  826. /*
  827. * 第1字节 第2字节 第3字节 第4字节 第5字节 第6字节 第7字节 第8字节 第9字节 第10字节 第11字节
  828. 帧头 ST SET_MOTOR CMDNO LTH 辅助指令码 参数1 参数2 参数3 参数4 参数5 校验和CRC
  829. 帧头 ST = 5E
  830. SET_MOTOR = 0x05
  831. CMDNO = 00
  832. LTH = 11
  833. 辅助指令码 = 高半字节(水平电机=1|扫描电机=2) + 低半字节(正转=0|反转=1|脱机=2|复位=3|绝对运动=4)
  834. 参数1,参数2:电机运动的脉冲值,参数1是高8位,参数2是低8位,组成16位的脉冲值;
  835. 参数3:0x00;
  836. 参数4,参数5:0x00,0x00
  837. */
  838. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x13, 0x00, 0x00, 0x00, 0x0B, 0xB8, 0x44 });
  839. CustomProtocolLength(custom);
  840. }
  841. /// <summary>
  842. /// 水平电机正向运动,长度11
  843. /// </summary>
  844. /// <param name="pulse">脉冲值</param>
  845. /// <returns></returns>
  846. public static void CreateHorizontalMotorForwardCommand(this CustomProtocol custom,int? pulse)
  847. {
  848. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  849. List<byte> command = new List<byte>();
  850. command.Add(0x5E);//帧头
  851. command.Add(0x05);//SET_MOTOR
  852. command.Add(0x00);//CMDNO
  853. command.Add(0x0B);//LTH
  854. command.Add(0x10);//辅助指令码
  855. if (BitConverter.IsLittleEndian)
  856. {
  857. command.Add(pulses[3]);//参数1 高
  858. command.Add(pulses[2]);//参数2
  859. command.Add(pulses[1]);//参数3
  860. command.Add(pulses[0]);//参数4 低
  861. }
  862. else
  863. {
  864. command.Add(pulses[0]);//参数1 高
  865. command.Add(pulses[1]);//参数2
  866. command.Add(pulses[2]);//参数3
  867. command.Add(pulses[3]);//参数4 低
  868. }
  869. command.Add(0x00);//参数5
  870. command.Add(0x00);//校验和CRC
  871. custom.sendBuffer = CreateORC(command.ToArray());
  872. CustomProtocolLength(custom);
  873. }
  874. /// <summary>
  875. /// 水平电机反向运动,长度11
  876. /// </summary>
  877. /// <returns></returns>
  878. public static void CreateHorizontalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
  879. {
  880. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  881. List<byte> command = new List<byte>();
  882. command.Add(0x5E);//帧头
  883. command.Add(0x05);//SET_MOTOR
  884. command.Add(0x00);//CMDNO
  885. command.Add(0x0B);//LTH
  886. command.Add(0x11);//辅助指令码
  887. if (BitConverter.IsLittleEndian)
  888. {
  889. command.Add(pulses[3]);//参数1 高
  890. command.Add(pulses[2]);//参数2
  891. command.Add(pulses[1]);//参数3
  892. command.Add(pulses[0]);//参数4 低
  893. }
  894. else
  895. {
  896. command.Add(pulses[0]);//参数1 高
  897. command.Add(pulses[1]);//参数2
  898. command.Add(pulses[2]);//参数3
  899. command.Add(pulses[3]);//参数4 低
  900. }
  901. command.Add(0x00);//参数5
  902. command.Add(0x00);//校验和CRC
  903. custom.sendBuffer = CreateORC(command.ToArray());
  904. CustomProtocolLength(custom);
  905. }
  906. /// <summary>
  907. /// 水平电机绝对运动
  908. /// </summary>
  909. /// <param name="pulse"></param>
  910. /// <returns></returns>
  911. public static void CreateHorizontalMotorMoveToCommand(this CustomProtocol custom,int? pulse)
  912. {
  913. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  914. List<byte> command = new List<byte>();
  915. command.Add(0x5E);//帧头
  916. command.Add(0x05);//SET_MOTOR
  917. command.Add(0x00);//CMDNO
  918. command.Add(0x0B);//LTH
  919. command.Add(0x14);//辅助指令码
  920. if (BitConverter.IsLittleEndian)
  921. {
  922. command.Add(pulses[3]);//参数1 高
  923. command.Add(pulses[2]);//参数2
  924. command.Add(pulses[1]);//参数3
  925. command.Add(pulses[0]);//参数4 低
  926. }
  927. else
  928. {
  929. command.Add(pulses[0]);//参数1 高
  930. command.Add(pulses[1]);//参数2
  931. command.Add(pulses[2]);//参数3
  932. command.Add(pulses[3]);//参数4 低
  933. }
  934. command.Add(0x00);//参数5
  935. command.Add(0x00);//校验和CRC
  936. custom.sendBuffer = CreateORC(command.ToArray());
  937. CustomProtocolLength(custom);
  938. }
  939. /// <summary>
  940. /// 垂直电机复位运动,长度11
  941. /// </summary>
  942. /// <returns></returns>
  943. public static void CreateVerticalMotorResetCommand(this CustomProtocol custom)
  944. {
  945. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x23, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x68 });
  946. CustomProtocolLength(custom);
  947. }
  948. /// <summary>
  949. /// 垂直电机正向运动,长度11
  950. /// </summary>
  951. /// <param name="pulse">脉冲值</param>
  952. /// <returns></returns>
  953. public static void CreateVerticalMotorForwardCommand(this CustomProtocol custom,int? pulse)
  954. {
  955. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  956. List<byte> command = new List<byte>();
  957. command.Add(0x5E);//帧头
  958. command.Add(0x05);//SET_MOTOR
  959. command.Add(0x00);//CMDNO
  960. command.Add(0x0B);//LTH
  961. command.Add(0x20);//辅助指令码
  962. if (BitConverter.IsLittleEndian)
  963. {
  964. command.Add(pulses[3]);//参数1 高
  965. command.Add(pulses[2]);//参数2
  966. command.Add(pulses[1]);//参数3
  967. command.Add(pulses[0]);//参数4 低
  968. }
  969. else
  970. {
  971. command.Add(pulses[0]);//参数1 高
  972. command.Add(pulses[1]);//参数2
  973. command.Add(pulses[2]);//参数3
  974. command.Add(pulses[3]);//参数4 低
  975. }
  976. command.Add(0x00);//参数5
  977. command.Add(0x00);//校验和CRC
  978. custom.sendBuffer = CreateORC(command.ToArray());
  979. CustomProtocolLength(custom);
  980. }
  981. /// <summary>
  982. /// 垂直电机绝对运动
  983. /// </summary>
  984. /// <param name="pulse"></param>
  985. /// <returns></returns>
  986. public static void CreateVerticalMotorAbsoluteMovementCommand(this CustomProtocol custom,int? pulse)
  987. {
  988. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  989. List<byte> command = new List<byte>();
  990. command.Add(0x5E);//帧头
  991. command.Add(0x05);//SET_MOTOR
  992. command.Add(0x00);//CMDNO
  993. command.Add(0x0B);//LTH
  994. command.Add(0x24);//辅助指令码
  995. if (BitConverter.IsLittleEndian)
  996. {
  997. command.Add(pulses[3]);//参数1 高
  998. command.Add(pulses[2]);//参数2
  999. command.Add(pulses[1]);//参数3
  1000. command.Add(pulses[0]);//参数4 低
  1001. }
  1002. else
  1003. {
  1004. command.Add(pulses[0]);//参数1 高
  1005. command.Add(pulses[1]);//参数2
  1006. command.Add(pulses[2]);//参数3
  1007. command.Add(pulses[3]);//参数4 低
  1008. }
  1009. command.Add(0x00);//参数5
  1010. command.Add(0x00);//校验和CRC
  1011. custom.sendBuffer = CreateORC(command.ToArray());
  1012. CustomProtocolLength(custom);
  1013. }
  1014. /// <summary>
  1015. /// 垂直电机反向运动,长度11
  1016. /// </summary>
  1017. /// <returns></returns>
  1018. public static void CreateVerticalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
  1019. {
  1020. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  1021. List<byte> command = new List<byte>();
  1022. command.Add(0x5E);//帧头
  1023. command.Add(0x05);//SET_MOTOR
  1024. command.Add(0x00);//CMDNO
  1025. command.Add(0x0B);//LTH
  1026. command.Add(0x21);//辅助指令码
  1027. if (BitConverter.IsLittleEndian)
  1028. {
  1029. command.Add(pulses[3]);//参数1 高
  1030. command.Add(pulses[2]);//参数2
  1031. command.Add(pulses[1]);//参数3
  1032. command.Add(pulses[0]);//参数4 低
  1033. }
  1034. else
  1035. {
  1036. command.Add(pulses[0]);//参数1 高
  1037. command.Add(pulses[1]);//参数2
  1038. command.Add(pulses[2]);//参数3
  1039. command.Add(pulses[3]);//参数4 低
  1040. }
  1041. command.Add(0x00);//参数5
  1042. command.Add(0x00);//校验和CRC
  1043. custom.sendBuffer = CreateORC(command.ToArray());
  1044. CustomProtocolLength(custom);
  1045. }
  1046. #endregion
  1047. #region
  1048. /// <summary>
  1049. /// 换气时打开气阀
  1050. /// </summary>
  1051. /// <returns></returns>
  1052. public static byte[] CreateOpenGasValveCommand()
  1053. {
  1054. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });//上电
  1055. }
  1056. /// <summary>
  1057. /// 换气时关闭气阀
  1058. /// </summary>
  1059. /// <returns></returns>
  1060. public static byte[] CreateCloseGasValveCommand()
  1061. {
  1062. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });//断电
  1063. }
  1064. /// <summary>
  1065. /// 培养指令
  1066. /// </summary>
  1067. /// <param name="isOpen"></param>
  1068. /// <returns></returns>
  1069. public static byte[] CreateGasCommand(bool isOpen)
  1070. {
  1071. //5E 09 00 07 02 01 71
  1072. if (isOpen)
  1073. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 });//开始培养
  1074. else
  1075. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 });//结束培养
  1076. }
  1077. /// <summary>
  1078. /// 读EEPROM->水平电机well间隔脉冲,返回长度10个字节
  1079. /// </summary>
  1080. /// <returns></returns>
  1081. public static byte[] CreateReadEEPROMhoriMtWellInterval()
  1082. {
  1083. var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x02, 0x24, 0x04, 0x00 };
  1084. return CreateORC(array);
  1085. }
  1086. /// <summary>
  1087. /// 读EEPROM->16垂直电机焦准脉冲数(零点),返回长度10个字节
  1088. /// </summary>
  1089. /// <returns></returns>
  1090. public static byte[] CreateReadEEPROMvertMtStartPulse1(int wellNum)
  1091. {
  1092. List<byte> command = new List<byte>();
  1093. command.Add(0x5E);
  1094. command.Add(0x11);
  1095. command.Add(0x00);
  1096. command.Add(0x09);
  1097. switch (wellNum)
  1098. {
  1099. case 1:
  1100. command.Add(0x00);
  1101. command.Add(0x04);
  1102. command.Add(0x08);
  1103. break;
  1104. case 2:
  1105. command.Add(0x00);
  1106. command.Add(0x04);
  1107. command.Add(0x0C);
  1108. break;
  1109. case 3:
  1110. command.Add(0x00);
  1111. command.Add(0x04);
  1112. command.Add(0x10);
  1113. break;
  1114. case 4:
  1115. command.Add(0x00);
  1116. command.Add(0x04);
  1117. command.Add(0x14);
  1118. break;
  1119. case 5:
  1120. command.Add(0x00);
  1121. command.Add(0x04);
  1122. command.Add(0x18);
  1123. break;
  1124. case 6:
  1125. command.Add(0x00);
  1126. command.Add(0x04);
  1127. command.Add(0x1C);
  1128. break;
  1129. case 7:
  1130. command.Add(0x00);
  1131. command.Add(0x04);
  1132. command.Add(0x20);
  1133. break;
  1134. case 8:
  1135. command.Add(0x00);
  1136. command.Add(0x04);
  1137. command.Add(0x24);
  1138. break;
  1139. case 9:
  1140. command.Add(0x00);
  1141. command.Add(0x04);
  1142. command.Add(0x28);
  1143. break;
  1144. case 10:
  1145. command.Add(0x00);
  1146. command.Add(0x04);
  1147. command.Add(0x2C);
  1148. break;
  1149. case 11:
  1150. command.Add(0x00);
  1151. command.Add(0x04);
  1152. command.Add(0x30);
  1153. break;
  1154. case 12:
  1155. command.Add(0x00);
  1156. command.Add(0x04);
  1157. command.Add(0x34);
  1158. break;
  1159. case 13:
  1160. command.Add(0x00);
  1161. command.Add(0x04);
  1162. command.Add(0x38);
  1163. break;
  1164. case 14:
  1165. command.Add(0x00);
  1166. command.Add(0x04);
  1167. command.Add(0x3C);
  1168. break;
  1169. case 15:
  1170. command.Add(0x00);
  1171. command.Add(0x04);
  1172. command.Add(0x40);
  1173. break;
  1174. case 16:
  1175. command.Add(0x00);
  1176. command.Add(0x04);
  1177. command.Add(0x44);
  1178. break;
  1179. default:
  1180. break;
  1181. }
  1182. command.Add(0x04);
  1183. command.Add(0x00);
  1184. var result = CreateORC(command.ToArray());
  1185. return result;
  1186. }
  1187. /// <summary>
  1188. /// 写EEPROM->水平电机1号Well位置(零点),返回长度6个字节
  1189. /// </summary>
  1190. /// <returns></returns>
  1191. public static byte[] CreateWriteEEPROMhoriMtWell1HoriPos(int pulse)
  1192. {
  1193. byte[] pulses = BitConverter.GetBytes(pulse);
  1194. List<byte> command = new List<byte>();
  1195. command.Add(0x5E);//帧头
  1196. command.Add(0x12);//WRITE_EEPROM
  1197. command.Add(0x00);//CMDNO
  1198. command.Add(0x0C);//LTH
  1199. command.Add(0x00);//地址(高)
  1200. command.Add(0x04);//地址(中)
  1201. command.Add(0x00);//地址(低)
  1202. if (BitConverter.IsLittleEndian)
  1203. {
  1204. command.Add(pulses[0]);//参数1(低)
  1205. command.Add(pulses[1]);//参数2
  1206. command.Add(pulses[2]);//参数3
  1207. command.Add(pulses[3]);//参数4(高)
  1208. }
  1209. else
  1210. {
  1211. command.Add(pulses[3]);//参数1(低)
  1212. command.Add(pulses[2]);//参数2
  1213. command.Add(pulses[1]);//参数3
  1214. command.Add(pulses[0]);//参数4(高)
  1215. }
  1216. command.Add(0x00);//校验和CRC
  1217. var result = CreateORC(command.ToArray());
  1218. return result;
  1219. }
  1220. /// <summary>
  1221. /// 写入EEPROM->水平电机well间隔脉冲,返回长度6个字节
  1222. /// </summary>
  1223. /// <returns></returns>
  1224. public static byte[] CreateWriteEEPROMhoriMtWellInterval(int pulse)
  1225. {
  1226. byte[] pulses = BitConverter.GetBytes(pulse);
  1227. List<byte> command = new List<byte>();
  1228. command.Add(0x5E);//帧头
  1229. command.Add(0x12);//WRITE_EEPROM
  1230. command.Add(0x00);//CMDNO
  1231. command.Add(0x0C);//LTH
  1232. command.Add(0x00);//地址(高)
  1233. command.Add(0x02);//地址(中)
  1234. command.Add(0x24);//地址(低)
  1235. if (BitConverter.IsLittleEndian)
  1236. {
  1237. command.Add(pulses[0]);//参数1(低)
  1238. command.Add(pulses[1]);//参数2
  1239. command.Add(pulses[2]);//参数3
  1240. command.Add(pulses[3]);//参数4(高)
  1241. }
  1242. else
  1243. {
  1244. command.Add(pulses[3]);//参数1(低)
  1245. command.Add(pulses[2]);//参数2
  1246. command.Add(pulses[1]);//参数3
  1247. command.Add(pulses[0]);//参数4(高)
  1248. }
  1249. command.Add(0x00);//校验和CRC
  1250. var result = CreateORC(command.ToArray());
  1251. return result;
  1252. }
  1253. /// <summary>
  1254. /// 写入EEPROM->换气标志
  1255. /// </summary>
  1256. /// <param name="flag">换气前写1,换气后写0。</param>
  1257. /// <returns></returns>
  1258. public static byte[] CreateWriteEEPROMChangeAir(uint flag)
  1259. {
  1260. byte[] pulses = BitConverter.GetBytes(flag);
  1261. List<byte> command = new List<byte>();
  1262. command.Add(0x5E);//帧头
  1263. command.Add(0x12);//WRITE_EEPROM
  1264. command.Add(0x00);//CMDNO
  1265. command.Add(0x0C);//LTH
  1266. command.Add(0x00);//地址(高)
  1267. command.Add(0x03);//地址(中)
  1268. command.Add(0x3C);//地址(低)
  1269. if (BitConverter.IsLittleEndian)
  1270. {
  1271. command.Add(pulses[0]);//参数1(低)
  1272. command.Add(pulses[1]);//参数2
  1273. command.Add(pulses[2]);//参数3
  1274. command.Add(pulses[3]);//参数4(高)
  1275. }
  1276. else
  1277. {
  1278. command.Add(pulses[3]);//参数1(低)
  1279. command.Add(pulses[2]);//参数2
  1280. command.Add(pulses[1]);//参数3
  1281. command.Add(pulses[0]);//参数4(高)
  1282. }
  1283. command.Add(0x00);//校验和CRC
  1284. var result = CreateORC(command.ToArray());
  1285. return result;
  1286. }
  1287. /// <summary>
  1288. /// 换气标志
  1289. /// </summary>
  1290. /// <param name="flag">flag=1表示换气前执行的操作</param>
  1291. /// <returns></returns>
  1292. public static byte[] CreateChangeAir(uint flag)
  1293. {
  1294. //5E 09 00 07 03 01 72 换气前
  1295. //5E 09 00 07 03 00 71 换气后
  1296. byte[] newValue = BitConverter.GetBytes(flag);
  1297. List<byte> command = new List<byte>();
  1298. command.Add(0x5E);//帧头
  1299. command.Add(0x09);//WRITE_EEPROM
  1300. command.Add(0x00);//CMDNO
  1301. command.Add(0x07);//LTH
  1302. command.Add(0x03);
  1303. if (flag == 1)
  1304. {
  1305. command.Add(0x01);
  1306. command.Add(0x72);
  1307. }
  1308. else
  1309. {
  1310. command.Add(0x00);
  1311. command.Add(0x71);
  1312. }
  1313. return command.ToArray();
  1314. }
  1315. #endregion
  1316. }
  1317. }