예제 #1
0
파일: USB.cs 프로젝트: smo-key/NXTLib
 /// <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);
                }
            }
        }