| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396 |
- using IvfTl.Control.Entity;
- namespace ivf_tl_SerialHelper.Util
- {
- public static class Commander
- {
- //public static int MachineModel { get; set; }
- /// <summary>
- /// 求累加和校验
- /// </summary>
- /// <param name="bytes"></param>
- /// <returns></returns>
- public static byte[] CreateORC(byte[] bytes)
- {
- byte orcByte = 0x00;
- for (int i = 0; i < bytes.Length - 1; i++)
- {
- orcByte += bytes[i];
- }
- bytes[bytes.Length - 1] = orcByte;
- return bytes;
- }
- /// <summary>
- /// 判断校验
- /// </summary>
- /// <param name="bytes"></param>
- /// <returns></returns>
- public static bool CheckORC(byte[] bytes)
- {
- byte orcByte = 0x00;
- for (int i = 0; i < bytes.Length - 1; i++)
- {
- orcByte += bytes[i];
- }
- return bytes[bytes.Length - 1] == orcByte;
- }
- public static void CustomProtocolLength(CustomProtocol custom)
- {
- custom.lenght = 6;
- custom.WaitTime = 0;
- switch (custom.sendBuffer[1])
- {
- case 0x01://握手指令
- custom.lenght = 6;
- break;
- case 0x02://自检指令
- custom.lenght = 6;
- break;
- case 0x04://设置目标温度
- custom.lenght = 7;
- break;
- case 0x05://电机控制指令
- custom.lenght = 6;
- break;
- case 0x06://读传感器信号
- custom.lenght = 9;
- break;
- case 0x08://读传感器AD
- custom.lenght = 9;
- break;
- case 0x09://设置IO
- custom.lenght = 6;
- break;
- case 0x10://获取IO
- custom.lenght = 7;
- break;
- case 0x11://读E方
- custom.lenght = 10;
- break;
- case 0x12://写E方
- custom.lenght = 6;
- break;
- case 0x18://读电机位置
- custom.lenght = 10;
- break;
- case 0x19://缓冲瓶补气
- custom.lenght = 6;
- break;
- case 0x20://读缓冲瓶数据
- custom.lenght = 12;
- break;
- }
- }
- #region 操作
- /// <summary>
- /// 握手 64
- /// </summary>
- /// <returns></returns>
- public static void CreateHandCommand(this CustomProtocol custom)
- {
-
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x01, 0x00, 0x05, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 打开CCD补光LED,长度7
- /// </summary>
- /// <returns></returns>
- public static void CreateOpenLEDCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x01, 0x6F };
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 关闭CCD补光LED,长度7
- /// </summary>
- /// <returns></returns>
- public static void CreateCloseLEDCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x00, 0x6E };
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 打开进气阀
- /// </summary>
- /// <returns></returns>
- public static void CreateOpenIntakeValveCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 关闭进气阀
- /// </summary>
- /// <returns></returns>
- public static void CreateCloseIntakeValveCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 打开排气阀
- /// </summary>
- /// <returns></returns>
- public static void CreateOpenExhaustValveCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 关闭排气阀
- /// </summary>
- /// <returns></returns>
- public static void CreateCloseExhaustValveCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 缓冲瓶补气 7C
- /// </summary>
- /// <returns></returns>
- public static void CreateBufferBottleAerationCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x19, 0x00, 0x05, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 仓室补气 72
- /// </summary>
- /// <returns></returns>
- public static void CreateHouseAerationCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x04, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 舱室排气
- /// </summary>
- /// <returns></returns>
- public static void CreateHouseVentCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x05, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读垂直电机位置
- /// </summary>
- /// <returns></returns>
- public static void CreateReadVerticalMotorCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x02, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读水平电机位置
- /// </summary>
- /// <returns></returns>
- public static void CreateReadHorizontalMotorCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读E方 仪器编号
- /// </summary>
- /// <returns></returns>
- public static void CreateReadTLNumCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x08, 0x04, 0x00 });
- CustomProtocolLength(custom);
- }
- #endregion
- #region 温度、压力、仓门状态
- /// <summary>
- /// 温度 6b(下盖板温度)
- /// </summary>
- /// <param name="wayNum"></param>
- /// <returns></returns>
- public static void CreateReadTemperatureCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x00, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 获取上盖板温度
- /// </summary>
- /// <returns></returns>
- public static void CreateReadShangTemperatureCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x01, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 获取玻璃片下方温度
- /// </summary>
- /// <returns></returns>
- public static void CreateReadBoLiTemperatureCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x02, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 压力
- /// </summary>
- /// <param name="wayNum"></param>
- /// <returns></returns>
- public static void CreateReadPressureCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x03, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 获取缓冲瓶气压 83
- /// </summary>
- /// <returns></returns>
- public static void CreateBufferBottlePressureCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x20, 0x00, 0x05, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 门
- /// </summary>
- /// <returns>5E 0A 00 06 02 71</returns>
- public static void CreateReadDoorCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x10, 0x00, 0x06, 0x02, 0x00 });
- CustomProtocolLength(custom);
- }
-
- #endregion
- /// <summary>
- /// 读EEPROM->水平电机Well位置,返回长度10个字节
- /// </summary>
- /// <param name="wellNum"></param>
- /// <returns></returns>
- public static void CreateReadEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum)
- {
- List<byte> command = new List<byte>();
- command.Add(0x5E);
- command.Add(0x11);
- command.Add(0x00);
- command.Add(0x09);
- switch (wellNum)
- {
- case 1:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x00);
- break;
- case 2:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x50);
- break;
- case 3:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x54);
- break;
- case 4:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x58);
- break;
- case 5:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x5C);
- break;
- case 6:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x60);
- break;
- case 7:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x64);
- break;
- case 8:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x68);
- break;
- case 9:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x6C);
- break;
- case 10:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x70);
- break;
- case 11:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x74);
- break;
- case 12:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x78);
- break;
- case 13:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x7C);
- break;
- case 14:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x80);
- break;
- case 15:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x84);
- break;
- case 16:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x04);
- break;
- default:
- break;
- }
- command.Add(0x04);
- command.Add(0x00);
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写EEPROM->水平电机Well位置,返回长度10个字节
- /// </summary>
- /// <param name="wellNum"></param>
- /// <returns></returns>
- public static void CreateWriteEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum, int newValue)
- {
- byte[] pulses = BitConverter.GetBytes(newValue);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- switch (wellNum)
- {
- case 1:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x00);
- break;
- case 2:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x50);
- break;
- case 3:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x54);
- break;
- case 4:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x58);
- break;
- case 5:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x5C);
- break;
- case 6:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x60);
- break;
- case 7:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x64);
- break;
- case 8:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x68);
- break;
- case 9:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x6C);
- break;
- case 10:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x70);
- break;
- case 11:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x74);
- break;
- case 12:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x78);
- break;
- case 13:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x7C);
- break;
- case 14:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x80);
- break;
- case 15:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x84);
- break;
- case 16:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x04);
- break;
- default:
- break;
- }
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 (高)
- }
-
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->下加热板目标温度
- /// </summary>
- /// <param name="wellNum"></param>
- /// <returns></returns>
- public static void CreateReadTargetTemp(this CustomProtocol custom)
- {
- List<byte> command = new List<byte>();
- command.Add(0x5E);
- command.Add(0x11);
- command.Add(0x00);
- command.Add(0x09);
- command.Add(0x00);
- command.Add(0x02);
- command.Add(0x38);
- command.Add(0x04);
- command.Add(0x00);
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->垂直电机焦准脉冲数(零点),返回长度10个字节
- /// </summary>
- /// <returns></returns>
- public static void CreateReadEEPROMvertMtStartPulse(this CustomProtocol custom,int i)
- {
- List<byte> command = new List<byte>();
- command.Add(0x5E);
- command.Add(0x11);
- command.Add(0x00);
- command.Add(0x09);
- switch (i)
- {
- case 1:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x08);
- break;
- case 2:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x0C);
- break;
- case 3:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x10);
- break;
- case 4:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x14);
- break;
- case 5:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x18);
- break;
- case 6:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x1C);
- break;
- case 7:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x20);
- break;
- case 8:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x24);
- break;
- case 9:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x28);
- break;
- case 10:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x2C);
- break;
- case 11:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x30);
- break;
- case 12:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x34);
- break;
- case 13:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x38);
- break;
- case 14:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x3C);
- break;
- case 15:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x40);
- break;
- case 16:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x44);
- break;
- default:
- break;
- }
- command.Add(0x04);
- command.Add(0x00);
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写入EEPROM->垂直电机焦准脉冲数(零点),返回长度6个字节
- /// </summary>
- /// <returns></returns>
- public static void CreateWriteEEPROMvertMtStartPulse(this CustomProtocol custom, int pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);//地址(高)
- command.Add(0x03);//地址(中)
- command.Add(0x1C);//地址(低)
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 (高)
- }
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->垂直电机扫描间隔脉冲,返回长度10个字节
- /// </summary>
- /// <returns></returns>
- public static void CreateReadEEPROMvertMtScanPluse(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x04, 0x48, 0x04, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写入EEPROM->垂直电机扫描间隔脉冲,返回长度6个字节
- /// </summary>
- /// <returns></returns>
- public static void CreateWriteEEPROMvertMtScanPluse(this CustomProtocol custom,int pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);//地址(高)
- command.Add(0x04);//地址(中)
- command.Add(0x48);//地址(低)
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->仓室进气阀打开时间
- /// </summary>
- /// <returns></returns>
- public static void CreateReadEEPROOpenIntakeTimeCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x0c, 0x04, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写EEPROM->仓室进气阀打开时间
- /// </summary>
- /// <param name="wellNum"></param>
- /// <returns></returns>
- public static void CreateWriteEEPROOpenIntakeTimeCommand(this CustomProtocol custom,int newValue)
- {
- byte[] pulses = BitConverter.GetBytes(newValue);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);
- command.Add(0x03);
- command.Add(0x0c);
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->缓冲瓶气阀打开时间
- /// </summary>
- /// <returns></returns>
- public static void CreateReadEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x05, 0x0c, 0x04, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写EEPROM->缓冲瓶进气阀打开时间
- /// </summary>
- /// <param name="wellNum"></param>
- /// <returns></returns>
- public static void CreateWriteEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom,int newValue)
- {
- byte[] pulses = BitConverter.GetBytes(newValue);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);
- command.Add(0x05);
- command.Add(0x0c);
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读E方 -->灯光亮度
- /// </summary>
- /// <param name="num"></param>
- /// <returns></returns>
- public static void CreateReadEEPROMLightNum(this CustomProtocol custom)
- {
- var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x05, 0x34, 0x04, 0x00 };
- custom.sendBuffer = CreateORC(array);
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 读EEPROM->CCDSN
- /// </summary>
- /// <returns></returns>
- public static void CreateGetModuleCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x10, 0x04, 0x00 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 写EEPROM
- /// </summary>
- /// <param name="address">地址</param>
- /// <param name="value">值</param>
- /// <returns></returns>
- public static void CreateWriteEEPROM(this CustomProtocol custom,int address, double value)
- {
- byte[] byteAddress = BitConverter.GetBytes(address);
- byte[] byteValue = BitConverter.GetBytes(value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- if (BitConverter.IsLittleEndian)
- {
- command.Add(byteAddress[2]);//地址(高)
- command.Add(byteAddress[1]);//地址(中)
- command.Add(byteAddress[0]);//地址(低)
- command.Add(byteValue[0]);//参数1(低)
- command.Add(byteValue[1]);//参数2
- command.Add(byteValue[2]);//参数3
- command.Add(byteValue[3]);//参数4(高)
- }
- else
- {
- command.Add(byteAddress[0]);//地址(高)
- command.Add(byteAddress[1]);//地址(中)
- command.Add(byteAddress[2]);//地址(低)
- command.Add(byteValue[3]);//参数1(低)
- command.Add(byteValue[2]);//参数2
- command.Add(byteValue[1]);//参数3
- command.Add(byteValue[0]);//参数4(高)
- }
-
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- #region 电机运动
- /// <summary>
- /// 水平电机复位运动,长度11
- /// </summary>
- /// <returns></returns>
- public static void CreateHorizontalMotorResetCommand(this CustomProtocol custom)
- {
- /*
- * 第1字节 第2字节 第3字节 第4字节 第5字节 第6字节 第7字节 第8字节 第9字节 第10字节 第11字节
- 帧头 ST SET_MOTOR CMDNO LTH 辅助指令码 参数1 参数2 参数3 参数4 参数5 校验和CRC
- 帧头 ST = 5E
- SET_MOTOR = 0x05
- CMDNO = 00
- LTH = 11
- 辅助指令码 = 高半字节(水平电机=1|扫描电机=2) + 低半字节(正转=0|反转=1|脱机=2|复位=3|绝对运动=4)
- 参数1,参数2:电机运动的脉冲值,参数1是高8位,参数2是低8位,组成16位的脉冲值;
- 参数3:0x00;
- 参数4,参数5:0x00,0x00
- */
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x13, 0x00, 0x00, 0x00, 0x0B, 0xB8, 0x44 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 水平电机正向运动,长度11
- /// </summary>
- /// <param name="pulse">脉冲值</param>
- /// <returns></returns>
- public static void CreateHorizontalMotorForwardCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x10);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 水平电机反向运动,长度11
- /// </summary>
- /// <returns></returns>
- public static void CreateHorizontalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x11);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 水平电机绝对运动
- /// </summary>
- /// <param name="pulse"></param>
- /// <returns></returns>
- public static void CreateHorizontalMotorMoveToCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x14);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 垂直电机复位运动,长度11
- /// </summary>
- /// <returns></returns>
- public static void CreateVerticalMotorResetCommand(this CustomProtocol custom)
- {
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x05, 0x00, 0x0B, 0x23, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x68 });
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 垂直电机正向运动,长度11
- /// </summary>
- /// <param name="pulse">脉冲值</param>
- /// <returns></returns>
- public static void CreateVerticalMotorForwardCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x20);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 垂直电机绝对运动
- /// </summary>
- /// <param name="pulse"></param>
- /// <returns></returns>
- public static void CreateVerticalMotorAbsoluteMovementCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x24);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- /// <summary>
- /// 垂直电机反向运动,长度11
- /// </summary>
- /// <returns></returns>
- public static void CreateVerticalMotorBackwardCommand(this CustomProtocol custom,int? pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse.Value);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x05);//SET_MOTOR
- command.Add(0x00);//CMDNO
- command.Add(0x0B);//LTH
- command.Add(0x21);//辅助指令码
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[3]);//参数1 高
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4 低
- }
- else
- {
- command.Add(pulses[0]);//参数1 高
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4 低
- }
- command.Add(0x00);//参数5
- command.Add(0x00);//校验和CRC
- custom.sendBuffer = CreateORC(command.ToArray());
- CustomProtocolLength(custom);
- }
- #endregion
- #region
- /// <summary>
- /// 换气时打开气阀
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateOpenGasValveCommand()
- {
- return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });//上电
- }
- /// <summary>
- /// 换气时关闭气阀
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateCloseGasValveCommand()
- {
- return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });//断电
- }
- /// <summary>
- /// 培养指令
- /// </summary>
- /// <param name="isOpen"></param>
- /// <returns></returns>
- public static byte[] CreateGasCommand(bool isOpen)
- {
- //5E 09 00 07 02 01 71
- if (isOpen)
- return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 });//开始培养
- else
- return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 });//结束培养
- }
- /// <summary>
- /// 读EEPROM->水平电机well间隔脉冲,返回长度10个字节
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateReadEEPROMhoriMtWellInterval()
- {
- var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x02, 0x24, 0x04, 0x00 };
- return CreateORC(array);
- }
- /// <summary>
- /// 读EEPROM->16垂直电机焦准脉冲数(零点),返回长度10个字节
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateReadEEPROMvertMtStartPulse1(int wellNum)
- {
- List<byte> command = new List<byte>();
- command.Add(0x5E);
- command.Add(0x11);
- command.Add(0x00);
- command.Add(0x09);
- switch (wellNum)
- {
- case 1:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x08);
- break;
- case 2:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x0C);
- break;
- case 3:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x10);
- break;
- case 4:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x14);
- break;
- case 5:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x18);
- break;
- case 6:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x1C);
- break;
- case 7:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x20);
- break;
- case 8:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x24);
- break;
- case 9:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x28);
- break;
- case 10:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x2C);
- break;
- case 11:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x30);
- break;
- case 12:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x34);
- break;
- case 13:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x38);
- break;
- case 14:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x3C);
- break;
- case 15:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x40);
- break;
- case 16:
- command.Add(0x00);
- command.Add(0x04);
- command.Add(0x44);
- break;
- default:
- break;
- }
- command.Add(0x04);
- command.Add(0x00);
- var result = CreateORC(command.ToArray());
- return result;
- }
- /// <summary>
- /// 写EEPROM->水平电机1号Well位置(零点),返回长度6个字节
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateWriteEEPROMhoriMtWell1HoriPos(int pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);//地址(高)
- command.Add(0x04);//地址(中)
- command.Add(0x00);//地址(低)
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- var result = CreateORC(command.ToArray());
- return result;
- }
- /// <summary>
- /// 写入EEPROM->水平电机well间隔脉冲,返回长度6个字节
- /// </summary>
- /// <returns></returns>
- public static byte[] CreateWriteEEPROMhoriMtWellInterval(int pulse)
- {
- byte[] pulses = BitConverter.GetBytes(pulse);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);//地址(高)
- command.Add(0x02);//地址(中)
- command.Add(0x24);//地址(低)
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- var result = CreateORC(command.ToArray());
- return result;
- }
- /// <summary>
- /// 写入EEPROM->换气标志
- /// </summary>
- /// <param name="flag">换气前写1,换气后写0。</param>
- /// <returns></returns>
- public static byte[] CreateWriteEEPROMChangeAir(uint flag)
- {
- byte[] pulses = BitConverter.GetBytes(flag);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x12);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x0C);//LTH
- command.Add(0x00);//地址(高)
- command.Add(0x03);//地址(中)
- command.Add(0x3C);//地址(低)
- if (BitConverter.IsLittleEndian)
- {
- command.Add(pulses[0]);//参数1(低)
- command.Add(pulses[1]);//参数2
- command.Add(pulses[2]);//参数3
- command.Add(pulses[3]);//参数4(高)
- }
- else
- {
- command.Add(pulses[3]);//参数1(低)
- command.Add(pulses[2]);//参数2
- command.Add(pulses[1]);//参数3
- command.Add(pulses[0]);//参数4(高)
- }
- command.Add(0x00);//校验和CRC
- var result = CreateORC(command.ToArray());
- return result;
- }
- /// <summary>
- /// 换气标志
- /// </summary>
- /// <param name="flag">flag=1表示换气前执行的操作</param>
- /// <returns></returns>
- public static byte[] CreateChangeAir(uint flag)
- {
- //5E 09 00 07 03 01 72 换气前
- //5E 09 00 07 03 00 71 换气后
- byte[] newValue = BitConverter.GetBytes(flag);
- List<byte> command = new List<byte>();
- command.Add(0x5E);//帧头
- command.Add(0x09);//WRITE_EEPROM
- command.Add(0x00);//CMDNO
- command.Add(0x07);//LTH
- command.Add(0x03);
- if (flag == 1)
- {
- command.Add(0x01);
- command.Add(0x72);
- }
- else
- {
- command.Add(0x00);
- command.Add(0x71);
- }
- return command.ToArray();
- }
- #endregion
- }
- }
|