Example #1
0
        //**************************************************************************
        // WriteFT4232HEEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Writes the specified values to the EEPROM of an FT4232H device.
        /// Calls FT_EE_Program in FTD2XX DLL
        /// </summary>
        /// <returns>FT_STATUS value from FT_EE_Program in FTD2XX DLL</returns>
        /// <param name="ee4232h">The EEPROM settings to be written to the device</param>
        /// <remarks>If the strings are too long, they will be truncated to their maximum permitted lengths</remarks>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS WriteFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Program != IntPtr.Zero)
            {
                tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT4232H that we are trying to write
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_4232H)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    // Check for VID and PID of 0x0000
                    if ((ee4232h.VendorID == 0x0000) | (ee4232h.ProductID == 0x0000))
                    {
                        // Do not allow users to program the device with VID or PID of 0x0000
                        return FT_STATUS.FT_INVALID_PARAMETER;
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 4;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Check lengths of strings to make sure that they are within our limits
                    // If not, trim them to make them our maximum length
                    if (ee4232h.Manufacturer.Length > 32)
                        ee4232h.Manufacturer = ee4232h.Manufacturer.Substring(0, 32);
                    if (ee4232h.ManufacturerID.Length > 16)
                        ee4232h.ManufacturerID = ee4232h.ManufacturerID.Substring(0, 16);
                    if (ee4232h.Description.Length > 64)
                        ee4232h.Description = ee4232h.Description.Substring(0, 64);
                    if (ee4232h.SerialNumber.Length > 16)
                        ee4232h.SerialNumber = ee4232h.SerialNumber.Substring(0, 16);

                    // Set string values
                    eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee4232h.Manufacturer);
                    eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee4232h.ManufacturerID);
                    eedata.Description = Marshal.StringToHGlobalAnsi(ee4232h.Description);
                    eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee4232h.SerialNumber);

                    // Map non-string elements to structure
                    // Standard elements
                    eedata.VendorID = ee4232h.VendorID;
                    eedata.ProductID = ee4232h.ProductID;
                    eedata.MaxPower = ee4232h.MaxPower;
                    eedata.SelfPowered = Convert.ToUInt16(ee4232h.SelfPowered);
                    eedata.RemoteWakeup = Convert.ToUInt16(ee4232h.RemoteWakeup);
                    // 4232H specific fields
                    eedata.PullDownEnable8 = Convert.ToByte(ee4232h.PullDownEnable);
                    eedata.SerNumEnable8 = Convert.ToByte(ee4232h.SerNumEnable);
                    eedata.ASlowSlew = Convert.ToByte(ee4232h.ASlowSlew);
                    eedata.ASchmittInput = Convert.ToByte(ee4232h.ASchmittInput);
                    eedata.ADriveCurrent = ee4232h.ADriveCurrent;
                    eedata.BSlowSlew = Convert.ToByte(ee4232h.BSlowSlew);
                    eedata.BSchmittInput = Convert.ToByte(ee4232h.BSchmittInput);
                    eedata.BDriveCurrent = ee4232h.BDriveCurrent;
                    eedata.CSlowSlew = Convert.ToByte(ee4232h.CSlowSlew);
                    eedata.CSchmittInput = Convert.ToByte(ee4232h.CSchmittInput);
                    eedata.CDriveCurrent = ee4232h.CDriveCurrent;
                    eedata.DSlowSlew = Convert.ToByte(ee4232h.DSlowSlew);
                    eedata.DSchmittInput = Convert.ToByte(ee4232h.DSchmittInput);
                    eedata.DDriveCurrent = ee4232h.DDriveCurrent;
                    eedata.ARIIsTXDEN = Convert.ToByte(ee4232h.ARIIsTXDEN);
                    eedata.BRIIsTXDEN = Convert.ToByte(ee4232h.BRIIsTXDEN);
                    eedata.CRIIsTXDEN = Convert.ToByte(ee4232h.CRIIsTXDEN);
                    eedata.DRIIsTXDEN = Convert.ToByte(ee4232h.DRIIsTXDEN);
                    eedata.AIsVCP8 = Convert.ToByte(ee4232h.AIsVCP);
                    eedata.BIsVCP8 = Convert.ToByte(ee4232h.BIsVCP);
                    eedata.CIsVCP8 = Convert.ToByte(ee4232h.CIsVCP);
                    eedata.DIsVCP8 = Convert.ToByte(ee4232h.DIsVCP);

                    // Call FT_EE_Program
                    ftStatus = FT_EE_Program(ftHandle, eedata);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);
                }
            }
            else
            {
                if (pFT_EE_Program == IntPtr.Zero)
                {
                    MessageBox.Show("Failed to load function FT_EE_Program.");
                }
            }
            return ftStatus;
        }
Example #2
0
        //**************************************************************************
        // WriteFT232REEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Writes the specified values to the EEPROM of an FT232R or FT245R device.
        /// Calls FT_EE_Program in FTD2XX DLL
        /// </summary>
        /// <returns>FT_STATUS value from FT_EE_Program in FTD2XX DLL</returns>
        /// <param name="ee232r">The EEPROM settings to be written to the device</param>
        /// <remarks>If the strings are too long, they will be truncated to their maximum permitted lengths</remarks>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS WriteFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Program != IntPtr.Zero)
            {
                tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT232R or FT245R that we are trying to write
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_232R)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    // Check for VID and PID of 0x0000
                    if ((ee232r.VendorID == 0x0000) | (ee232r.ProductID == 0x0000))
                    {
                        // Do not allow users to program the device with VID or PID of 0x0000
                        return FT_STATUS.FT_INVALID_PARAMETER;
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 2;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Check lengths of strings to make sure that they are within our limits
                    // If not, trim them to make them our maximum length
                    if (ee232r.Manufacturer.Length > 32)
                        ee232r.Manufacturer = ee232r.Manufacturer.Substring(0, 32);
                    if (ee232r.ManufacturerID.Length > 16)
                        ee232r.ManufacturerID = ee232r.ManufacturerID.Substring(0, 16);
                    if (ee232r.Description.Length > 64)
                        ee232r.Description = ee232r.Description.Substring(0, 64);
                    if (ee232r.SerialNumber.Length > 16)
                        ee232r.SerialNumber = ee232r.SerialNumber.Substring(0, 16);

                    // Set string values
                    eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee232r.Manufacturer);
                    eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee232r.ManufacturerID);
                    eedata.Description = Marshal.StringToHGlobalAnsi(ee232r.Description);
                    eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee232r.SerialNumber);

                    // Map non-string elements to structure
                    // Standard elements
                    eedata.VendorID = ee232r.VendorID;
                    eedata.ProductID = ee232r.ProductID;
                    eedata.MaxPower = ee232r.MaxPower;
                    eedata.SelfPowered = Convert.ToUInt16(ee232r.SelfPowered);
                    eedata.RemoteWakeup = Convert.ToUInt16(ee232r.RemoteWakeup);
                    // 232R specific fields
                    eedata.PullDownEnableR = Convert.ToByte(ee232r.PullDownEnable);
                    eedata.SerNumEnableR = Convert.ToByte(ee232r.SerNumEnable);
                    eedata.UseExtOsc = Convert.ToByte(ee232r.UseExtOsc);
                    eedata.HighDriveIOs = Convert.ToByte(ee232r.HighDriveIOs);
                    // Override any endpoint size the user has selected and force 64 bytes
                    // Some users have been known to wreck devices by setting 0 here...
                    eedata.EndpointSize = 64;
                    eedata.PullDownEnableR = Convert.ToByte(ee232r.PullDownEnable);
                    eedata.SerNumEnableR = Convert.ToByte(ee232r.SerNumEnable);
                    eedata.InvertTXD = Convert.ToByte(ee232r.InvertTXD);
                    eedata.InvertRXD = Convert.ToByte(ee232r.InvertRXD);
                    eedata.InvertRTS = Convert.ToByte(ee232r.InvertRTS);
                    eedata.InvertCTS = Convert.ToByte(ee232r.InvertCTS);
                    eedata.InvertDTR = Convert.ToByte(ee232r.InvertDTR);
                    eedata.InvertDSR = Convert.ToByte(ee232r.InvertDSR);
                    eedata.InvertDCD = Convert.ToByte(ee232r.InvertDCD);
                    eedata.InvertRI = Convert.ToByte(ee232r.InvertRI);
                    eedata.Cbus0 = ee232r.Cbus0;
                    eedata.Cbus1 = ee232r.Cbus1;
                    eedata.Cbus2 = ee232r.Cbus2;
                    eedata.Cbus3 = ee232r.Cbus3;
                    eedata.Cbus4 = ee232r.Cbus4;
                    eedata.RIsD2XX = Convert.ToByte(ee232r.RIsD2XX);

                    // Call FT_EE_Program
                    ftStatus = FT_EE_Program(ftHandle, eedata);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);
                }
            }
            else
            {
                if (pFT_EE_Program == IntPtr.Zero)
                {
                    MessageBox.Show("Failed to load function FT_EE_Program.");
                }
            }
            return ftStatus;
        }
Example #3
0
        //**************************************************************************
        // ReadFT4232HEEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Reads the EEPROM contents of an FT4232H device.
        /// </summary>
        /// <returns>FT_STATUS value from FT_EE_Read in FTD2XX DLL</returns>
        /// <param name="ee4232h">An FT4232H_EEPROM_STRUCTURE which contains only the relevant information for an FT4232H device.</param>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS ReadFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Read != IntPtr.Zero)
            {
                tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT4232H that we are trying to read
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_4232H)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 4;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Call FT_EE_Read
                    ftStatus = FT_EE_Read(ftHandle, eedata);

                    // Retrieve string values
                    ee4232h.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
                    ee4232h.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
                    ee4232h.Description = Marshal.PtrToStringAnsi(eedata.Description);
                    ee4232h.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);

                    // Map non-string elements to structure to be returned
                    // Standard elements
                    ee4232h.VendorID = eedata.VendorID;
                    ee4232h.ProductID = eedata.ProductID;
                    ee4232h.MaxPower = eedata.MaxPower;
                    ee4232h.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
                    ee4232h.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
                    // 4232H specific fields
                    ee4232h.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable8);
                    ee4232h.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable8);
                    ee4232h.ASlowSlew = Convert.ToBoolean(eedata.ASlowSlew);
                    ee4232h.ASchmittInput = Convert.ToBoolean(eedata.ASchmittInput);
                    ee4232h.ADriveCurrent = eedata.ADriveCurrent;
                    ee4232h.BSlowSlew = Convert.ToBoolean(eedata.BSlowSlew);
                    ee4232h.BSchmittInput = Convert.ToBoolean(eedata.BSchmittInput);
                    ee4232h.BDriveCurrent = eedata.BDriveCurrent;
                    ee4232h.CSlowSlew = Convert.ToBoolean(eedata.CSlowSlew);
                    ee4232h.CSchmittInput = Convert.ToBoolean(eedata.CSchmittInput);
                    ee4232h.CDriveCurrent = eedata.CDriveCurrent;
                    ee4232h.DSlowSlew = Convert.ToBoolean(eedata.DSlowSlew);
                    ee4232h.DSchmittInput = Convert.ToBoolean(eedata.DSchmittInput);
                    ee4232h.DDriveCurrent = eedata.DDriveCurrent;
                    ee4232h.ARIIsTXDEN = Convert.ToBoolean(eedata.ARIIsTXDEN);
                    ee4232h.BRIIsTXDEN = Convert.ToBoolean(eedata.BRIIsTXDEN);
                    ee4232h.CRIIsTXDEN = Convert.ToBoolean(eedata.CRIIsTXDEN);
                    ee4232h.DRIIsTXDEN = Convert.ToBoolean(eedata.DRIIsTXDEN);
                    ee4232h.AIsVCP = Convert.ToBoolean(eedata.AIsVCP8);
                    ee4232h.BIsVCP = Convert.ToBoolean(eedata.BIsVCP8);
                    ee4232h.CIsVCP = Convert.ToBoolean(eedata.CIsVCP8);
                    ee4232h.DIsVCP = Convert.ToBoolean(eedata.DIsVCP8);
                }
            }
            else
            {
                if (pFT_EE_Read == IntPtr.Zero)
                {
                    MessageBox.Show("Failed to load function FT_EE_Read.");
                }
            }
            return ftStatus;
        }
Example #4
0
        //**************************************************************************
        // ReadFT232REEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Reads the EEPROM contents of an FT232R or FT245R device.
        /// Calls FT_EE_Read in FTD2XX DLL
        /// </summary>
        /// <returns>An FT232R_EEPROM_STRUCTURE which contains only the relevant information for an FT232R and FT245R device.</returns>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS ReadFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Read != IntPtr.Zero)
            {
                tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT232R or FT245R that we are trying to read
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_232R)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 2;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Call FT_EE_Read
                    ftStatus = FT_EE_Read(ftHandle, eedata);

                    // Retrieve string values
                    ee232r.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
                    ee232r.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
                    ee232r.Description = Marshal.PtrToStringAnsi(eedata.Description);
                    ee232r.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);

                    // Map non-string elements to structure to be returned
                    // Standard elements
                    ee232r.VendorID = eedata.VendorID;
                    ee232r.ProductID = eedata.ProductID;
                    ee232r.MaxPower = eedata.MaxPower;
                    ee232r.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
                    ee232r.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
                    // 232R specific fields
                    ee232r.UseExtOsc = Convert.ToBoolean(eedata.UseExtOsc);
                    ee232r.HighDriveIOs = Convert.ToBoolean(eedata.HighDriveIOs);
                    ee232r.EndpointSize = eedata.EndpointSize;
                    ee232r.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnableR);
                    ee232r.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnableR);
                    ee232r.InvertTXD = Convert.ToBoolean(eedata.InvertTXD);
                    ee232r.InvertRXD = Convert.ToBoolean(eedata.InvertRXD);
                    ee232r.InvertRTS = Convert.ToBoolean(eedata.InvertRTS);
                    ee232r.InvertCTS = Convert.ToBoolean(eedata.InvertCTS);
                    ee232r.InvertDTR = Convert.ToBoolean(eedata.InvertDTR);
                    ee232r.InvertDSR = Convert.ToBoolean(eedata.InvertDSR);
                    ee232r.InvertDCD = Convert.ToBoolean(eedata.InvertDCD);
                    ee232r.InvertRI = Convert.ToBoolean(eedata.InvertRI);
                    ee232r.Cbus0 = eedata.Cbus0;
                    ee232r.Cbus1 = eedata.Cbus1;
                    ee232r.Cbus2 = eedata.Cbus2;
                    ee232r.Cbus3 = eedata.Cbus3;
                    ee232r.Cbus4 = eedata.Cbus4;
                    ee232r.RIsD2XX = Convert.ToBoolean(eedata.RIsD2XX);
                }
            }
            else
            {
                if (pFT_EE_Read == IntPtr.Zero)
                {
                    MessageBox.Show("Failed to load function FT_EE_Read.");
                }
            }
            return ftStatus;
        }
Example #5
0
        //**************************************************************************
        // ReadFT232HEEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Reads the EEPROM contents of an FT232H device.
        /// </summary>
        /// <returns>FT_STATUS value from FT_EE_Read in FTD2XX DLL</returns>
        /// <param name="ee232h">An FT232H_EEPROM_STRUCTURE which contains only the relevant information for an FT232H device.</param>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS ReadFT232HEEPROM(FT232H_EEPROM_STRUCTURE ee232h)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Read != IntPtr.Zero)
            {
                tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT232H that we are trying to read
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_232H)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 5;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Call FT_EE_Read
                    ftStatus = FT_EE_Read(ftHandle, eedata);

                    // Retrieve string values
                    ee232h.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
                    ee232h.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
                    ee232h.Description = Marshal.PtrToStringAnsi(eedata.Description);
                    ee232h.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);

                    // Map non-string elements to structure to be returned
                    // Standard elements
                    ee232h.VendorID = eedata.VendorID;
                    ee232h.ProductID = eedata.ProductID;
                    ee232h.MaxPower = eedata.MaxPower;
                    ee232h.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
                    ee232h.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
                    // 232H specific fields
                    ee232h.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnableH);
                    ee232h.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnableH);
                    ee232h.ACSlowSlew = Convert.ToBoolean(eedata.ACSlowSlewH);
                    ee232h.ACSchmittInput = Convert.ToBoolean(eedata.ACSchmittInputH);
                    ee232h.ACDriveCurrent = eedata.ACDriveCurrentH;
                    ee232h.ADSlowSlew = Convert.ToBoolean(eedata.ADSlowSlewH);
                    ee232h.ADSchmittInput = Convert.ToBoolean(eedata.ADSchmittInputH);
                    ee232h.ADDriveCurrent = eedata.ADDriveCurrentH;
                    ee232h.Cbus0 = eedata.Cbus0H;
                    ee232h.Cbus1 = eedata.Cbus1H;
                    ee232h.Cbus2 = eedata.Cbus2H;
                    ee232h.Cbus3 = eedata.Cbus3H;
                    ee232h.Cbus4 = eedata.Cbus4H;
                    ee232h.Cbus5 = eedata.Cbus5H;
                    ee232h.Cbus6 = eedata.Cbus6H;
                    ee232h.Cbus7 = eedata.Cbus7H;
                    ee232h.Cbus8 = eedata.Cbus8H;
                    ee232h.Cbus9 = eedata.Cbus9H;
                    ee232h.IsFifo = Convert.ToBoolean(eedata.IsFifoH);
                    ee232h.IsFifoTar = Convert.ToBoolean(eedata.IsFifoTarH);
                    ee232h.IsFastSer = Convert.ToBoolean(eedata.IsFastSerH);
                    ee232h.IsFT1248 = Convert.ToBoolean(eedata.IsFT1248H);
                    ee232h.FT1248Cpol = Convert.ToBoolean(eedata.FT1248CpolH);
                    ee232h.FT1248Lsb =  Convert.ToBoolean(eedata.FT1248LsbH);
                    ee232h.FT1248FlowControl = Convert.ToBoolean(eedata.FT1248FlowControlH);
                    ee232h.IsVCP = Convert.ToBoolean(eedata.IsVCPH);
                    ee232h.PowerSaveEnable = Convert.ToBoolean(eedata.PowerSaveEnableH);
                }
            }
            else
            {
                if (pFT_EE_Read == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_EE_Read.");
                }
            }
            return ftStatus;
        }
Example #6
0
        //**************************************************************************
        // ReadFT232BEEPROM
        //**************************************************************************
        // Intellisense comments
        /// <summary>
        /// Reads the EEPROM contents of an FT232B or FT245B device.
        /// </summary>
        /// <returns>FT_STATUS value from FT_EE_Read in FTD2XX DLL</returns>
        /// <param name="ee232b">An FT232B_EEPROM_STRUCTURE which contains only the relevant information for an FT232B and FT245B device.</param>
        /// <exception cref="FT_EXCEPTION">Thrown when the current device does not match the type required by this method.</exception>
        public FT_STATUS ReadFT232BEEPROM(FT232B_EEPROM_STRUCTURE ee232b)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_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_EE_Read != IntPtr.Zero)
            {
                tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));

                if (ftHandle != IntPtr.Zero)
                {
                    FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
                    // Check that it is an FT232B or FT245B that we are trying to read
                    GetDeviceType(ref DeviceType);
                    if (DeviceType != FT_DEVICE.FT_DEVICE_BM)
                    {
                        // If it is not, throw an exception
                        ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();

                    // Set up structure headers
                    eedata.Signature1 = 0x00000000;
                    eedata.Signature2 = 0xFFFFFFFF;
                    eedata.Version = 2;

                    // Allocate space from unmanaged heap
                    eedata.Manufacturer = Marshal.AllocHGlobal(32);
                    eedata.ManufacturerID = Marshal.AllocHGlobal(16);
                    eedata.Description = Marshal.AllocHGlobal(64);
                    eedata.SerialNumber = Marshal.AllocHGlobal(16);

                    // Call FT_EE_Read
                    ftStatus = FT_EE_Read(ftHandle, eedata);

                    // Retrieve string values
                    ee232b.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
                    ee232b.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
                    ee232b.Description = Marshal.PtrToStringAnsi(eedata.Description);
                    ee232b.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);

                    // Free unmanaged buffers
                    Marshal.FreeHGlobal(eedata.Manufacturer);
                    Marshal.FreeHGlobal(eedata.ManufacturerID);
                    Marshal.FreeHGlobal(eedata.Description);
                    Marshal.FreeHGlobal(eedata.SerialNumber);

                    // Map non-string elements to structure to be returned
                    // Standard elements
                    ee232b.VendorID = eedata.VendorID;
                    ee232b.ProductID = eedata.ProductID;
                    ee232b.MaxPower = eedata.MaxPower;
                    ee232b.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
                    ee232b.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
                    // B specific fields
                    ee232b.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable);
                    ee232b.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable);
                    ee232b.USBVersionEnable = Convert.ToBoolean(eedata.USBVersionEnable);
                    ee232b.USBVersion = eedata.USBVersion;
                }
            }
            else
            {
                if (pFT_EE_Read == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_EE_Read.");
                }
            }
            return ftStatus;
        }