/// <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. To reestablisch the communication the <see cref="IConnectionManagement.ConnectReq"/> /// must be called first. /// </returns> TFrameEndSignalRes ICommunicationLayer.FrameEndSignal(CommunicationLayer.UMessage frame) { if (!IsConnected) { return(TFrameEndSignalRes.DisInd); } try { Debug.Assert(m_Socket != null, "We can send a frame only after creating the socket, it can be disposed but must exist"); if (m_Socket.Connected) { m_Socket.Send(frame.GetManagedBuffer()); return(TFrameEndSignalRes.Success); } this.TraceEvent(TraceEventType.Information, 712, "FrameEndSignal: Disconnected by the remote station."); } catch (SocketException ex) { MarkSocketException(ex, 718); } catch (ObjectDisposedException ex) { MarkSocketException(ex, 723); } catch (Exception ex) { MarkException(String.Format(m_ExceptionMesage, ex.Message), TraceEventType.Error, 728, ex); } return(TFrameEndSignalRes.DisInd); }
/// <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); }