예제 #1
0
        /// <summary>
        /// Sends the given standard command to the given address
        /// and returns true if the peer responded with an ACK.
        /// </summary>
        /// <param name="toAddress">Example: new DeviceId("12.34.56")</param>
        public bool SendStandardCommandToAddress(DeviceId toAddress, byte command1, byte command2)
        {
            bool result = false;

            this.plm.exceptionHandler(() =>
            {
                byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response(
                    toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2);
                byte flags = DeviceMessage.MessageFlags(responseAck);
                result     = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0;
            });
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Sends the given standard command to the given address
        /// and returns true if the peer responded with an ACK, also returns the data from the message.
        /// </summary>
        /// <param name="toAddress">Example: new DeviceId("12.34.56")</param>
        public bool GetByteFromAddress(DeviceId toAddress, byte command1, byte command2, out byte data)
        {
            bool result = false;

            byte[] responseAck = null;
            this.plm.exceptionHandler(() =>
            {
                responseAck = this.plm.sendStandardLengthMessageAndWait4Response(
                    toAddress, Constants.MSG_FLAGS_DIRECT, command1, command2);
                byte flags = DeviceMessage.MessageFlags(responseAck);
                result     = (flags & Constants.MSG_FLAGS_DIRECT_ACK) > 0;
            });
            if (result)
            {
                data = DeviceMessage.Command2(responseAck);
            }
            else
            {
                data = 0;
            }
            return(result);
        }
예제 #3
0
        internal byte[] waitForStandardMessageFrom(DeviceId peerAddress)
        {
            byte[]   result     = null;
            int      tryCounter = 0;
            DeviceId originator;

            do
            {
                result     = this.serialPortController.GetIncomingMessageOfType(MSG_TYPE_RECV_STANDARD);
                originator = DeviceMessage.DeviceMessageOriginator(result);
                if (originator != peerAddress)
                {
                    queueReceivedMessage(result);
                    result = null;
                    tryCounter++;
                    if (tryCounter > 3)
                    {
                        throw new TimeoutException("Timed out waiting for response from " + peerAddress.ToString());
                    }
                }
            } while (result == null);
            return(result);
        }