/// <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>0 (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public Int32 SendCommandToEmbedded(ICommDevice commDevice, ICommRequest requestObj)
        {
            // Send the SOM and receive it
            Int32 commError = (Int32)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != 0)
            {
                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(errorCode);
            }

            // 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(errorCode);
            }

            return(0);
        }
        /// <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 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>0 (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public Int32 SendDataRequestToEmbedded(ICommDevice commDevice, ICommRequest requestObj, Byte[] rxMessage)
        {
            // Send the SOM and receive it
            Int32 commError = (Int32)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != 0)
            {
                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(-1);
            }

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

            return(0);
        }
        /// <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);
        }
Example #5
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>
        /// <returns>Success, if the communication request was successful; otherwise, an error code.</returns>
        public CommunicationError GetSelfTestSpecialMessage(out Int16 Result, out Int16 Reason)
        {
            Result = -1;
            Reason = -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 valid       = m_RxMessage[8];
            Byte messageMode = m_RxMessage[9];

            if (m_CommDevice.IsTargetBigEndian())
            {
                valid       = Utils.ReverseByteOrder(valid);
                messageMode = Utils.ReverseByteOrder(messageMode);
            }

            if (valid != 1)
            {
                return(CommunicationError.UnknownError);
            }

            if (messageMode != STC_MSG_MODE_SPECIAL)
            {
                return(CommunicationError.BadResponse);
            }

            Result = BitConverter.ToInt16(m_RxMessage, 12);
            Byte bReason = m_RxMessage[15];

            if (m_CommDevice.IsTargetBigEndian())
            {
                Result  = Utils.ReverseByteOrder(Result);
                bReason = Utils.ReverseByteOrder(bReason);
            }

            Reason = bReason;

            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 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>0 (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public Int32 SendCommandToEmbedded(ICommDevice commDevice, ProtocolPTU.PacketType packetRequestType)
        {
            // Send the SOM and receive it
            Int32 commError = (Int32)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != 0)
            {
                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(errorCode);
            }

            // 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(errorCode);
            }

            return(0);
        }
        /// <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>0 (0) if all is well; otherwise another enumeration which is less than 0</returns>
        public Int32 SendDataRequestToEmbedded(ICommDevice commDevice, ProtocolPTU.PacketType packetRequestType, Byte[] rxMessage)
        {
            // Send the SOM and receive it
            Int32 commError = (Int32)commDevice.SendReceiveSOM();

            // Verify the sending and receiving of SOM is /RX OK
            if (commError != 0)
            {
                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(-1);
            }

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

            return(0);
        }
        /// <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 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 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;
        }