private const int IDX_FRAMETAIL_RESP = 27; // 帧尾=0xef #region Implementation of ISensorAdapter public void Request(ref SensorAcqResult sensorAcq) { try { if (sensorAcq.Sensor.ModuleNo > ushort.MaxValue) { sensorAcq.ErrorCode = (int)Errors.ERR_INVALID_MODULE; sensorAcq.Request = null; return; } byte[] package = new byte[19]; package[IDX_FrameH] = 0xfe; package[IDX_FrameH + 1] = 0x54; package[IDX_FrameH + 2] = 0x46; package[IDX_FrameH + 3] = 0x4c; package[IDX_FRAME_LEN] = 19; ValueHelper.WriteUShort_BE(package, IDX_DEST, (ushort)sensorAcq.Sensor.ModuleNo); package[IDX_CMD] = 0x03; package[IDX_CONTENT] = Convert.ToByte(sensorAcq.Sensor.ChannelNo); package[IDX_CHSUM_Req] = ValueHelper.CheckXor(package, 0, IDX_CHSUM_Req); package[IDX_FRAMETAIL_REQ] = 0xef; sensorAcq.ErrorCode = (int)Errors.SUCCESS; sensorAcq.Request = package; } catch { sensorAcq.Request = null; sensorAcq.ErrorCode = (int)Errors.ERR_UNKNOW; } }
private const int IDX_YDATA = 11; // Y方向角度 public void Request(ref SensorAcqResult sensorAcq) { try { if (sensorAcq.Sensor.ModuleNo > ushort.MaxValue) { sensorAcq.ErrorCode = (int)Errors.ERR_INVALID_MODULE; sensorAcq.Request = null; return; } var package = new byte[17]; package[IDX_FrameH] = 0xfe; package[IDX_FrameH + 1] = 0x43; package[IDX_FrameH + 2] = 0x58; package[IDX_FRAMEL] = 0xef; ValueHelper.WriteUShort_BE(package, IDX_DEST, (ushort)sensorAcq.Sensor.ModuleNo); package[IDX_CHSUM] = ValueHelper.CheckXor(package, 0, IDX_CHSUM); sensorAcq.ErrorCode = (int)Errors.SUCCESS; sensorAcq.Request = package; } catch { sensorAcq.Request = null; sensorAcq.ErrorCode = (int)Errors.ERR_UNKNOW; } }
private int IsValid(byte[] data) { if (data.Length != 24) return (int)Errors.ERR_INVALID_DATA; if (data[IDX_FrameH] != 0xfe || data[IDX_FrameH + 1] != 0xCD || data[IDX_FRAMETAIL_RESP] != 0xef) return (int)Errors.ERR_INVALID_DATA; byte check = data[IDX_CHSUM_Resp]; if (check == ValueHelper.CheckXor(data, 0, IDX_CHSUM_Resp)) { return (int)Errors.SUCCESS; } return (int)Errors.ERR_CRC; }
private const int IDX_FRAMETAIL_RESP = 23; // 帧尾=0xef #region Implementation of ISensorAdapter public void Request(ref SensorAcqResult sensorAcq) { try { if (sensorAcq.Sensor.ModuleNo > ushort.MaxValue) { sensorAcq.ErrorCode = (int)Errors.ERR_INVALID_MODULE; sensorAcq.Request = null; return; } var packet = new byte[14]; packet[IDX_FrameH] = 0xFE; packet[IDX_FrameH + 1] = 0xCD; ValueHelper.WriteUShort_BE(packet, IDX_ADRESS, (ushort)sensorAcq.Sensor.ModuleNo); packet[IDX_CMD] = 0x04; packet[IDX_CONTENT] = Convert.ToByte(sensorAcq.Sensor.ChannelNo); short vol; try { if (!short.TryParse(sensorAcq.Sensor.Parameters[7].Value.ToString(), out vol)) { vol = 20; } if (vol == 0) { vol = 20; } } catch { vol = 20; } ValueHelper.WriteShort_BE(packet, (short)(IDX_CONTENT + 1), vol); packet[IDX_CHSUM_Req] = ValueHelper.CheckXor(packet, 0, IDX_CHSUM_Req); packet[IDX_FRAMETAIL_REQ] = 0xef; sensorAcq.ErrorCode = (int)Errors.SUCCESS; sensorAcq.Request = packet; } catch { sensorAcq.Request = null; sensorAcq.ErrorCode = (int)Errors.ERR_UNKNOW; } }
private int IsValid(byte[] data) { if (data.Length != 17) { return((int)Errors.ERR_INVALID_DATA); } if (data[IDX_FrameH] != 0xfe || data[IDX_FrameH + 1] != 0x43 || data[IDX_FrameH + 2] != 0x58 || data[IDX_FRAMEL] != 0xef) { return((int)Errors.ERR_INVALID_DATA); } byte check = data[IDX_CHSUM]; if (check != ValueHelper.CheckXor(data, 0, IDX_CHSUM)) { return((int)Errors.ERR_CRC); } return((int)Errors.SUCCESS); }
private int IsValid(byte[] data) { if (data.Length != 28) { return((int)Errors.ERR_INVALID_DATA); } if (data[IDX_FrameH] != 0xfe || data[IDX_FrameH + 1] != 0x54 || data[IDX_FrameH + 2] != 0x46 || data[IDX_FrameH + 3] != 0x4c || data[IDX_FRAMETAIL_RESP] != 0xef) { return((int)Errors.ERR_INVALID_DATA); } byte check = data[IDX_CHSUM_Resp]; if (check == ValueHelper.CheckXor(data, 0, IDX_CHSUM_Resp)) { return((int)Errors.SUCCESS); } return((int)Errors.ERR_CRC); }
private int IsValid(byte[] data) { if (data.Length < 24 || data.Length > 26) { return((int)Errors.ERR_INVALID_DATA); } if (data[IDX_FrameH] != 0xfe || data[IDX_FrameH + 1] != 0x46 || data[IDX_FrameH + 2] != 0x41 || data[IDX_FrameH + 3] != 0x53 || data[data.Length - 1] != 0xef) { return((int)Errors.ERR_INVALID_DATA); } var xorValue = data[data.Length - 2]; var xorCalc = 0; xorCalc = data.Length == 25 ? ValueHelper.CheckXor(data, 0, data.Length - 3) : ValueHelper.CheckXor(data, 0, data.Length - 2); if (xorCalc == xorValue) { return((int)Errors.SUCCESS); } return((int)Errors.ERR_CRC); }
public int IsValid(byte[] data) { if (data == null || data.Length != data[IDX_FLAMELEN]) { return((int)Errors.ERR_INVALID_DATA); } if (data[IDX_FLAG] != 0xAA) { return((int)Errors.ERR_INVALID_DATA); } if (data[IDX_CMD] != 0 && data[IDX_CMD] != 0x10) { return((int)Errors.ERR_INVALID_DATA); } var xor = data[data.Length - 1]; if (xor == ValueHelper.CheckXor(data, 0, data.Length - 2)) { return((int)Errors.SUCCESS); } return((int)Errors.ERR_CRC); }
public void Request(ref SensorAcqResult sensorAcq) { try { DateTime time = DateTime.Now; byte[] package = new byte[10]; package[IDX_FLAG] = 0x55; package[IDX_FLAMELEN] = 0x0A; package[IDX_CMD] = 0x00; package[IDX_TIME] = Convert.ToByte(time.Year.ToString().Substring(2, 2)); package[IDX_TIME + 1] = (byte)time.Month; package[IDX_TIME + 2] = (byte)time.Day; if (time.Minute < 30) { package[IDX_TIME + 3] = (byte)(time.Hour - 1); } else { package[IDX_TIME + 3] = (byte)(time.Hour); } package[IDX_HOURSCOUNT] = 1; package[IDX_CHECK] = 0; // 每周进行一次时间同步 if (time.DayOfWeek == DayOfWeek.Sunday && (time.Hour == 0 && time.Minute < 30)) { package[IDX_CMD] = 0x10; package[IDX_TIME + 3] = (byte)time.Minute; } package[IDX_CHECK + 1] = ValueHelper.CheckXor(package, 0, IDX_CHECK); sensorAcq.ErrorCode = (int)Errors.SUCCESS; sensorAcq.Request = package; } catch { sensorAcq.Request = null; sensorAcq.ErrorCode = (int)Errors.ERR_UNKNOW; } }
public int IsValid(byte[] data) { if (data == null || data.Length != 13) { return((int)Errors.ERR_INVALID_DATA); } if (data[0] != 0x24 && data[12] != 0x0D) { return((int)Errors.ERR_INVALID_DATA); } byte[] check = { data[data.Length - 3], data[data.Length - 2] }; byte result = ValueHelper.CheckXor(data, 1, data.Length - 3); byte high = (byte)char.Parse((((byte)(result & 0xf0) >> 4).ToString("X"))); byte low = (byte)char.Parse((((byte)(result & 0x0f)).ToString("X"))); if ((check[0] == high) && (check[1] == low)) { return((int)Errors.SUCCESS); } return((int)Errors.ERR_CRC); }
private const int IDX_FRAMETAIL_RESP = 27; // 帧尾=0xef #region Implementation of ISensorAdapter public void Request(ref SensorAcqResult sensorAcq) { try { if (sensorAcq.Sensor.ModuleNo > ushort.MaxValue || sensorAcq.Sensor.ModuleNo < ushort.MinValue) { sensorAcq.ErrorCode = (int)Errors.ERR_INVALID_MODULE; sensorAcq.Request = null; return; } var packet = new byte[19]; packet[IDX_FrameH] = 0xfe; packet[IDX_FrameH + 1] = 0x46; packet[IDX_FrameH + 2] = 0x41; packet[IDX_FrameH + 3] = 0x53; packet[IDX_FRAME_LEN] = 19; ValueHelper.WriteUShort_BE(packet, IDX_DEST, (ushort)sensorAcq.Sensor.ModuleNo); packet[IDX_CMD] = 0x01; byte control = 0; //int range = si.Parameters != null && si.ParamCount >= 3 ? (int) si.Parameters[3].Value : 1; //Id Range //1 0~5V //2 -5~5V //3 0~10V //4 -10~10V var range = (VoltageSensorRange)EnumHelper.GetItemFromDesc(typeof(VoltageSensorRange), sensorAcq.Sensor.ProductCode); switch (range) { case VoltageSensorRange.FSLF10: control = 0x40; // 0x47 break; case VoltageSensorRange.FSLF25: control = 0x41; // 0x4f break; case VoltageSensorRange.FSLF50: control = 0x50; // 0x57 break; case VoltageSensorRange.FSLF100: control = 0x51; // 0x5f break; case VoltageSensorRange.FS_LFV_V0P5: control = 0x40; break; case VoltageSensorRange.FS_LFV_V0P10: control = 0x50; break; case VoltageSensorRange.FS_LFV_VM5P5: control = 0x48; break; case VoltageSensorRange.FS_LFV_VM10P10: control = 0x58; break; default: control = 0x40; break; } control = (byte)(control | (byte)(0x07 & (byte)(sensorAcq.Sensor.ChannelNo - 1))); packet[IDX_CONTENT] = control; packet[IDX_CONTENT + 1] = (byte)(sensorAcq.Sensor.ChannelNo); packet[IDX_CHSUM_Req] = ValueHelper.CheckXor(packet, 0, IDX_CHSUM_Req); packet[IDX_FRAMETAIL_REQ] = 0xef; sensorAcq.ErrorCode = (int)Errors.SUCCESS; sensorAcq.Request = packet; } catch { sensorAcq.Request = null; sensorAcq.ErrorCode = (int)Errors.ERR_UNKNOW; } }