| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415 |
- 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>
- /// 是否开启自动换气
- /// </summary>
- /// <param name="custom"></param>
- public static void CreateAutoCommand(this CustomProtocol custom, bool auto)
- {
- if (auto)
- {
- //7B
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x16, 0x00, 0x06, 0x01, 0x00 });
- }
- else
- {
- //7A
- custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x16, 0x00, 0x06, 0x00, 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
- }
- }
|