public void DecodeInternal() { while (RunDecodeThread) { if (Decode) { List <Original> list = RxQueue.PopAll(); if (list != null && list.Count > 0) { foreach (var o in list) { OriginalBytes obytes = o as OriginalBytes; if (o != null && obytes.Data.Count() == 6) { LaserBaseResponse responseList = Decoder.Decode(obytes); if (responseList != null) { RxMsgQueue.Push(responseList); } //LogHelper.GetLogger<LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}", // ByteHelper.Byte2ReadalbeXstring(obytes.Data))); } } } } Thread.Sleep(10); } }
/// <summary> /// 发送消息之前必须先设置解码器 /// </summary> /// <param name="type"></param> public void SetDecoder(byte type) { if (Decoders.ContainsKey(type)) { Decoder = Decoders[type]; } }
private void InitializeDecoders() { Decoders = new Dictionary <byte, LaserBaseResponse>(); Decoders[0x00] = new LaserC00Response(); Decoders[0x01] = new LaserC01Response(); Decoders[0x03] = new LaserC03Response(); Decoders[0x04] = new LaserC04Response(); Decoders[0x05] = new LaserC05Response(); Decoders[0x06] = new LaserC06Response(); Decoders[0x07] = new LaserC07Response(); Decoders[0x08] = new LaserC08Response(); Decoders[0x09] = new LaserC09Response(); Decoders[0x0B] = new LaserC0BResponse(); Decoders[0x0C] = new LaserC0CResponse(); Decoders[0x70] = new LaserC70Response(); Decoders[0x71] = new LaserC71Response(); Decoders[0x72] = new LaserC72Response(); Decoders[0x73] = new LaserC73Response(); Decoders[0x74] = new LaserC74Response(); Decoders[0x75] = new LaserC75Response(); Decoders[0x76] = new LaserC76Response(); //initialize default decoder Decoder = Decoders[0x00]; }