public void WriteSendMessage(SECSMessage msg) { if (msg == null) { this.logger.Error("WriteSendMessage msg == null"); return; } byte[] bs = null; try { bs = new SECSEncoding(msg).GetEncodingData((int)msg.DeviceIdID, msg.WBit, msg.SystemBytes); if (bs.Length > 0 && msg.WBit) { this.mHsmsTimer.StartT3Timer(msg); this.logger.Debug(string.Format("WriteSendMessage: StartT3Timer {0}", msg.SystemBytes)); } } catch (Exception exception) { this.logger.Error("WriteSendMessage: encoder", exception); SECSTransaction t = msg.Transaction; if (this.OnWriteError != null) { this.OnWriteError(SECSEventType.PrimarySent, t, string.Format("{0}: Invalid SECS Message Format or Data.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.WriteError))); } } if (bs != null && bs.Length > 0) { try { this.writer.Write(bs); this.writer.Flush(); //this.logger.Info(string.Format("[SEND] S{0}F{1} {2} SystemBytes={3}\n{4}", new object[] //{ // msg.Stream, // msg.Function, // msg.WBit ? "W" : "", // msg.SystemBytes, // ByteStringBuilder.ToLogString(bs) //})); //this.logger.Warn("[SEND] " + SecsItem2Str.GetSecsMessageStr(msg)); if (this.OnWriteCompleted != null) { this.OnWriteCompleted(false, msg); } } catch (Exception exception2) { this.logger.Error("WriteSendMessage", exception2); SECSTransaction transaction = msg.Transaction; if (this.OnWriteError != null) { this.OnWriteError(SECSEventType.PrimarySent, transaction, string.Format("{0}: Socket Error.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.WriteError))); } this.FireDisconnect(exception2.Message); } } }
protected override void Run() { while (this.running) { try { if (this.SendMsg == null && this.sendQueue.Count > 0) { lock (this.syncObject) { this.SendMsg = this.sendQueue.Dequeue(); } } if (this.SendMsg != null && this.secs1.PortStatus == eSECS1_PORT_STATUS.PortIdle) { lock (this.syncObject) { byte[] encodingBytes = new SECSEncoding(this.SendMsg).GetEncodingData((int)this.SendMsg.DeviceIdID, this.SendMsg.WBit, this.SendMsg.SystemBytes); this.SendBlocks = this.GetSECS1Bytes(encodingBytes); this.SendBlock = this.SendBlocks.Dequeue(); while (this.secs1.UpdatePortStatus(eSECS1_PORT_STATUS.PortIdle, eSECS1_PORT_STATUS.PortCtrl) != 0) { Thread.Sleep(50); } this.secs1.StopTimer(eTimeout.T2); this.secs1.SendENQ(); this.RetryCount = this.secs1.SECS1Para.RetryCount; } } } catch (Exception exception) { this.logger.Error("HSMSTimer.Run ", exception); } Thread.Sleep(50); } }