Commander.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  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. // ── M-01/M-02/M-03 合并遗留补齐:写/读舱室排气阀打开时间、写灯光亮度 ──
  790. // 字节与合并前 operate 端 ivf_tl_Entity/ComEntitys/Commander.cs 同名方法逐字一致(地址表/小端/CreateORC),
  791. // 该实现真机已用;补此三 builder 以解除 SerialChannelImpl 的 M-01/M-02/M-03 桩(此前 control Commander 缺对应 builder)。
  792. /// <summary>
  793. /// 写EEPROM->舱室排气阀打开时间(地址 00 03 08,与写进气阀 00 03 0c 仅地址低字节不同)
  794. /// </summary>
  795. public static void CreateWriteEEPROOpenVentTimeCommand(this CustomProtocol custom, int newValue)
  796. {
  797. byte[] pulses = BitConverter.GetBytes(newValue);
  798. List<byte> command = new List<byte>();
  799. command.Add(0x5E);//帧头
  800. command.Add(0x12);//WRITE_EEPROM
  801. command.Add(0x00);//CMDNO
  802. command.Add(0x0C);//LTH
  803. command.Add(0x00);
  804. command.Add(0x03);
  805. command.Add(0x08);
  806. if (BitConverter.IsLittleEndian)
  807. {
  808. command.Add(pulses[0]);//参数1(低)
  809. command.Add(pulses[1]);//参数2
  810. command.Add(pulses[2]);//参数3
  811. command.Add(pulses[3]);//参数4(高)
  812. }
  813. else
  814. {
  815. command.Add(pulses[3]);//参数1(低)
  816. command.Add(pulses[2]);//参数2
  817. command.Add(pulses[1]);//参数3
  818. command.Add(pulses[0]);//参数4(高)
  819. }
  820. command.Add(0x00);//校验和CRC
  821. custom.sendBuffer = CreateORC(command.ToArray());
  822. CustomProtocolLength(custom);
  823. }
  824. /// <summary>
  825. /// 读E方 -->舱室排气阀打开时间(地址 00 03 08)
  826. /// </summary>
  827. public static void CreateReadEEPROMVentNum(this CustomProtocol custom)
  828. {
  829. var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x08, 0x04, 0x00 };
  830. custom.sendBuffer = CreateORC(array);
  831. CustomProtocolLength(custom);
  832. }
  833. /// <summary>
  834. /// 写E方 -->灯光亮度(地址 00 05 34,与读灯光亮度同地址)
  835. /// </summary>
  836. public static void CreateWriteEEPROMLightNum(this CustomProtocol custom, int num)
  837. {
  838. byte[] newValue = BitConverter.GetBytes(num);
  839. List<byte> command = new List<byte>();
  840. command.Add(0x5E);//帧头
  841. command.Add(0x12);//WRITE_EEPROM
  842. command.Add(0x00);//CMDNO
  843. command.Add(0x0C);//LTH
  844. command.Add(0x00);//地址(高)
  845. command.Add(0x05);//地址(中)
  846. command.Add(0x34);//地址(低)
  847. if (BitConverter.IsLittleEndian)
  848. {
  849. command.Add(newValue[0]);//参数1(低)
  850. command.Add(newValue[1]);//参数2
  851. command.Add(newValue[2]);//参数3
  852. command.Add(newValue[3]);//参数4(高)
  853. }
  854. else
  855. {
  856. command.Add(newValue[3]);//参数1(低)
  857. command.Add(newValue[2]);//参数2
  858. command.Add(newValue[1]);//参数3
  859. command.Add(newValue[0]);//参数4(高)
  860. }
  861. command.Add(0x00);//校验和CRC
  862. custom.sendBuffer = CreateORC(command.ToArray());
  863. CustomProtocolLength(custom);
  864. }
  865. /// <summary>
  866. /// 读EEPROM->CCDSN
  867. /// </summary>
  868. /// <returns></returns>
  869. public static void CreateGetModuleCommand(this CustomProtocol custom)
  870. {
  871. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x10, 0x04, 0x00 });
  872. CustomProtocolLength(custom);
  873. }
  874. /// <summary>
  875. /// 写EEPROM
  876. /// </summary>
  877. /// <param name="address">地址</param>
  878. /// <param name="value">值</param>
  879. /// <returns></returns>
  880. public static void CreateWriteEEPROM(this CustomProtocol custom,int address, double value)
  881. {
  882. byte[] byteAddress = BitConverter.GetBytes(address);
  883. byte[] byteValue = BitConverter.GetBytes(value);
  884. List<byte> command = new List<byte>();
  885. command.Add(0x5E);//帧头
  886. command.Add(0x12);//WRITE_EEPROM
  887. command.Add(0x00);//CMDNO
  888. command.Add(0x0C);//LTH
  889. if (BitConverter.IsLittleEndian)
  890. {
  891. command.Add(byteAddress[2]);//地址(高)
  892. command.Add(byteAddress[1]);//地址(中)
  893. command.Add(byteAddress[0]);//地址(低)
  894. command.Add(byteValue[0]);//参数1(低)
  895. command.Add(byteValue[1]);//参数2
  896. command.Add(byteValue[2]);//参数3
  897. command.Add(byteValue[3]);//参数4(高)
  898. }
  899. else
  900. {
  901. command.Add(byteAddress[0]);//地址(高)
  902. command.Add(byteAddress[1]);//地址(中)
  903. command.Add(byteAddress[2]);//地址(低)
  904. command.Add(byteValue[3]);//参数1(低)
  905. command.Add(byteValue[2]);//参数2
  906. command.Add(byteValue[1]);//参数3
  907. command.Add(byteValue[0]);//参数4(高)
  908. }
  909. command.Add(0x00);//校验和CRC
  910. custom.sendBuffer = CreateORC(command.ToArray());
  911. CustomProtocolLength(custom);
  912. }
  913. #region 电机运动
  914. /// <summary>
  915. /// 水平电机复位运动,长度11
  916. /// </summary>
  917. /// <returns></returns>
  918. public static void CreateHorizontalMotorResetCommand(this CustomProtocol custom)
  919. {
  920. /*
  921. * 第1字节 第2字节 第3字节 第4字节 第5字节 第6字节 第7字节 第8字节 第9字节 第10字节 第11字节
  922. 帧头 ST SET_MOTOR CMDNO LTH 辅助指令码 参数1 参数2 参数3 参数4 参数5 校验和CRC
  923. 帧头 ST = 5E
  924. SET_MOTOR = 0x05
  925. CMDNO = 00
  926. LTH = 11
  927. 辅助指令码 = 高半字节(水平电机=1|扫描电机=2) + 低半字节(正转=0|反转=1|脱机=2|复位=3|绝对运动=4)
  928. 参数1,参数2:电机运动的脉冲值,参数1是高8位,参数2是低8位,组成16位的脉冲值;
  929. 参数3:0x00;
  930. 参数4,参数5:0x00,0x00
  931. */
  932. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x13, 0x00, 0x00, 0x00, 0x0B, 0xB8, 0x44 });
  933. CustomProtocolLength(custom);
  934. }
  935. /// <summary>
  936. /// 水平电机正向运动,长度11
  937. /// </summary>
  938. /// <param name="pulse">脉冲值</param>
  939. /// <returns></returns>
  940. public static void CreateHorizontalMotorForwardCommand(this CustomProtocol custom,int? pulse)
  941. {
  942. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  943. List<byte> command = new List<byte>();
  944. command.Add(0x5E);//帧头
  945. command.Add(0x05);//SET_MOTOR
  946. command.Add(0x00);//CMDNO
  947. command.Add(0x0B);//LTH
  948. command.Add(0x10);//辅助指令码
  949. if (BitConverter.IsLittleEndian)
  950. {
  951. command.Add(pulses[3]);//参数1 高
  952. command.Add(pulses[2]);//参数2
  953. command.Add(pulses[1]);//参数3
  954. command.Add(pulses[0]);//参数4 低
  955. }
  956. else
  957. {
  958. command.Add(pulses[0]);//参数1 高
  959. command.Add(pulses[1]);//参数2
  960. command.Add(pulses[2]);//参数3
  961. command.Add(pulses[3]);//参数4 低
  962. }
  963. command.Add(0x00);//参数5
  964. command.Add(0x00);//校验和CRC
  965. custom.sendBuffer = CreateORC(command.ToArray());
  966. CustomProtocolLength(custom);
  967. }
  968. /// <summary>
  969. /// 水平电机反向运动,长度11
  970. /// </summary>
  971. /// <returns></returns>
  972. public static void CreateHorizontalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
  973. {
  974. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  975. List<byte> command = new List<byte>();
  976. command.Add(0x5E);//帧头
  977. command.Add(0x05);//SET_MOTOR
  978. command.Add(0x00);//CMDNO
  979. command.Add(0x0B);//LTH
  980. command.Add(0x11);//辅助指令码
  981. if (BitConverter.IsLittleEndian)
  982. {
  983. command.Add(pulses[3]);//参数1 高
  984. command.Add(pulses[2]);//参数2
  985. command.Add(pulses[1]);//参数3
  986. command.Add(pulses[0]);//参数4 低
  987. }
  988. else
  989. {
  990. command.Add(pulses[0]);//参数1 高
  991. command.Add(pulses[1]);//参数2
  992. command.Add(pulses[2]);//参数3
  993. command.Add(pulses[3]);//参数4 低
  994. }
  995. command.Add(0x00);//参数5
  996. command.Add(0x00);//校验和CRC
  997. custom.sendBuffer = CreateORC(command.ToArray());
  998. CustomProtocolLength(custom);
  999. }
  1000. /// <summary>
  1001. /// 水平电机绝对运动
  1002. /// </summary>
  1003. /// <param name="pulse"></param>
  1004. /// <returns></returns>
  1005. public static void CreateHorizontalMotorMoveToCommand(this CustomProtocol custom,int? pulse)
  1006. {
  1007. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  1008. List<byte> command = new List<byte>();
  1009. command.Add(0x5E);//帧头
  1010. command.Add(0x05);//SET_MOTOR
  1011. command.Add(0x00);//CMDNO
  1012. command.Add(0x0B);//LTH
  1013. command.Add(0x14);//辅助指令码
  1014. if (BitConverter.IsLittleEndian)
  1015. {
  1016. command.Add(pulses[3]);//参数1 高
  1017. command.Add(pulses[2]);//参数2
  1018. command.Add(pulses[1]);//参数3
  1019. command.Add(pulses[0]);//参数4 低
  1020. }
  1021. else
  1022. {
  1023. command.Add(pulses[0]);//参数1 高
  1024. command.Add(pulses[1]);//参数2
  1025. command.Add(pulses[2]);//参数3
  1026. command.Add(pulses[3]);//参数4 低
  1027. }
  1028. command.Add(0x00);//参数5
  1029. command.Add(0x00);//校验和CRC
  1030. custom.sendBuffer = CreateORC(command.ToArray());
  1031. CustomProtocolLength(custom);
  1032. }
  1033. /// <summary>
  1034. /// 垂直电机复位运动,长度11
  1035. /// </summary>
  1036. /// <returns></returns>
  1037. public static void CreateVerticalMotorResetCommand(this CustomProtocol custom)
  1038. {
  1039. custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x23, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x68 });
  1040. CustomProtocolLength(custom);
  1041. }
  1042. /// <summary>
  1043. /// 垂直电机正向运动,长度11
  1044. /// </summary>
  1045. /// <param name="pulse">脉冲值</param>
  1046. /// <returns></returns>
  1047. public static void CreateVerticalMotorForwardCommand(this CustomProtocol custom,int? pulse)
  1048. {
  1049. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  1050. List<byte> command = new List<byte>();
  1051. command.Add(0x5E);//帧头
  1052. command.Add(0x05);//SET_MOTOR
  1053. command.Add(0x00);//CMDNO
  1054. command.Add(0x0B);//LTH
  1055. command.Add(0x20);//辅助指令码
  1056. if (BitConverter.IsLittleEndian)
  1057. {
  1058. command.Add(pulses[3]);//参数1 高
  1059. command.Add(pulses[2]);//参数2
  1060. command.Add(pulses[1]);//参数3
  1061. command.Add(pulses[0]);//参数4 低
  1062. }
  1063. else
  1064. {
  1065. command.Add(pulses[0]);//参数1 高
  1066. command.Add(pulses[1]);//参数2
  1067. command.Add(pulses[2]);//参数3
  1068. command.Add(pulses[3]);//参数4 低
  1069. }
  1070. command.Add(0x00);//参数5
  1071. command.Add(0x00);//校验和CRC
  1072. custom.sendBuffer = CreateORC(command.ToArray());
  1073. CustomProtocolLength(custom);
  1074. }
  1075. /// <summary>
  1076. /// 垂直电机绝对运动
  1077. /// </summary>
  1078. /// <param name="pulse"></param>
  1079. /// <returns></returns>
  1080. public static void CreateVerticalMotorAbsoluteMovementCommand(this CustomProtocol custom,int? pulse)
  1081. {
  1082. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  1083. List<byte> command = new List<byte>();
  1084. command.Add(0x5E);//帧头
  1085. command.Add(0x05);//SET_MOTOR
  1086. command.Add(0x00);//CMDNO
  1087. command.Add(0x0B);//LTH
  1088. command.Add(0x24);//辅助指令码
  1089. if (BitConverter.IsLittleEndian)
  1090. {
  1091. command.Add(pulses[3]);//参数1 高
  1092. command.Add(pulses[2]);//参数2
  1093. command.Add(pulses[1]);//参数3
  1094. command.Add(pulses[0]);//参数4 低
  1095. }
  1096. else
  1097. {
  1098. command.Add(pulses[0]);//参数1 高
  1099. command.Add(pulses[1]);//参数2
  1100. command.Add(pulses[2]);//参数3
  1101. command.Add(pulses[3]);//参数4 低
  1102. }
  1103. command.Add(0x00);//参数5
  1104. command.Add(0x00);//校验和CRC
  1105. custom.sendBuffer = CreateORC(command.ToArray());
  1106. CustomProtocolLength(custom);
  1107. }
  1108. /// <summary>
  1109. /// 垂直电机反向运动,长度11
  1110. /// </summary>
  1111. /// <returns></returns>
  1112. public static void CreateVerticalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
  1113. {
  1114. byte[] pulses = BitConverter.GetBytes(pulse.Value);
  1115. List<byte> command = new List<byte>();
  1116. command.Add(0x5E);//帧头
  1117. command.Add(0x05);//SET_MOTOR
  1118. command.Add(0x00);//CMDNO
  1119. command.Add(0x0B);//LTH
  1120. command.Add(0x21);//辅助指令码
  1121. if (BitConverter.IsLittleEndian)
  1122. {
  1123. command.Add(pulses[3]);//参数1 高
  1124. command.Add(pulses[2]);//参数2
  1125. command.Add(pulses[1]);//参数3
  1126. command.Add(pulses[0]);//参数4 低
  1127. }
  1128. else
  1129. {
  1130. command.Add(pulses[0]);//参数1 高
  1131. command.Add(pulses[1]);//参数2
  1132. command.Add(pulses[2]);//参数3
  1133. command.Add(pulses[3]);//参数4 低
  1134. }
  1135. command.Add(0x00);//参数5
  1136. command.Add(0x00);//校验和CRC
  1137. custom.sendBuffer = CreateORC(command.ToArray());
  1138. CustomProtocolLength(custom);
  1139. }
  1140. #endregion
  1141. #region
  1142. /// <summary>
  1143. /// 换气时打开气阀
  1144. /// </summary>
  1145. /// <returns></returns>
  1146. public static byte[] CreateOpenGasValveCommand()
  1147. {
  1148. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });//上电
  1149. }
  1150. /// <summary>
  1151. /// 换气时关闭气阀
  1152. /// </summary>
  1153. /// <returns></returns>
  1154. public static byte[] CreateCloseGasValveCommand()
  1155. {
  1156. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });//断电
  1157. }
  1158. /// <summary>
  1159. /// 培养指令
  1160. /// </summary>
  1161. /// <param name="isOpen"></param>
  1162. /// <returns></returns>
  1163. public static byte[] CreateGasCommand(bool isOpen)
  1164. {
  1165. //5E 09 00 07 02 01 71
  1166. if (isOpen)
  1167. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 });//开始培养
  1168. else
  1169. return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 });//结束培养
  1170. }
  1171. /// <summary>
  1172. /// 读EEPROM->水平电机well间隔脉冲,返回长度10个字节
  1173. /// </summary>
  1174. /// <returns></returns>
  1175. public static byte[] CreateReadEEPROMhoriMtWellInterval()
  1176. {
  1177. var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x02, 0x24, 0x04, 0x00 };
  1178. return CreateORC(array);
  1179. }
  1180. /// <summary>
  1181. /// 读EEPROM->16垂直电机焦准脉冲数(零点),返回长度10个字节
  1182. /// </summary>
  1183. /// <returns></returns>
  1184. public static byte[] CreateReadEEPROMvertMtStartPulse1(int wellNum)
  1185. {
  1186. List<byte> command = new List<byte>();
  1187. command.Add(0x5E);
  1188. command.Add(0x11);
  1189. command.Add(0x00);
  1190. command.Add(0x09);
  1191. switch (wellNum)
  1192. {
  1193. case 1:
  1194. command.Add(0x00);
  1195. command.Add(0x04);
  1196. command.Add(0x08);
  1197. break;
  1198. case 2:
  1199. command.Add(0x00);
  1200. command.Add(0x04);
  1201. command.Add(0x0C);
  1202. break;
  1203. case 3:
  1204. command.Add(0x00);
  1205. command.Add(0x04);
  1206. command.Add(0x10);
  1207. break;
  1208. case 4:
  1209. command.Add(0x00);
  1210. command.Add(0x04);
  1211. command.Add(0x14);
  1212. break;
  1213. case 5:
  1214. command.Add(0x00);
  1215. command.Add(0x04);
  1216. command.Add(0x18);
  1217. break;
  1218. case 6:
  1219. command.Add(0x00);
  1220. command.Add(0x04);
  1221. command.Add(0x1C);
  1222. break;
  1223. case 7:
  1224. command.Add(0x00);
  1225. command.Add(0x04);
  1226. command.Add(0x20);
  1227. break;
  1228. case 8:
  1229. command.Add(0x00);
  1230. command.Add(0x04);
  1231. command.Add(0x24);
  1232. break;
  1233. case 9:
  1234. command.Add(0x00);
  1235. command.Add(0x04);
  1236. command.Add(0x28);
  1237. break;
  1238. case 10:
  1239. command.Add(0x00);
  1240. command.Add(0x04);
  1241. command.Add(0x2C);
  1242. break;
  1243. case 11:
  1244. command.Add(0x00);
  1245. command.Add(0x04);
  1246. command.Add(0x30);
  1247. break;
  1248. case 12:
  1249. command.Add(0x00);
  1250. command.Add(0x04);
  1251. command.Add(0x34);
  1252. break;
  1253. case 13:
  1254. command.Add(0x00);
  1255. command.Add(0x04);
  1256. command.Add(0x38);
  1257. break;
  1258. case 14:
  1259. command.Add(0x00);
  1260. command.Add(0x04);
  1261. command.Add(0x3C);
  1262. break;
  1263. case 15:
  1264. command.Add(0x00);
  1265. command.Add(0x04);
  1266. command.Add(0x40);
  1267. break;
  1268. case 16:
  1269. command.Add(0x00);
  1270. command.Add(0x04);
  1271. command.Add(0x44);
  1272. break;
  1273. default:
  1274. break;
  1275. }
  1276. command.Add(0x04);
  1277. command.Add(0x00);
  1278. var result = CreateORC(command.ToArray());
  1279. return result;
  1280. }
  1281. /// <summary>
  1282. /// 写EEPROM->水平电机1号Well位置(零点),返回长度6个字节
  1283. /// </summary>
  1284. /// <returns></returns>
  1285. public static byte[] CreateWriteEEPROMhoriMtWell1HoriPos(int pulse)
  1286. {
  1287. byte[] pulses = BitConverter.GetBytes(pulse);
  1288. List<byte> command = new List<byte>();
  1289. command.Add(0x5E);//帧头
  1290. command.Add(0x12);//WRITE_EEPROM
  1291. command.Add(0x00);//CMDNO
  1292. command.Add(0x0C);//LTH
  1293. command.Add(0x00);//地址(高)
  1294. command.Add(0x04);//地址(中)
  1295. command.Add(0x00);//地址(低)
  1296. if (BitConverter.IsLittleEndian)
  1297. {
  1298. command.Add(pulses[0]);//参数1(低)
  1299. command.Add(pulses[1]);//参数2
  1300. command.Add(pulses[2]);//参数3
  1301. command.Add(pulses[3]);//参数4(高)
  1302. }
  1303. else
  1304. {
  1305. command.Add(pulses[3]);//参数1(低)
  1306. command.Add(pulses[2]);//参数2
  1307. command.Add(pulses[1]);//参数3
  1308. command.Add(pulses[0]);//参数4(高)
  1309. }
  1310. command.Add(0x00);//校验和CRC
  1311. var result = CreateORC(command.ToArray());
  1312. return result;
  1313. }
  1314. /// <summary>
  1315. /// 写入EEPROM->水平电机well间隔脉冲,返回长度6个字节
  1316. /// </summary>
  1317. /// <returns></returns>
  1318. public static byte[] CreateWriteEEPROMhoriMtWellInterval(int pulse)
  1319. {
  1320. byte[] pulses = BitConverter.GetBytes(pulse);
  1321. List<byte> command = new List<byte>();
  1322. command.Add(0x5E);//帧头
  1323. command.Add(0x12);//WRITE_EEPROM
  1324. command.Add(0x00);//CMDNO
  1325. command.Add(0x0C);//LTH
  1326. command.Add(0x00);//地址(高)
  1327. command.Add(0x02);//地址(中)
  1328. command.Add(0x24);//地址(低)
  1329. if (BitConverter.IsLittleEndian)
  1330. {
  1331. command.Add(pulses[0]);//参数1(低)
  1332. command.Add(pulses[1]);//参数2
  1333. command.Add(pulses[2]);//参数3
  1334. command.Add(pulses[3]);//参数4(高)
  1335. }
  1336. else
  1337. {
  1338. command.Add(pulses[3]);//参数1(低)
  1339. command.Add(pulses[2]);//参数2
  1340. command.Add(pulses[1]);//参数3
  1341. command.Add(pulses[0]);//参数4(高)
  1342. }
  1343. command.Add(0x00);//校验和CRC
  1344. var result = CreateORC(command.ToArray());
  1345. return result;
  1346. }
  1347. /// <summary>
  1348. /// 写入EEPROM->换气标志
  1349. /// </summary>
  1350. /// <param name="flag">换气前写1,换气后写0。</param>
  1351. /// <returns></returns>
  1352. public static byte[] CreateWriteEEPROMChangeAir(uint flag)
  1353. {
  1354. byte[] pulses = BitConverter.GetBytes(flag);
  1355. List<byte> command = new List<byte>();
  1356. command.Add(0x5E);//帧头
  1357. command.Add(0x12);//WRITE_EEPROM
  1358. command.Add(0x00);//CMDNO
  1359. command.Add(0x0C);//LTH
  1360. command.Add(0x00);//地址(高)
  1361. command.Add(0x03);//地址(中)
  1362. command.Add(0x3C);//地址(低)
  1363. if (BitConverter.IsLittleEndian)
  1364. {
  1365. command.Add(pulses[0]);//参数1(低)
  1366. command.Add(pulses[1]);//参数2
  1367. command.Add(pulses[2]);//参数3
  1368. command.Add(pulses[3]);//参数4(高)
  1369. }
  1370. else
  1371. {
  1372. command.Add(pulses[3]);//参数1(低)
  1373. command.Add(pulses[2]);//参数2
  1374. command.Add(pulses[1]);//参数3
  1375. command.Add(pulses[0]);//参数4(高)
  1376. }
  1377. command.Add(0x00);//校验和CRC
  1378. var result = CreateORC(command.ToArray());
  1379. return result;
  1380. }
  1381. /// <summary>
  1382. /// 换气标志
  1383. /// </summary>
  1384. /// <param name="flag">flag=1表示换气前执行的操作</param>
  1385. /// <returns></returns>
  1386. public static byte[] CreateChangeAir(uint flag)
  1387. {
  1388. //5E 09 00 07 03 01 72 换气前
  1389. //5E 09 00 07 03 00 71 换气后
  1390. byte[] newValue = BitConverter.GetBytes(flag);
  1391. List<byte> command = new List<byte>();
  1392. command.Add(0x5E);//帧头
  1393. command.Add(0x09);//WRITE_EEPROM
  1394. command.Add(0x00);//CMDNO
  1395. command.Add(0x07);//LTH
  1396. command.Add(0x03);
  1397. if (flag == 1)
  1398. {
  1399. command.Add(0x01);
  1400. command.Add(0x72);
  1401. }
  1402. else
  1403. {
  1404. command.Add(0x00);
  1405. command.Add(0x71);
  1406. }
  1407. return command.ToArray();
  1408. }
  1409. #endregion
  1410. }
  1411. }