Commander.cs 50 KB

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