Пример #1
0
        /// <summary>
        /// Send the command to the device. Preferred method for adding command bytes
        /// </summary>
        /// <param name="cmd">USB command</param>
        /// <param name="readBuffer">Pre-allocated byte array</param>
        /// <param name="commandBytes">command bytes passed in order from byte0..byte1..byte(n)
        ///                            They are appended to the writeBuffer</param>
        /// <returns>False if read or write error. True otherwise.</returns>
        private bool sendCommand(USBcommand cmd, byte[] readBuffer, params byte[] commandBytes)
        {
            int bytesRead, bytesWritten;

            byte[] writeBuffer = new byte[commandBytes.Length + 1];
            writeBuffer[0] = (byte)cmd;
            for (int i = 0; i < commandBytes.Length; i++)
            {
                writeBuffer[i + 1] = commandBytes[i];
            }

            this.ec = writer.Write(writeBuffer, Constants.TIMEOUT, out bytesWritten);
            if (this.ec != ErrorCode.None)
            {
                return(false);
            }

            this.ec = reader.Read(readBuffer, Constants.TIMEOUT, out bytesRead);
            if (this.ec != ErrorCode.None)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        /*************************************************
        * Methods for talking to the device             *
        * sendCommand() should not be called directly   *
        *************************************************/
        /// <summary>
        /// Send command with no command bytes in the writeBuffer
        /// </summary>
        /// <param name="cmd">USB command</param>
        /// <param name="readBuffer">Pre-allocated byte array</param>
        /// <returns>False if read or write error. True otherwise</returns>
        private bool sendCommand(USBcommand cmd, byte[] readBuffer)
        {
            int bytesRead, bytesWritten;

            byte[] writeBuffer = { (byte)cmd };

            this.ec = writer.Write(writeBuffer, Constants.TIMEOUT, out bytesWritten);
            if (this.ec != ErrorCode.None)
            {
                return(false);
            }

            this.ec = reader.Read(readBuffer, Constants.TIMEOUT, out bytesRead);
            if (this.ec != ErrorCode.None)
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Send the command to the device. Preferred method for adding command bytes
        /// </summary>
        /// <param name="cmd">USB command</param>
        /// <param name="readBuffer">Pre-allocated byte array</param>
        /// <param name="commandBytes">command bytes passed in order from byte0..byte1..byte(n). They are appended to the writeBuffer</param>
        /// <returns>False if read or write error. True otherwise.</returns>
        private bool sendCommand(USBcommand cmd, byte[] readBuffer, params byte[] commandBytes)
        {
            int bytesRead, bytesWritten;
            byte[] writeBuffer = new byte[commandBytes.Length + 1];
            writeBuffer[0] = (byte)cmd;
            for (int i = 0; i < commandBytes.Length; i++)
            {
                writeBuffer[i + 1] = commandBytes[i];
            }

            this.ec = writer.Write(writeBuffer, Constants.USB_TIMEOUT, out bytesWritten);
            if (this.ec != ErrorCode.None)
                return false;

            this.ec = reader.Read(readBuffer, Constants.USB_TIMEOUT, out bytesRead);
            if (this.ec != ErrorCode.None)
                return false;

            return true;
        }
Пример #4
0
        /*************************************************
         * Methods for talking to the device             *
         * sendCommand() should not be called directly   *
         *************************************************/
        //TODO revamp the send command to comply with USB Interface Protocol Rev A
        /// <summary>
        /// Send command with no command bytes in the writeBuffer
        /// </summary>
        /// <param name="cmd">USB command</param>
        /// <param name="readBuffer">Pre-allocated byte array</param>
        /// <returns>False if read or write error. True otherwise</returns>
        private bool sendCommand(USBcommand cmd, byte[] readBuffer)
        {
            int bytesRead, bytesWritten;
            byte[] writeBuffer = { (byte)cmd };

            this.ec = writer.Write(writeBuffer, Constants.USB_TIMEOUT, out bytesWritten);
            if (this.ec != ErrorCode.None)
                return false;

            this.ec = reader.Read(readBuffer, Constants.USB_TIMEOUT, out bytesRead);
            if (this.ec != ErrorCode.None)
                return false;
            return true;
        }