first commit

This commit is contained in:
Wesley Hofman
2025-09-18 14:23:18 +02:00
commit 2f1f4199ad
293 changed files with 54467 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EEPROM</RootNamespace>
<AssemblyName>EEPROM</AssemblyName>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FTD2XX_NET, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Utils\FTD2XX_NET\FTD2XX_NET\FTD2XX_NET\bin\Release\FTD2XX_NET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,341 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using FTD2XX_NET;
namespace EEPROM
{
class Program
{
static void Main(string[] args)
{
UInt32 ftdiDeviceCount = 0;
FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
// Create new instance of the FTDI device class
FTDI myFtdiDevice = new FTDI();
// Determine the number of FTDI devices connected to the machine
ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
// Check status
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
Console.WriteLine("Number of FTDI devices: " + ftdiDeviceCount.ToString());
Console.WriteLine("");
}
else
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// If no devices available, return
if (ftdiDeviceCount == 0)
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Allocate storage for device info list
FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
// Populate our device list
ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
for (UInt32 i = 0; i < ftdiDeviceCount; i++)
{
Console.WriteLine("Device Index: " + i.ToString());
Console.WriteLine("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
Console.WriteLine("Type: " + ftdiDeviceList[i].Type.ToString());
Console.WriteLine("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
Console.WriteLine("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
Console.WriteLine("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
Console.WriteLine("Description: " + ftdiDeviceList[i].Description.ToString());
Console.WriteLine("");
}
}
// Open first device in our list by serial number
ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to open device (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Create our device EEPROM structure based on the type of device we have open
if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_232R)
{
// We have an FT232R or FT245R so use FT232R EEPROM structure
FTDI.FT232R_EEPROM_STRUCTURE myEEData = new FTDI.FT232R_EEPROM_STRUCTURE();
// Read the device EEPROM
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT232REEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT232REEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
myEEData.SerialNumber = String.Empty;
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT232REEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT232REEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
else if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_2232)
{
// We have an FT2232 so use FT2232 EEPROM structure
FTDI.FT2232_EEPROM_STRUCTURE myEEData = new FTDI.FT2232_EEPROM_STRUCTURE();
// Read the device EEPROM
ftStatus = myFtdiDevice.ReadFT2232EEPROM(myEEData);
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT2232EEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT2232EEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
myEEData.SerialNumber = String.Empty;
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT2232EEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT2232EEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
else if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_BM)
{
// We have an FT232B or FT245B so use FT232B EEPROM structure
FTDI.FT232B_EEPROM_STRUCTURE myEEData = new FTDI.FT232B_EEPROM_STRUCTURE();
// Read the device EEPROM
ftStatus = myFtdiDevice.ReadFT232BEEPROM(myEEData);
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT232BEEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT232BEEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
myEEData.SerialNumber = String.Empty;
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT232BEEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT232BEEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
// Use cycle port to force a re-enumeration of the device.
// In the FTD2XX_NET class library, the cycle port method also
// closes the open handle so no need to call the Close method separately.
ftStatus = myFtdiDevice.CyclePort();
UInt32 newFtdiDeviceCount = 0;
do
{
// Wait for device to be re-enumerated
// The device will have the same location since it has not been
// physically unplugged, so we will keep trying to open it until it succeeds
ftStatus = myFtdiDevice.OpenByLocation(ftdiDeviceList[0].LocId);
Thread.Sleep(1000);
} while (ftStatus != FTDI.FT_STATUS.FT_OK);
// Close the device
myFtdiDevice.Close();
// Re-create our device list
ftStatus = myFtdiDevice.GetNumberOfDevices(ref newFtdiDeviceCount);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Re-populate our device list
ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
for (UInt32 i = 0; i < ftdiDeviceCount; i++)
{
Console.WriteLine("Device Index: " + i.ToString());
Console.WriteLine("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
Console.WriteLine("Type: " + ftdiDeviceList[i].Type.ToString());
Console.WriteLine("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
Console.WriteLine("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
Console.WriteLine("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
Console.WriteLine("Description: " + ftdiDeviceList[i].Description.ToString());
Console.WriteLine("");
}
}
// Wait for a key press
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
return;
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EEPROM")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("FTDI")]
[assembly: AssemblyProduct("EEPROM")]
[assembly: AssemblyCopyright("Copyright © FTDI 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4276d0d9-348e-4699-ba99-1b72708463d2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EEPROM</RootNamespace>
<AssemblyName>EEPROM</AssemblyName>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FTD2XX_NET, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\FTD2XX_NET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EEPROM", "EEPROM.csproj", "{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2256AEA0-6A5A-4506-9F4B-99AB11C0ECA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,347 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using FTD2XX_NET;
namespace EEPROM
{
class Program
{
static void Main(string[] args)
{
UInt32 ftdiDeviceCount = 0;
FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
// Create new instance of the FTDI device class
FTDI myFtdiDevice = new FTDI();
// Determine the number of FTDI devices connected to the machine
ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
// Check status
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
Console.WriteLine("Number of FTDI devices: " + ftdiDeviceCount.ToString());
Console.WriteLine("");
}
else
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// If no devices available, return
if (ftdiDeviceCount == 0)
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Allocate storage for device info list
FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
// Populate our device list
ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
for (UInt32 i = 0; i < ftdiDeviceCount; i++)
{
Console.WriteLine("Device Index: " + i.ToString());
Console.WriteLine("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
Console.WriteLine("Type: " + ftdiDeviceList[i].Type.ToString());
Console.WriteLine("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
Console.WriteLine("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
Console.WriteLine("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
Console.WriteLine("Description: " + ftdiDeviceList[i].Description.ToString());
Console.WriteLine("");
}
}
// Open first device in our list by serial number
ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[0].SerialNumber);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to open device (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Create our device EEPROM structure based on the type of device we have open
if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_232R)
{
// We have an FT232R or FT245R so use FT232R EEPROM structure
FTDI.FT232R_EEPROM_STRUCTURE myEEData = new FTDI.FT232R_EEPROM_STRUCTURE();
// Read the device EEPROM
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT232REEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT232REEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
//myEEData.SerialNumber = String.Empty;
// Wim: Set to defined string
myEEData.SerialNumber ="ChamChat_01";
myEEData.Description = "FDTI_USB_COM422_WE";
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT232REEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT232REEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
else if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_2232)
{
// We have an FT2232 so use FT2232 EEPROM structure
FTDI.FT2232_EEPROM_STRUCTURE myEEData = new FTDI.FT2232_EEPROM_STRUCTURE();
// Read the device EEPROM
ftStatus = myFtdiDevice.ReadFT2232EEPROM(myEEData);
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT2232EEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT2232EEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
myEEData.SerialNumber = String.Empty;
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT2232EEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT2232EEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
else if (ftdiDeviceList[0].Type == FTDI.FT_DEVICE.FT_DEVICE_BM)
{
// We have an FT232B or FT245B so use FT232B EEPROM structure
FTDI.FT232B_EEPROM_STRUCTURE myEEData = new FTDI.FT232B_EEPROM_STRUCTURE();
// Read the device EEPROM
ftStatus = myFtdiDevice.ReadFT232BEEPROM(myEEData);
// This can throw an exception if trying to read a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.ReadFT232BEEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling ReadFT232BEEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to read device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
// Write common EEPROM elements to our console
Console.WriteLine("EEPROM Contents for device at index 0:");
Console.WriteLine("Vendor ID: " + String.Format("{0:x}", myEEData.VendorID));
Console.WriteLine("Product ID: " + String.Format("{0:x}", myEEData.ProductID));
Console.WriteLine("Manufacturer: " + myEEData.Manufacturer.ToString());
Console.WriteLine("Manufacturer ID: " + myEEData.ManufacturerID.ToString());
Console.WriteLine("Description: " + myEEData.Description.ToString());
Console.WriteLine("Serial Number: " + myEEData.SerialNumber.ToString());
Console.WriteLine("Max Power: " + myEEData.MaxPower.ToString() + "mA");
Console.WriteLine("Self Powered: " + myEEData.SelfPowered.ToString());
Console.WriteLine("Remote Wakeup Enabled: " + myEEData.RemoteWakeup.ToString());
Console.WriteLine("");
// Change our serial number to write back to device
// By setting to an empty string, we allow the FTD2XX DLL
// to generate a serial number
myEEData.SerialNumber = String.Empty;
// Write our modified data structure back to the device EEPROM
// This can throw an exception if trying to write a device type that does not
// match the EEPROM structure being used, so should always use a
// try - catch block when calling
try
{
ftStatus = myFtdiDevice.WriteFT232BEEPROM(myEEData);
}
catch (FTDI.FT_EXCEPTION)
{
Console.WriteLine("Exception thrown when calling WriteFT232BEEPROM");
}
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to write device EEPROM (error " + ftStatus.ToString() + ")");
Console.ReadKey();
// Close the device
myFtdiDevice.Close();
return;
}
}
// Use cycle port to force a re-enumeration of the device.
// In the FTD2XX_NET class library, the cycle port method also
// closes the open handle so no need to call the Close method separately.
ftStatus = myFtdiDevice.CyclePort();
UInt32 newFtdiDeviceCount = 0;
do
{
// Wait for device to be re-enumerated
// The device will have the same location since it has not been
// physically unplugged, so we will keep trying to open it until it succeeds
ftStatus = myFtdiDevice.OpenByLocation(ftdiDeviceList[0].LocId);
Thread.Sleep(1000);
} while (ftStatus != FTDI.FT_STATUS.FT_OK);
// Close the device
myFtdiDevice.Close();
// Re-create our device list
ftStatus = myFtdiDevice.GetNumberOfDevices(ref newFtdiDeviceCount);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
// Wait for a key press
Console.WriteLine("Failed to get number of devices (error " + ftStatus.ToString() + ")");
Console.ReadKey();
return;
}
// Re-populate our device list
ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
for (UInt32 i = 0; i < ftdiDeviceCount; i++)
{
Console.WriteLine("Device Index: " + i.ToString());
Console.WriteLine("Flags: " + String.Format("{0:x}", ftdiDeviceList[i].Flags));
Console.WriteLine("Type: " + ftdiDeviceList[i].Type.ToString());
Console.WriteLine("ID: " + String.Format("{0:x}", ftdiDeviceList[i].ID));
Console.WriteLine("Location ID: " + String.Format("{0:x}", ftdiDeviceList[i].LocId));
Console.WriteLine("Serial Number: " + ftdiDeviceList[i].SerialNumber.ToString());
Console.WriteLine("Description: " + ftdiDeviceList[i].Description.ToString());
Console.WriteLine("");
}
}
// Wait for a key press
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
return;
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EEPROM")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("FTDI")]
[assembly: AssemblyProduct("EEPROM")]
[assembly: AssemblyCopyright("Copyright © FTDI 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4276d0d9-348e-4699-ba99-1b72708463d2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]