/// <summary> /// Read Data /// </summary> /// <param name="block">Block description to be read</param> /// <param name="station">Address of the remote station connected to the common field bus. –1 if not applicable. /// </param> /// <param name="data">The buffer with the requested data.</param> /// <param name="retries">Number of retries to get data.</param> /// <returns>Result of the operation</returns> AL_ReadData_Result IApplicationLayerMaster.ReadData(IBlockDescription block, int station, out IReadValue data, byte retries) { lock (this) { m_rPackNum++; data = null; myStatistic.IncStTxFrameCounter(); if ((m_errorfrequency > 0) && (m_rPackNum % (ulong)m_errorfrequency == 0)) { myStatistic.IncStRxFragmentedCounter(); myStatistic.RxDataBlock(false); return(AL_ReadData_Result.ALRes_DatTransferErrr); } data = (IReadValue)pool.GetEmptyISesDBuffer(); // Processes.Timer.Wait(Processes.Timer.TInOneSecond/4); ((NULL_message)data).SetBlockDescription(station, block); ((NULL_message)data).ReadFromDB(); bool success = true; if (CommunicationThroughCommunicationLayer) { success = SendReceive(); } if (success) { myStatistic.IncStRxFrameCounter(); } myStatistic.RxDataBlock(success); return(AL_ReadData_Result.ALRes_Success); } }
/// <summary> /// Send values to the data provider /// </summary> /// <param name="data"> /// Data to be send. Always null after return. Data buffer must be returned to the pool. /// </param> /// <param name="retries">Number of retries to wrtie data.</param> /// <returns>Result of the operation.</returns> AL_ReadData_Result IApplicationLayerMaster.WriteData(ref IWriteValue data, byte retries) { lock (this) { InterFrameStopwatch.Reset(); InterFrameStopwatch.Start(); m_wPackNum++; myStatistic.IncStTxFrameCounter(); if ((m_errorfrequency > 0) && (m_rPackNum % (100 / (ulong)m_errorfrequency)) == 0) { data.ReturnEmptyEnvelope(); data = null; myStatistic.IncStRxFragmentedCounter(); myStatistic.TxDataBlock(false); return(AL_ReadData_Result.ALRes_DatTransferErrr); } ((Message)data).WriteToDB(); data.ReturnEmptyEnvelope(); data = null; myStatistic.IncStTxFrameCounter(); myStatistic.IncStRxFrameCounter(); myStatistic.TxDataBlock(true); myStatistic.TimeMaxResponseDelayAdd(InterFrameStopwatch.ElapsedMilliseconds); return(AL_ReadData_Result.ALRes_Success); } }