/// <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> /// Gets the embedded information stored on the target which is used to determine the project /// car ID and software version. /// </summary> /// <param name="getEmbInfo">structure that stores all of the target information, which includes project, /// version number, car ID, etc.</param> /// <returns>CommunicationError.Success (0) if all is well; otherwise another enumeration which is less than 0</returns> public CommunicationError GetEmbeddedInformation(ref ProtocolPTU.GetEmbeddedInfoRes getEmbInfo) { CommunicationError commError = m_PtuTargetCommunication.SendDataRequestToEmbedded(m_CommDevice, ProtocolPTU.PacketType.GET_EMBEDDED_INFORMATION, m_RxMessage); if (commError == CommunicationError.Success) { Regex rgx = new Regex(@"[^\u0020-\u007F]"); // Map bytes in m_RxMessage to GetEmbeddedInfoRes getEmbInfo.SoftwareVersion = Encoding.UTF8.GetString(m_RxMessage, 8, 41); getEmbInfo.SoftwareVersion = rgx.Replace(getEmbInfo.SoftwareVersion, String.Empty); getEmbInfo.CarID = Encoding.UTF8.GetString(m_RxMessage, 49, 11); getEmbInfo.CarID = rgx.Replace(getEmbInfo.CarID, String.Empty); getEmbInfo.SubSystemName = Encoding.UTF8.GetString(m_RxMessage, 60, 41); getEmbInfo.SubSystemName = rgx.Replace(getEmbInfo.SubSystemName, String.Empty); getEmbInfo.IdentifierString = Encoding.UTF8.GetString(m_RxMessage, 101, 4); getEmbInfo.IdentifierString = rgx.Replace(getEmbInfo.IdentifierString, String.Empty); getEmbInfo.ConfigurationMask = BitConverter.ToUInt32(m_RxMessage, 106); } return commError; }
/// <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; }