/// <summary> /// Send PDU to server /// </summary> /// <param name="pdu">HARTFrame</param> /// <returns>HARTFrame</returns> private HARTFrame PDU(HARTFrame pdu) { var frame = new HARTIPFrame(SequenceNumber, messageID: MessageID.PDU, payload: pdu.Serialize()); stream.Write(frame.Serialize()); var buffer = new Byte[256]; stream.Read(buffer, 0, buffer.Length); var response = new HARTFrame(new HARTIPFrame(buffer).GetPayload()); SequenceNumber++; return(response); }
/// <summary> /// send initiate with timeout in ms /// </summary> /// <param name="timeout">int</param> /// <returns></returns> private bool Initiate(int timeout) { byte[] initiateTimeout = new byte[] { 0x01 }; initiateTimeout = initiateTimeout.Concat(BitConverter.GetBytes(timeout).Reverse()).ToArray(); var frame = new HARTIPFrame(SequenceNumber, messageID: MessageID.Initiate, payload: initiateTimeout); stream.Write(frame.Serialize()); SequenceNumber++; var buffer = new Byte[13]; stream.Read(buffer, 0, buffer.Length); var response = new HARTIPFrame(buffer); if (frame.GetPayload().SequenceEqual(response.GetPayload())) { return(true); // return true if intiate is reciprocated } else { return(false); } }