Commander.cs 54 KB

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