private TFrameEndSignalRes TransmitFrame(out byte[] buff, ICommunicationLayer ComPortCli) { buff = get_buffor(); NULL_message message = pool.GetEmptyISesDBuffer(); message.userDataLength = (ushort)buff.Length; for (int i = 0; i < buff.Length; i++) { message.WriteByte(buff[i]); } // czas na wyslanie ramki: ComPortCli.Flush(); string msg = "sending frame: " + buff.Length.ToString() + " size"; m_TraceSource.TraceVerbose(382, "TransmitFrame", msg); TFrameEndSignalRes lastRes = ComPortCli.FrameEndSignal(message); m_TraceSource.TraceVerbose(382, "TransmitFrame", "Frame has been sent"); message.ReturnEmptyEnvelope(); return(lastRes); }
/// <summary> /// Transmits the data contained in the frame. /// </summary> /// <param name="frame">Frame with the data to be transmitted.</param> /// <returns> /// Success: /// Operation accomplished successfully /// DisInd: /// Disconnect indication – connection has been shut down remotely or lost because of communication error. /// Data is unavailable /// </returns> TFrameEndSignalRes ICommunicationLayer.FrameEndSignal(CommunicationLayer.UMessage frame) { TFrameEndSignalRes cRes = TFrameEndSignalRes.Success; try { if (!m_SerialPort.IsOpen) { TraceEvent(TraceProgError, 190, "FrameEndSignal is called while in {0} state.", CurrentLayerState); Debug.Assert(CurrentLayerState != LayerState.Connected); return(TFrameEndSignalRes.DisInd); } byte[] cDataOut = frame.GetManagedBuffer(); m_SerialPort.Write(cDataOut, 0, cDataOut.Length); Console.WriteLine("FrameEndSignal:" + this.ToString() + "; " + frame.ToString()); } catch (TimeoutException timeoutex) { TraceEvent(TraceCommError, 199, "FrameEndSignal: TimeoutException cought from the underling layer: " + timeoutex.Message); // chyba zawsze powinnismy poinformowac warstwe wyzsza - bo przeciez skoro zapisujemy - to myslelismy ze jest polaczenie //(moze i port jest otworzony, lub zamkniety - ale stan naszego communication layer moze byc zupelnie inny) MarkException("FrameEndSignal: TimeoutException cought from the underling layer", TraceCommError, 205, timeoutex); cRes = TFrameEndSignalRes.DisInd; } catch (Exception ex) { if (m_SerialPort.IsOpen) { TraceEvent(TraceCommError, 205, "FrameEndSignal: Exception cought from the underling layer: " + ex.Message); } else { MarkException("FrameEndSignal: Exception cought from the underling layer", TraceCommError, 205, ex); cRes = TFrameEndSignalRes.DisInd; } } return(cRes); }