コード例 #1
0
        /// <summary>
        /// Get the self test results.
        /// </summary>
        /// <param name="resultAvailable">A flag to indicate whether a valid result is available. A value of 1 indicates that a valid result is
        /// available; otherwise,  0.</param>
        /// <param name="messageMode">The type of message returned from the VCU.</param>
        /// <param name="testIdentifier">The test result identifier; the interpretation of this value is dependent upon the message mode. For detailed
        /// messages, this value represents the self test identifier.</param>
        /// <param name="testCase">The test case number associated with the message.</param>
        /// <param name="testResult">Used with the passive and logic self tests to define whether the test passed or failed. A value of 1 indicates
        /// that the test passed; otherwise, the test failed.</param>
        /// <param name="truckInformation">An enumerator to define the truck information associated with the message.</param>
        /// <param name="variableCount">The number of variables associated with the message.</param>
        /// <param name="results">An array of <see cref="InteractiveResults_t"/> structures containing the value of each self test variable associated
        /// with the current interactive test.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.GetSelfTestResult() method is not 
        /// CommunicationError.Success.</exception>
        /// <remarks>In C# the sizeof the InteractiveResults_t structure is 16 bytes as the size is rounded up to the nearest quad word. This is 
        /// inconsistent with the size of the InteractiveResults_t structure used in PTUDLL32.dll - 12 bytes. To ensure that the results are 
        /// interpreted correctly the results are passed as a byte array which is then mapped to an array of InteractiveResults structures.</remarks>
        public void GetSelfTestResult(out short resultAvailable, out MessageMode messageMode, out short testIdentifier, out short testCase,
                                             out short testResult, out TruckInformation truckInformation, out short variableCount,
                                             out InteractiveResults_t[] results)
        {

            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.GetSelfTestResult() - [m_MutexCommuncationInterface != null]");

            results = new InteractiveResults_t[Parameter.WatchSizeInteractiveTest];

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = m_SelfTestMarshal.GetSelfTestResult(out resultAvailable, out messageMode, out testIdentifier, out testCase, out testResult,
                                                                out truckInformation, out variableCount, results);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestResult()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }


            if (DebugMode.Enabled == true)
            {
                DebugMode.GetSelfTestResult_t getSelfTestResult = new DebugMode.GetSelfTestResult_t(resultAvailable, messageMode, testIdentifier,
                                                                                                    testCase, testResult, truckInformation,
                                                                                                    variableCount, results, errorCode);
                DebugMode.Write(getSelfTestResult.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestResult()", errorCode);
            }
        }
コード例 #2
0
        /// <summary>
        /// Get the self test results.
        /// </summary>
        /// <param name="resultAvailable">A flag to indicate whether a valid result is available. A value of 1 indicates that a valid result is
        /// available; otherwise,  0.</param>
        /// <param name="messageMode">The type of message returned from the VCU.</param>
        /// <param name="testIdentifier">The test result identifier; the interpretation of this value is dependent upon the message mode. For detailed
        /// messages, this value represents the self test identifier.</param>
        /// <param name="testCase">The test case number associated with the message.</param>
        /// <param name="testResult">Used with the passive and logic self tests to define whether the test passed or failed. A value of 1 indicates
        /// that the test passed; otherwise, the test failed.</param>
        /// <param name="truckInformation">An enumerator to define the truck information associated with the message.</param>
        /// <param name="variableCount">The number of variables associated with the message.</param>
        /// <param name="results">An array of <see cref="InteractiveResults_t"/> structures containing the value of each self test variable associated
        /// with the current interactive test.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.GetSelfTestResult() method is not 
        /// CommunicationError.Success.</exception>
        /// <remarks>In C# the sizeof the InteractiveResults_t structure is 16 bytes as the size is rounded up to the nearest quad word. This is 
        /// inconsistent with the size of the InteractiveResults_t structure used in PTUDLL32.dll - 12 bytes. To ensure that the results are 
        /// interpreted correctly the results are passed as a byte array which is then mapped to an array of InteractiveResults structures.</remarks>
        public unsafe void GetSelfTestResult(out short resultAvailable, out MessageMode messageMode, out short testIdentifier, out short testCase,
                                             out short testResult, out TruckInformation truckInformation, out short variableCount,
                                             out InteractiveResults_t[] results)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_GetSelfTestResult != null,
                         "CommunicationSelfTest.GetSelfTestResult() - [m_GetSelfTestResult != null]");
            Debug.Assert(m_MutexCommuncationInterface != null,
                         "CommunicationSelfTest.GetSelfTestResult() - [m_MutexCommuncationInterface != null]");

            results = new InteractiveResults_t[Parameter.WatchSizeInteractiveTest];
            int sizeOfInteractiveResultInPTUDLL32 = sizeof(double) + sizeof(int);
            byte[] interactiveResultsAsByteArray = new byte[Parameter.WatchSizeInteractiveTest * sizeOfInteractiveResultInPTUDLL32];

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                unsafe
                {
                    fixed (byte* interactiveResults = &interactiveResultsAsByteArray[0])
                    {
                        errorCode = (CommunicationError)m_GetSelfTestResult(out resultAvailable, out messageMode,
                                                                            out testIdentifier, out testCase, out testResult,
                                                                            out truckInformation, out variableCount,
                                                                            interactiveResults);
                    }
                }
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestResult()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            // Convert the byte array returned from the call to an array of InteractiveResults_t structures.
            int offset = 0;
            for (int index = 0; index < variableCount; index++)
            {
                offset = index * sizeOfInteractiveResultInPTUDLL32;
                results[index].Value = BitConverter.ToDouble(interactiveResultsAsByteArray, offset);
                results[index].Tag = BitConverter.ToInt32(interactiveResultsAsByteArray, offset + sizeof(double));
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.GetSelfTestResult_t getSelfTestResult = new DebugMode.GetSelfTestResult_t(resultAvailable, messageMode, testIdentifier,
                                                                                                    testCase, testResult, truckInformation,
                                                                                                    variableCount, results, errorCode);
                DebugMode.Write(getSelfTestResult.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationSelfTest.GetSelfTestResult()", errorCode);
            }
        }
コード例 #3
0
        /// <summary>
        /// Get the self test results.
        /// </summary>
        /// <param name="ValidResult">A flag to indicate whether a valid result is available. A value of 1 indicates that a valid result is
        /// available; otherwise, 0.</param>
        /// <param name="MessageMode">The type of message returned from the VCU.</param>
        /// <param name="TestID">The test result identifier; the interpretation of this value is dependent upon the message mode. For detailed
        /// messages, this value represents the self test identifier.</param>
        /// <param name="TestCase">The test case number associated with the message.</param>
        /// <param name="TestResult">Used with the passive and logic self tests to define whether the test passed or failed. A value of 1 indicates
        /// that the test passed; otherwise, the test failed.</param>
        /// <param name="SetInfo">An enumerator to define the truck information associated with the message.</param>
        /// <param name="NumOfVars">The number of variables associated with the message.</param>
        /// <param name="InteractiveResults">Array that stores the interactive results</param>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError GetSelfTestResult(out Int16 ValidResult, out MessageMode MessageMode, out Int16 TestID,
                                                     out Int16 TestCase, out Int16 TestResult, out TruckInformation SetInfo,
                                                     out Int16 NumOfVars, InteractiveResults_t[] InteractiveResults)
        {
            const Byte MAXSTVARIABLES = 16;

            ValidResult = -1;
            MessageMode = MessageMode.Undefined;
            TestID = -1;
            TestCase = -1;
            TestResult = -1;
            SetInfo = TruckInformation.Undefined;
            NumOfVars = -1;

            // Initiate transaction with embedded target
            CommunicationError commError = m_PtuTargetCommunication.SendDataRequestToEmbedded(m_CommDevice, ProtocolPTU.PacketType.GET_SELF_TEST_PACKET, m_RxMessage);

            if (commError != CommunicationError.Success)
            {
                return commError;
            }

            // Extract all of the information from the received data
            Byte validResult = m_RxMessage[8];
            Byte messageMode = m_RxMessage[9];
            UInt16 setInfo = BitConverter.ToUInt16(m_RxMessage, 10);
            UInt16 testID = BitConverter.ToUInt16(m_RxMessage, 12);
            Byte testCase = m_RxMessage[15];
            Byte numOfVars = m_RxMessage[16];
            Byte testResult = m_RxMessage[17];


            if (m_CommDevice.IsTargetBigEndian())
            {
                validResult = Utils.ReverseByteOrder(validResult);
                messageMode = Utils.ReverseByteOrder(messageMode);
                setInfo = Utils.ReverseByteOrder(setInfo);
                testID = Utils.ReverseByteOrder(testID);
                testCase = Utils.ReverseByteOrder(testCase);
                numOfVars = Utils.ReverseByteOrder(numOfVars);
                testResult = Utils.ReverseByteOrder(testResult);
            }

            ValidResult = validResult;
            MessageMode = (MessageMode)messageMode;
            TestID = (Int16)testID;
            TestCase = testCase;
            TestResult = testResult;
            SetInfo = (TruckInformation)setInfo;
            NumOfVars = numOfVars;


            if (numOfVars > MAXSTVARIABLES)
            {
                numOfVars = MAXSTVARIABLES;
            }

            if ((messageMode == STC_MSG_MODE_INTERACTIVE) && (validResult == 1))
            {

                UInt16 valueOffset = 28;
                UInt16 tagOffset = 32;
                UInt16 typeOffSet = 33;
                for (Byte index = 0; index < numOfVars; index++)
                {
                    Byte varType = m_RxMessage[typeOffSet];
                    Byte tag = m_RxMessage[tagOffset];
                    if (m_CommDevice.IsTargetBigEndian())
                    {
                        varType = Utils.ReverseByteOrder(varType);
                        tag = Utils.ReverseByteOrder(tag);
                    }

                    InteractiveResults[index].Tag = tag;

                    // All data written to "value" is 32 bits. Therefore, all values
                    // can be extracted as a 32 bit number
                    switch ((ProtocolPTU.VariableType)varType)
                    {
                        case ProtocolPTU.VariableType.UINT_8_TYPE:
                        case ProtocolPTU.VariableType.UINT_16_TYPE:
                        case ProtocolPTU.VariableType.UINT_32_TYPE:
                            UInt32 u32 = BitConverter.ToUInt32(m_RxMessage, valueOffset);
                            if (m_CommDevice.IsTargetBigEndian())
                            {
                                u32 = Utils.ReverseByteOrder(u32);
                            }
                            InteractiveResults[index].Value = (double)u32;;
                            break;

                        case ProtocolPTU.VariableType.INT_8_TYPE:
                        case ProtocolPTU.VariableType.INT_16_TYPE:
                        case ProtocolPTU.VariableType.INT_32_TYPE:
                            Int32 i32 = BitConverter.ToInt32(m_RxMessage, valueOffset);
                            if (m_CommDevice.IsTargetBigEndian())
                            {
                                i32 = Utils.ReverseByteOrder(i32);
                            }
                            InteractiveResults[index].Value = (double)i32;
                            break;

                        default:
                            InteractiveResults[index].Value = 0;
                            break;

                    }

                    typeOffSet += 6;
                    valueOffset += 6;
                    tagOffset += 6;
                }
            }
            
            return CommunicationError.Success;
        }
コード例 #4
0
        /// <summary>
        /// Get the self test results.
        /// </summary>
        /// <param name="resultAvailable">A flag to indicate whether a valid result is available. A value of 1 indicates that a valid result is
        /// available; otherwise, 0.</param>
        /// <param name="messageMode">The type of message returned from the VCU.</param>
        /// <param name="testIdentifier">The test result identifier; the interpretation of this value is dependent upon the message mode. For detailed
        /// messages, this value represents the self test identifier.</param>
        /// <param name="testCase">The test case number associated with the message.</param>
        /// <param name="testResult">Used with the passive and logic self tests to define whether the test passed or failed. A value of 1 indicates
        /// that the test passed; otherwise, the test failed.</param>
        /// <param name="truckInformation">An enumerator to define the truck information associated with the message.</param>
        /// <param name="variableCount">The number of variables associated with the message.</param>
        /// <param name="results">An array of <see cref="InteractiveResults_t"/> structures containing the value of each self test variable associated
        /// with the current interactive test.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.GetSelfTestResult() method is not 
        /// CommunicationError.Success.</exception>
        /// <remarks>In C# the sizeof the InteractiveResults_t structure is 16 bytes as the size is rounded up to the nearest quad word. This is 
        /// inconsistent with the size of the InteractiveResults_t structure used in PTUDLL32.dll - 12 bytes. To ensure that the results are 
        /// interpreted correctly the results are passed as a byte array which is then mapped to an array of InteractiveResults structures.</remarks>
        public unsafe void GetSelfTestResult(out short resultAvailable, out MessageMode messageMode, out short testIdentifier, out short testCase,
                                             out short testResult, out TruckInformation truckInformation, out short variableCount,
                                             out InteractiveResults_t[] results)
        {
            messageMode = MessageMode.Brief;
            testCase = 0;
            testResult = ResultPassed;
            truckInformation = TruckInformation.None;
            resultAvailable = ResultAvailable;

            if ((m_UserAbort == false) && (m_LoopsExecuted < m_STLoopCount) && (m_QueuedTestList.Count > 0))
            {
                testIdentifier = (short)m_QueuedTestList[m_CurrentTestIndex];
                m_CurrentTestIndex += 1;

                if (m_CurrentTestIndex >= m_QueuedTestList.Count)
                {
                    m_CurrentTestIndex = 0;
                    m_LoopsExecuted += 1;
                }
            }
            else
            {
                if (m_UserAbort == true)
                {
                    testIdentifier = (short)SpecialMessageIdentifier.TestAborted;
                    m_UserAbort = false;
                }
                else
                {
                    testIdentifier = (short)SpecialMessageIdentifier.TestComplete;
                }

                messageMode = MessageMode.Special;
                variableCount = 0;
                results = new InteractiveResults_t[0];

                m_LoopsExecuted = 0;
                m_CurrentTestIndex = 0;
                return;
            }

            try
            {
                List<SelfTestVariable> variableList = Lookup.SelfTestTableBySelfTestNumber.Items[testIdentifier].SelfTestVariableList;
                variableCount = (short)variableList.Count;
                throw new Exception(); 
            }
            catch
            {
                variableCount = 0;
            }

            results = new InteractiveResults_t[variableCount];

            for (int index = 0; index < variableCount; index++)
            {
                results[index].Value = 0.0;
                results[index].Tag = 0;
            }
        }