Пример #1
0
 /// <summary>
 /// Recieves the reply from the NXT.
 /// </summary>
 /// <returns>Returns the reply from the NXT, as a byte array.</returns>
 public override byte[] RecieveReply()
 {
     if (!IsConnected)
     {
         throw new NXTNotConnected();
     }
     lock (commLock)
     {
         byte[] reply = usb.ReadDataViaBulkTransfer();
         if (reply == null)
         {
             throw new NXTNoReply();
         }
         return(reply);
     }
 }
Пример #2
0
        /// <summary>
        /// <para>Sends a request for the NXT brick, and if applicable, receive the reply.</para>
        /// </summary>
        /// <param name="request">The request</param>
        /// <returns>The reply as a byte-array, or null</returns>
        protected override byte[] Send(byte[] request)
        {
            lock (usbLock)
            {
                usb.SendDataViaBulkTransfers(request);

                // 0x80 indicates that we should expect a reply.
                if ((request[0] & 0x80) == 0)
                {
                    return(usb.ReadDataViaBulkTransfer());
                }
                else
                {
                    return(null);
                }
            }
        }