/// <summary> /// Initializes a new instance of the class. Initializes the: communication interface; main window interface; cyclic queues; max/min values and /// read/write locks. /// </summary> /// <param name="communicationInterface">Reference to the communication interface used to communicate with the target hardware.</param> /// <param name="cyclicQueueRecordSize">The required size of the cyclic buffer used to record watch data.</param> /// <param name="cyclicQueueLogSize">The required size of the cyclic buffer used to log watch data.</param> /// <param name="formWatchView">Reference to the form that called this form.</param> public ThreadPollWatch(ICommunicationWatch communicationInterface, int cyclicQueueRecordSize, int cyclicQueueLogSize, FormViewWatch formWatchView) { m_CommunicationInterface = communicationInterface; Debug.Assert(m_CommunicationInterface != null); m_FormViewWatch = formWatchView; Debug.Assert(m_FormViewWatch != null, "ThreadPollWatch.Ctor() - [m_FormViewWatch != null]"); m_CyclicQueueRecord = new CyclicQueue <WatchFrame_t>(cyclicQueueRecordSize); m_CyclicQueueLog = new CyclicQueue <WatchFrame_t>(cyclicQueueLogSize); m_MutexPause = new Mutex(); m_MutexPauseFeedback = new Mutex(); m_MutexCommunicationFault = new Mutex(); m_MutexRecord = new Mutex(); m_MutexAutoScaleWatchValues = new Mutex(); #region - [AutoScale] - m_AutoScaleWatchValues = new AutoScale_t[Parameter.WatchSize]; #endregion - [AutoScale] - m_PacketCount = 0; m_PollScheduler = new PollScheduler(); m_ReadTimeoutCountdown = ReadTimeoutCountdown; }
/// <summary> /// Upload the specified value to the specified watch variable. /// </summary> /// <param name="communicationInterface">Reference to the selected communication interface.</param> /// <param name="oldIdentifier">The old identifier associated with the watch variable.</param> /// <param name="value">The value that is to be uploaded to the VCU.</param> /// <exception cref="ArgumentNullException">Thrown if the communication interface is not specified.</exception> public static void UploadValue(ICommunicationWatch communicationInterface, short oldIdentifier, double value) { if (communicationInterface == null) { throw new ArgumentNullException("communicationInterface"); } WatchVariable watchVariable; try { watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; if (watchVariable == null) { return; } } catch (Exception) { return; } VariableType variableType = watchVariable.VariableType; // The actual value that is to be uploaded to the VCU. double uploadValue; switch (variableType) { case VariableType.Scalar: uploadValue = value / watchVariable.ScaleFactor; break; default: uploadValue = value; break; } // Note: the DataType must be of type u32 for the write operation to work correctly. communicationInterface.SendVariable(watchVariable.Identifier, (short)DataType_e.u32, uploadValue); }
/// <summary> /// Initializes a new instance of the class. Initializes the: communication interface; main window interface; cyclic queues; max/min values and /// read/write locks. /// </summary> /// <param name="communicationInterface">Reference to the communication interface used to communicate with the target hardware.</param> /// <param name="cyclicQueueRecordSize">The required size of the cyclic buffer used to record watch data.</param> /// <param name="cyclicQueueLogSize">The required size of the cyclic buffer used to log watch data.</param> /// <param name="formWatchView">Reference to the form that called this form.</param> public ThreadPollWatch(ICommunicationWatch communicationInterface, int cyclicQueueRecordSize, int cyclicQueueLogSize, FormViewWatch formWatchView) { m_CommunicationInterface = communicationInterface; Debug.Assert(m_CommunicationInterface != null); m_FormViewWatch = formWatchView; Debug.Assert(m_FormViewWatch != null, "ThreadPollWatch.Ctor() - [m_FormViewWatch != null]"); m_CyclicQueueRecord = new CyclicQueue<WatchFrame_t>(cyclicQueueRecordSize); m_CyclicQueueLog = new CyclicQueue<WatchFrame_t>(cyclicQueueLogSize); m_MutexPause = new Mutex(); m_MutexPauseFeedback = new Mutex(); m_MutexCommunicationFault = new Mutex(); m_MutexRecord = new Mutex(); m_MutexAutoScaleWatchValues = new Mutex(); #region - [AutoScale] - m_AutoScaleWatchValues = new AutoScale_t[Parameter.WatchSize]; #endregion - [AutoScale] - m_PacketCount = 0; m_PollScheduler = new PollScheduler(); m_ReadTimeoutCountdown = ReadTimeoutCountdown; }