FTD2XX_NET.FTDI.SetLatency C# (CSharp) Method

SetLatency() public method

Sets the value of the latency timer. Default value is 16ms.
public SetLatency ( byte Latency ) : FT_STATUS
Latency byte The latency timer value in ms. /// Valid values are 2ms - 255ms for FT232BM, FT245BM and FT2232 devices. /// Valid values are 0ms - 255ms for other devices.
return FT_STATUS
        public FT_STATUS SetLatency(byte Latency)
        {
            // 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_SetLatencyTimer != IntPtr.Zero)
            {
                tFT_SetLatencyTimer FT_SetLatencyTimer = (tFT_SetLatencyTimer)Marshal.GetDelegateForFunctionPointer(pFT_SetLatencyTimer, typeof(tFT_SetLatencyTimer));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Set Bit Mode does not apply to FT8U232AM, FT8U245AM or FT8U100AX devices
                    GetDeviceType(ref DeviceType);
                    if ((DeviceType == FT_DEVICE.FT_DEVICE_BM) || (DeviceType == FT_DEVICE.FT_DEVICE_2232))
                    {
                        // Do not allow latency of 1ms or 0ms for older devices
                        // since this can cause problems/lock up due to buffering mechanism
                        if (Latency < 2)
                            Latency = 2;
                    }

                    // Call FT_SetLatencyTimer
                    ftStatus = FT_SetLatencyTimer(ftHandle, Latency);
                }
            }
            else
            {
                if (pFT_SetLatencyTimer == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_SetLatencyTimer.");
                }
            }
            return ftStatus;
        }

Usage Example

コード例 #1
1
        //-------------------------------------------------------------------------------------------------
        public FTDI.FT_STATUS InitializeFTDI()
        {
            // Create new instance of the FTDI device class
             SPI_Device= new FTDI();
            uint ftdiDeviceCount = 0;

            int i;

            Initialize_SPI_Constants();

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

            // Check status
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // If no devices available, return
            if (ftdiDeviceCount == 0)
            {
                ftStatus = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND;
                return (ftStatus);
            }

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

            // Populate our device list
            ftStatus = SPI_Device.GetDeviceList(ftdiDeviceList);

            if (ftStatus == FTDI.FT_STATUS.FT_OK)
            {
                for (i = 0; i < ftdiDeviceCount; i++)
                {
                    //MessageBox.Show("Device Index: " + i.ToString());
                    //MessageBox.Show("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
                    //MessageBox.Show("Type: " + ftdiDeviceList[i].Type.ToString());
                    //MessageBox.Show("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
                    //MessageBox.Show("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
                    //MessageBox.Show("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
                    //MessageBox.Show("Description: " + ftdiDeviceList[i].Description.ToString());
                    //MessageBox.Show("");
                }
            }


            // Open first device in our list by serial number
            ftStatus = SPI_Device.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }
            // Set latency timer
            ftStatus = SPI_Device.SetLatency(2);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Reset the controller
            ftStatus = SPI_Device.SetBitMode(0, 0);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Set synchronous bit bang mode
            ftStatus = SPI_Device.SetBitMode(FT232Routputs, 4);  // Set device to mode 4 and sets outputs
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            // Set baud rate/bit clock settings
            ftStatus = SPI_Device.SetBaudRate(3000000);
            if (ftStatus != FTDI.FT_STATUS.FT_OK)
            {
                return (ftStatus);
            }

            presetShiftRegisterOutputs();

            return (ftStatus);
        }
All Usage Examples Of FTD2XX_NET.FTDI::SetLatency