/// <summary> /// Xử lý sau kkhi nhận được dữ liệu /// </summary> public override void ProcessRawData() { try { var allbyte = ByteData; _tempbuffer = string.Concat(_tempbuffer, Encoding.ASCII.GetString(allbyte)); foreach (var onebyte in allbyte) { if (onebyte.Equals((byte)DeviceHelper.ENQ)) { Log.Debug(@"CobasE6000: <ENQ>"); _objAstm.CallGetENQ(_objDataEventArgs); DumpStateMachine(_objWorkFlowRuntime, _instanceId); //SendByte((byte)DeviceHelper.ACK); //RaiseEventSendENQToWF(null, onebyte); _bufferData = _tempbuffer = string.Empty; } else if (onebyte.Equals((byte)DeviceHelper.LF)) { Log.Debug("CobasE6000: {0}", _tempbuffer); var temp = DeviceHelper.GetStringAfterCheckSum(_tempbuffer); _tempbuffer = string.Empty; if (temp != string.Empty) { //SendStringData(DeviceHelper.ACK.ToString()); _objAstm.CallGetRightFrame(_objDataEventArgs); _bufferData = string.Concat(_bufferData, temp); } else { //SendByte((byte)DeviceHelper.NAK); _objAstm.CallGetWrongFrame(_objDataEventArgs); } } else if (onebyte.Equals((byte)DeviceHelper.EOT)) { Log.Debug(@"CobasE6000: <EOT>"); _objAstm.CallGetEOT(_objDataEventArgs); ProcessData(); //Send((int)EventID.GetEOT,_newQuery); } else if (onebyte.Equals((byte)DeviceHelper.ACK)) { //Send((int) EventID.GetACK); Log.Debug(@"CobasE6000: <ACK>"); _objAstm.CallGetACK(_objDataEventArgs); if ((_currentOrder != null) && (_currentOrder.Count != 0) && (_currentOrderIdx < _currentOrder.Count)) { _prvLastStringRequest = _currentOrder[_currentOrderIdx]; _currentOrderIdx++; SendStringData(_prvLastStringRequest); Log.Debug("Host: {0}", _prvLastStringRequest); } else { //SendByte((byte)DeviceHelper.EOT); Log.Debug(@"Session closing ..."); _objAstm.CallCloseSession(_objDataEventArgs); if (_prvRequestArray != null && _prvRequestArray.Count != 0) { _objAstm.CallGetQuery(_objDataEventArgs); } } } else if (onebyte.Equals((byte)DeviceHelper.NAK)) { Log.Debug(@"CobasE6000: <NAK>"); _objAstm.CallGetNAK(_objDataEventArgs); SendStringData(_prvLastStringRequest); } } } catch (Exception ex) { Log.FatalException("Fatal Error: ", ex); } finally { ClearData(); } }
/// <summary> /// Hàm được gọi khi có sự kiện dữ liệu tồn tại trên cổng COM của thiết bị /// </summary> /// <param name="obj"></param> public override void OnInCommingData(object obj) { try { // Chuyển kiểu dữ liệu về dạng DataReceiveRs232 do lớp Base Devices chỉ gửi Object var rawData = (DataReceiveRs232)obj; if (rawData != null) { // Nếu chưa gán Port thì gán SetNetStream(rawData.Port); byte[] allbyte = rawData.Data; _tempbuffer = string.Concat(_tempbuffer, Encoding.ASCII.GetString(allbyte)); for (int i = 0; i < allbyte.Length; ++i) { byte onebyte = allbyte[i]; if (onebyte.Equals((byte)DeviceHelper.ENQ)) { Log.Debug(@"Centaur: <ENQ>"); DumpStateMachine(objWorkFlowRuntime, InstanceId); objASTM.CallGetENQ(objDataEventArgs); //SendByte((byte)DeviceHelper.ACK); //RaiseEventSendENQToWF(null, onebyte); BufferData = _tempbuffer = string.Empty; _timeoutManager.Start(); } else if (onebyte.Equals((byte)DeviceHelper.LF)) { Log.Debug("Centaur: {0}", _tempbuffer); _timeoutManager.Stop(); string temp = DeviceHelper.GetStringAfterCheckSum(_tempbuffer); _tempbuffer = string.Empty; if (temp != string.Empty) { //SendStringData(DeviceHelper.ACK.ToString()); objASTM.CallGetRightFrame(objDataEventArgs); BufferData = string.Concat(BufferData, temp); } else { //SendByte((byte)DeviceHelper.NAK); objASTM.CallGetWrongFrame(objDataEventArgs); } _timeoutManager.Start(); } else if (onebyte.Equals((byte)DeviceHelper.EOT)) { Log.Debug(@"Centaur: <EOT>"); objASTM.CallGetEOT(objDataEventArgs); _timeoutManager.Stop(); ProcessData(); //Send((int)EventID.GetEOT,_newQuery); } else if (onebyte.Equals((byte)DeviceHelper.ACK)) { //Send((int) EventID.GetACK); Log.Debug(@"Centaur: <ACK>"); DumpStateMachine(objWorkFlowRuntime, InstanceId); _timeoutManager.Stop(); objASTM.CallGetACK(objDataEventArgs); if (((PrvRequestArray != null) && (PrvRequestArray.Count != 0)) && (_lastState == 0)) { _lastState++; prvLastStringRequest = PrvRequestArray.Dequeue(); Log.Debug("Send String Data: {0}", prvLastStringRequest); SendStringData(prvLastStringRequest); _timeoutManager.Start(); } else { //SendByte((byte)DeviceHelper.EOT); _timeoutManager.Stop(); Log.Debug(@"Session closing ..."); objASTM.CallCloseSession(objDataEventArgs); if (PrvRequestArray != null && PrvRequestArray.Count != 0) { objASTM.CallGetQuery(objDataEventArgs); _lastState = 0; _timeoutManager.Start(); } } } else if (onebyte.Equals((byte)DeviceHelper.NAK)) { _timeoutManager.Stop(); Log.Debug(@"Centaur: <NAK>"); if (++_failSending < 5) { if (_lastState > 0) { objASTM.CallGetNAK(objDataEventArgs); SendStringData(prvLastStringRequest); } else { Log.Debug(@"Get NAK. Session closing ..."); objASTM.CallCloseSession(objDataEventArgs); } _timeoutManager.Start(); } else { Log.Error("Too much NAK! Session closed!"); objASTM.CallCloseSession(objDataEventArgs); } } } } } catch (Exception ex) { Log.FatalException("Fatal Error: ", ex); } }
public override void ProcessRawData() { try { byte[] allbyte = ByteData; Log.Trace(allbyte); _tempbuffer = string.Concat(_tempbuffer, Encoding.ASCII.GetString(allbyte)); for (int i = 0; i < allbyte.Length; ++i) { byte onebyte = allbyte[i]; if (onebyte.Equals((byte)DeviceHelper.ENQ)) { objASTM.CallGetENQ(objDataEventArgs); //DumpStateMachine(objWorkFlowRuntime, InstanceId); //SendByte((byte)DeviceHelper.ACK); //RaiseEventSendENQToWF(null, onebyte); BufferData = _tempbuffer = string.Empty; } else if (onebyte.Equals((byte)DeviceHelper.LF)) { string temp = DeviceHelper.GetStringAfterCheckSum(_tempbuffer); Log.Trace(temp); _tempbuffer = string.Empty; if (temp != string.Empty) { //SendStringData(DeviceHelper.ACK.ToString()); objASTM.CallGetRightFrame(objDataEventArgs); BufferData = BufferData.StartsWith(@"R") ? string.Format("{0}{1}{2}", BufferData, DeviceHelper.CR, temp) : string.Concat(BufferData, temp); } else { //SendByte((byte)DeviceHelper.NAK); objASTM.CallGetWrongFrame(objDataEventArgs); } } else if (onebyte.Equals((byte)DeviceHelper.EOT)) { objASTM.CallGetEOT(objDataEventArgs); ProcessData(); //Send((int)EventID.GetEOT,_newQuery); } else if (onebyte.Equals((byte)DeviceHelper.ACK)) { //Send((int) EventID.GetACK); objASTM.CallGetACK(objDataEventArgs); if ((PrvRequestArray != null) && (PrvRequestArray.Count != 0)) { prvLastStringRequest = PrvRequestArray[0]; PrvRequestArray.RemoveAt(0); SendStringData(prvLastStringRequest); } else { //SendByte((byte)DeviceHelper.EOT); objASTM.CallCloseSession(objDataEventArgs); } } else if (onebyte.Equals((byte)DeviceHelper.NAK)) { //Send((int)EventID.GetNAK); objASTM.CallGetNAK(objDataEventArgs); SendStringData(prvLastStringRequest); } } } catch (Exception ex) { Log.Error(String.Format("Error While Process Raw Data: {0}", ex)); } finally { ClearData(); } }