/// <summary>
        /// Method requests and retrieves from the embedded target the chart variable information based on
        /// the chart index provided. The PTU variable index is retrieved
        /// </summary>
        /// <param name="ChartIndex">The chart variable index (starting at 0) and not to equal or exceed the amount
        /// of chart recorder variables</param>
        /// <param name="VariableIndex">The variable index that is currently part of the chart recorder outputs</param>
        /// <returns>0 (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public Int32 GetChartIndex(Int16 ChartIndex, ref Int16 VariableIndex)
        {
            ProtocolPTU.GetChartIndexReq request = new ProtocolPTU.GetChartIndexReq((Byte)ChartIndex);

            Int32 commError = m_PtuTargetCommunication.SendDataRequestToEmbedded(m_CommDevice, request, m_RxMessage);

            if (commError != 0)
            {
                return(commError);
            }

            // Get the desired variable index from the receive message
            VariableIndex = BitConverter.ToInt16(m_RxMessage, 8);

            // check for endianess
            if (m_CommDevice.IsTargetBigEndian())
            {
                VariableIndex = Utils.ReverseByteOrder(VariableIndex);
            }

            return(0);
        }
Exemple #2
0
        /// <summary>
        /// Sends and receives a BTU request/response to the target. Uses existing PTU functionality.
        /// The response is saved (the Mode isn't)
        /// </summary>
        /// <param name="mode">desired mode</param>
        /// <param name="requestBuffer">request buffer (must be populated with desired payload prior to being called)</param>
        /// <returns></returns>
        public static int PTU_MVB_Interface(ushort mode, ushort [] requestBuffer)
        {
            if (m_SerComm == null)
            {
                return(-2);
            }
            ushort[] payload = new ushort[17];

            for (int i = 0; i < payload.Length; i++)
            {
                payload[i] = requestBuffer[i];
            }

            // Create the BTU request object with the Mode and the Request
            ProtocolPTU.BtuReq request = new ProtocolPTU.BtuReq(mode, payload);

            PtuTargetCommunication ptuTargetComm = new PtuTargetCommunication();

            // Transmit the message... the response is stored in rxMessage
            byte [] rxMessage = new byte[1024];
            int     commError = ptuTargetComm.SendDataRequestToEmbedded(m_SerComm, request, rxMessage);

            // If no errors exist, store the target response starting at byte 10 (bytes 0-7 are the header
            // bytes 8 & 9 are the "Mode")
            if (commError == 0)
            {
                for (int i = 0; i < 17; i++)
                {
                    m_ResultBuffer[i] = BitConverter.ToUInt16(rxMessage, ((i * 2) + 10));
                    if (m_SerComm.IsTargetBigEndian())
                    {
                        m_ResultBuffer[i] = Utils.ReverseByteOrder(m_ResultBuffer[i]);
                    }
                }
            }

            return(commError);
        }