OpenByDescription() public method

Opens the FTDI device with the specified description.
Initialises the device to 8 data bits, 1 stop bit, no parity, no flow control and 9600 Baud.
public OpenByDescription ( string description ) : FT_STATUS
description string Description of the device to open.
return FT_STATUS
Example #1
0
        // public methods
        /// <summary>
        /// Attempt to open RHA2000-EVAL board connected to USB port.
        /// </summary>
        /// <param name="firmwareID1">Board ID number (1 of 3)</param>
        /// <param name="firmwareID2">Board ID number (2 of 3)</param>
        /// <param name="firmwareID3">Board ID number (3 of 3)</param>
        public void Open(ref int firmwareID1, ref int firmwareID2, ref int firmwareID3)
        {
            // Open FTDI USB device.
            UInt32 ftdiDeviceCount = 0;
            FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;

            // Create new instance of the FTDI device class.
            myFtdiDeviceA = new FTDI();

            // Determine the number of FTDI devices connected to the machine.
            ftStatus = myFtdiDeviceA.GetNumberOfDevices(ref ftdiDeviceCount);

            // Check status.
            if (!(ftStatus == FTDI.FT_STATUS.FT_OK))
            {
                UsbException e = new UsbException("USB Setup Error: Failed to get number devices");
                throw e;
            }

            // If no devices available, return.
            if (ftdiDeviceCount == 0)
            {
                UsbException e = new UsbException("No valid USB devices detected");
                throw e;
            }

            // Allocate storage for device info list.
            FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];

            // Populate our device list.
            ftStatus = myFtdiDeviceA.GetDeviceList(ftdiDeviceList);
            // There could be a status error here, but we're not checking for it...

            // The Intan Technologies RHA2000-EVAL board uses an FTDI FT2232H chip to provide a USB
            // interface to a PC.  Detailed information on this chip may be found at:
            //
            //   http://www.ftdichip.com/Products/ICs/FT2232H.htm
            //
            // The FT2232H supports two independent FIFO channels.  The channel used by the RHA2000-EVAL
            // board is factory-configured with the name "Intan I/O board 1.0 A".  (FTDI provides software
            // routines to open device by its name.)

            ftStatus = myFtdiDeviceA.OpenByDescription("Intan I/O Board 1.0 A");
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                UsbException e = new UsbException("Intan USB device A not found");
                throw e;
            }

            // Set read timeout to 5 seconds, write timeout to infinite
            ftStatus = myFtdiDeviceA.SetTimeouts(5000, 0);
            // There could be status error here, but we're not checking for it...

            this.Stop();

            // Purge receive buffer

            myFtdiDeviceA.Purge(FTDI.FT_PURGE.FT_PURGE_RX);

            // Check board ID and version number
            //
            // The RHA2000-EVAL board is controlled by sending one-byte ASCII command characters over
            // the USB interface.  The 'I' character commands the board to return a 3-byte ID/version
            // number.

            UInt32 numBytesWritten = 0;
            Byte[] myChars = { 73 };   // 'I' = request board ID and version number

            ftStatus = myFtdiDeviceA.Write(myChars, 1, ref numBytesWritten);

            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                UsbException e = new UsbException("Could not write to Intan USB device");
                throw e;
            }

            const UInt32 numBytesToRead = 3;

            // Wait until the desired number of bytes have been received.
            UInt32 numBytesAvailable = 0;

            while (numBytesAvailable < numBytesToRead)
            {
                ftStatus = myFtdiDeviceA.GetRxBytesAvailable(ref numBytesAvailable);

                if (ftStatus != FTDI.FT_STATUS.FT_OK)
                {
                    UsbException e = new UsbException("Failed to get number of USB bytes available to read");
                    throw e;
                }
            }

            // Now that we have the amount of data we want available, read it.

            UInt32 numBytesRead = 0;

            ftStatus = myFtdiDeviceA.Read(readDataBufferA, numBytesToRead, ref numBytesRead);

            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                UsbException e = new UsbException("USB read error");
                throw e;
            }

            firmwareID1 = Convert.ToInt32(readDataBufferA[0]);
            firmwareID2 = Convert.ToInt32(readDataBufferA[1]);
            firmwareID3 = Convert.ToInt32(readDataBufferA[2]);

            Debug.WriteLine("Board ID: " + readDataBufferA[0] + " " + (Convert.ToInt32(readDataBufferA[1])).ToString() + " " + (Convert.ToInt32(readDataBufferA[2])).ToString());

            this.ZCheckOff();
            this.SettleOff();

            // Purge receive buffer.
            myFtdiDeviceA.Purge(FTDI.FT_PURGE.FT_PURGE_RX);

            dataJustStarted = true;
        }