FTD2XX_NET.FTDI.ReadFT232HEEPROM C# (CSharp) Method

ReadFT232HEEPROM() public method

Reads the EEPROM contents of an FT232H device.
Thrown when the current device does not match the type required by this method.
public ReadFT232HEEPROM ( FT232H_EEPROM_STRUCTURE ee232h ) : FT_STATUS
ee232h FT232H_EEPROM_STRUCTURE An FT232H_EEPROM_STRUCTURE which contains only the relevant information for an FT232H device.
return FT_STATUS
        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;
        }