FTD2XX_NET.FTDI.SetBaudRate C# (CSharp) Method

SetBaudRate() public method

Sets the current Baud rate.
public SetBaudRate ( UInt32 BaudRate ) : FT_STATUS
BaudRate System.UInt32 The desired Baud rate for the device.
return FT_STATUS
        public FT_STATUS SetBaudRate(UInt32 BaudRate)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;

            // If the DLL hasn't been loaded, just return here
            if (hFTD2XXDLL == IntPtr.Zero)
                return ftStatus;

            // Check for our required function pointers being set up
            if (pFT_SetBaudRate != IntPtr.Zero)
            {
                tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));

                if (ftHandle != IntPtr.Zero)
                {
                    // Call FT_SetBaudRate
                    ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
                }
            }
            else
            {
                if (pFT_SetBaudRate == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_SetBaudRate.");
                }
            }
            return ftStatus;
        }

Usage Example

コード例 #1
1
        /// <summary>
        /// Create a USB Relay Device and open it by the serial number
        /// </summary>
        /// <param name="serialNumber">Device serial number</param>
        public UsbRelay8( String serialNumber )
        {
            // Open the relay device by serial number
            //  The serial number is always uniques, so the safest
            _device = new FTDI();
            _status = _device.OpenBySerialNumber(serialNumber);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayDeviceNotFoundException();
            }

            // Set the baud rate
            _status = _device.SetBaudRate(BaudRate);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayConfigurationException();
            }

            // Set the bit mode
            _status = _device.SetBitMode(BitMask, BitMode);
            if (_status != FTDI.FT_STATUS.FT_OK)
            {
                throw new UsbRelayConfigurationException();
            }

            // Clear all the relays
            // Note: From the Data Sheet, when in Sync Mode you can
            //  only read the interface pins when writing.  So start
            //  start out with all the values cleared.
            _values = 0x00;
            SetRelays(_values);
        }
All Usage Examples Of FTD2XX_NET.FTDI::SetBaudRate