/// <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); } }
/// <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) { ((NULL_message)data).WriteToDB(); data.ReturnEmptyEnvelope(); myStatistic.IncStTxFrameCounter(); myStatistic.IncStRxFrameCounter(); myStatistic.TxDataBlock(true); 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> /// ALRes_Success: Operation accomplished successfully /// ALRes_DatTransferErrr: Data transfer is imposible because of a communication error – loss of /// communication with a station /// ALRes_DisInd: Disconnect indication – connection has been shut down remotely or lost because of /// communication error. Data is unavailable /// </returns> AL_ReadData_Result IApplicationLayerMaster.WriteData(ref IWriteValue data, byte retries) { if (!m_protocol.GetICommunicationLayer.Connected) { return(AL_ReadData_Result.ALRes_DisInd); } AL_ReadData_Result response = TxGetResponse((T_ALMessage)data, retries); data.ReturnEmptyEnvelope(); data = null; m_protocol.GetIProtocolParent.TxDataBlock(response == AL_ReadData_Result.ALRes_Success); return(response); }
private void WriteOperation(ref long bytesCounter) { m_Block.Change(m_RegisterAddress, m_Length, m_ResourceSelected); m_OperationResult.Log.Add(String.Format(Properties.Resources.OperationLogHeaderFormat, m_Block.dataType, m_Block.length, m_Block.startAddress, StationAddress, "Write")); IWriteValue _value = ApplicationLayerMaster.GetEmptyWriteDataBuffor(m_Block, m_StationAddress); for (int _vix = 0; _vix < m_RegistersCount; _vix++) { _value.WriteValue(m_ValueToBeWritten, _vix); } bytesCounter += ((ProtocolALMessage)_value).userDataLength; ApplicationLayerMaster.WriteData(ref _value, c_Retries); }
public static void Set( [NotNull] this IWriteValue <string> writeValue, [NotNull] string key, object value) { if (writeValue == null) { throw new ArgumentNullException(nameof(writeValue)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } writeValue.Set(key, value.ToType <string>()); }
public void GoTest() { FacadeApplicationLayerMaster m_Master = new FacadeApplicationLayerMaster(); string m_MasterToString = m_Master.ToString(); GuardedDataProvider m_gp = new GuardedDataProvider("GoTest", m_Master); string m_gpToString = m_gp.ToString(); Assert.AreEqual(m_gpToString, m_MasterToString, "ToString error"); StringAddress m_address = new StringAddress("DummyAddress"); Assert.IsFalse(m_gp.Connected, "State error"); m_gp.ConnectReq(m_address); Assert.IsTrue(m_gp.Connected, "State error"); FacadeBlockDescription m_block = new FacadeBlockDescription(int.MaxValue, 100, short.MaxValue); IReadValue m_readVal; switch (m_gp.ReadData(m_block, int.MaxValue, out m_readVal, byte.MaxValue)) { case AL_ReadData_Result.ALRes_DatTransferErrr: case AL_ReadData_Result.ALRes_DisInd: Assert.Fail("incorrect return value from ReadData"); break; case AL_ReadData_Result.ALRes_Success: Assert.IsNotNull(m_readVal, "ReadData returned null"); m_readVal.ReturnEmptyEnvelope(); break; } Assert.IsTrue(m_gp.Connected, "State error"); IWriteValue m_writeVal = m_gp.GetEmptyWriteDataBuffor(m_block, int.MaxValue); m_writeVal.WriteValue(int.MaxValue, 0); switch (m_gp.WriteData(ref m_writeVal, byte.MaxValue)) { case AL_ReadData_Result.ALRes_DatTransferErrr: case AL_ReadData_Result.ALRes_DisInd: Assert.Fail("incorrect return value from ReadData"); break; case AL_ReadData_Result.ALRes_Success: Assert.IsNull(m_writeVal, "WriteData has not returned the envelope to a pool"); break; } Assert.IsTrue(m_gp.Connected, "State error"); m_gp.DisReq(); Assert.IsFalse(m_gp.Connected, "State error"); m_gp.Dispose(); }
/// <summary> /// Writes process data down to the selected location and device resources. /// </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> /// <see cref="AL_ReadData_Result"/> result of the operation. /// </returns> public AL_ReadData_Result WriteData(ref IWriteValue data, byte retries) { try { return(mDataProvider.WriteData(ref data, retries)); } catch (Exception ex) { if ((data != null) && !data.InPool) { data.ReturnEmptyEnvelope(); } data = null; TraceException(ex, 72); return(AL_ReadData_Result.ALRes_DatTransferErrr); } }
/// <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) { m_wPackNum++; myStatistic.IncStTxFrameCounter(); if ((m_errorfrequency > 0) && (m_wPackNum % (ulong)m_errorfrequency == 0)) { data.ReturnEmptyEnvelope(); data = null; myStatistic.IncStRxFragmentedCounter(); myStatistic.TxDataBlock(false); return(AL_ReadData_Result.ALRes_DatTransferErrr); } ((NULL_message)data).WriteToDB(); data.ReturnEmptyEnvelope(); data = null; myStatistic.IncStRxFrameCounter(); myStatistic.TxDataBlock(true); return(AL_ReadData_Result.ALRes_Success); }
public void Write <T>(IKpk12MeasuringUnit unit, IWriteValue <T> value, string source) { ThrowIfRegisterNull(value.Register); var register = value.Register; try { ((Register <T>)register).Value = value.Expected; unit.Write(register); var message = _formatter.For(register) .With(value) .ModuleId(unit.UnitIdRegister.Value) .Request(); _logger.Info(message, source); } catch (Exception exception) { _logger.Error(string.Format("Ошибка записи регистра '{0}' модуль '{1}'", register.Address, unit.UnitIdRegister.Value), source, exception); throw; } }
public AL_ReadData_Result WriteData(ref IWriteValue data, byte retries) { Assert.IsTrue(myConnected, "Must be connected while WriteData"); MonitorEnter(); data.ReturnEmptyEnvelope(); data = null; myNumberOfWriteOperations++; if (myBreakConnection) { myBreakConnection = false; myMakeError = false; myConnected = false; MonitorExit(); return(AL_ReadData_Result.ALRes_DisInd); } if (!myMakeError) { MonitorExit(); return(AL_ReadData_Result.ALRes_Success); } myMakeError = false; MonitorExit(); return(AL_ReadData_Result.ALRes_DatTransferErrr); }
void DoBusyBeaver() { long startBytes = System.GC.GetTotalMemory(true); int startTime = Environment.TickCount; graph = new Turing3Graph(); actions = new Turing3Actions(graph); procEnv = new LGSPGraphProcessingEnvironment(graph, actions); // Initialize tape BandPosition bp = graph.CreateNodeBandPosition(); // Initialize states State sA = graph.CreateNodeState(); procEnv.SetVariableValue("sA", sA); State sB = graph.CreateNodeState(); procEnv.SetVariableValue("sB", sB); State sC = graph.CreateNodeState(); procEnv.SetVariableValue("sC", sC); State sD = graph.CreateNodeState(); procEnv.SetVariableValue("sD", sD); State sE = graph.CreateNodeState(); procEnv.SetVariableValue("sE", sE); State sH = graph.CreateNodeState(); procEnv.SetVariableValue("sH", sH); // Create state transitions GenStateTransition("sA", 0, "sB", 1, L); GenStateTransition("sA", 1, "sD", 1, L); GenStateTransition("sB", 0, "sC", 1, R); GenStateTransition("sB", 1, "sE", 0, R); GenStateTransition("sC", 0, "sA", 0, L); GenStateTransition("sC", 1, "sB", 0, R); GenStateTransition("sD", 0, "sE", 1, L); GenStateTransition("sD", 1, "sH", 1, L); GenStateTransition("sE", 0, "sC", 1, R); GenStateTransition("sE", 1, "sC", 1, L); // Initialize head procEnv.SetVariableValue("curState", sA); procEnv.SetVariableValue("curPos", bp); // A little warm up for the beaver // Using a graph rewrite sequence with the new and more expressive syntax procEnv.ApplyGraphRewriteSequence( @"( ((curValue:WriteValue)=readOneRule(curState, curPos) || (curValue)=readZeroRule(curState,curPos)) && (ensureMoveLeftValidRule(curValue, curPos) || ensureMoveRightValidRule(curValue, curPos) || true) && ((curState, curPos)=moveLeftRule(curValue, curPos) || (curState, curPos)=moveRightRule(curValue, curPos)) )[100]"); Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found."); // Reset counters of the PerformanceInfo object procEnv.PerformanceInfo.Reset(); // Calculate search plans to optimize performance graph.AnalyzeGraph(); actions.GenerateActions("readOneRule", "readZeroRule", "ensureMoveLeftValidRule", "ensureMoveRightValidRule", "moveLeftRule", "moveRightRule"); // Go, beaver, go! #if USE_SEQUENCE procEnv.ApplyGraphRewriteSequence( @"( ((curValue:WriteValue)=readOneRule(curState, curPos) || (curValue)=readZeroRule(curState,curPos)) && (ensureMoveLeftValidRule(curValue, curPos) || ensureMoveRightValidRule(curValue, curPos) || true) && ((curState, curPos)=moveLeftRule(curValue, curPos) || (curState, curPos)=moveRightRule(curValue, curPos)) )*"); #else // the graph rewrite sequence from above formulated in C# with the API of GrGen.NET 2.5 IState curState = (IState)procEnv.GetVariableValue("curState"); IBandPosition curPos = (IBandPosition)procEnv.GetVariableValue("curPos"); IWriteValue curValue = (IWriteValue)procEnv.GetVariableValue("curValue"); bool expressionToIterateSucceeded; do { expressionToIterateSucceeded = (actions.readOneRule.Apply(procEnv, curState, curPos, ref curValue) || actions.readZeroRule.Apply(procEnv, curState, curPos, ref curValue)) && (actions.ensureMoveLeftValidRule.Apply(procEnv, curValue, curPos) || actions.ensureMoveRightValidRule.Apply(procEnv, curValue, curPos) || true) && (actions.moveLeftRule.Apply(procEnv, curValue, curPos, ref curState, ref curPos) || actions.moveRightRule.Apply(procEnv, curValue, curPos, ref curState, ref curPos)); }while(expressionToIterateSucceeded); #endif int stopTime = Environment.TickCount; // Count "BandPosition" nodes with a "value" attribute being one int numOnes = 0; foreach (BandPosition bpNode in graph.GetExactNodes(BandPosition.TypeInstance)) { if (bpNode.value == 1) { numOnes++; } } int countTime = Environment.TickCount - stopTime; Console.WriteLine(procEnv.PerformanceInfo.MatchesFound + " matches found." + "\nNumber of ones written: " + numOnes + "\nTime needed for counting ones: " + countTime + " ms"); long endBytes = System.GC.GetTotalMemory(true); Console.WriteLine("Time: " + (stopTime - startTime) + " ms" + "\nMemory usage: " + (endBytes - startBytes) + " bytes" + "\nNum nodes: " + graph.NumNodes + "\nNum edges: " + graph.NumEdges); }
public void WriteDataTest() { IWriteValue _valueToWrite = null; m_Item2Test.WriteData(ref _valueToWrite, 0); }
public RegisterValueFormatter With <T>(IWriteValue <T> value) { _value = _formatter.Format(value.Expected); return(this); }
/// <summary> /// Writes process data down to the selected location and device resources. /// </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 write data.</param> /// <returns><see cref="T:CAS.Lib.CommonBus.ApplicationLayer.AL_ReadData_Result" /> result of the operation.</returns> /// <exception cref="System.NotImplementedException"></exception> /// TODO Edit XML Comment Template for WriteData public AL_ReadData_Result WriteData(ref IWriteValue data, byte retries) { throw new NotImplementedException(); }