/// <summary> /// 发送数据消费者,每隔50ms读取队列数据,通过USB发送数据 /// </summary> public void UsbTxStart() { latch.Acquire(); while (NeedRunning) { var list = txQueue.PopAll(); foreach (var np in list) { try { var data = np.encode(); int len = data.Length; usb.sendDataSynchronous(ref data, ref len); LogHelper.GetLogger <ProcThread>().Debug("Send Data: " + ByteHelper.Byte2ReadalbeXstring(data)); } catch (Exception ex) { LogHelper.GetLogger <ProcThread>().Error(string.Format("Send data Error. Reason: {0}, Detail: {1}.", ex.ToString(), ex.StackTrace)); } } if (!NeedRunning) { break; } Thread.Sleep(50); } }
protected string PrintOriginalData() { string originalData = ""; if (this.OriginalBytes != null && this.OriginalBytes.Data != null) { originalData = string.Format("接收到的原始数据为: {0}", ByteHelper.Byte2ReadalbeXstring(this.OriginalBytes.Data)); } return(originalData); }
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) { MotorProtocol mp = motorProtocol.DePackage(obytes.Data); byte[] data = mp.CodeRegion; byte commandCode = data[0]; byte additionCode = data[1]; MotorBaseResponse mr = Decoders[commandCode].Decode(obytes); if (mr != null) { RxMsgQueue.Push(mr); LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}", ByteHelper.Byte2ReadalbeXstring(obytes.Data))); } } } } } } Thread.Sleep(10); } }
public void UsbRxStart() { latch.Acquire(); while (NeedRunning) { try { byte[] data; if (usb.readDataSynchronous(out data)) { //rxQueue.Push(data); LogHelper.GetLogger <ProcThread>().Debug(string.Format("Received Data: {0}", ByteHelper.Byte2ReadalbeXstring(data))); } } catch (Exception ex) { LogHelper.GetLogger <ProcThread>().Error(string.Format("Received data Error. Reason: {0}, Detail: {1}.", ex.ToString(), ex.StackTrace)); } } }
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) { LaserProtocol lp = laserProtocol.DePackage(obytes.Data); byte[] data = lp.Body; byte markHead = data[0]; byte type = GetMsgType(); byte[] appData = new byte[data.Length - 2]; Array.Copy(data, 1, appData, 0, data.Length - 2); LaserBasePackage bp = new LaserBasePackage(markHead, type, appData); List <LaserBaseResponse> responseList = Decoder.Decode(bp, obytes); if (responseList != null && responseList.Count > 0) { RxMsgQueue.Push(responseList); } LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}", ByteHelper.Byte2ReadalbeXstring(obytes.Data))); } } } } Thread.Sleep(10); } }