/// <summary>
        /// This method is used to send a command to the embedded PTU target using the type of
        /// device specified in the argument. The difference between this method and the 3 parameter
        /// method of the same name is that this method is used when there is no payload with the command.
        /// </summary>
        /// <param name="commDevice">The comm device used to communicate with target</param>
        /// <param name="packetRequestType">The command sent to the target</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SendCommandToEmbedded(ICommDevice commDevice, ProtocolPTU.PacketType packetRequestType)
        {
            // Send the SOM and receive it
            CommunicationError commError = (CommunicationError)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != CommunicationError.Success)
            {
                return(commError);
            }

            // Create the message header for a command and command type; "null" as 1st argument indicates no payload
            ProtocolPTU.DataPacketProlog dpp = new ProtocolPTU.DataPacketProlog();
            Byte[] txMessage = dpp.GetByteArray(null, packetRequestType, ProtocolPTU.ResponseType.COMMANDRESPONSE, commDevice.IsTargetBigEndian());

            // Send the command to the target
            Int32 errorCode = commDevice.SendMessageToTarget(txMessage);

            // Verify the command was sent without errors
            if (errorCode < 0)
            {
                return(CommunicationError.BadRequest);
            }

            // Since no return data is expected, verify the embedded target responds with an Acknowledge (implicit
            // acknowledge with TCP, but 232 has no such entity
            errorCode = commDevice.ReceiveTargetAcknowledge();
            if (errorCode < 0)
            {
                return(CommunicationError.BadResponse);
            }

            return(CommunicationError.Success);
        }
        /// <summary>
        /// This method is used to send a data request to the embedded PTU target using the type of
        /// device specified in the argument. The difference between this method and the method of the same name
        /// is that this method is used when there is NO payload with the data request.
        /// </summary>
        /// <param name="commDevice">The comm device used to communicate with target</param>
        /// <param name="packetRequestType">The command sent to the target</param>
        /// <param name="rxMessage">Used to store the response from the embedded target</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SendDataRequestToEmbedded(ICommDevice commDevice, ProtocolPTU.PacketType packetRequestType, Byte[] rxMessage)
        {
            // Send the SOM and receive it
            CommunicationError commError = (CommunicationError)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != CommunicationError.Success)
            {
                return(commError);
            }

            // Create the message header for a command and command type; "null" as 1st argument indicates no payload
            ProtocolPTU.DataPacketProlog dpp = new ProtocolPTU.DataPacketProlog();
            Byte[] txMessage = dpp.GetByteArray(null, packetRequestType, ProtocolPTU.ResponseType.DATARESPONSE, commDevice.IsTargetBigEndian());

            // Send the command to the target
            Int32 errorCode = commDevice.SendMessageToTarget(txMessage);

            if (errorCode < 0)
            {
                return(CommunicationError.BadRequest);
            }

            // Verify the target responds with data
            errorCode = commDevice.ReceiveTargetDataPacket(rxMessage);
            if (errorCode < 0)
            {
                return(CommunicationError.BadResponse);
            }

            return(CommunicationError.Success);
        }
        /// <summary>
        /// This method is used to send a command to the embedded PTU target using the type of
        /// device specified in the argument. The difference between this method and the 2 parameter
        /// method of the same name is that this method is used when there is a payload with the command.
        /// </summary>
        /// <param name="commDevice">The comm device used to communicate with target</param>
        /// <param name="requestObj">This object is a request that already has the all of the necessary payload
        /// parameters ready to be formed into a message to be sent to embedded target</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SendCommandToEmbedded(ICommDevice commDevice, ICommRequest requestObj)
        {
            // Send the SOM and receive it
            CommunicationError commError = (CommunicationError)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != CommunicationError.Success)
            {
                return(commError);
            }

            // Create the message header and payload for a command and command type
            Byte[] txMessage = requestObj.GetByteArray(commDevice.IsTargetBigEndian());

            // Send the command and payload to the target
            Int32 errorCode = commDevice.SendMessageToTarget(txMessage);

            // Verify the command was sent without errors
            if (errorCode < 0)
            {
                return(CommunicationError.BadRequest);
            }

            // Since no return data is expected, verify the embedded target responds with an Acknowledge (implicit
            // acknowledge with TCP, but 232 has no such entity
            errorCode = commDevice.ReceiveTargetAcknowledge();
            if (errorCode < 0)
            {
                return(CommunicationError.BadResponse);
            }

            return(CommunicationError.Success);
        }
        /// <summary>
        /// This method is used to send a data request to the embedded PTU target using the type of
        /// device specified in the argument. The difference between this method and the method of the same name
        /// is that this method is used when there is a payload with the data request.
        /// </summary>
        /// <param name="commDevice">The comm device used to communicate with target</param>
        /// <param name="requestObj">This object is a request that already has the all of the necessary payload
        /// parameters ready to be formed into a message to be sent to embedded target</param>
        /// <param name="rxMessage">Used to store the response from the embedded target</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SendDataRequestToEmbedded(ICommDevice commDevice, ICommRequest requestObj, Byte[] rxMessage)
        {
            // Send the SOM and receive it
            CommunicationError commError = (CommunicationError)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != CommunicationError.Success)
            {
                return(commError);
            }

            // Create the message header and payload for a command and command type
            Byte[] txMessage = requestObj.GetByteArray(commDevice.IsTargetBigEndian());

            // Send the command and payload to the target
            Int32 errorCode = commDevice.SendMessageToTarget(txMessage);

            if (errorCode < 0)
            {
                return(CommunicationError.BadRequest);
            }

            // Verify the target responds with data
            errorCode = commDevice.ReceiveTargetDataPacket(rxMessage);
            if (errorCode < 0)
            {
                return(CommunicationError.BadResponse);
            }

            return(CommunicationError.Success);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Exit the self test task.
        /// </summary>
        /// <remarks>This request will end the self test process on the VCU.</remarks>
        /// <param name="result">The result of the call. A value of: (1) 1 represents success; (2) indicates that the error message defined by the
        /// <paramref name="reason"/> parameter applies and (3) represents an unknown error.</param>
        /// <param name="reason">A value of 1 represents success; otherwise, the value is mapped to the <c>ERRID</c> field of the
        /// <c>SELFTESTERRMESS</c> table
        /// of the data dictionary in order to determine the error message returned from the VCU.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.ExitSelfestTask() method is not
        /// CommunicationError.Success.</exception>
        public void ExitSelfTestTask(out short result, out short reason)
        {
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.ExitSelfTestTask() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.ExitSelfTestTask(out result, out reason);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.ExitSelfTestTask()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.ExitSelfTestTask_t exitSelfTestTask = new DebugMode.ExitSelfTestTask_t(result, reason, errorCode);
                DebugMode.Write(exitSelfTestTask.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.ExitSelfestTask()", errorCode);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Run the predefined self tests associated with the specified test list identifier, these tests are defined in the data dictionary.
        /// </summary>
        /// <param name="testListIdentifier">The test list identifier of the predefined self tests that are to be executed.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.RunPredefinedSTTests() method is
        /// not CommunicationError.Success.</exception>
        public void RunPredefinedSTTests(short testListIdentifier)
        {
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.RunPredefinedSTTests() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.RunPredefinedSTTests(testListIdentifier);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.RunPredefinedSTTests()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.RunPredefinedSTTests_t runPredefinedSTTests = new DebugMode.RunPredefinedSTTests_t(testListIdentifier, errorCode);
                DebugMode.Write(runPredefinedSTTests.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.RunPredefinedSTTests()", errorCode);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Update the self test mode.
        /// </summary>
        /// <remarks>This call is used to check whether communication with the VCU has been lost.</remarks>
        /// <param name="selfTestMode">The required self test mode.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.UpdateSTMode() method is not
        /// CommunicationError.Success.</exception>
        public void UpdateSTMode(SelfTestMode selfTestMode)
        {
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.UpdateSTMode() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.UpdateSTMode((Int16)selfTestMode);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.UpdateSTMode()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.UpdateSTMode_t updateSTMode = new DebugMode.UpdateSTMode_t(selfTestMode, errorCode);
                DebugMode.Write(updateSTMode.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.UpdateSTMode()", errorCode);
            }
        }
Exemplo n.º 8
0
 public CommunicationException(string message, string serviceName,
                               CommunicationError code)
     : base(message)
 {
     _serviceName = serviceName;
     _code        = code;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Send self test communication watchdog message to the VCU
        /// </summary>
        /// <remarks>This method will send a communication watchdog message to the VCU. A response is expected back from the VCU. No action
        /// is taken in the VCU side. </remarks>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to m_SelfTestMarshal.CommunicationWatchdog() method is not
        /// CommunicationError.Success.</exception>
        /// <param name="InSelfTest">true if target hardware is in self test mode; false otherwise</param>
        public void CommunicationWatchdog(ref Boolean InSelfTest)
        {
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.CommunicationWatchdog() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.CommunicationWatchdog(ref InSelfTest);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.CommunicationWatchdog()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                //TODO DAS DebugMode.UpdateSTTestList_t updateSTTestList = new DebugMode.UpdateSTTestList_t(testCount, tests, errorCode);
                //TODO DAS DebugMode.Write(updateSTTestList.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.CommunicationWatchdog()", errorCode);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Execute the self tests that are defined in the current list.
        /// </summary>
        /// <param name="truckInformation">The truck to which the self tests apply. This does not apply on the CTA project as separate self-tests are
        /// set up for each truck.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.ExecuteSTTestList() method is not
        /// CommunicationError.Success.</exception>
        public void ExecuteSTTestList(TruckInformation truckInformation)
        {
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.ExecuteSTTestList() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.ExecuteSTTestList((short)truckInformation);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.ExecuteSTTestList()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.ExecuteSTTestList_t executeSTTestList = new DebugMode.ExecuteSTTestList_t(truckInformation, errorCode);
                DebugMode.Write(executeSTTestList.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.ExecuteSTTestList()", errorCode);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Partial method that can optionally be defined to extract the error
        /// message, code, and details in a service specific manner.
        /// </summary>
        /// <param name="content">The error content.</param>
        /// <param name="responseHeaders">The response headers.</param>
        /// <param name="message">The error message.</param>
        /// <param name="errorCode">The error code.</param>
        /// <param name="additionalInfo">Additional error details.</param>
        protected override void ExtractFailureContent(
            string content,
            ResponseHeaders responseHeaders,
            ref string message,
            ref string errorCode,
            ref IDictionary <string, string> additionalInfo
            )
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            try
            {
                using var document = JsonDocument.Parse(content);

                foreach (var property in document.RootElement.EnumerateObject())
                {
                    if (property.NameEquals("error"))
                    {
                        var communicationError = CommunicationError.DeserializeCommunicationError(property.Value);
                        errorCode      = communicationError.Code;
                        message        = communicationError.Message;
                        additionalInfo = new Dictionary <string, string>()
                        {
                            ["target"] = communicationError.Target
                        };
                        break;
                    }
                }
            }
            catch
            { }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get the self test special message.
        /// </summary>
        /// <param name="result">The result of the call. A value of: (1) 1 represents success; (2) indicates that the error message defined by the
        /// <paramref name="reason"/> parameter applies and (3) represents an unknown error.</param>
        /// <param name="reason">A value of 1 represents success; otherwise, the value is mapped to the <c>ERRID</c> field of the
        /// <c>SELFTESTERRMESS</c> table
        /// of the data dictionary in order to determine the error message returned from the VCU.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.GetSelfTestSpecialMessage()
        /// method is not CommunicationError.Success.</exception>
        public void GetSelfTestSpecialMessage(out short result, out short reason)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.GetSelfTestSpecialMessage() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.GetSelfTestSpecialMessage(out result, out reason);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestSpecialMessage()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.GetSelfTestSpecialMessage_t getSelfTestSpecialMessage = new DebugMode.GetSelfTestSpecialMessage_t(result, reason, errorCode);
                DebugMode.Write(getSelfTestSpecialMessage.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestSpecialMessage()", errorCode);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Set the car identifier.
        /// </summary>
        /// <param name="carIdentifier">The car identfier.</param>
        public void SetCarID(string carIdentifier)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_SetCarID != null, "CommunicationApplication.SetCarID() - [m_SetCarID != null]");
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationApplication.SetCarID() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = (CommunicationError)m_SetCarID(carIdentifier);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMCarIDSetFailed, errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMCarIDSetFailed, errorCode);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Write the specified data to the watch variable specified by the <paramref name="dictionaryIndex"/> parameter.
        /// </summary>
        /// <param name="dictionaryIndex">The dictionary index.</param>
        /// <param name="dataType">The data type.</param>
        /// <param name="data">The data.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.CloseCommunication() method is not
        /// CommunicationError.Success.</exception>
        public void SendVariable(short dictionaryIndex, short dataType, double data)
        {
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationWatch.SendVariable() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = (CommunicationError)m_WatchClockMarshal.SendVariable(dictionaryIndex, dataType, data);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMSendVariableFailed, errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMSendVariableFailed, errorCode);
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.SendVariable_t sendVariable = new DebugMode.SendVariable_t(dictionaryIndex, dataType, data, errorCode);
                DebugMode.Write(sendVariable.ToXML());
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Set the time and date on the target hardware.
        /// </summary>
        /// <param name="use4DigitYearCode">A flag that specifies whether the Vehicle Control Unit uses a 2 or 4 digit year code. True, if it
        /// uses a 4 digit year code; otherwise, false.</param>
        /// <param name="dateTime">The time and date as a .NET <c>DateTime</c> object.</param>
        public void SetTimeDate(bool use4DigitYearCode, DateTime dateTime)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_SetTimeDate != null, "CommunicationApplication.SetTimeDate() - [m_SetTimeDate != null]");
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationApplication.SetTimeDate() - [m_MutexCommuncationInterface != null]");

            // Set the parameters according to whether the VCU uses 2 or 4 digit year code.
            short use4DigitYearCodeAsShort = (use4DigitYearCode == true) ? Use4DigitYearCodeTrue : Use4DigitYearCodeFalse;
            short year = (use4DigitYearCode == true) ? (short)dateTime.Year : ConvertYearTo2DigitFormat((short)dateTime.Year);

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = (CommunicationError)m_SetTimeDate(use4DigitYearCodeAsShort, year, (short)dateTime.Month, (short)dateTime.Day, (short)dateTime.Hour,
                                                              (short)dateTime.Minute, (short)dateTime.Second);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMTimeDateSetFailed, errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMTimeDateSetFailed, errorCode);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Update the number of times that the selected tests are to be run.
        /// </summary>
        /// <param name="loopCount">The number of cycles/loops of the defined tests that are to be performed.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the m_SelfTestMarshal.UpdateSTLoopCount() method is not
        /// CommunicationError.Success.</exception>
        public void UpdateSTLoopCount(short loopCount)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.UpdateSTLoopCount() - [m_MutexCommuncationInterface != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.UpdateSTLoopCount(loopCount);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.UpdateSTLoopCount()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.UpdateSTLoopCount_t updateSTLoopCount = new DebugMode.UpdateSTLoopCount_t(loopCount, errorCode);
                DebugMode.Write(updateSTLoopCount.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.UpdateSTLoopCount()", errorCode);
            }
        }
        /// <summary>
        /// Assign the specified watch variable to the specified chart recorder channel index.
        /// </summary>
        /// <param name="ChartIndex">The chart recorder channel index.</param>
        /// <param name="VariableIndex">The watch identifier of the watch variable that is to be assigned to the channel.</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SetChartIndex(Int16 ChartIndex, Int16 VariableIndex)
        {
            ProtocolPTU.SetChartIndexReq request = new ProtocolPTU.SetChartIndexReq(ChartIndex, VariableIndex);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
        /// <summary>
        /// Map the watch identifiers listed in <paramref name="WatchElements"/> to the watch element array monitored by the embedded target.
        /// </summary>
        /// <param name="WatchElements">TArray containing the watch identifiers that are to be mapped to each element of the watch element array.
        /// </param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SetWatchElements(Int16[] WatchElements)
        {
            ProtocolPTU.SetWatchElementsReq request = new ProtocolPTU.SetWatchElementsReq(WatchElements);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
        /// <summary>
        /// Sets the chart mode of the chart recorder outputs
        /// </summary>
        /// <param name="TargetChartMode">the desired chart mode (data, ramp, full scale or zero)</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SetChartMode(Int16 TargetChartMode)
        {
            ProtocolPTU.SetChartModeReq request = new ProtocolPTU.SetChartModeReq((byte)TargetChartMode);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Run the predefined self tests associated with the specified test list identifier, these tests are defined in the data dictionary.
        /// </summary>
        /// <param name="TestID">The test list identifier of the predefined self tests that are to be executed.</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError RunPredefinedSTTests(Int16 TestID)
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_SEL_LIST, 0, (UInt16)TestID);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Update the self test mode.
        /// </summary>
        /// <remarks>This call is used to check whether communication with the VCU has been lost.</remarks>
        /// <param name="NewMode">The required self test mode.</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError UpdateSTMode(Int16 NewMode)
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_UPDT_MODE, 0, (UInt16)NewMode);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Update the list of individually selected self tests that are to be executed.
        /// </summary>
        /// <remarks>This method will define the list of self-tests that are to be executed once the tester selects the execute command. The self tests
        /// are defined using the self test identifiers defined in the data dictionary.</remarks>
        /// <param name="NumberOfTests">The number of tests in the list.</param>
        /// <param name="TestList">A list of the self test identifiers.</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError UpdateSTTestList(Int16 NumberOfTests, Int16[] TestList)
        {
            ProtocolPTU.SelfTestUpdateListReq request = new ProtocolPTU.SelfTestUpdateListReq(STC_CMD_UPDT_LIST, NumberOfTests, TestList);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Send an operator acknowledge message.
        /// </summary>
        /// <remarks>This request allows the operator to move to the next step of an interactive test.</remarks>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError SendOperatorAcknowledge()
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_OPRTR_ACK, 0, 0);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Abort the self test sequence.
        /// </summary>
        /// <remarks>This request will stop the execution of the self-test process on the VCU and return control to the propulsion software.</remarks>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError AbortSTSequence()
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_ABORT_SEQ, 0, 0);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Update the number of times that the selected tests are to be run.
        /// </summary>
        /// <param name="LoopCount">The number of cycles/loops of the defined tests that are to be performed.</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError UpdateSTLoopCount(Int16 LoopCount)
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_UPDT_LOOP_CNT, 0, (UInt16)LoopCount);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Execute the self tests that are defined in the current list.
        /// </summary>
        /// <param name="TruckInformation">The truck to which the self tests apply. This does not apply on the CTA project, separate self-tests are set
        /// up for each truck.</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError ExecuteSTTestList(Int16 TruckInformation)
        {
            ProtocolPTU.SelfTestCommand request = new ProtocolPTU.SelfTestCommand(STC_CMD_EXECUTE_LIST, (Byte)TruckInformation, 0);

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
        /// <summary>
        /// Write the specified data to the watch variable specified by the <paramref name="DictionaryIndex"/> parameter.
        /// </summary>
        /// <param name="DictionaryIndex">The dictionary index.</param>
        /// <param name="DataType">The data type.</param>
        /// <param name="Data">The value of the data to be written.</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SendVariable(Int16 DictionaryIndex, Int16 DataType, Double Data)
        {
            UInt32 data = (UInt32)Data;

            ProtocolPTU.SendVariableReq request = new ProtocolPTU.SendVariableReq(DictionaryIndex, data);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
        /// <summary>
        /// This method updates the embedded target real time clock with the desired date and time.
        /// </summary>
        /// <param name="Use4DigitYearCode">true if the embedded target expects a 4 digit year code; false otherwise</param>
        /// <param name="Year">Year</param>
        /// <param name="Month">Month</param>
        /// <param name="Day">Day</param>
        /// <param name="Hour">Hour</param>
        /// <param name="Minute">Minute</param>
        /// <param name="Second">Second</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SetTimeDate(Boolean Use4DigitYearCode, Int16 Year, Int16 Month, Int16 Day, Int16 Hour, Int16 Minute, Int16 Second)
        {
            ProtocolPTU.SetTimeDateReq request =
                new ProtocolPTU.SetTimeDateReq(Use4DigitYearCode, (Byte)Hour, (Byte)Minute, (Byte)Second,
                                               (UInt16)Year, (Byte)Month, (Byte)Day);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Map the watch identifiers listed in <paramref name="watchElementList"/> to the watch element array monitored by the target hardware.
        /// </summary>
        /// <remarks> The number of watch identifiers in the list must not exceed <c>WatchSize</c>.</remarks>
        /// <param name="watchElementList">The list containing the watch identifiers that are to be mapped to each element of the watch element array.
        /// </param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.SetWatchElements() method is not
        /// CommunicationError.Success.</exception>
        public void SetWatchElements(List <short> watchElementList)
        {
            Debug.Assert(m_SetWatchElements != null, "CommunicationWatch.SetWatchElements() - [m_SetWatchElementDelegates != null]");
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationWatch.SetWatchElements() - [m_MutexCommuncationInterface != null]");

            // Skip, if the parameter isn't defined.
            if (watchElementList == null)
            {
                return;
            }

            Debug.Assert(watchElementList.Count <= Parameter.WatchSize,
                         "CommunicationWatch.SetWatchElements - [watchElementList.Count <= Parameter.WatchSize]");

            short[] watchElements = new short[Parameter.WatchSize];
            Array.Copy(watchElementList.ToArray(), watchElements, watchElementList.Count);

            // Send the mapping to the target hardware.
            CommunicationError errorCode = CommunicationError.UnknownError;

            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = (CommunicationError)m_SetWatchElements(watchElements);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMSetWatchElementsFailed, errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.SetWatchElements_t setWatchElements = new DebugMode.SetWatchElements_t(watchElements, errorCode);
                DebugMode.Write(setWatchElements.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMSetWatchElementsFailed, errorCode);
            }

            // Keep a record up the new mapping beween the each element index and the watch identifier.
            for (short elementIndex = 0; elementIndex < Parameter.WatchSize; elementIndex++)
            {
                m_WatchElements[elementIndex].WatchIdentifier = watchElements[elementIndex];

                // Required to map between the watch identifier and the element index.
                m_WatchElements[elementIndex].ElementIndex = elementIndex;
            }
        }
        /// <summary>
        /// Set the chart scaling for the specified watch variable.
        /// </summary>
        /// <param name="DictionaryIndex">The watch identifier of the watch variables that is to be scaled.</param>
        /// <param name="MaxScale">The watch variable engineering value associated with the maximum Y axis value.</param>
        /// <param name="MinScale">The watch variable engineering value associated with the minimum Y axis value.</param>
        /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public CommunicationError SetChartScale(Int16 DictionaryIndex, Double MaxScale, Double MinScale)
        {
            Int32 maxScale = (Int32)MaxScale;
            Int32 minScale = (Int32)MinScale;

            ProtocolPTU.SetChartScaleReq request = new ProtocolPTU.SetChartScaleReq(DictionaryIndex, maxScale, minScale);

            CommunicationError commError = m_PtuTargetCommunication.SendCommandToEmbedded(m_CommDevice, request);

            return(commError);
        }
Exemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the communications exception class. This constructor is used when the exception is thrown as a result of receiving an error
 /// code other than CommunicationError.Success from a call to one of the methods included in PTUDLL32.dll.
 /// </summary>
 /// <remarks>The PTUDLL32.dll dynamic link library is a set of communication methods developed in C++ to support communication with the VCU.</remarks>
 /// <param name="auxMessage">A message to be passed to the exception handler.</param>
 /// <param name="communicationError">The error code returned from the call to the PTUDLL32 dynamic link library..</param>
 public CommunicationException(string auxMessage, CommunicationError communicationError)
     : base(String.Format("{0}", auxMessage))
 {
     m_CommunicationError = communicationError;
 }
 public CommunicationException(string message, CommunicationError code,
     Exception inner)
     : base(message, inner)
 {
     _code = code;
 }
 public CommunicationException(string message, string serviceName,
     CommunicationError code)
     : base(message)
 {
     _serviceName = serviceName;
     _code = code;
 }