using IvfTl.Control.Entity; namespace ivf_tl_SerialHelper.Util { public static class Commander { //public static int MachineModel { get; set; } /// /// 求累加和校验 /// /// /// 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; } /// /// 判断校验 /// /// /// 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 操作 /// /// 握手 64 /// /// public static void CreateHandCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x01, 0x00, 0x05, 0x00 }); CustomProtocolLength(custom); } /// /// 是否开启自动换气 /// /// 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); } /// /// 打开CCD补光LED,长度7 /// /// public static void CreateOpenLEDCommand(this CustomProtocol custom) { custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x01, 0x6F }; CustomProtocolLength(custom); } /// /// 关闭CCD补光LED,长度7 /// /// public static void CreateCloseLEDCommand(this CustomProtocol custom) { custom.sendBuffer = new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x00, 0x00, 0x6E }; CustomProtocolLength(custom); } /// /// 打开进气阀 /// /// public static void CreateOpenIntakeValveCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 关闭进气阀 /// /// public static void CreateCloseIntakeValveCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 }); CustomProtocolLength(custom); } /// /// 打开排气阀 /// /// public static void CreateOpenExhaustValveCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 关闭排气阀 /// /// public static void CreateCloseExhaustValveCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x02, 0x00, 0x00 }); CustomProtocolLength(custom); } /// /// 缓冲瓶补气 7C /// /// public static void CreateBufferBottleAerationCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x19, 0x00, 0x05, 0x00 }); CustomProtocolLength(custom); } /// /// 仓室补气 72 /// /// public static void CreateHouseAerationCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x04, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 舱室排气 /// /// public static void CreateHouseVentCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x05, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 读垂直电机位置 /// /// public static void CreateReadVerticalMotorCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x02, 0x00 }); CustomProtocolLength(custom); } /// /// 读水平电机位置 /// /// public static void CreateReadHorizontalMotorCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x18, 0x00, 0x06, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 读E方 仪器编号 /// /// 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 温度、压力、仓门状态 /// /// 温度 6b(下盖板温度) /// /// /// public static void CreateReadTemperatureCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x00, 0x00 }); CustomProtocolLength(custom); } /// /// 获取上盖板温度 /// /// public static void CreateReadShangTemperatureCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x01, 0x00 }); CustomProtocolLength(custom); } /// /// 获取玻璃片下方温度 /// /// public static void CreateReadBoLiTemperatureCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x02, 0x00 }); CustomProtocolLength(custom); } /// /// 压力 /// /// /// public static void CreateReadPressureCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x06, 0x00, 0x06, 0x03, 0x00 }); CustomProtocolLength(custom); } /// /// 获取缓冲瓶气压 83 /// /// public static void CreateBufferBottlePressureCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x20, 0x00, 0x05, 0x00 }); CustomProtocolLength(custom); } /// /// 门 /// /// 5E 0A 00 06 02 71 public static void CreateReadDoorCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x10, 0x00, 0x06, 0x02, 0x00 }); CustomProtocolLength(custom); } #endregion /// /// 读EEPROM->水平电机Well位置,返回长度10个字节 /// /// /// public static void CreateReadEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum) { List command = new List(); 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); } /// /// 写EEPROM->水平电机Well位置,返回长度10个字节 /// /// /// public static void CreateWriteEEPROMhoriMtWellHoriPos(this CustomProtocol custom,int wellNum, int newValue) { byte[] pulses = BitConverter.GetBytes(newValue); List command = new List(); 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); } /// /// 读EEPROM->下加热板目标温度 /// /// /// public static void CreateReadTargetTemp(this CustomProtocol custom) { List command = new List(); 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); } /// /// 读EEPROM->垂直电机焦准脉冲数(零点),返回长度10个字节 /// /// public static void CreateReadEEPROMvertMtStartPulse(this CustomProtocol custom,int i) { List command = new List(); 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); } /// /// 写入EEPROM->垂直电机焦准脉冲数(零点),返回长度6个字节 /// /// public static void CreateWriteEEPROMvertMtStartPulse(this CustomProtocol custom, int pulse) { byte[] pulses = BitConverter.GetBytes(pulse); List command = new List(); 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); } /// /// 读EEPROM->垂直电机扫描间隔脉冲,返回长度10个字节 /// /// public static void CreateReadEEPROMvertMtScanPluse(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x04, 0x48, 0x04, 0x00 }); CustomProtocolLength(custom); } /// /// 写入EEPROM->垂直电机扫描间隔脉冲,返回长度6个字节 /// /// public static void CreateWriteEEPROMvertMtScanPluse(this CustomProtocol custom,int pulse) { byte[] pulses = BitConverter.GetBytes(pulse); List command = new List(); 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); } /// /// 读EEPROM->仓室进气阀打开时间 /// /// public static void CreateReadEEPROOpenIntakeTimeCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x0c, 0x04, 0x00 }); CustomProtocolLength(custom); } /// /// 写EEPROM->仓室进气阀打开时间 /// /// /// public static void CreateWriteEEPROOpenIntakeTimeCommand(this CustomProtocol custom,int newValue) { byte[] pulses = BitConverter.GetBytes(newValue); List command = new List(); 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); } /// /// 读EEPROM->缓冲瓶气阀打开时间 /// /// public static void CreateReadEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x05, 0x0c, 0x04, 0x00 }); CustomProtocolLength(custom); } /// /// 写EEPROM->缓冲瓶进气阀打开时间 /// /// /// public static void CreateWriteEEPROOpenIntakeTimeBufferCommand(this CustomProtocol custom,int newValue) { byte[] pulses = BitConverter.GetBytes(newValue); List command = new List(); 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); } /// /// 读E方 -->灯光亮度 /// /// /// 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); } // ── M-01/M-02/M-03 合并遗留补齐:写/读舱室排气阀打开时间、写灯光亮度 ── // 字节与合并前 operate 端 ivf_tl_Entity/ComEntitys/Commander.cs 同名方法逐字一致(地址表/小端/CreateORC), // 该实现真机已用;补此三 builder 以解除 SerialChannelImpl 的 M-01/M-02/M-03 桩(此前 control Commander 缺对应 builder)。 /// /// 写EEPROM->舱室排气阀打开时间(地址 00 03 08,与写进气阀 00 03 0c 仅地址低字节不同) /// public static void CreateWriteEEPROOpenVentTimeCommand(this CustomProtocol custom, int newValue) { byte[] pulses = BitConverter.GetBytes(newValue); List command = new List(); command.Add(0x5E);//帧头 command.Add(0x12);//WRITE_EEPROM command.Add(0x00);//CMDNO command.Add(0x0C);//LTH command.Add(0x00); command.Add(0x03); command.Add(0x08); 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); } /// /// 读E方 -->舱室排气阀打开时间(地址 00 03 08) /// public static void CreateReadEEPROMVentNum(this CustomProtocol custom) { var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x08, 0x04, 0x00 }; custom.sendBuffer = CreateORC(array); CustomProtocolLength(custom); } /// /// 写E方 -->灯光亮度(地址 00 05 34,与读灯光亮度同地址) /// public static void CreateWriteEEPROMLightNum(this CustomProtocol custom, int num) { byte[] newValue = BitConverter.GetBytes(num); List command = new List(); command.Add(0x5E);//帧头 command.Add(0x12);//WRITE_EEPROM command.Add(0x00);//CMDNO command.Add(0x0C);//LTH command.Add(0x00);//地址(高) command.Add(0x05);//地址(中) command.Add(0x34);//地址(低) if (BitConverter.IsLittleEndian) { command.Add(newValue[0]);//参数1(低) command.Add(newValue[1]);//参数2 command.Add(newValue[2]);//参数3 command.Add(newValue[3]);//参数4(高) } else { command.Add(newValue[3]);//参数1(低) command.Add(newValue[2]);//参数2 command.Add(newValue[1]);//参数3 command.Add(newValue[0]);//参数4(高) } command.Add(0x00);//校验和CRC custom.sendBuffer = CreateORC(command.ToArray()); CustomProtocolLength(custom); } /// /// 读EEPROM->CCDSN /// /// public static void CreateGetModuleCommand(this CustomProtocol custom) { custom.sendBuffer = CreateORC(new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x00, 0x10, 0x04, 0x00 }); CustomProtocolLength(custom); } /// /// 写EEPROM /// /// 地址 /// 值 /// public static void CreateWriteEEPROM(this CustomProtocol custom,int address, double value) { byte[] byteAddress = BitConverter.GetBytes(address); byte[] byteValue = BitConverter.GetBytes(value); List command = new List(); 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 电机运动 /// /// 水平电机复位运动,长度11 /// /// 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); } /// /// 水平电机正向运动,长度11 /// /// 脉冲值 /// public static void CreateHorizontalMotorForwardCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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); } /// /// 水平电机反向运动,长度11 /// /// public static void CreateHorizontalMotorBackwardCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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); } /// /// 水平电机绝对运动 /// /// /// public static void CreateHorizontalMotorMoveToCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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); } /// /// 垂直电机复位运动,长度11 /// /// 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); } /// /// 垂直电机正向运动,长度11 /// /// 脉冲值 /// public static void CreateVerticalMotorForwardCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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); } /// /// 垂直电机绝对运动 /// /// /// public static void CreateVerticalMotorAbsoluteMovementCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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); } /// /// 垂直电机反向运动,长度11 /// /// public static void CreateVerticalMotorBackwardCommand(this CustomProtocol custom,int? pulse) { byte[] pulses = BitConverter.GetBytes(pulse.Value); List command = new List(); 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 /// /// 换气时打开气阀 /// /// public static byte[] CreateOpenGasValveCommand() { return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x01, 0x00 });//上电 } /// /// 换气时关闭气阀 /// /// public static byte[] CreateCloseGasValveCommand() { return CreateORC(new byte[] { 0x5E, 0x09, 0x00, 0x07, 0x01, 0x00, 0x00 });//断电 } /// /// 培养指令 /// /// /// 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 });//结束培养 } /// /// 读EEPROM->水平电机well间隔脉冲,返回长度10个字节 /// /// public static byte[] CreateReadEEPROMhoriMtWellInterval() { var array = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x02, 0x24, 0x04, 0x00 }; return CreateORC(array); } /// /// 读EEPROM->16垂直电机焦准脉冲数(零点),返回长度10个字节 /// /// public static byte[] CreateReadEEPROMvertMtStartPulse1(int wellNum) { List command = new List(); 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; } /// /// 写EEPROM->水平电机1号Well位置(零点),返回长度6个字节 /// /// public static byte[] CreateWriteEEPROMhoriMtWell1HoriPos(int pulse) { byte[] pulses = BitConverter.GetBytes(pulse); List command = new List(); 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; } /// /// 写入EEPROM->水平电机well间隔脉冲,返回长度6个字节 /// /// public static byte[] CreateWriteEEPROMhoriMtWellInterval(int pulse) { byte[] pulses = BitConverter.GetBytes(pulse); List command = new List(); 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; } /// /// 写入EEPROM->换气标志 /// /// 换气前写1,换气后写0。 /// public static byte[] CreateWriteEEPROMChangeAir(uint flag) { byte[] pulses = BitConverter.GetBytes(flag); List command = new List(); 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; } /// /// 换气标志 /// /// flag=1表示换气前执行的操作 /// 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 command = new List(); 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 } }