Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// send keep-alive
        /// </summary>
        /// <returns>bool</returns>
        private bool KeepAlive()
        {
            var frame = new HARTIPFrame(SequenceNumber).Serialize();

            stream.Write(frame);
            var buffer = new Byte[256];

            stream.Read(buffer, 0, buffer.Length);
            var response = new HARTIPFrame(buffer).Serialize();

            frame[1] = 0x01;
            SequenceNumber++;
            if (frame.SequenceEqual(response))
            {
                return(true); //return true if answered
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }