28 using System.Collections.Generic;
30 using System.Runtime.InteropServices;
31 using System.Threading;
33 using System.ComponentModel;
35 namespace DirectOutput.Cab.Out.FTDIChip
42 private AutoResetEvent receivedDataEvent;
43 private BackgroundWorker dataReceivedHandler;
45 #region CONSTRUCTOR_DESTRUCTOR
53 if (hFTD2XXDLL == IntPtr.Zero)
56 hFTD2XXDLL = LoadLibrary(
@"FTD2XX.DLL");
57 if (hFTD2XXDLL == IntPtr.Zero)
62 hFTD2XXDLL = LoadLibrary(@Path.GetDirectoryName(GetType().Assembly.Location) +
"\\FTD2XX.DLL");
67 if (hFTD2XXDLL != IntPtr.Zero)
70 pFT_CreateDeviceInfoList = GetProcAddress(hFTD2XXDLL,
"FT_CreateDeviceInfoList");
71 pFT_GetDeviceInfoDetail = GetProcAddress(hFTD2XXDLL,
"FT_GetDeviceInfoDetail");
72 pFT_Open = GetProcAddress(hFTD2XXDLL,
"FT_Open");
73 pFT_OpenEx = GetProcAddress(hFTD2XXDLL,
"FT_OpenEx");
74 pFT_Close = GetProcAddress(hFTD2XXDLL,
"FT_Close");
75 pFT_Read = GetProcAddress(hFTD2XXDLL,
"FT_Read");
76 pFT_Write = GetProcAddress(hFTD2XXDLL,
"FT_Write");
77 pFT_GetQueueStatus = GetProcAddress(hFTD2XXDLL,
"FT_GetQueueStatus");
78 pFT_GetModemStatus = GetProcAddress(hFTD2XXDLL,
"FT_GetModemStatus");
79 pFT_GetStatus = GetProcAddress(hFTD2XXDLL,
"FT_GetStatus");
80 pFT_SetBaudRate = GetProcAddress(hFTD2XXDLL,
"FT_SetBaudRate");
81 pFT_SetDataCharacteristics = GetProcAddress(hFTD2XXDLL,
"FT_SetDataCharacteristics");
82 pFT_SetFlowControl = GetProcAddress(hFTD2XXDLL,
"FT_SetFlowControl");
83 pFT_SetDtr = GetProcAddress(hFTD2XXDLL,
"FT_SetDtr");
84 pFT_ClrDtr = GetProcAddress(hFTD2XXDLL,
"FT_ClrDtr");
85 pFT_SetRts = GetProcAddress(hFTD2XXDLL,
"FT_SetRts");
86 pFT_ClrRts = GetProcAddress(hFTD2XXDLL,
"FT_ClrRts");
87 pFT_ResetDevice = GetProcAddress(hFTD2XXDLL,
"FT_ResetDevice");
88 pFT_ResetPort = GetProcAddress(hFTD2XXDLL,
"FT_ResetPort");
89 pFT_CyclePort = GetProcAddress(hFTD2XXDLL,
"FT_CyclePort");
90 pFT_Rescan = GetProcAddress(hFTD2XXDLL,
"FT_Rescan");
91 pFT_Reload = GetProcAddress(hFTD2XXDLL,
"FT_Reload");
92 pFT_Purge = GetProcAddress(hFTD2XXDLL,
"FT_Purge");
93 pFT_SetTimeouts = GetProcAddress(hFTD2XXDLL,
"FT_SetTimeouts");
94 pFT_SetBreakOn = GetProcAddress(hFTD2XXDLL,
"FT_SetBreakOn");
95 pFT_SetBreakOff = GetProcAddress(hFTD2XXDLL,
"FT_SetBreakOff");
96 pFT_GetDeviceInfo = GetProcAddress(hFTD2XXDLL,
"FT_GetDeviceInfo");
97 pFT_SetResetPipeRetryCount = GetProcAddress(hFTD2XXDLL,
"FT_SetResetPipeRetryCount");
98 pFT_StopInTask = GetProcAddress(hFTD2XXDLL,
"FT_StopInTask");
99 pFT_RestartInTask = GetProcAddress(hFTD2XXDLL,
"FT_RestartInTask");
100 pFT_GetDriverVersion = GetProcAddress(hFTD2XXDLL,
"FT_GetDriverVersion");
101 pFT_GetLibraryVersion = GetProcAddress(hFTD2XXDLL,
"FT_GetLibraryVersion");
102 pFT_SetDeadmanTimeout = GetProcAddress(hFTD2XXDLL,
"FT_SetDeadmanTimeout");
103 pFT_SetChars = GetProcAddress(hFTD2XXDLL,
"FT_SetChars");
104 pFT_SetEventNotification = GetProcAddress(hFTD2XXDLL,
"FT_SetEventNotification");
105 pFT_GetComPortNumber = GetProcAddress(hFTD2XXDLL,
"FT_GetComPortNumber");
106 pFT_SetLatencyTimer = GetProcAddress(hFTD2XXDLL,
"FT_SetLatencyTimer");
107 pFT_GetLatencyTimer = GetProcAddress(hFTD2XXDLL,
"FT_GetLatencyTimer");
108 pFT_SetBitMode = GetProcAddress(hFTD2XXDLL,
"FT_SetBitMode");
109 pFT_GetBitMode = GetProcAddress(hFTD2XXDLL,
"FT_GetBitMode");
110 pFT_SetUSBParameters = GetProcAddress(hFTD2XXDLL,
"FT_SetUSBParameters");
111 pFT_ReadEE = GetProcAddress(hFTD2XXDLL,
"FT_ReadEE");
112 pFT_WriteEE = GetProcAddress(hFTD2XXDLL,
"FT_WriteEE");
113 pFT_EraseEE = GetProcAddress(hFTD2XXDLL,
"FT_EraseEE");
114 pFT_EE_UASize = GetProcAddress(hFTD2XXDLL,
"FT_EE_UASize");
115 pFT_EE_UARead = GetProcAddress(hFTD2XXDLL,
"FT_EE_UARead");
116 pFT_EE_UAWrite = GetProcAddress(hFTD2XXDLL,
"FT_EE_UAWrite");
117 pFT_EE_Read = GetProcAddress(hFTD2XXDLL,
"FT_EE_Read");
118 pFT_EE_Program = GetProcAddress(hFTD2XXDLL,
"FT_EE_Program");
119 pFT_EEPROM_Read = GetProcAddress(hFTD2XXDLL,
"FT_EEPROM_Read");
120 pFT_EEPROM_Program = GetProcAddress(hFTD2XXDLL,
"FT_EEPROM_Program");
125 throw new Exception(
"Failed to load FTD2XX.DLL. Are the FTDI drivers installed?");
132 private void ReadData(
object pSender, DoWorkEventArgs pEventArgs)
134 UInt32 nrOfBytesAvailable = 0;
138 this.receivedDataEvent.WaitOne();
141 FTDI.
FT_STATUS status = GetRxBytesAvailable(ref nrOfBytesAvailable);
146 if (nrOfBytesAvailable > 0)
162 FreeLibrary(hFTD2XXDLL);
163 hFTD2XXDLL = IntPtr.Zero;
167 #region LOAD_LIBRARIES
172 [DllImport(
"kernel32.dll")]
173 private static extern IntPtr LoadLibrary(
string dllToLoad);
174 [DllImport(
"kernel32.dll")]
175 private static extern IntPtr GetProcAddress(IntPtr hModule,
string procedureName);
176 [DllImport(
"kernel32.dll")]
177 private static extern bool FreeLibrary(IntPtr hModule);
182 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
183 private delegate FT_STATUS tFT_CreateDeviceInfoList(ref UInt32 numdevs);
184 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
185 private delegate FT_STATUS tFT_GetDeviceInfoDetail(UInt32 index, ref UInt32 flags, ref FT_DEVICE chiptype, ref UInt32
id, ref UInt32 locid, byte[] serialnumber, byte[] description, ref IntPtr ftHandle);
187 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
188 private delegate FT_STATUS tFT_Open(UInt32 index, ref IntPtr ftHandle);
189 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
190 private delegate FT_STATUS tFT_OpenEx(
string devstring, UInt32 dwFlags, ref IntPtr ftHandle);
191 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
192 private delegate FT_STATUS tFT_OpenExLoc(UInt32 devloc, UInt32 dwFlags, ref IntPtr ftHandle);
193 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
194 private delegate FT_STATUS tFT_Close(IntPtr ftHandle);
196 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
197 private delegate FT_STATUS tFT_Read(IntPtr ftHandle, byte[] lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesReturned);
198 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
199 private delegate FT_STATUS tFT_Write(IntPtr ftHandle, byte[] lpBuffer, UInt32 dwBytesToWrite, ref UInt32 lpdwBytesWritten);
201 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
202 private delegate FT_STATUS tFT_GetQueueStatus(IntPtr ftHandle, ref UInt32 lpdwAmountInRxQueue);
203 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
204 private delegate FT_STATUS tFT_GetModemStatus(IntPtr ftHandle, ref UInt32 lpdwModemStatus);
205 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
206 private delegate FT_STATUS tFT_GetStatus(IntPtr ftHandle, ref UInt32 lpdwAmountInRxQueue, ref UInt32 lpdwAmountInTxQueue, ref UInt32 lpdwEventStatus);
207 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
208 private delegate FT_STATUS tFT_SetBaudRate(IntPtr ftHandle, UInt32 dwBaudRate);
209 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
210 private delegate FT_STATUS tFT_SetDataCharacteristics(IntPtr ftHandle, byte uWordLength, byte uStopBits, byte uParity);
211 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
212 private delegate FT_STATUS tFT_SetFlowControl(IntPtr ftHandle, UInt16 usFlowControl, byte uXon, byte uXoff);
213 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
214 private delegate FT_STATUS tFT_SetDtr(IntPtr ftHandle);
215 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
216 private delegate FT_STATUS tFT_ClrDtr(IntPtr ftHandle);
217 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
218 private delegate FT_STATUS tFT_SetRts(IntPtr ftHandle);
219 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
220 private delegate FT_STATUS tFT_ClrRts(IntPtr ftHandle);
221 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
222 private delegate FT_STATUS tFT_ResetDevice(IntPtr ftHandle);
223 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
224 private delegate FT_STATUS tFT_ResetPort(IntPtr ftHandle);
225 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
226 private delegate FT_STATUS tFT_CyclePort(IntPtr ftHandle);
227 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
228 private delegate FT_STATUS tFT_Rescan();
229 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
230 private delegate FT_STATUS tFT_Reload(UInt16 wVID, UInt16 wPID);
231 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
232 private delegate FT_STATUS tFT_Purge(IntPtr ftHandle, UInt32 dwMask);
233 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
234 private delegate FT_STATUS tFT_SetTimeouts(IntPtr ftHandle, UInt32 dwReadTimeout, UInt32 dwWriteTimeout);
235 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
236 private delegate FT_STATUS tFT_SetBreakOn(IntPtr ftHandle);
237 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
238 private delegate FT_STATUS tFT_SetBreakOff(IntPtr ftHandle);
240 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
241 private delegate FT_STATUS tFT_GetDeviceInfo(IntPtr ftHandle, ref FT_DEVICE pftType, ref UInt32 lpdwID, byte[] pcSerialNumber, byte[] pcDescription, IntPtr pvDummy);
243 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
244 private delegate FT_STATUS tFT_SetResetPipeRetryCount(IntPtr ftHandle, UInt32 dwCount);
245 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
246 private delegate FT_STATUS tFT_StopInTask(IntPtr ftHandle);
247 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
248 private delegate FT_STATUS tFT_RestartInTask(IntPtr ftHandle);
249 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
250 private delegate FT_STATUS tFT_GetDriverVersion(IntPtr ftHandle, ref UInt32 lpdwDriverVersion);
251 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
252 private delegate FT_STATUS tFT_GetLibraryVersion(ref UInt32 lpdwLibraryVersion);
253 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
254 private delegate FT_STATUS tFT_SetDeadmanTimeout(IntPtr ftHandle, UInt32 dwDeadmanTimeout);
255 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
256 private delegate FT_STATUS tFT_SetChars(IntPtr ftHandle, byte uEventCh, byte uEventChEn, byte uErrorCh, byte uErrorChEn);
257 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
258 private delegate FT_STATUS tFT_SetEventNotification(IntPtr ftHandle, UInt32 dwEventMask, SafeHandle hEvent);
259 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
260 private delegate FT_STATUS tFT_GetComPortNumber(IntPtr ftHandle, ref Int32 dwComPortNumber);
262 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
263 private delegate FT_STATUS tFT_SetLatencyTimer(IntPtr ftHandle, byte ucLatency);
264 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
265 private delegate FT_STATUS tFT_GetLatencyTimer(IntPtr ftHandle, ref byte ucLatency);
266 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
267 private delegate FT_STATUS tFT_SetBitMode(IntPtr ftHandle, byte ucMask, byte ucMode);
268 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
269 private delegate FT_STATUS tFT_GetBitMode(IntPtr ftHandle, ref byte ucMode);
270 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
271 private delegate FT_STATUS tFT_SetUSBParameters(IntPtr ftHandle, UInt32 dwInTransferSize, UInt32 dwOutTransferSize);
273 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
274 private delegate FT_STATUS tFT_ReadEE(IntPtr ftHandle, UInt32 dwWordOffset, ref UInt16 lpwValue);
275 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
276 private delegate FT_STATUS tFT_WriteEE(IntPtr ftHandle, UInt32 dwWordOffset, UInt16 wValue);
277 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
278 private delegate FT_STATUS tFT_EraseEE(IntPtr ftHandle);
280 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
281 private delegate FT_STATUS tFT_EE_UASize(IntPtr ftHandle, ref UInt32 dwSize);
282 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
283 private delegate FT_STATUS tFT_EE_UARead(IntPtr ftHandle, byte[] pucData, Int32 dwDataLen, ref UInt32 lpdwDataRead);
284 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
285 private delegate FT_STATUS tFT_EE_UAWrite(IntPtr ftHandle, byte[] pucData, Int32 dwDataLen);
287 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
288 private delegate FT_STATUS tFT_EE_Read(IntPtr ftHandle, FT_PROGRAM_DATA pData);
289 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
290 private delegate FT_STATUS tFT_EE_Program(IntPtr ftHandle, FT_PROGRAM_DATA pData);
292 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
293 private delegate FT_STATUS tFT_EEPROM_Read(IntPtr ftHandle, IntPtr eepromData, UInt32 eepromDataSize, byte[] manufacturer, byte[] manufacturerID, byte[] description, byte[] serialnumber);
294 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
295 private delegate FT_STATUS tFT_EEPROM_Program(IntPtr ftHandle, IntPtr eepromData, UInt32 eepromDataSize, byte[] manufacturer, byte[] manufacturerID, byte[] description, byte[] serialnumber);
298 #region CONSTANT_VALUES
320 FT_DEVICE_NOT_OPENED,
328 FT_INSUFFICIENT_RESOURCES,
332 FT_INVALID_PARAMETER,
336 FT_INVALID_BAUD_RATE,
340 FT_DEVICE_NOT_OPENED_FOR_ERASE,
344 FT_DEVICE_NOT_OPENED_FOR_WRITE,
348 FT_FAILED_TO_WRITE_DEVICE,
352 FT_EEPROM_READ_FAILED,
356 FT_EEPROM_WRITE_FAILED,
360 FT_EEPROM_ERASE_FAILED,
364 FT_EEPROM_NOT_PRESENT,
368 FT_EEPROM_NOT_PROGRAMMED,
383 private enum FT_ERROR
392 private const UInt32 FT_OPEN_BY_SERIAL_NUMBER = 0x00000001;
393 private const UInt32 FT_OPEN_BY_DESCRIPTION = 0x00000002;
394 private const UInt32 FT_OPEN_BY_LOCATION = 0x00000004;
405 public const byte FT_BITS_8 = 0x08;
409 public const byte FT_BITS_7 = 0x07;
421 public const byte FT_STOP_BITS_1 = 0x00;
425 public const byte FT_STOP_BITS_2 = 0x02;
437 public const byte FT_PARITY_NONE = 0x00;
441 public const byte FT_PARITY_ODD = 0x01;
445 public const byte FT_PARITY_EVEN = 0x02;
449 public const byte FT_PARITY_MARK = 0x03;
453 public const byte FT_PARITY_SPACE = 0x04;
465 public const UInt16 FT_FLOW_NONE = 0x0000;
469 public const UInt16 FT_FLOW_RTS_CTS = 0x0100;
473 public const UInt16 FT_FLOW_DTR_DSR = 0x0200;
477 public const UInt16 FT_FLOW_XON_XOFF = 0x0400;
489 public const byte FT_PURGE_RX = 0x01;
493 public const byte FT_PURGE_TX = 0x02;
505 public const byte FT_CTS = 0x10;
509 public const byte FT_DSR = 0x20;
513 public const byte FT_RI = 0x40;
517 public const byte FT_DCD = 0x80;
529 public const byte FT_OE = 0x02;
533 public const byte FT_PE = 0x04;
537 public const byte FT_FE = 0x08;
541 public const byte FT_BI = 0x10;
553 public const UInt32 FT_EVENT_RXCHAR = 0x00000001;
557 public const UInt32 FT_EVENT_MODEM_STATUS = 0x00000002;
561 public const UInt32 FT_EVENT_LINE_STATUS = 0x00000004;
573 public const byte FT_BIT_MODE_RESET = 0x00;
577 public const byte FT_BIT_MODE_ASYNC_BITBANG = 0x01;
581 public const byte FT_BIT_MODE_MPSSE = 0x02;
585 public const byte FT_BIT_MODE_SYNC_BITBANG = 0x04;
589 public const byte FT_BIT_MODE_MCU_HOST = 0x08;
593 public const byte FT_BIT_MODE_FAST_SERIAL = 0x10;
597 public const byte FT_BIT_MODE_CBUS_BITBANG = 0x20;
601 public const byte FT_BIT_MODE_SYNC_FIFO = 0x40;
613 public const byte FT_CBUS_TXDEN = 0x00;
617 public const byte FT_CBUS_PWRON = 0x01;
621 public const byte FT_CBUS_RXLED = 0x02;
625 public const byte FT_CBUS_TXLED = 0x03;
629 public const byte FT_CBUS_TXRXLED = 0x04;
633 public const byte FT_CBUS_SLEEP = 0x05;
637 public const byte FT_CBUS_CLK48 = 0x06;
641 public const byte FT_CBUS_CLK24 = 0x07;
645 public const byte FT_CBUS_CLK12 = 0x08;
649 public const byte FT_CBUS_CLK6 = 0x09;
653 public const byte FT_CBUS_IOMODE = 0x0A;
657 public const byte FT_CBUS_BITBANG_WR = 0x0B;
661 public const byte FT_CBUS_BITBANG_RD = 0x0C;
673 public const byte FT_CBUS_TRISTATE = 0x00;
677 public const byte FT_CBUS_RXLED = 0x01;
681 public const byte FT_CBUS_TXLED = 0x02;
685 public const byte FT_CBUS_TXRXLED = 0x03;
689 public const byte FT_CBUS_PWREN = 0x04;
693 public const byte FT_CBUS_SLEEP = 0x05;
697 public const byte FT_CBUS_DRIVE_0 = 0x06;
701 public const byte FT_CBUS_DRIVE_1 = 0x07;
705 public const byte FT_CBUS_IOMODE = 0x08;
709 public const byte FT_CBUS_TXDEN = 0x09;
713 public const byte FT_CBUS_CLK30 = 0x0A;
717 public const byte FT_CBUS_CLK15 = 0x0B;
720 public const byte FT_CBUS_CLK7_5 = 0x0C;
731 public const byte FT_CBUS_TRISTATE = 0x00;
735 public const byte FT_CBUS_RXLED = 0x01;
739 public const byte FT_CBUS_TXLED = 0x02;
743 public const byte FT_CBUS_TXRXLED = 0x03;
747 public const byte FT_CBUS_PWREN = 0x04;
751 public const byte FT_CBUS_SLEEP = 0x05;
755 public const byte FT_CBUS_Drive_0 = 0x06;
759 public const byte FT_CBUS_Drive_1 = 0x07;
763 public const byte FT_CBUS_GPIO = 0x08;
767 public const byte FT_CBUS_TXDEN = 0x09;
771 public const byte FT_CBUS_CLK24MHz = 0x0A;
775 public const byte FT_CBUS_CLK12MHz = 0x0B;
779 public const byte FT_CBUS_CLK6MHz = 0x0C;
783 public const byte FT_CBUS_BCD_Charger = 0x0D;
787 public const byte FT_CBUS_BCD_Charger_N = 0x0E;
791 public const byte FT_CBUS_I2C_TXE = 0x0F;
795 public const byte FT_CBUS_I2C_RXF = 0x10;
799 public const byte FT_CBUS_VBUS_Sense = 0x11;
803 public const byte FT_CBUS_BitBang_WR = 0x12;
807 public const byte FT_CBUS_BitBang_RD = 0x13;
811 public const byte FT_CBUS_Time_Stamp = 0x14;
815 public const byte FT_CBUS_Keep_Awake = 0x15;
827 public const UInt32 FT_FLAGS_OPENED = 0x00000001;
831 public const UInt32 FT_FLAGS_HISPEED = 0x00000002;
843 public const byte FT_DRIVE_CURRENT_4MA = 4;
847 public const byte FT_DRIVE_CURRENT_8MA = 8;
851 public const byte FT_DRIVE_CURRENT_12MA = 12;
855 public const byte FT_DRIVE_CURRENT_16MA = 16;
907 #region DEFAULT_VALUES
908 private const UInt32 FT_DEFAULT_BAUD_RATE = 9600;
909 private const UInt32 FT_DEFAULT_DEADMAN_TIMEOUT = 5000;
910 private const Int32 FT_COM_PORT_NOT_ASSIGNED = -1;
911 private const UInt32 FT_DEFAULT_IN_TRANSFER_SIZE = 0x1000;
912 private const UInt32 FT_DEFAULT_OUT_TRANSFER_SIZE = 0x1000;
913 private const byte FT_DEFAULT_LATENCY = 16;
914 private const UInt32 FT_DEFAULT_DEVICE_ID = 0x04036001;
919 private IntPtr ftHandle = IntPtr.Zero;
961 #region EEPROM_STRUCTURES
964 [StructLayout(LayoutKind.Sequential, Pack = 4)]
965 private class FT_PROGRAM_DATA
967 public UInt32 Signature1;
968 public UInt32 Signature2;
969 public UInt32 Version;
970 public UInt16 VendorID;
971 public UInt16 ProductID;
973 public IntPtr Manufacturer;
974 public IntPtr ManufacturerID;
975 public IntPtr Description;
976 public IntPtr SerialNumber;
978 public UInt16 MaxPower;
980 public UInt16 SelfPowered;
981 public UInt16 RemoteWakeup;
986 public byte PullDownEnable;
987 public byte SerNumEnable;
988 public byte USBVersionEnable;
989 public UInt16 USBVersion;
996 public byte PullDownEnable5;
997 public byte SerNumEnable5;
998 public byte USBVersionEnable5;
999 public UInt16 USBVersion5;
1000 public byte AIsHighCurrent;
1001 public byte BIsHighCurrent;
1002 public byte IFAIsFifo;
1003 public byte IFAIsFifoTar;
1004 public byte IFAIsFastSer;
1006 public byte IFBIsFifo;
1007 public byte IFBIsFifoTar;
1008 public byte IFBIsFastSer;
1011 public byte UseExtOsc;
1012 public byte HighDriveIOs;
1013 public byte EndpointSize;
1014 public byte PullDownEnableR;
1015 public byte SerNumEnableR;
1016 public byte InvertTXD;
1017 public byte InvertRXD;
1018 public byte InvertRTS;
1019 public byte InvertCTS;
1020 public byte InvertDTR;
1021 public byte InvertDSR;
1022 public byte InvertDCD;
1023 public byte InvertRI;
1029 public byte RIsD2XX;
1031 public byte PullDownEnable7;
1032 public byte SerNumEnable7;
1033 public byte ALSlowSlew;
1034 public byte ALSchmittInput;
1035 public byte ALDriveCurrent;
1036 public byte AHSlowSlew;
1037 public byte AHSchmittInput;
1038 public byte AHDriveCurrent;
1039 public byte BLSlowSlew;
1040 public byte BLSchmittInput;
1041 public byte BLDriveCurrent;
1042 public byte BHSlowSlew;
1043 public byte BHSchmittInput;
1044 public byte BHDriveCurrent;
1045 public byte IFAIsFifo7;
1046 public byte IFAIsFifoTar7;
1047 public byte IFAIsFastSer7;
1048 public byte AIsVCP7;
1049 public byte IFBIsFifo7;
1050 public byte IFBIsFifoTar7;
1051 public byte IFBIsFastSer7;
1052 public byte BIsVCP7;
1053 public byte PowerSaveEnable;
1055 public byte PullDownEnable8;
1056 public byte SerNumEnable8;
1057 public byte ASlowSlew;
1058 public byte ASchmittInput;
1059 public byte ADriveCurrent;
1060 public byte BSlowSlew;
1061 public byte BSchmittInput;
1062 public byte BDriveCurrent;
1063 public byte CSlowSlew;
1064 public byte CSchmittInput;
1065 public byte CDriveCurrent;
1066 public byte DSlowSlew;
1067 public byte DSchmittInput;
1068 public byte DDriveCurrent;
1069 public byte ARIIsTXDEN;
1070 public byte BRIIsTXDEN;
1071 public byte CRIIsTXDEN;
1072 public byte DRIIsTXDEN;
1073 public byte AIsVCP8;
1074 public byte BIsVCP8;
1075 public byte CIsVCP8;
1076 public byte DIsVCP8;
1078 public byte PullDownEnableH;
1079 public byte SerNumEnableH;
1080 public byte ACSlowSlewH;
1081 public byte ACSchmittInputH;
1082 public byte ACDriveCurrentH;
1083 public byte ADSlowSlewH;
1084 public byte ADSchmittInputH;
1085 public byte ADDriveCurrentH;
1096 public byte IsFifoH;
1097 public byte IsFifoTarH;
1098 public byte IsFastSerH;
1099 public byte IsFT1248H;
1100 public byte FT1248CpolH;
1101 public byte FT1248LsbH;
1102 public byte FT1248FlowControlH;
1104 public byte PowerSaveEnableH;
1107 [StructLayout(LayoutKind.Sequential, Pack = 4)]
1108 struct FT_EEPROM_HEADER
1110 public UInt32 deviceType;
1112 public UInt16 VendorId;
1113 public UInt16 ProductId;
1114 public byte SerNumEnable;
1116 public UInt16 MaxPower;
1117 public byte SelfPowered;
1118 public byte RemoteWakeup;
1120 public byte PullDownEnable;
1123 [StructLayout(LayoutKind.Sequential, Pack = 4)]
1124 struct FT_XSERIES_DATA
1126 public FT_EEPROM_HEADER common;
1128 public byte ACSlowSlew;
1129 public byte ACSchmittInput;
1130 public byte ACDriveCurrent;
1131 public byte ADSlowSlew;
1132 public byte ADSchmittInput;
1133 public byte ADDriveCurrent;
1143 public byte InvertTXD;
1144 public byte InvertRXD;
1145 public byte InvertRTS;
1146 public byte InvertCTS;
1147 public byte InvertDTR;
1148 public byte InvertDSR;
1149 public byte InvertDCD;
1150 public byte InvertRI;
1152 public byte BCDEnable;
1153 public byte BCDForceCbusPWREN;
1154 public byte BCDDisableSleep;
1156 public UInt16 I2CSlaveAddress;
1157 public UInt32 I2CDeviceId;
1158 public byte I2CDisableSchmitt;
1160 public byte FT1248Cpol;
1161 public byte FT1248Lsb;
1162 public byte FT1248FlowControl;
1164 public byte RS485EchoSuppress;
1165 public byte PowerSaveEnable;
1167 public byte DriverType;
1182 public UInt16 VendorID = 0x0403;
1186 public UInt16 ProductID = 0x6001;
1190 public string Manufacturer =
"FTDI";
1194 public string ManufacturerID =
"FT";
1198 public string Description =
"USB-Serial Converter";
1202 public string SerialNumber =
"";
1206 public UInt16 MaxPower = 0x0090;
1211 public bool SelfPowered =
false;
1215 public bool RemoteWakeup =
false;
1231 public bool PullDownEnable =
false;
1235 public bool SerNumEnable =
true;
1239 public bool USBVersionEnable =
true;
1243 public UInt16 USBVersion = 0x0200;
1261 public bool PullDownEnable =
false;
1265 public bool SerNumEnable =
true;
1269 public bool USBVersionEnable =
true;
1273 public UInt16 USBVersion = 0x0200;
1277 public bool AIsHighCurrent =
false;
1281 public bool BIsHighCurrent =
false;
1285 public bool IFAIsFifo =
false;
1289 public bool IFAIsFifoTar =
false;
1293 public bool IFAIsFastSer =
false;
1297 public bool AIsVCP =
true;
1301 public bool IFBIsFifo =
false;
1305 public bool IFBIsFifoTar =
false;
1309 public bool IFBIsFastSer =
false;
1313 public bool BIsVCP =
true;
1327 public bool UseExtOsc =
false;
1331 public bool HighDriveIOs =
false;
1335 public byte EndpointSize = 64;
1339 public bool PullDownEnable =
false;
1343 public bool SerNumEnable =
true;
1347 public bool InvertTXD =
false;
1351 public bool InvertRXD =
false;
1355 public bool InvertRTS =
false;
1359 public bool InvertCTS =
false;
1363 public bool InvertDTR =
false;
1367 public bool InvertDSR =
false;
1371 public bool InvertDCD =
false;
1375 public bool InvertRI =
false;
1414 public bool RIsD2XX =
false;
1427 public bool PullDownEnable =
false;
1431 public bool SerNumEnable =
true;
1435 public bool ALSlowSlew =
false;
1439 public bool ALSchmittInput =
false;
1447 public bool AHSlowSlew =
false;
1451 public bool AHSchmittInput =
false;
1459 public bool BLSlowSlew =
false;
1463 public bool BLSchmittInput =
false;
1471 public bool BHSlowSlew =
false;
1475 public bool BHSchmittInput =
false;
1483 public bool IFAIsFifo =
false;
1487 public bool IFAIsFifoTar =
false;
1491 public bool IFAIsFastSer =
false;
1495 public bool AIsVCP =
true;
1499 public bool IFBIsFifo =
false;
1503 public bool IFBIsFifoTar =
false;
1507 public bool IFBIsFastSer =
false;
1511 public bool BIsVCP =
true;
1515 public bool PowerSaveEnable =
false;
1528 public bool PullDownEnable =
false;
1532 public bool SerNumEnable =
true;
1536 public bool ASlowSlew =
false;
1540 public bool ASchmittInput =
false;
1548 public bool BSlowSlew =
false;
1552 public bool BSchmittInput =
false;
1560 public bool CSlowSlew =
false;
1564 public bool CSchmittInput =
false;
1572 public bool DSlowSlew =
false;
1576 public bool DSchmittInput =
false;
1584 public bool ARIIsTXDEN =
false;
1588 public bool BRIIsTXDEN =
false;
1592 public bool CRIIsTXDEN =
false;
1596 public bool DRIIsTXDEN =
false;
1600 public bool AIsVCP =
true;
1604 public bool BIsVCP =
true;
1608 public bool CIsVCP =
true;
1612 public bool DIsVCP =
true;
1624 public bool PullDownEnable =
false;
1628 public bool SerNumEnable =
true;
1632 public bool ACSlowSlew =
false;
1636 public bool ACSchmittInput =
false;
1644 public bool ADSlowSlew =
false;
1648 public bool ADSchmittInput =
false;
1721 public bool IsFifo =
false;
1725 public bool IsFifoTar =
false;
1729 public bool IsFastSer =
false;
1733 public bool IsFT1248 =
false;
1737 public bool FT1248Cpol =
false;
1741 public bool FT1248Lsb =
false;
1745 public bool FT1248FlowControl =
false;
1749 public bool IsVCP =
true;
1753 public bool PowerSaveEnable =
false;
1765 public bool PullDownEnable =
false;
1769 public bool SerNumEnable =
true;
1773 public bool USBVersionEnable =
true;
1777 public UInt16 USBVersion = 0x0200;
1942 #region EXCEPTION_HANDLING
1946 [global::System.Serializable]
1963 public FT_EXCEPTION(
string message, Exception inner) : base(message, inner) { }
1970 System.Runtime.Serialization.SerializationInfo info,
1971 System.Runtime.Serialization.StreamingContext context)
1972 : base(info, context) { }
1976 #region FUNCTION_IMPORTS_FTD2XX.DLL
1978 IntPtr hFTD2XXDLL = IntPtr.Zero;
1981 IntPtr pFT_CreateDeviceInfoList = IntPtr.Zero;
1982 IntPtr pFT_GetDeviceInfoDetail = IntPtr.Zero;
1983 IntPtr pFT_Open = IntPtr.Zero;
1984 IntPtr pFT_OpenEx = IntPtr.Zero;
1985 IntPtr pFT_Close = IntPtr.Zero;
1986 IntPtr pFT_Read = IntPtr.Zero;
1987 IntPtr pFT_Write = IntPtr.Zero;
1988 IntPtr pFT_GetQueueStatus = IntPtr.Zero;
1989 IntPtr pFT_GetModemStatus = IntPtr.Zero;
1990 IntPtr pFT_GetStatus = IntPtr.Zero;
1991 IntPtr pFT_SetBaudRate = IntPtr.Zero;
1992 IntPtr pFT_SetDataCharacteristics = IntPtr.Zero;
1993 IntPtr pFT_SetFlowControl = IntPtr.Zero;
1994 IntPtr pFT_SetDtr = IntPtr.Zero;
1995 IntPtr pFT_ClrDtr = IntPtr.Zero;
1996 IntPtr pFT_SetRts = IntPtr.Zero;
1997 IntPtr pFT_ClrRts = IntPtr.Zero;
1998 IntPtr pFT_ResetDevice = IntPtr.Zero;
1999 IntPtr pFT_ResetPort = IntPtr.Zero;
2000 IntPtr pFT_CyclePort = IntPtr.Zero;
2001 IntPtr pFT_Rescan = IntPtr.Zero;
2002 IntPtr pFT_Reload = IntPtr.Zero;
2003 IntPtr pFT_Purge = IntPtr.Zero;
2004 IntPtr pFT_SetTimeouts = IntPtr.Zero;
2005 IntPtr pFT_SetBreakOn = IntPtr.Zero;
2006 IntPtr pFT_SetBreakOff = IntPtr.Zero;
2007 IntPtr pFT_GetDeviceInfo = IntPtr.Zero;
2008 IntPtr pFT_SetResetPipeRetryCount = IntPtr.Zero;
2009 IntPtr pFT_StopInTask = IntPtr.Zero;
2010 IntPtr pFT_RestartInTask = IntPtr.Zero;
2011 IntPtr pFT_GetDriverVersion = IntPtr.Zero;
2012 IntPtr pFT_GetLibraryVersion = IntPtr.Zero;
2013 IntPtr pFT_SetDeadmanTimeout = IntPtr.Zero;
2014 IntPtr pFT_SetChars = IntPtr.Zero;
2015 IntPtr pFT_SetEventNotification = IntPtr.Zero;
2016 IntPtr pFT_GetComPortNumber = IntPtr.Zero;
2017 IntPtr pFT_SetLatencyTimer = IntPtr.Zero;
2018 IntPtr pFT_GetLatencyTimer = IntPtr.Zero;
2019 IntPtr pFT_SetBitMode = IntPtr.Zero;
2020 IntPtr pFT_GetBitMode = IntPtr.Zero;
2021 IntPtr pFT_SetUSBParameters = IntPtr.Zero;
2022 IntPtr pFT_ReadEE = IntPtr.Zero;
2023 IntPtr pFT_WriteEE = IntPtr.Zero;
2024 IntPtr pFT_EraseEE = IntPtr.Zero;
2025 IntPtr pFT_EE_UASize = IntPtr.Zero;
2026 IntPtr pFT_EE_UARead = IntPtr.Zero;
2027 IntPtr pFT_EE_UAWrite = IntPtr.Zero;
2028 IntPtr pFT_EE_Read = IntPtr.Zero;
2029 IntPtr pFT_EE_Program = IntPtr.Zero;
2030 IntPtr pFT_EEPROM_Read = IntPtr.Zero;
2031 IntPtr pFT_EEPROM_Program = IntPtr.Zero;
2034 #region METHOD_DEFINITIONS
2050 if (hFTD2XXDLL == IntPtr.Zero)
2054 if (pFT_CreateDeviceInfoList != IntPtr.Zero)
2056 tFT_CreateDeviceInfoList FT_CreateDeviceInfoList = (tFT_CreateDeviceInfoList)Marshal.GetDelegateForFunctionPointer(pFT_CreateDeviceInfoList, typeof(tFT_CreateDeviceInfoList));
2059 ftStatus = FT_CreateDeviceInfoList(ref devcount);
2063 throw new Exception(
"Failed to load function FT_CreateDeviceInfoList.");
2084 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
2087 if (hFTD2XXDLL == IntPtr.Zero)
2091 if ((pFT_CreateDeviceInfoList != IntPtr.Zero) & (pFT_GetDeviceInfoDetail != IntPtr.Zero))
2093 UInt32 devcount = 0;
2095 tFT_CreateDeviceInfoList FT_CreateDeviceInfoList = (tFT_CreateDeviceInfoList)Marshal.GetDelegateForFunctionPointer(pFT_CreateDeviceInfoList, typeof(tFT_CreateDeviceInfoList));
2096 tFT_GetDeviceInfoDetail FT_GetDeviceInfoDetail = (tFT_GetDeviceInfoDetail)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfoDetail, typeof(tFT_GetDeviceInfoDetail));
2099 ftStatus = FT_CreateDeviceInfoList(ref devcount);
2103 byte[] sernum =
new byte[16];
2104 byte[] desc =
new byte[64];
2109 if (devicelist.Length < devcount)
2112 ftErrorCondition = FT_ERROR.FT_BUFFER_SIZE;
2114 ErrorHandler(ftStatus, ftErrorCondition);
2118 for (UInt32 i = 0; i < devcount; i++)
2122 ftStatus = FT_GetDeviceInfoDetail(i, ref devicelist[i].Flags, ref devicelist[i].Type, ref devicelist[i].ID, ref devicelist[i].LocId, sernum, desc, ref devicelist[i].ftHandle);
2124 devicelist[i].
SerialNumber = Encoding.ASCII.GetString(sernum);
2125 devicelist[i].
Description = Encoding.ASCII.GetString(desc);
2128 devicelist[i].
Description = devicelist[i].
Description.Substring(0, devicelist[i].Description.IndexOf(
"\0"));
2134 if (pFT_CreateDeviceInfoList == IntPtr.Zero)
2136 throw new Exception(
"Failed to load function FT_CreateDeviceInfoList.");
2138 if (pFT_GetDeviceInfoDetail == IntPtr.Zero)
2140 throw new Exception(
"Failed to load function FT_GetDeviceInfoListDetail.");
2158 public FT_STATUS OpenByIndex(UInt32 index)
2164 if (hFTD2XXDLL == IntPtr.Zero)
2168 if ((pFT_Open != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2170 tFT_Open FT_Open = (tFT_Open)Marshal.GetDelegateForFunctionPointer(pFT_Open, typeof(tFT_Open));
2171 tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
2172 tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
2173 tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
2176 ftStatus = FT_Open(index, ref ftHandle);
2180 ftHandle = IntPtr.Zero;
2182 if (ftHandle != IntPtr.Zero)
2188 ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2193 ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2195 UInt32 BaudRate = 9600;
2196 ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2201 if (pFT_Open == IntPtr.Zero)
2203 throw new Exception(
"Failed to load function FT_Open.");
2205 if (pFT_SetDataCharacteristics == IntPtr.Zero)
2207 throw new Exception(
"Failed to load function FT_SetDataCharacteristics.");
2209 if (pFT_SetFlowControl == IntPtr.Zero)
2211 throw new Exception(
"Failed to load function FT_SetFlowControl.");
2213 if (pFT_SetBaudRate == IntPtr.Zero)
2215 throw new Exception(
"Failed to load function FT_SetBaudRate.");
2240 public FT_STATUS OpenBySerialNumber(
string serialnumber)
2246 if (hFTD2XXDLL == IntPtr.Zero)
2250 if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2252 tFT_OpenEx FT_OpenEx = (tFT_OpenEx)Marshal.GetDelegateForFunctionPointer(pFT_OpenEx, typeof(tFT_OpenEx));
2253 tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
2254 tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
2255 tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
2258 ftStatus = FT_OpenEx(serialnumber, FT_OPEN_BY_SERIAL_NUMBER, ref ftHandle);
2262 ftHandle = IntPtr.Zero;
2264 if (ftHandle != IntPtr.Zero)
2270 ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2275 ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2277 UInt32 BaudRate = 9600;
2278 ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2283 if (pFT_OpenEx == IntPtr.Zero)
2285 throw new Exception(
"Failed to load function FT_OpenEx.");
2287 if (pFT_SetDataCharacteristics == IntPtr.Zero)
2289 throw new Exception(
"Failed to load function FT_SetDataCharacteristics.");
2291 if (pFT_SetFlowControl == IntPtr.Zero)
2293 throw new Exception(
"Failed to load function FT_SetFlowControl.");
2295 if (pFT_SetBaudRate == IntPtr.Zero)
2297 throw new Exception(
"Failed to load function FT_SetBaudRate.");
2301 if (ftStatus == FT_STATUS.FT_OK)
2321 public FT_STATUS OpenByDescription(
string description)
2327 if (hFTD2XXDLL == IntPtr.Zero)
2331 if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2333 tFT_OpenEx FT_OpenEx = (tFT_OpenEx)Marshal.GetDelegateForFunctionPointer(pFT_OpenEx, typeof(tFT_OpenEx));
2334 tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
2335 tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
2336 tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
2339 ftStatus = FT_OpenEx(description, FT_OPEN_BY_DESCRIPTION, ref ftHandle);
2343 ftHandle = IntPtr.Zero;
2345 if (ftHandle != IntPtr.Zero)
2351 ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2356 ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2358 UInt32 BaudRate = 9600;
2359 ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2364 if (pFT_OpenEx == IntPtr.Zero)
2366 throw new Exception(
"Failed to load function FT_OpenEx.");
2368 if (pFT_SetDataCharacteristics == IntPtr.Zero)
2370 throw new Exception(
"Failed to load function FT_SetDataCharacteristics.");
2372 if (pFT_SetFlowControl == IntPtr.Zero)
2374 throw new Exception(
"Failed to load function FT_SetFlowControl.");
2376 if (pFT_SetBaudRate == IntPtr.Zero)
2378 throw new Exception(
"Failed to load function FT_SetBaudRate.");
2382 if (ftStatus == FT_STATUS.FT_OK)
2400 public FT_STATUS OpenByLocation(UInt32 location)
2403 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2406 if (hFTD2XXDLL == IntPtr.Zero)
2410 if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2412 tFT_OpenExLoc FT_OpenEx = (tFT_OpenExLoc)Marshal.GetDelegateForFunctionPointer(pFT_OpenEx, typeof(tFT_OpenExLoc));
2413 tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
2414 tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
2415 tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
2418 ftStatus = FT_OpenEx(location, FT_OPEN_BY_LOCATION, ref ftHandle);
2422 ftHandle = IntPtr.Zero;
2424 if (ftHandle != IntPtr.Zero)
2430 ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2435 ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2437 UInt32 BaudRate = 9600;
2438 ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2443 if (pFT_OpenEx == IntPtr.Zero)
2445 throw new Exception(
"Failed to load function FT_OpenEx.");
2447 if (pFT_SetDataCharacteristics == IntPtr.Zero)
2449 throw new Exception(
"Failed to load function FT_SetDataCharacteristics.");
2451 if (pFT_SetFlowControl == IntPtr.Zero)
2453 throw new Exception(
"Failed to load function FT_SetFlowControl.");
2455 if (pFT_SetBaudRate == IntPtr.Zero)
2457 throw new Exception(
"Failed to load function FT_SetBaudRate.");
2461 if (ftStatus == FT_STATUS.FT_OK)
2470 private void SetupEvent() {
2471 receivedDataEvent =
new AutoResetEvent(
false);
2472 FT_STATUS Status = SetEventNotification(FTDI.FT_EVENTS.FT_EVENT_RXCHAR, receivedDataEvent);
2473 ErrorHandler(Status, FT_ERROR.FT_NO_ERROR);
2475 dataReceivedHandler =
new BackgroundWorker();
2476 dataReceivedHandler.DoWork += ReadData;
2477 if (!dataReceivedHandler.IsBusy)
2479 dataReceivedHandler.RunWorkerAsync();
2487 public event EventHandler<EventArgs> CharReceived;
2491 private void OnCharReceived()
2493 if (CharReceived != null)
2495 CharReceived(
this,
new EventArgs());
2508 public FT_STATUS Close()
2511 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2514 if (hFTD2XXDLL == IntPtr.Zero)
2518 if (pFT_Close != IntPtr.Zero)
2520 tFT_Close FT_Close = (tFT_Close)Marshal.GetDelegateForFunctionPointer(pFT_Close, typeof(tFT_Close));
2523 ftStatus = FT_Close(ftHandle);
2527 ftHandle = IntPtr.Zero;
2532 if (pFT_Close == IntPtr.Zero)
2534 throw new Exception(
"Failed to load function FT_Close.");
2552 public FT_STATUS Read(byte[] dataBuffer, UInt32 numBytesToRead, ref UInt32 numBytesRead)
2555 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2558 if (hFTD2XXDLL == IntPtr.Zero)
2562 if (pFT_Read != IntPtr.Zero)
2565 tFT_Read FT_Read = (tFT_Read)Marshal.GetDelegateForFunctionPointer(pFT_Read, typeof(tFT_Read));
2568 if (dataBuffer.Length < numBytesToRead)
2570 numBytesToRead = (uint)dataBuffer.Length;
2573 if (ftHandle != IntPtr.Zero)
2576 ftStatus = FT_Read(ftHandle, dataBuffer, numBytesToRead, ref numBytesRead);
2581 if (pFT_Read == IntPtr.Zero)
2583 throw new Exception(
"Failed to load function FT_Read.");
2597 public FT_STATUS Read(out
string dataBuffer, UInt32 numBytesToRead, ref UInt32 numBytesRead)
2600 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2603 dataBuffer =
string.Empty;
2606 if (hFTD2XXDLL == IntPtr.Zero)
2610 if (pFT_Read != IntPtr.Zero)
2612 tFT_Read FT_Read = (tFT_Read)Marshal.GetDelegateForFunctionPointer(pFT_Read, typeof(tFT_Read));
2614 byte[] byteDataBuffer =
new byte[numBytesToRead];
2616 if (ftHandle != IntPtr.Zero)
2619 ftStatus = FT_Read(ftHandle, byteDataBuffer, numBytesToRead, ref numBytesRead);
2622 dataBuffer = Encoding.ASCII.GetString(byteDataBuffer);
2624 dataBuffer = dataBuffer.Substring(0, (
int)numBytesRead);
2629 if (pFT_Read == IntPtr.Zero)
2631 throw new Exception(
"Failed to load function FT_Read.");
2648 public FT_STATUS Write(byte[] dataBuffer, Int32 numBytesToWrite, ref UInt32 numBytesWritten)
2651 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2654 if (hFTD2XXDLL == IntPtr.Zero)
2658 if (pFT_Write != IntPtr.Zero)
2660 tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2662 if (ftHandle != IntPtr.Zero)
2665 ftStatus = FT_Write(ftHandle, dataBuffer, (UInt32)numBytesToWrite, ref numBytesWritten);
2670 if (pFT_Write == IntPtr.Zero)
2672 throw new Exception(
"Failed to load function FT_Write.");
2686 public FT_STATUS Write(byte[] dataBuffer, UInt32 numBytesToWrite, ref UInt32 numBytesWritten)
2689 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2692 if (hFTD2XXDLL == IntPtr.Zero)
2696 if (pFT_Write != IntPtr.Zero)
2698 tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2700 if (ftHandle != IntPtr.Zero)
2703 ftStatus = FT_Write(ftHandle, dataBuffer, numBytesToWrite, ref numBytesWritten);
2708 if (pFT_Write == IntPtr.Zero)
2710 throw new Exception(
"Failed to load function FT_Write.");
2724 public FT_STATUS Write(
string dataBuffer, Int32 numBytesToWrite, ref UInt32 numBytesWritten)
2727 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2730 if (hFTD2XXDLL == IntPtr.Zero)
2734 if (pFT_Write != IntPtr.Zero)
2736 tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2739 byte[] byteDataBuffer = Encoding.ASCII.GetBytes(dataBuffer);
2741 if (ftHandle != IntPtr.Zero)
2744 ftStatus = FT_Write(ftHandle, byteDataBuffer, (UInt32)numBytesToWrite, ref numBytesWritten);
2749 if (pFT_Write == IntPtr.Zero)
2751 throw new Exception(
"Failed to load function FT_Write.");
2765 public FT_STATUS Write(
string dataBuffer, UInt32 numBytesToWrite, ref UInt32 numBytesWritten)
2768 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2771 if (hFTD2XXDLL == IntPtr.Zero)
2775 if (pFT_Write != IntPtr.Zero)
2777 tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2780 byte[] byteDataBuffer = Encoding.ASCII.GetBytes(dataBuffer);
2782 if (ftHandle != IntPtr.Zero)
2785 ftStatus = FT_Write(ftHandle, byteDataBuffer, numBytesToWrite, ref numBytesWritten);
2790 if (pFT_Write == IntPtr.Zero)
2792 throw new Exception(
"Failed to load function FT_Write.");
2806 public FT_STATUS ResetDevice()
2809 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2812 if (hFTD2XXDLL == IntPtr.Zero)
2816 if (pFT_ResetDevice != IntPtr.Zero)
2818 tFT_ResetDevice FT_ResetDevice = (tFT_ResetDevice)Marshal.GetDelegateForFunctionPointer(pFT_ResetDevice, typeof(tFT_ResetDevice));
2820 if (ftHandle != IntPtr.Zero)
2823 ftStatus = FT_ResetDevice(ftHandle);
2828 if (pFT_ResetDevice == IntPtr.Zero)
2830 throw new Exception(
"Failed to load function FT_ResetDevice.");
2845 public FT_STATUS Purge(UInt32 purgemask)
2848 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2851 if (hFTD2XXDLL == IntPtr.Zero)
2855 if (pFT_Purge != IntPtr.Zero)
2857 tFT_Purge FT_Purge = (tFT_Purge)Marshal.GetDelegateForFunctionPointer(pFT_Purge, typeof(tFT_Purge));
2859 if (ftHandle != IntPtr.Zero)
2862 ftStatus = FT_Purge(ftHandle, purgemask);
2867 if (pFT_Purge == IntPtr.Zero)
2869 throw new Exception(
"Failed to load function FT_Purge.");
2886 private FT_STATUS SetEventNotification(UInt32 eventmask, EventWaitHandle eventhandle)
2889 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2892 if (hFTD2XXDLL == IntPtr.Zero)
2896 if (pFT_SetEventNotification != IntPtr.Zero)
2898 tFT_SetEventNotification FT_SetEventNotification = (tFT_SetEventNotification)Marshal.GetDelegateForFunctionPointer(pFT_SetEventNotification, typeof(tFT_SetEventNotification));
2900 if (ftHandle != IntPtr.Zero)
2903 ftStatus = FT_SetEventNotification(ftHandle, eventmask, eventhandle.SafeWaitHandle);
2908 if (pFT_SetEventNotification == IntPtr.Zero)
2910 throw new Exception(
"Failed to load function FT_SetEventNotification.");
2924 public FT_STATUS StopInTask()
2927 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2930 if (hFTD2XXDLL == IntPtr.Zero)
2934 if (pFT_StopInTask != IntPtr.Zero)
2936 tFT_StopInTask FT_StopInTask = (tFT_StopInTask)Marshal.GetDelegateForFunctionPointer(pFT_StopInTask, typeof(tFT_StopInTask));
2938 if (ftHandle != IntPtr.Zero)
2941 ftStatus = FT_StopInTask(ftHandle);
2946 if (pFT_StopInTask == IntPtr.Zero)
2948 throw new Exception(
"Failed to load function FT_StopInTask.");
2962 public FT_STATUS RestartInTask()
2965 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2968 if (hFTD2XXDLL == IntPtr.Zero)
2972 if (pFT_RestartInTask != IntPtr.Zero)
2974 tFT_RestartInTask FT_RestartInTask = (tFT_RestartInTask)Marshal.GetDelegateForFunctionPointer(pFT_RestartInTask, typeof(tFT_RestartInTask));
2976 if (ftHandle != IntPtr.Zero)
2979 ftStatus = FT_RestartInTask(ftHandle);
2984 if (pFT_RestartInTask == IntPtr.Zero)
2986 throw new Exception(
"Failed to load function FT_RestartInTask.");
3000 public FT_STATUS ResetPort()
3003 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3006 if (hFTD2XXDLL == IntPtr.Zero)
3010 if (pFT_ResetPort != IntPtr.Zero)
3012 tFT_ResetPort FT_ResetPort = (tFT_ResetPort)Marshal.GetDelegateForFunctionPointer(pFT_ResetPort, typeof(tFT_ResetPort));
3014 if (ftHandle != IntPtr.Zero)
3017 ftStatus = FT_ResetPort(ftHandle);
3022 if (pFT_ResetPort == IntPtr.Zero)
3024 throw new Exception(
"Failed to load function FT_ResetPort.");
3039 public FT_STATUS CyclePort()
3042 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3045 if (hFTD2XXDLL == IntPtr.Zero)
3049 if ((pFT_CyclePort != IntPtr.Zero) & (pFT_Close != IntPtr.Zero))
3051 tFT_CyclePort FT_CyclePort = (tFT_CyclePort)Marshal.GetDelegateForFunctionPointer(pFT_CyclePort, typeof(tFT_CyclePort));
3052 tFT_Close FT_Close = (tFT_Close)Marshal.GetDelegateForFunctionPointer(pFT_Close, typeof(tFT_Close));
3054 if (ftHandle != IntPtr.Zero)
3057 ftStatus = FT_CyclePort(ftHandle);
3061 ftStatus = FT_Close(ftHandle);
3064 ftHandle = IntPtr.Zero;
3071 if (pFT_CyclePort == IntPtr.Zero)
3073 throw new Exception(
"Failed to load function FT_CyclePort.");
3075 if (pFT_Close == IntPtr.Zero)
3077 throw new Exception(
"Failed to load function FT_Close.");
3091 public FT_STATUS Rescan()
3094 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3097 if (hFTD2XXDLL == IntPtr.Zero)
3101 if (pFT_Rescan != IntPtr.Zero)
3103 tFT_Rescan FT_Rescan = (tFT_Rescan)Marshal.GetDelegateForFunctionPointer(pFT_Rescan, typeof(tFT_Rescan));
3106 ftStatus = FT_Rescan();
3110 if (pFT_Rescan == IntPtr.Zero)
3112 throw new Exception(
"Failed to load function FT_Rescan.");
3129 public FT_STATUS Reload(UInt16 VendorID, UInt16 ProductID)
3132 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3135 if (hFTD2XXDLL == IntPtr.Zero)
3139 if (pFT_Reload != IntPtr.Zero)
3141 tFT_Reload FT_Reload = (tFT_Reload)Marshal.GetDelegateForFunctionPointer(pFT_Reload, typeof(tFT_Reload));
3144 ftStatus = FT_Reload(VendorID, ProductID);
3148 if (pFT_Reload == IntPtr.Zero)
3150 throw new Exception(
"Failed to load function FT_Reload.");
3174 public FT_STATUS SetBitMode(byte Mask, byte BitMode)
3177 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3178 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3181 if (hFTD2XXDLL == IntPtr.Zero)
3185 if (pFT_SetBitMode != IntPtr.Zero)
3187 tFT_SetBitMode FT_SetBitMode = (tFT_SetBitMode)Marshal.GetDelegateForFunctionPointer(pFT_SetBitMode, typeof(tFT_SetBitMode));
3189 if (ftHandle != IntPtr.Zero)
3194 GetDeviceType(ref DeviceType);
3195 if (DeviceType ==
FT_DEVICE.FT_DEVICE_AM)
3198 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3199 ErrorHandler(ftStatus, ftErrorCondition);
3201 else if (DeviceType ==
FT_DEVICE.FT_DEVICE_100AX)
3204 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3205 ErrorHandler(ftStatus, ftErrorCondition);
3212 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3213 ErrorHandler(ftStatus, ftErrorCondition);
3221 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3222 ErrorHandler(ftStatus, ftErrorCondition);
3228 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3229 ErrorHandler(ftStatus, ftErrorCondition);
3237 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3238 ErrorHandler(ftStatus, ftErrorCondition);
3246 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3247 ErrorHandler(ftStatus, ftErrorCondition);
3253 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3254 ErrorHandler(ftStatus, ftErrorCondition);
3262 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3263 ErrorHandler(ftStatus, ftErrorCondition);
3269 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3270 ErrorHandler(ftStatus, ftErrorCondition);
3279 ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3280 ErrorHandler(ftStatus, ftErrorCondition);
3287 ftStatus = FT_SetBitMode(ftHandle, Mask, BitMode);
3292 if (pFT_SetBitMode == IntPtr.Zero)
3294 throw new Exception(
"Failed to load function FT_SetBitMode.");
3309 public FT_STATUS GetPinStates(ref byte BitMode)
3312 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3315 if (hFTD2XXDLL == IntPtr.Zero)
3319 if (pFT_GetBitMode != IntPtr.Zero)
3321 tFT_GetBitMode FT_GetBitMode = (tFT_GetBitMode)Marshal.GetDelegateForFunctionPointer(pFT_GetBitMode, typeof(tFT_GetBitMode));
3323 if (ftHandle != IntPtr.Zero)
3326 ftStatus = FT_GetBitMode(ftHandle, ref BitMode);
3331 if (pFT_GetBitMode == IntPtr.Zero)
3333 throw new Exception(
"Failed to load function FT_GetBitMode.");
3349 public FT_STATUS ReadEEPROMLocation(UInt32 Address, ref UInt16 EEValue)
3352 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3355 if (hFTD2XXDLL == IntPtr.Zero)
3359 if (pFT_ReadEE != IntPtr.Zero)
3361 tFT_ReadEE FT_ReadEE = (tFT_ReadEE)Marshal.GetDelegateForFunctionPointer(pFT_ReadEE, typeof(tFT_ReadEE));
3363 if (ftHandle != IntPtr.Zero)
3366 ftStatus = FT_ReadEE(ftHandle, Address, ref EEValue);
3371 if (pFT_ReadEE == IntPtr.Zero)
3373 throw new Exception(
"Failed to load function FT_ReadEE.");
3389 public FT_STATUS WriteEEPROMLocation(UInt32 Address, UInt16 EEValue)
3392 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3395 if (hFTD2XXDLL == IntPtr.Zero)
3399 if (pFT_WriteEE != IntPtr.Zero)
3401 tFT_WriteEE FT_WriteEE = (tFT_WriteEE)Marshal.GetDelegateForFunctionPointer(pFT_WriteEE, typeof(tFT_WriteEE));
3403 if (ftHandle != IntPtr.Zero)
3406 ftStatus = FT_WriteEE(ftHandle, Address, EEValue);
3411 if (pFT_WriteEE == IntPtr.Zero)
3413 throw new Exception(
"Failed to load function FT_WriteEE.");
3428 public FT_STATUS EraseEEPROM()
3431 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3432 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3435 if (hFTD2XXDLL == IntPtr.Zero)
3439 if (pFT_EraseEE != IntPtr.Zero)
3441 tFT_EraseEE FT_EraseEE = (tFT_EraseEE)Marshal.GetDelegateForFunctionPointer(pFT_EraseEE, typeof(tFT_EraseEE));
3443 if (ftHandle != IntPtr.Zero)
3447 GetDeviceType(ref DeviceType);
3448 if (DeviceType ==
FT_DEVICE.FT_DEVICE_232R)
3451 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3452 ErrorHandler(ftStatus, ftErrorCondition);
3456 ftStatus = FT_EraseEE(ftHandle);
3461 if (pFT_EraseEE == IntPtr.Zero)
3463 throw new Exception(
"Failed to load function FT_EraseEE.");
3479 public FT_STATUS ReadFT232BEEPROM(FT232B_EEPROM_STRUCTURE ee232b)
3482 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3483 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3486 if (hFTD2XXDLL == IntPtr.Zero)
3490 if (pFT_EE_Read != IntPtr.Zero)
3492 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3494 if (ftHandle != IntPtr.Zero)
3498 GetDeviceType(ref DeviceType);
3499 if (DeviceType !=
FT_DEVICE.FT_DEVICE_BM)
3502 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3503 ErrorHandler(ftStatus, ftErrorCondition);
3506 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
3509 eedata.Signature1 = 0x00000000;
3510 eedata.Signature2 = 0xFFFFFFFF;
3514 eedata.Manufacturer = Marshal.AllocHGlobal(32);
3515 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3516 eedata.Description = Marshal.AllocHGlobal(64);
3517 eedata.SerialNumber = Marshal.AllocHGlobal(16);
3520 ftStatus = FT_EE_Read(ftHandle, eedata);
3523 ee232b.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
3524 ee232b.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
3525 ee232b.Description = Marshal.PtrToStringAnsi(eedata.Description);
3526 ee232b.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
3529 Marshal.FreeHGlobal(eedata.Manufacturer);
3530 Marshal.FreeHGlobal(eedata.ManufacturerID);
3531 Marshal.FreeHGlobal(eedata.Description);
3532 Marshal.FreeHGlobal(eedata.SerialNumber);
3536 ee232b.VendorID = eedata.VendorID;
3537 ee232b.ProductID = eedata.ProductID;
3538 ee232b.MaxPower = eedata.MaxPower;
3539 ee232b.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
3540 ee232b.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
3542 ee232b.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable);
3543 ee232b.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable);
3544 ee232b.USBVersionEnable = Convert.ToBoolean(eedata.USBVersionEnable);
3545 ee232b.USBVersion = eedata.USBVersion;
3550 if (pFT_EE_Read == IntPtr.Zero)
3552 throw new Exception(
"Failed to load function FT_EE_Read.");
3568 public FT_STATUS ReadFT2232EEPROM(FT2232_EEPROM_STRUCTURE ee2232)
3571 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3572 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3575 if (hFTD2XXDLL == IntPtr.Zero)
3579 if (pFT_EE_Read != IntPtr.Zero)
3581 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3583 if (ftHandle != IntPtr.Zero)
3587 GetDeviceType(ref DeviceType);
3588 if (DeviceType !=
FT_DEVICE.FT_DEVICE_2232)
3591 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3592 ErrorHandler(ftStatus, ftErrorCondition);
3595 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
3598 eedata.Signature1 = 0x00000000;
3599 eedata.Signature2 = 0xFFFFFFFF;
3603 eedata.Manufacturer = Marshal.AllocHGlobal(32);
3604 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3605 eedata.Description = Marshal.AllocHGlobal(64);
3606 eedata.SerialNumber = Marshal.AllocHGlobal(16);
3609 ftStatus = FT_EE_Read(ftHandle, eedata);
3612 ee2232.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
3613 ee2232.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
3614 ee2232.Description = Marshal.PtrToStringAnsi(eedata.Description);
3615 ee2232.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
3618 Marshal.FreeHGlobal(eedata.Manufacturer);
3619 Marshal.FreeHGlobal(eedata.ManufacturerID);
3620 Marshal.FreeHGlobal(eedata.Description);
3621 Marshal.FreeHGlobal(eedata.SerialNumber);
3625 ee2232.VendorID = eedata.VendorID;
3626 ee2232.ProductID = eedata.ProductID;
3627 ee2232.MaxPower = eedata.MaxPower;
3628 ee2232.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
3629 ee2232.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
3631 ee2232.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable5);
3632 ee2232.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable5);
3633 ee2232.USBVersionEnable = Convert.ToBoolean(eedata.USBVersionEnable5);
3634 ee2232.USBVersion = eedata.USBVersion5;
3635 ee2232.AIsHighCurrent = Convert.ToBoolean(eedata.AIsHighCurrent);
3636 ee2232.BIsHighCurrent = Convert.ToBoolean(eedata.BIsHighCurrent);
3637 ee2232.IFAIsFifo = Convert.ToBoolean(eedata.IFAIsFifo);
3638 ee2232.IFAIsFifoTar = Convert.ToBoolean(eedata.IFAIsFifoTar);
3639 ee2232.IFAIsFastSer = Convert.ToBoolean(eedata.IFAIsFastSer);
3640 ee2232.AIsVCP = Convert.ToBoolean(eedata.AIsVCP);
3641 ee2232.IFBIsFifo = Convert.ToBoolean(eedata.IFBIsFifo);
3642 ee2232.IFBIsFifoTar = Convert.ToBoolean(eedata.IFBIsFifoTar);
3643 ee2232.IFBIsFastSer = Convert.ToBoolean(eedata.IFBIsFastSer);
3644 ee2232.BIsVCP = Convert.ToBoolean(eedata.BIsVCP);
3649 if (pFT_EE_Read == IntPtr.Zero)
3651 throw new Exception(
"Failed to load function FT_EE_Read.");
3667 public FT_STATUS ReadFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
3670 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3671 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3674 if (hFTD2XXDLL == IntPtr.Zero)
3678 if (pFT_EE_Read != IntPtr.Zero)
3680 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3682 if (ftHandle != IntPtr.Zero)
3686 GetDeviceType(ref DeviceType);
3687 if (DeviceType !=
FT_DEVICE.FT_DEVICE_232R)
3690 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3691 ErrorHandler(ftStatus, ftErrorCondition);
3694 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
3697 eedata.Signature1 = 0x00000000;
3698 eedata.Signature2 = 0xFFFFFFFF;
3702 eedata.Manufacturer = Marshal.AllocHGlobal(32);
3703 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3704 eedata.Description = Marshal.AllocHGlobal(64);
3705 eedata.SerialNumber = Marshal.AllocHGlobal(16);
3708 ftStatus = FT_EE_Read(ftHandle, eedata);
3711 ee232r.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
3712 ee232r.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
3713 ee232r.Description = Marshal.PtrToStringAnsi(eedata.Description);
3714 ee232r.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
3717 Marshal.FreeHGlobal(eedata.Manufacturer);
3718 Marshal.FreeHGlobal(eedata.ManufacturerID);
3719 Marshal.FreeHGlobal(eedata.Description);
3720 Marshal.FreeHGlobal(eedata.SerialNumber);
3724 ee232r.VendorID = eedata.VendorID;
3725 ee232r.ProductID = eedata.ProductID;
3726 ee232r.MaxPower = eedata.MaxPower;
3727 ee232r.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
3728 ee232r.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
3730 ee232r.UseExtOsc = Convert.ToBoolean(eedata.UseExtOsc);
3731 ee232r.HighDriveIOs = Convert.ToBoolean(eedata.HighDriveIOs);
3732 ee232r.EndpointSize = eedata.EndpointSize;
3733 ee232r.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnableR);
3734 ee232r.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnableR);
3735 ee232r.InvertTXD = Convert.ToBoolean(eedata.InvertTXD);
3736 ee232r.InvertRXD = Convert.ToBoolean(eedata.InvertRXD);
3737 ee232r.InvertRTS = Convert.ToBoolean(eedata.InvertRTS);
3738 ee232r.InvertCTS = Convert.ToBoolean(eedata.InvertCTS);
3739 ee232r.InvertDTR = Convert.ToBoolean(eedata.InvertDTR);
3740 ee232r.InvertDSR = Convert.ToBoolean(eedata.InvertDSR);
3741 ee232r.InvertDCD = Convert.ToBoolean(eedata.InvertDCD);
3742 ee232r.InvertRI = Convert.ToBoolean(eedata.InvertRI);
3743 ee232r.Cbus0 = eedata.Cbus0;
3744 ee232r.Cbus1 = eedata.Cbus1;
3745 ee232r.Cbus2 = eedata.Cbus2;
3746 ee232r.Cbus3 = eedata.Cbus3;
3747 ee232r.Cbus4 = eedata.Cbus4;
3748 ee232r.RIsD2XX = Convert.ToBoolean(eedata.RIsD2XX);
3753 if (pFT_EE_Read == IntPtr.Zero)
3755 throw new Exception(
"Failed to load function FT_EE_Read.");
3771 public FT_STATUS ReadFT2232HEEPROM(FT2232H_EEPROM_STRUCTURE ee2232h)
3774 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3775 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3778 if (hFTD2XXDLL == IntPtr.Zero)
3782 if (pFT_EE_Read != IntPtr.Zero)
3784 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3786 if (ftHandle != IntPtr.Zero)
3790 GetDeviceType(ref DeviceType);
3791 if (DeviceType !=
FT_DEVICE.FT_DEVICE_2232H)
3794 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3795 ErrorHandler(ftStatus, ftErrorCondition);
3798 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
3801 eedata.Signature1 = 0x00000000;
3802 eedata.Signature2 = 0xFFFFFFFF;
3806 eedata.Manufacturer = Marshal.AllocHGlobal(32);
3807 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3808 eedata.Description = Marshal.AllocHGlobal(64);
3809 eedata.SerialNumber = Marshal.AllocHGlobal(16);
3812 ftStatus = FT_EE_Read(ftHandle, eedata);
3815 ee2232h.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
3816 ee2232h.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
3817 ee2232h.Description = Marshal.PtrToStringAnsi(eedata.Description);
3818 ee2232h.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
3821 Marshal.FreeHGlobal(eedata.Manufacturer);
3822 Marshal.FreeHGlobal(eedata.ManufacturerID);
3823 Marshal.FreeHGlobal(eedata.Description);
3824 Marshal.FreeHGlobal(eedata.SerialNumber);
3828 ee2232h.VendorID = eedata.VendorID;
3829 ee2232h.ProductID = eedata.ProductID;
3830 ee2232h.MaxPower = eedata.MaxPower;
3831 ee2232h.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
3832 ee2232h.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
3834 ee2232h.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable7);
3835 ee2232h.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable7);
3836 ee2232h.ALSlowSlew = Convert.ToBoolean(eedata.ALSlowSlew);
3837 ee2232h.ALSchmittInput = Convert.ToBoolean(eedata.ALSchmittInput);
3838 ee2232h.ALDriveCurrent = eedata.ALDriveCurrent;
3839 ee2232h.AHSlowSlew = Convert.ToBoolean(eedata.AHSlowSlew);
3840 ee2232h.AHSchmittInput = Convert.ToBoolean(eedata.AHSchmittInput);
3841 ee2232h.AHDriveCurrent = eedata.AHDriveCurrent;
3842 ee2232h.BLSlowSlew = Convert.ToBoolean(eedata.BLSlowSlew);
3843 ee2232h.BLSchmittInput = Convert.ToBoolean(eedata.BLSchmittInput);
3844 ee2232h.BLDriveCurrent = eedata.BLDriveCurrent;
3845 ee2232h.BHSlowSlew = Convert.ToBoolean(eedata.BHSlowSlew);
3846 ee2232h.BHSchmittInput = Convert.ToBoolean(eedata.BHSchmittInput);
3847 ee2232h.BHDriveCurrent = eedata.BHDriveCurrent;
3848 ee2232h.IFAIsFifo = Convert.ToBoolean(eedata.IFAIsFifo7);
3849 ee2232h.IFAIsFifoTar = Convert.ToBoolean(eedata.IFAIsFifoTar7);
3850 ee2232h.IFAIsFastSer = Convert.ToBoolean(eedata.IFAIsFastSer7);
3851 ee2232h.AIsVCP = Convert.ToBoolean(eedata.AIsVCP7);
3852 ee2232h.IFBIsFifo = Convert.ToBoolean(eedata.IFBIsFifo7);
3853 ee2232h.IFBIsFifoTar = Convert.ToBoolean(eedata.IFBIsFifoTar7);
3854 ee2232h.IFBIsFastSer = Convert.ToBoolean(eedata.IFBIsFastSer7);
3855 ee2232h.BIsVCP = Convert.ToBoolean(eedata.BIsVCP7);
3856 ee2232h.PowerSaveEnable = Convert.ToBoolean(eedata.PowerSaveEnable);
3861 if (pFT_EE_Read == IntPtr.Zero)
3863 throw new Exception(
"Failed to load function FT_EE_Read.");
3879 public FT_STATUS ReadFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
3882 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3883 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3886 if (hFTD2XXDLL == IntPtr.Zero)
3890 if (pFT_EE_Read != IntPtr.Zero)
3892 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3894 if (ftHandle != IntPtr.Zero)
3898 GetDeviceType(ref DeviceType);
3899 if (DeviceType !=
FT_DEVICE.FT_DEVICE_4232H)
3902 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3903 ErrorHandler(ftStatus, ftErrorCondition);
3906 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
3909 eedata.Signature1 = 0x00000000;
3910 eedata.Signature2 = 0xFFFFFFFF;
3914 eedata.Manufacturer = Marshal.AllocHGlobal(32);
3915 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3916 eedata.Description = Marshal.AllocHGlobal(64);
3917 eedata.SerialNumber = Marshal.AllocHGlobal(16);
3920 ftStatus = FT_EE_Read(ftHandle, eedata);
3923 ee4232h.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
3924 ee4232h.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
3925 ee4232h.Description = Marshal.PtrToStringAnsi(eedata.Description);
3926 ee4232h.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
3929 Marshal.FreeHGlobal(eedata.Manufacturer);
3930 Marshal.FreeHGlobal(eedata.ManufacturerID);
3931 Marshal.FreeHGlobal(eedata.Description);
3932 Marshal.FreeHGlobal(eedata.SerialNumber);
3936 ee4232h.VendorID = eedata.VendorID;
3937 ee4232h.ProductID = eedata.ProductID;
3938 ee4232h.MaxPower = eedata.MaxPower;
3939 ee4232h.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
3940 ee4232h.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
3942 ee4232h.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnable8);
3943 ee4232h.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnable8);
3944 ee4232h.ASlowSlew = Convert.ToBoolean(eedata.ASlowSlew);
3945 ee4232h.ASchmittInput = Convert.ToBoolean(eedata.ASchmittInput);
3946 ee4232h.ADriveCurrent = eedata.ADriveCurrent;
3947 ee4232h.BSlowSlew = Convert.ToBoolean(eedata.BSlowSlew);
3948 ee4232h.BSchmittInput = Convert.ToBoolean(eedata.BSchmittInput);
3949 ee4232h.BDriveCurrent = eedata.BDriveCurrent;
3950 ee4232h.CSlowSlew = Convert.ToBoolean(eedata.CSlowSlew);
3951 ee4232h.CSchmittInput = Convert.ToBoolean(eedata.CSchmittInput);
3952 ee4232h.CDriveCurrent = eedata.CDriveCurrent;
3953 ee4232h.DSlowSlew = Convert.ToBoolean(eedata.DSlowSlew);
3954 ee4232h.DSchmittInput = Convert.ToBoolean(eedata.DSchmittInput);
3955 ee4232h.DDriveCurrent = eedata.DDriveCurrent;
3956 ee4232h.ARIIsTXDEN = Convert.ToBoolean(eedata.ARIIsTXDEN);
3957 ee4232h.BRIIsTXDEN = Convert.ToBoolean(eedata.BRIIsTXDEN);
3958 ee4232h.CRIIsTXDEN = Convert.ToBoolean(eedata.CRIIsTXDEN);
3959 ee4232h.DRIIsTXDEN = Convert.ToBoolean(eedata.DRIIsTXDEN);
3960 ee4232h.AIsVCP = Convert.ToBoolean(eedata.AIsVCP8);
3961 ee4232h.BIsVCP = Convert.ToBoolean(eedata.BIsVCP8);
3962 ee4232h.CIsVCP = Convert.ToBoolean(eedata.CIsVCP8);
3963 ee4232h.DIsVCP = Convert.ToBoolean(eedata.DIsVCP8);
3968 if (pFT_EE_Read == IntPtr.Zero)
3970 throw new Exception(
"Failed to load function FT_EE_Read.");
3986 public FT_STATUS ReadFT232HEEPROM(FT232H_EEPROM_STRUCTURE ee232h)
3989 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3990 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3993 if (hFTD2XXDLL == IntPtr.Zero)
3997 if (pFT_EE_Read != IntPtr.Zero)
3999 tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
4001 if (ftHandle != IntPtr.Zero)
4005 GetDeviceType(ref DeviceType);
4006 if (DeviceType !=
FT_DEVICE.FT_DEVICE_232H)
4009 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4010 ErrorHandler(ftStatus, ftErrorCondition);
4013 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4016 eedata.Signature1 = 0x00000000;
4017 eedata.Signature2 = 0xFFFFFFFF;
4021 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4022 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4023 eedata.Description = Marshal.AllocHGlobal(64);
4024 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4027 ftStatus = FT_EE_Read(ftHandle, eedata);
4030 ee232h.Manufacturer = Marshal.PtrToStringAnsi(eedata.Manufacturer);
4031 ee232h.ManufacturerID = Marshal.PtrToStringAnsi(eedata.ManufacturerID);
4032 ee232h.Description = Marshal.PtrToStringAnsi(eedata.Description);
4033 ee232h.SerialNumber = Marshal.PtrToStringAnsi(eedata.SerialNumber);
4036 Marshal.FreeHGlobal(eedata.Manufacturer);
4037 Marshal.FreeHGlobal(eedata.ManufacturerID);
4038 Marshal.FreeHGlobal(eedata.Description);
4039 Marshal.FreeHGlobal(eedata.SerialNumber);
4043 ee232h.VendorID = eedata.VendorID;
4044 ee232h.ProductID = eedata.ProductID;
4045 ee232h.MaxPower = eedata.MaxPower;
4046 ee232h.SelfPowered = Convert.ToBoolean(eedata.SelfPowered);
4047 ee232h.RemoteWakeup = Convert.ToBoolean(eedata.RemoteWakeup);
4049 ee232h.PullDownEnable = Convert.ToBoolean(eedata.PullDownEnableH);
4050 ee232h.SerNumEnable = Convert.ToBoolean(eedata.SerNumEnableH);
4051 ee232h.ACSlowSlew = Convert.ToBoolean(eedata.ACSlowSlewH);
4052 ee232h.ACSchmittInput = Convert.ToBoolean(eedata.ACSchmittInputH);
4053 ee232h.ACDriveCurrent = eedata.ACDriveCurrentH;
4054 ee232h.ADSlowSlew = Convert.ToBoolean(eedata.ADSlowSlewH);
4055 ee232h.ADSchmittInput = Convert.ToBoolean(eedata.ADSchmittInputH);
4056 ee232h.ADDriveCurrent = eedata.ADDriveCurrentH;
4057 ee232h.Cbus0 = eedata.Cbus0H;
4058 ee232h.Cbus1 = eedata.Cbus1H;
4059 ee232h.Cbus2 = eedata.Cbus2H;
4060 ee232h.Cbus3 = eedata.Cbus3H;
4061 ee232h.Cbus4 = eedata.Cbus4H;
4062 ee232h.Cbus5 = eedata.Cbus5H;
4063 ee232h.Cbus6 = eedata.Cbus6H;
4064 ee232h.Cbus7 = eedata.Cbus7H;
4065 ee232h.Cbus8 = eedata.Cbus8H;
4066 ee232h.Cbus9 = eedata.Cbus9H;
4067 ee232h.IsFifo = Convert.ToBoolean(eedata.IsFifoH);
4068 ee232h.IsFifoTar = Convert.ToBoolean(eedata.IsFifoTarH);
4069 ee232h.IsFastSer = Convert.ToBoolean(eedata.IsFastSerH);
4070 ee232h.IsFT1248 = Convert.ToBoolean(eedata.IsFT1248H);
4071 ee232h.FT1248Cpol = Convert.ToBoolean(eedata.FT1248CpolH);
4072 ee232h.FT1248Lsb = Convert.ToBoolean(eedata.FT1248LsbH);
4073 ee232h.FT1248FlowControl = Convert.ToBoolean(eedata.FT1248FlowControlH);
4074 ee232h.IsVCP = Convert.ToBoolean(eedata.IsVCPH);
4075 ee232h.PowerSaveEnable = Convert.ToBoolean(eedata.PowerSaveEnableH);
4080 if (pFT_EE_Read == IntPtr.Zero)
4082 throw new Exception(
"Failed to load function FT_EE_Read.");
4098 public FT_STATUS ReadXSeriesEEPROM(FT_XSERIES_EEPROM_STRUCTURE eeX)
4101 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4102 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4105 if (hFTD2XXDLL == IntPtr.Zero)
4109 if (pFT_EEPROM_Read != IntPtr.Zero)
4111 tFT_EEPROM_Read FT_EEPROM_Read = (tFT_EEPROM_Read)Marshal.GetDelegateForFunctionPointer(pFT_EEPROM_Read, typeof(tFT_EEPROM_Read));
4113 if (ftHandle != IntPtr.Zero)
4117 GetDeviceType(ref DeviceType);
4118 if (DeviceType !=
FT_DEVICE.FT_DEVICE_X_SERIES)
4121 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4122 ErrorHandler(ftStatus, ftErrorCondition);
4125 FT_XSERIES_DATA eeData =
new FT_XSERIES_DATA();
4126 FT_EEPROM_HEADER eeHeader =
new FT_EEPROM_HEADER();
4128 byte[] manufacturer =
new byte[32];
4129 byte[] manufacturerID =
new byte[16];
4130 byte[] description =
new byte[64];
4131 byte[] serialNumber =
new byte[16];
4133 eeHeader.deviceType = (uint)
FT_DEVICE.FT_DEVICE_X_SERIES;
4134 eeData.common = eeHeader;
4137 int size = Marshal.SizeOf(eeData);
4140 IntPtr eeDataMarshal = Marshal.AllocHGlobal(size);
4141 Marshal.StructureToPtr(eeData, eeDataMarshal,
false);
4144 ftStatus = FT_EEPROM_Read(ftHandle, eeDataMarshal, (uint)size, manufacturer, manufacturerID, description, serialNumber);
4149 eeData = (FT_XSERIES_DATA)Marshal.PtrToStructure(eeDataMarshal, typeof(FT_XSERIES_DATA));
4152 System.Text.UTF8Encoding enc =
new System.Text.UTF8Encoding();
4153 eeX.Manufacturer = enc.GetString(manufacturer);
4154 eeX.ManufacturerID = enc.GetString(manufacturerID);
4155 eeX.Description = enc.GetString(description);
4156 eeX.SerialNumber = enc.GetString(serialNumber);
4159 eeX.VendorID = eeData.common.VendorId;
4160 eeX.ProductID = eeData.common.ProductId;
4161 eeX.MaxPower = eeData.common.MaxPower;
4162 eeX.SelfPowered = Convert.ToBoolean(eeData.common.SelfPowered);
4163 eeX.RemoteWakeup = Convert.ToBoolean(eeData.common.RemoteWakeup);
4164 eeX.SerNumEnable = Convert.ToBoolean(eeData.common.SerNumEnable);
4165 eeX.PullDownEnable = Convert.ToBoolean(eeData.common.PullDownEnable);
4168 eeX.Cbus0 = eeData.Cbus0;
4169 eeX.Cbus1 = eeData.Cbus1;
4170 eeX.Cbus2 = eeData.Cbus2;
4171 eeX.Cbus3 = eeData.Cbus3;
4172 eeX.Cbus4 = eeData.Cbus4;
4173 eeX.Cbus5 = eeData.Cbus5;
4174 eeX.Cbus6 = eeData.Cbus6;
4176 eeX.ACDriveCurrent = eeData.ACDriveCurrent;
4177 eeX.ACSchmittInput = eeData.ACSchmittInput;
4178 eeX.ACSlowSlew = eeData.ACSlowSlew;
4179 eeX.ADDriveCurrent = eeData.ADDriveCurrent;
4180 eeX.ADSchmittInput = eeData.ADSchmittInput;
4181 eeX.ADSlowSlew = eeData.ADSlowSlew;
4183 eeX.BCDDisableSleep = eeData.BCDDisableSleep;
4184 eeX.BCDEnable = eeData.BCDEnable;
4185 eeX.BCDForceCbusPWREN = eeData.BCDForceCbusPWREN;
4187 eeX.FT1248Cpol = eeData.FT1248Cpol;
4188 eeX.FT1248FlowControl = eeData.FT1248FlowControl;
4189 eeX.FT1248Lsb = eeData.FT1248Lsb;
4191 eeX.I2CDeviceId = eeData.I2CDeviceId;
4192 eeX.I2CDisableSchmitt = eeData.I2CDisableSchmitt;
4193 eeX.I2CSlaveAddress = eeData.I2CSlaveAddress;
4195 eeX.InvertCTS = eeData.InvertCTS;
4196 eeX.InvertDCD = eeData.InvertDCD;
4197 eeX.InvertDSR = eeData.InvertDSR;
4198 eeX.InvertDTR = eeData.InvertDTR;
4199 eeX.InvertRI = eeData.InvertRI;
4200 eeX.InvertRTS = eeData.InvertRTS;
4201 eeX.InvertRXD = eeData.InvertRXD;
4202 eeX.InvertTXD = eeData.InvertTXD;
4204 eeX.PowerSaveEnable = eeData.PowerSaveEnable;
4205 eeX.RS485EchoSuppress = eeData.RS485EchoSuppress;
4207 eeX.IsVCP = eeData.DriverType;
4213 if (pFT_EE_Read == IntPtr.Zero)
4215 throw new Exception(
"Failed to load function FT_EE_Read.");
4232 public FT_STATUS WriteFT232BEEPROM(FT232B_EEPROM_STRUCTURE ee232b)
4235 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4236 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4239 if (hFTD2XXDLL == IntPtr.Zero)
4243 if (pFT_EE_Program != IntPtr.Zero)
4245 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4247 if (ftHandle != IntPtr.Zero)
4251 GetDeviceType(ref DeviceType);
4252 if (DeviceType !=
FT_DEVICE.FT_DEVICE_BM)
4255 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4256 ErrorHandler(ftStatus, ftErrorCondition);
4260 if ((ee232b.VendorID == 0x0000) | (ee232b.ProductID == 0x0000))
4266 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4269 eedata.Signature1 = 0x00000000;
4270 eedata.Signature2 = 0xFFFFFFFF;
4274 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4275 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4276 eedata.Description = Marshal.AllocHGlobal(64);
4277 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4281 if (ee232b.Manufacturer.Length > 32)
4282 ee232b.Manufacturer = ee232b.Manufacturer.Substring(0, 32);
4283 if (ee232b.ManufacturerID.Length > 16)
4284 ee232b.ManufacturerID = ee232b.ManufacturerID.Substring(0, 16);
4285 if (ee232b.Description.Length > 64)
4286 ee232b.Description = ee232b.Description.Substring(0, 64);
4287 if (ee232b.SerialNumber.Length > 16)
4288 ee232b.SerialNumber = ee232b.SerialNumber.Substring(0, 16);
4291 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee232b.Manufacturer);
4292 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee232b.ManufacturerID);
4293 eedata.Description = Marshal.StringToHGlobalAnsi(ee232b.Description);
4294 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee232b.SerialNumber);
4298 eedata.VendorID = ee232b.VendorID;
4299 eedata.ProductID = ee232b.ProductID;
4300 eedata.MaxPower = ee232b.MaxPower;
4301 eedata.SelfPowered = Convert.ToUInt16(ee232b.SelfPowered);
4302 eedata.RemoteWakeup = Convert.ToUInt16(ee232b.RemoteWakeup);
4304 eedata.Rev4 = Convert.ToByte(
true);
4305 eedata.PullDownEnable = Convert.ToByte(ee232b.PullDownEnable);
4306 eedata.SerNumEnable = Convert.ToByte(ee232b.SerNumEnable);
4307 eedata.USBVersionEnable = Convert.ToByte(ee232b.USBVersionEnable);
4308 eedata.USBVersion = ee232b.USBVersion;
4311 ftStatus = FT_EE_Program(ftHandle, eedata);
4314 Marshal.FreeHGlobal(eedata.Manufacturer);
4315 Marshal.FreeHGlobal(eedata.ManufacturerID);
4316 Marshal.FreeHGlobal(eedata.Description);
4317 Marshal.FreeHGlobal(eedata.SerialNumber);
4322 if (pFT_EE_Program == IntPtr.Zero)
4324 throw new Exception(
"Failed to load function FT_EE_Program.");
4342 public FT_STATUS WriteFT2232EEPROM(FT2232_EEPROM_STRUCTURE ee2232)
4345 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4346 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4349 if (hFTD2XXDLL == IntPtr.Zero)
4353 if (pFT_EE_Program != IntPtr.Zero)
4355 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4357 if (ftHandle != IntPtr.Zero)
4361 GetDeviceType(ref DeviceType);
4362 if (DeviceType !=
FT_DEVICE.FT_DEVICE_2232)
4365 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4366 ErrorHandler(ftStatus, ftErrorCondition);
4370 if ((ee2232.VendorID == 0x0000) | (ee2232.ProductID == 0x0000))
4376 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4379 eedata.Signature1 = 0x00000000;
4380 eedata.Signature2 = 0xFFFFFFFF;
4384 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4385 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4386 eedata.Description = Marshal.AllocHGlobal(64);
4387 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4391 if (ee2232.Manufacturer.Length > 32)
4392 ee2232.Manufacturer = ee2232.Manufacturer.Substring(0, 32);
4393 if (ee2232.ManufacturerID.Length > 16)
4394 ee2232.ManufacturerID = ee2232.ManufacturerID.Substring(0, 16);
4395 if (ee2232.Description.Length > 64)
4396 ee2232.Description = ee2232.Description.Substring(0, 64);
4397 if (ee2232.SerialNumber.Length > 16)
4398 ee2232.SerialNumber = ee2232.SerialNumber.Substring(0, 16);
4401 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee2232.Manufacturer);
4402 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee2232.ManufacturerID);
4403 eedata.Description = Marshal.StringToHGlobalAnsi(ee2232.Description);
4404 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee2232.SerialNumber);
4408 eedata.VendorID = ee2232.VendorID;
4409 eedata.ProductID = ee2232.ProductID;
4410 eedata.MaxPower = ee2232.MaxPower;
4411 eedata.SelfPowered = Convert.ToUInt16(ee2232.SelfPowered);
4412 eedata.RemoteWakeup = Convert.ToUInt16(ee2232.RemoteWakeup);
4414 eedata.Rev5 = Convert.ToByte(
true);
4415 eedata.PullDownEnable5 = Convert.ToByte(ee2232.PullDownEnable);
4416 eedata.SerNumEnable5 = Convert.ToByte(ee2232.SerNumEnable);
4417 eedata.USBVersionEnable5 = Convert.ToByte(ee2232.USBVersionEnable);
4418 eedata.USBVersion5 = ee2232.USBVersion;
4419 eedata.AIsHighCurrent = Convert.ToByte(ee2232.AIsHighCurrent);
4420 eedata.BIsHighCurrent = Convert.ToByte(ee2232.BIsHighCurrent);
4421 eedata.IFAIsFifo = Convert.ToByte(ee2232.IFAIsFifo);
4422 eedata.IFAIsFifoTar = Convert.ToByte(ee2232.IFAIsFifoTar);
4423 eedata.IFAIsFastSer = Convert.ToByte(ee2232.IFAIsFastSer);
4424 eedata.AIsVCP = Convert.ToByte(ee2232.AIsVCP);
4425 eedata.IFBIsFifo = Convert.ToByte(ee2232.IFBIsFifo);
4426 eedata.IFBIsFifoTar = Convert.ToByte(ee2232.IFBIsFifoTar);
4427 eedata.IFBIsFastSer = Convert.ToByte(ee2232.IFBIsFastSer);
4428 eedata.BIsVCP = Convert.ToByte(ee2232.BIsVCP);
4431 ftStatus = FT_EE_Program(ftHandle, eedata);
4434 Marshal.FreeHGlobal(eedata.Manufacturer);
4435 Marshal.FreeHGlobal(eedata.ManufacturerID);
4436 Marshal.FreeHGlobal(eedata.Description);
4437 Marshal.FreeHGlobal(eedata.SerialNumber);
4442 if (pFT_EE_Program == IntPtr.Zero)
4444 throw new Exception(
"Failed to load function FT_EE_Program.");
4462 public FT_STATUS WriteFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
4465 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4466 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4469 if (hFTD2XXDLL == IntPtr.Zero)
4473 if (pFT_EE_Program != IntPtr.Zero)
4475 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4477 if (ftHandle != IntPtr.Zero)
4481 GetDeviceType(ref DeviceType);
4482 if (DeviceType !=
FT_DEVICE.FT_DEVICE_232R)
4485 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4486 ErrorHandler(ftStatus, ftErrorCondition);
4490 if ((ee232r.VendorID == 0x0000) | (ee232r.ProductID == 0x0000))
4496 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4499 eedata.Signature1 = 0x00000000;
4500 eedata.Signature2 = 0xFFFFFFFF;
4504 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4505 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4506 eedata.Description = Marshal.AllocHGlobal(64);
4507 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4511 if (ee232r.Manufacturer.Length > 32)
4512 ee232r.Manufacturer = ee232r.Manufacturer.Substring(0, 32);
4513 if (ee232r.ManufacturerID.Length > 16)
4514 ee232r.ManufacturerID = ee232r.ManufacturerID.Substring(0, 16);
4515 if (ee232r.Description.Length > 64)
4516 ee232r.Description = ee232r.Description.Substring(0, 64);
4517 if (ee232r.SerialNumber.Length > 16)
4518 ee232r.SerialNumber = ee232r.SerialNumber.Substring(0, 16);
4521 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee232r.Manufacturer);
4522 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee232r.ManufacturerID);
4523 eedata.Description = Marshal.StringToHGlobalAnsi(ee232r.Description);
4524 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee232r.SerialNumber);
4528 eedata.VendorID = ee232r.VendorID;
4529 eedata.ProductID = ee232r.ProductID;
4530 eedata.MaxPower = ee232r.MaxPower;
4531 eedata.SelfPowered = Convert.ToUInt16(ee232r.SelfPowered);
4532 eedata.RemoteWakeup = Convert.ToUInt16(ee232r.RemoteWakeup);
4534 eedata.PullDownEnableR = Convert.ToByte(ee232r.PullDownEnable);
4535 eedata.SerNumEnableR = Convert.ToByte(ee232r.SerNumEnable);
4536 eedata.UseExtOsc = Convert.ToByte(ee232r.UseExtOsc);
4537 eedata.HighDriveIOs = Convert.ToByte(ee232r.HighDriveIOs);
4540 eedata.EndpointSize = 64;
4541 eedata.PullDownEnableR = Convert.ToByte(ee232r.PullDownEnable);
4542 eedata.SerNumEnableR = Convert.ToByte(ee232r.SerNumEnable);
4543 eedata.InvertTXD = Convert.ToByte(ee232r.InvertTXD);
4544 eedata.InvertRXD = Convert.ToByte(ee232r.InvertRXD);
4545 eedata.InvertRTS = Convert.ToByte(ee232r.InvertRTS);
4546 eedata.InvertCTS = Convert.ToByte(ee232r.InvertCTS);
4547 eedata.InvertDTR = Convert.ToByte(ee232r.InvertDTR);
4548 eedata.InvertDSR = Convert.ToByte(ee232r.InvertDSR);
4549 eedata.InvertDCD = Convert.ToByte(ee232r.InvertDCD);
4550 eedata.InvertRI = Convert.ToByte(ee232r.InvertRI);
4551 eedata.Cbus0 = ee232r.Cbus0;
4552 eedata.Cbus1 = ee232r.Cbus1;
4553 eedata.Cbus2 = ee232r.Cbus2;
4554 eedata.Cbus3 = ee232r.Cbus3;
4555 eedata.Cbus4 = ee232r.Cbus4;
4556 eedata.RIsD2XX = Convert.ToByte(ee232r.RIsD2XX);
4559 ftStatus = FT_EE_Program(ftHandle, eedata);
4562 Marshal.FreeHGlobal(eedata.Manufacturer);
4563 Marshal.FreeHGlobal(eedata.ManufacturerID);
4564 Marshal.FreeHGlobal(eedata.Description);
4565 Marshal.FreeHGlobal(eedata.SerialNumber);
4570 if (pFT_EE_Program == IntPtr.Zero)
4572 throw new Exception(
"Failed to load function FT_EE_Program.");
4590 public FT_STATUS WriteFT2232HEEPROM(FT2232H_EEPROM_STRUCTURE ee2232h)
4593 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4594 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4597 if (hFTD2XXDLL == IntPtr.Zero)
4601 if (pFT_EE_Program != IntPtr.Zero)
4603 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4605 if (ftHandle != IntPtr.Zero)
4609 GetDeviceType(ref DeviceType);
4610 if (DeviceType !=
FT_DEVICE.FT_DEVICE_2232H)
4613 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4614 ErrorHandler(ftStatus, ftErrorCondition);
4618 if ((ee2232h.VendorID == 0x0000) | (ee2232h.ProductID == 0x0000))
4624 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4627 eedata.Signature1 = 0x00000000;
4628 eedata.Signature2 = 0xFFFFFFFF;
4632 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4633 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4634 eedata.Description = Marshal.AllocHGlobal(64);
4635 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4639 if (ee2232h.Manufacturer.Length > 32)
4640 ee2232h.Manufacturer = ee2232h.Manufacturer.Substring(0, 32);
4641 if (ee2232h.ManufacturerID.Length > 16)
4642 ee2232h.ManufacturerID = ee2232h.ManufacturerID.Substring(0, 16);
4643 if (ee2232h.Description.Length > 64)
4644 ee2232h.Description = ee2232h.Description.Substring(0, 64);
4645 if (ee2232h.SerialNumber.Length > 16)
4646 ee2232h.SerialNumber = ee2232h.SerialNumber.Substring(0, 16);
4649 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee2232h.Manufacturer);
4650 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee2232h.ManufacturerID);
4651 eedata.Description = Marshal.StringToHGlobalAnsi(ee2232h.Description);
4652 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee2232h.SerialNumber);
4656 eedata.VendorID = ee2232h.VendorID;
4657 eedata.ProductID = ee2232h.ProductID;
4658 eedata.MaxPower = ee2232h.MaxPower;
4659 eedata.SelfPowered = Convert.ToUInt16(ee2232h.SelfPowered);
4660 eedata.RemoteWakeup = Convert.ToUInt16(ee2232h.RemoteWakeup);
4662 eedata.PullDownEnable7 = Convert.ToByte(ee2232h.PullDownEnable);
4663 eedata.SerNumEnable7 = Convert.ToByte(ee2232h.SerNumEnable);
4664 eedata.ALSlowSlew = Convert.ToByte(ee2232h.ALSlowSlew);
4665 eedata.ALSchmittInput = Convert.ToByte(ee2232h.ALSchmittInput);
4666 eedata.ALDriveCurrent = ee2232h.ALDriveCurrent;
4667 eedata.AHSlowSlew = Convert.ToByte(ee2232h.AHSlowSlew);
4668 eedata.AHSchmittInput = Convert.ToByte(ee2232h.AHSchmittInput);
4669 eedata.AHDriveCurrent = ee2232h.AHDriveCurrent;
4670 eedata.BLSlowSlew = Convert.ToByte(ee2232h.BLSlowSlew);
4671 eedata.BLSchmittInput = Convert.ToByte(ee2232h.BLSchmittInput);
4672 eedata.BLDriveCurrent = ee2232h.BLDriveCurrent;
4673 eedata.BHSlowSlew = Convert.ToByte(ee2232h.BHSlowSlew);
4674 eedata.BHSchmittInput = Convert.ToByte(ee2232h.BHSchmittInput);
4675 eedata.BHDriveCurrent = ee2232h.BHDriveCurrent;
4676 eedata.IFAIsFifo7 = Convert.ToByte(ee2232h.IFAIsFifo);
4677 eedata.IFAIsFifoTar7 = Convert.ToByte(ee2232h.IFAIsFifoTar);
4678 eedata.IFAIsFastSer7 = Convert.ToByte(ee2232h.IFAIsFastSer);
4679 eedata.AIsVCP7 = Convert.ToByte(ee2232h.AIsVCP);
4680 eedata.IFBIsFifo7 = Convert.ToByte(ee2232h.IFBIsFifo);
4681 eedata.IFBIsFifoTar7 = Convert.ToByte(ee2232h.IFBIsFifoTar);
4682 eedata.IFBIsFastSer7 = Convert.ToByte(ee2232h.IFBIsFastSer);
4683 eedata.BIsVCP7 = Convert.ToByte(ee2232h.BIsVCP);
4684 eedata.PowerSaveEnable = Convert.ToByte(ee2232h.PowerSaveEnable);
4687 ftStatus = FT_EE_Program(ftHandle, eedata);
4690 Marshal.FreeHGlobal(eedata.Manufacturer);
4691 Marshal.FreeHGlobal(eedata.ManufacturerID);
4692 Marshal.FreeHGlobal(eedata.Description);
4693 Marshal.FreeHGlobal(eedata.SerialNumber);
4698 if (pFT_EE_Program == IntPtr.Zero)
4700 throw new Exception(
"Failed to load function FT_EE_Program.");
4718 public FT_STATUS WriteFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
4721 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4722 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4725 if (hFTD2XXDLL == IntPtr.Zero)
4729 if (pFT_EE_Program != IntPtr.Zero)
4731 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4733 if (ftHandle != IntPtr.Zero)
4737 GetDeviceType(ref DeviceType);
4738 if (DeviceType !=
FT_DEVICE.FT_DEVICE_4232H)
4741 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4742 ErrorHandler(ftStatus, ftErrorCondition);
4746 if ((ee4232h.VendorID == 0x0000) | (ee4232h.ProductID == 0x0000))
4752 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4755 eedata.Signature1 = 0x00000000;
4756 eedata.Signature2 = 0xFFFFFFFF;
4760 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4761 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4762 eedata.Description = Marshal.AllocHGlobal(64);
4763 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4767 if (ee4232h.Manufacturer.Length > 32)
4768 ee4232h.Manufacturer = ee4232h.Manufacturer.Substring(0, 32);
4769 if (ee4232h.ManufacturerID.Length > 16)
4770 ee4232h.ManufacturerID = ee4232h.ManufacturerID.Substring(0, 16);
4771 if (ee4232h.Description.Length > 64)
4772 ee4232h.Description = ee4232h.Description.Substring(0, 64);
4773 if (ee4232h.SerialNumber.Length > 16)
4774 ee4232h.SerialNumber = ee4232h.SerialNumber.Substring(0, 16);
4777 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee4232h.Manufacturer);
4778 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee4232h.ManufacturerID);
4779 eedata.Description = Marshal.StringToHGlobalAnsi(ee4232h.Description);
4780 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee4232h.SerialNumber);
4784 eedata.VendorID = ee4232h.VendorID;
4785 eedata.ProductID = ee4232h.ProductID;
4786 eedata.MaxPower = ee4232h.MaxPower;
4787 eedata.SelfPowered = Convert.ToUInt16(ee4232h.SelfPowered);
4788 eedata.RemoteWakeup = Convert.ToUInt16(ee4232h.RemoteWakeup);
4790 eedata.PullDownEnable8 = Convert.ToByte(ee4232h.PullDownEnable);
4791 eedata.SerNumEnable8 = Convert.ToByte(ee4232h.SerNumEnable);
4792 eedata.ASlowSlew = Convert.ToByte(ee4232h.ASlowSlew);
4793 eedata.ASchmittInput = Convert.ToByte(ee4232h.ASchmittInput);
4794 eedata.ADriveCurrent = ee4232h.ADriveCurrent;
4795 eedata.BSlowSlew = Convert.ToByte(ee4232h.BSlowSlew);
4796 eedata.BSchmittInput = Convert.ToByte(ee4232h.BSchmittInput);
4797 eedata.BDriveCurrent = ee4232h.BDriveCurrent;
4798 eedata.CSlowSlew = Convert.ToByte(ee4232h.CSlowSlew);
4799 eedata.CSchmittInput = Convert.ToByte(ee4232h.CSchmittInput);
4800 eedata.CDriveCurrent = ee4232h.CDriveCurrent;
4801 eedata.DSlowSlew = Convert.ToByte(ee4232h.DSlowSlew);
4802 eedata.DSchmittInput = Convert.ToByte(ee4232h.DSchmittInput);
4803 eedata.DDriveCurrent = ee4232h.DDriveCurrent;
4804 eedata.ARIIsTXDEN = Convert.ToByte(ee4232h.ARIIsTXDEN);
4805 eedata.BRIIsTXDEN = Convert.ToByte(ee4232h.BRIIsTXDEN);
4806 eedata.CRIIsTXDEN = Convert.ToByte(ee4232h.CRIIsTXDEN);
4807 eedata.DRIIsTXDEN = Convert.ToByte(ee4232h.DRIIsTXDEN);
4808 eedata.AIsVCP8 = Convert.ToByte(ee4232h.AIsVCP);
4809 eedata.BIsVCP8 = Convert.ToByte(ee4232h.BIsVCP);
4810 eedata.CIsVCP8 = Convert.ToByte(ee4232h.CIsVCP);
4811 eedata.DIsVCP8 = Convert.ToByte(ee4232h.DIsVCP);
4814 ftStatus = FT_EE_Program(ftHandle, eedata);
4817 Marshal.FreeHGlobal(eedata.Manufacturer);
4818 Marshal.FreeHGlobal(eedata.ManufacturerID);
4819 Marshal.FreeHGlobal(eedata.Description);
4820 Marshal.FreeHGlobal(eedata.SerialNumber);
4825 if (pFT_EE_Program == IntPtr.Zero)
4827 throw new Exception(
"Failed to load function FT_EE_Program.");
4845 public FT_STATUS WriteFT232HEEPROM(FT232H_EEPROM_STRUCTURE ee232h)
4848 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4849 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4852 if (hFTD2XXDLL == IntPtr.Zero)
4856 if (pFT_EE_Program != IntPtr.Zero)
4858 tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4860 if (ftHandle != IntPtr.Zero)
4864 GetDeviceType(ref DeviceType);
4865 if (DeviceType !=
FT_DEVICE.FT_DEVICE_232H)
4868 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4869 ErrorHandler(ftStatus, ftErrorCondition);
4873 if ((ee232h.VendorID == 0x0000) | (ee232h.ProductID == 0x0000))
4879 FT_PROGRAM_DATA eedata =
new FT_PROGRAM_DATA();
4882 eedata.Signature1 = 0x00000000;
4883 eedata.Signature2 = 0xFFFFFFFF;
4887 eedata.Manufacturer = Marshal.AllocHGlobal(32);
4888 eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4889 eedata.Description = Marshal.AllocHGlobal(64);
4890 eedata.SerialNumber = Marshal.AllocHGlobal(16);
4894 if (ee232h.Manufacturer.Length > 32)
4895 ee232h.Manufacturer = ee232h.Manufacturer.Substring(0, 32);
4896 if (ee232h.ManufacturerID.Length > 16)
4897 ee232h.ManufacturerID = ee232h.ManufacturerID.Substring(0, 16);
4898 if (ee232h.Description.Length > 64)
4899 ee232h.Description = ee232h.Description.Substring(0, 64);
4900 if (ee232h.SerialNumber.Length > 16)
4901 ee232h.SerialNumber = ee232h.SerialNumber.Substring(0, 16);
4904 eedata.Manufacturer = Marshal.StringToHGlobalAnsi(ee232h.Manufacturer);
4905 eedata.ManufacturerID = Marshal.StringToHGlobalAnsi(ee232h.ManufacturerID);
4906 eedata.Description = Marshal.StringToHGlobalAnsi(ee232h.Description);
4907 eedata.SerialNumber = Marshal.StringToHGlobalAnsi(ee232h.SerialNumber);
4911 eedata.VendorID = ee232h.VendorID;
4912 eedata.ProductID = ee232h.ProductID;
4913 eedata.MaxPower = ee232h.MaxPower;
4914 eedata.SelfPowered = Convert.ToUInt16(ee232h.SelfPowered);
4915 eedata.RemoteWakeup = Convert.ToUInt16(ee232h.RemoteWakeup);
4917 eedata.PullDownEnableH = Convert.ToByte(ee232h.PullDownEnable);
4918 eedata.SerNumEnableH = Convert.ToByte(ee232h.SerNumEnable);
4919 eedata.ACSlowSlewH = Convert.ToByte(ee232h.ACSlowSlew);
4920 eedata.ACSchmittInputH = Convert.ToByte(ee232h.ACSchmittInput);
4921 eedata.ACDriveCurrentH = Convert.ToByte(ee232h.ACDriveCurrent);
4922 eedata.ADSlowSlewH = Convert.ToByte(ee232h.ADSlowSlew);
4923 eedata.ADSchmittInputH = Convert.ToByte(ee232h.ADSchmittInput);
4924 eedata.ADDriveCurrentH = Convert.ToByte(ee232h.ADDriveCurrent);
4925 eedata.Cbus0H = Convert.ToByte(ee232h.Cbus0);
4926 eedata.Cbus1H = Convert.ToByte(ee232h.Cbus1);
4927 eedata.Cbus2H = Convert.ToByte(ee232h.Cbus2);
4928 eedata.Cbus3H = Convert.ToByte(ee232h.Cbus3);
4929 eedata.Cbus4H = Convert.ToByte(ee232h.Cbus4);
4930 eedata.Cbus5H = Convert.ToByte(ee232h.Cbus5);
4931 eedata.Cbus6H = Convert.ToByte(ee232h.Cbus6);
4932 eedata.Cbus7H = Convert.ToByte(ee232h.Cbus7);
4933 eedata.Cbus8H = Convert.ToByte(ee232h.Cbus8);
4934 eedata.Cbus9H = Convert.ToByte(ee232h.Cbus9);
4935 eedata.IsFifoH = Convert.ToByte(ee232h.IsFifo);
4936 eedata.IsFifoTarH = Convert.ToByte(ee232h.IsFifoTar);
4937 eedata.IsFastSerH = Convert.ToByte(ee232h.IsFastSer);
4938 eedata.IsFT1248H = Convert.ToByte(ee232h.IsFT1248);
4939 eedata.FT1248CpolH = Convert.ToByte(ee232h.FT1248Cpol);
4940 eedata.FT1248LsbH = Convert.ToByte(ee232h.FT1248Lsb);
4941 eedata.FT1248FlowControlH = Convert.ToByte(ee232h.FT1248FlowControl);
4942 eedata.IsVCPH = Convert.ToByte(ee232h.IsVCP);
4943 eedata.PowerSaveEnableH = Convert.ToByte(ee232h.PowerSaveEnable);
4946 ftStatus = FT_EE_Program(ftHandle, eedata);
4949 Marshal.FreeHGlobal(eedata.Manufacturer);
4950 Marshal.FreeHGlobal(eedata.ManufacturerID);
4951 Marshal.FreeHGlobal(eedata.Description);
4952 Marshal.FreeHGlobal(eedata.SerialNumber);
4957 if (pFT_EE_Program == IntPtr.Zero)
4959 throw new Exception(
"Failed to load function FT_EE_Program.");
4977 public FT_STATUS WriteXSeriesEEPROM(FT_XSERIES_EEPROM_STRUCTURE eeX)
4980 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4981 FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4983 byte[] manufacturer, manufacturerID, description, serialNumber;
4986 if (hFTD2XXDLL == IntPtr.Zero)
4990 if (pFT_EEPROM_Program != IntPtr.Zero)
4992 tFT_EEPROM_Program FT_EEPROM_Program = (tFT_EEPROM_Program)Marshal.GetDelegateForFunctionPointer(pFT_EEPROM_Program, typeof(tFT_EEPROM_Program));
4994 if (ftHandle != IntPtr.Zero)
4998 GetDeviceType(ref DeviceType);
4999 if (DeviceType !=
FT_DEVICE.FT_DEVICE_X_SERIES)
5002 ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
5003 ErrorHandler(ftStatus, ftErrorCondition);
5007 if ((eeX.VendorID == 0x0000) | (eeX.ProductID == 0x0000))
5013 FT_XSERIES_DATA eeData =
new FT_XSERIES_DATA();
5017 manufacturer =
new byte[32];
5018 manufacturerID =
new byte[16];
5019 description =
new byte[64];
5020 serialNumber =
new byte[16];
5024 if (eeX.Manufacturer.Length > 32)
5025 eeX.Manufacturer = eeX.Manufacturer.Substring(0, 32);
5026 if (eeX.ManufacturerID.Length > 16)
5027 eeX.ManufacturerID = eeX.ManufacturerID.Substring(0, 16);
5028 if (eeX.Description.Length > 64)
5029 eeX.Description = eeX.Description.Substring(0, 64);
5030 if (eeX.SerialNumber.Length > 16)
5031 eeX.SerialNumber = eeX.SerialNumber.Substring(0, 16);
5034 System.Text.UTF8Encoding encoding =
new System.Text.UTF8Encoding();
5035 manufacturer = encoding.GetBytes(eeX.Manufacturer);
5036 manufacturerID = encoding.GetBytes(eeX.ManufacturerID);
5037 description = encoding.GetBytes(eeX.Description);
5038 serialNumber = encoding.GetBytes(eeX.SerialNumber);
5042 eeData.common.deviceType = (uint)
FT_DEVICE.FT_DEVICE_X_SERIES;
5043 eeData.common.VendorId = eeX.VendorID;
5044 eeData.common.ProductId = eeX.ProductID;
5045 eeData.common.MaxPower = eeX.MaxPower;
5046 eeData.common.SelfPowered = Convert.ToByte(eeX.SelfPowered);
5047 eeData.common.RemoteWakeup = Convert.ToByte(eeX.RemoteWakeup);
5048 eeData.common.SerNumEnable = Convert.ToByte(eeX.SerNumEnable);
5049 eeData.common.PullDownEnable = Convert.ToByte(eeX.PullDownEnable);
5052 eeData.Cbus0 = eeX.Cbus0;
5053 eeData.Cbus1 = eeX.Cbus1;
5054 eeData.Cbus2 = eeX.Cbus2;
5055 eeData.Cbus3 = eeX.Cbus3;
5056 eeData.Cbus4 = eeX.Cbus4;
5057 eeData.Cbus5 = eeX.Cbus5;
5058 eeData.Cbus6 = eeX.Cbus6;
5060 eeData.ACDriveCurrent = eeX.ACDriveCurrent;
5061 eeData.ACSchmittInput = eeX.ACSchmittInput;
5062 eeData.ACSlowSlew = eeX.ACSlowSlew;
5063 eeData.ADDriveCurrent = eeX.ADDriveCurrent;
5064 eeData.ADSchmittInput = eeX.ADSchmittInput;
5065 eeData.ADSlowSlew = eeX.ADSlowSlew;
5067 eeData.BCDDisableSleep = eeX.BCDDisableSleep;
5068 eeData.BCDEnable = eeX.BCDEnable;
5069 eeData.BCDForceCbusPWREN = eeX.BCDForceCbusPWREN;
5071 eeData.FT1248Cpol = eeX.FT1248Cpol;
5072 eeData.FT1248FlowControl = eeX.FT1248FlowControl;
5073 eeData.FT1248Lsb = eeX.FT1248Lsb;
5075 eeData.I2CDeviceId = eeX.I2CDeviceId;
5076 eeData.I2CDisableSchmitt = eeX.I2CDisableSchmitt;
5077 eeData.I2CSlaveAddress = eeX.I2CSlaveAddress;
5079 eeData.InvertCTS = eeX.InvertCTS;
5080 eeData.InvertDCD = eeX.InvertDCD;
5081 eeData.InvertDSR = eeX.InvertDSR;
5082 eeData.InvertDTR = eeX.InvertDTR;
5083 eeData.InvertRI = eeX.InvertRI;
5084 eeData.InvertRTS = eeX.InvertRTS;
5085 eeData.InvertRXD = eeX.InvertRXD;
5086 eeData.InvertTXD = eeX.InvertTXD;
5088 eeData.PowerSaveEnable = eeX.PowerSaveEnable;
5089 eeData.RS485EchoSuppress = eeX.RS485EchoSuppress;
5091 eeData.DriverType = eeX.IsVCP;
5094 int size = Marshal.SizeOf(eeData);
5096 IntPtr eeDataMarshal = Marshal.AllocHGlobal(size);
5097 Marshal.StructureToPtr(eeData, eeDataMarshal,
false);
5099 ftStatus = FT_EEPROM_Program(ftHandle, eeDataMarshal, (uint)size, manufacturer, manufacturerID, description, serialNumber);
5103 return FT_STATUS.FT_DEVICE_NOT_FOUND;
5116 public FT_STATUS EEReadUserArea(byte[] UserAreaDataBuffer, ref UInt32 numBytesRead)
5119 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5122 if (hFTD2XXDLL == IntPtr.Zero)
5126 if ((pFT_EE_UASize != IntPtr.Zero) & (pFT_EE_UARead != IntPtr.Zero))
5128 tFT_EE_UASize FT_EE_UASize = (tFT_EE_UASize)Marshal.GetDelegateForFunctionPointer(pFT_EE_UASize, typeof(tFT_EE_UASize));
5129 tFT_EE_UARead FT_EE_UARead = (tFT_EE_UARead)Marshal.GetDelegateForFunctionPointer(pFT_EE_UARead, typeof(tFT_EE_UARead));
5131 if (ftHandle != IntPtr.Zero)
5136 ftStatus = FT_EE_UASize(ftHandle, ref UASize);
5139 if (UserAreaDataBuffer.Length >= UASize)
5142 ftStatus = FT_EE_UARead(ftHandle, UserAreaDataBuffer, UserAreaDataBuffer.Length, ref numBytesRead);
5148 if (pFT_EE_UASize == IntPtr.Zero)
5150 throw new Exception(
"Failed to load function FT_EE_UASize.");
5152 if (pFT_EE_UARead == IntPtr.Zero)
5154 throw new Exception(
"Failed to load function FT_EE_UARead.");
5169 public FT_STATUS EEWriteUserArea(byte[] UserAreaDataBuffer)
5172 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5175 if (hFTD2XXDLL == IntPtr.Zero)
5179 if ((pFT_EE_UASize != IntPtr.Zero) & (pFT_EE_UAWrite != IntPtr.Zero))
5181 tFT_EE_UASize FT_EE_UASize = (tFT_EE_UASize)Marshal.GetDelegateForFunctionPointer(pFT_EE_UASize, typeof(tFT_EE_UASize));
5182 tFT_EE_UAWrite FT_EE_UAWrite = (tFT_EE_UAWrite)Marshal.GetDelegateForFunctionPointer(pFT_EE_UAWrite, typeof(tFT_EE_UAWrite));
5184 if (ftHandle != IntPtr.Zero)
5189 ftStatus = FT_EE_UASize(ftHandle, ref UASize);
5192 if (UserAreaDataBuffer.Length <= UASize)
5195 ftStatus = FT_EE_UAWrite(ftHandle, UserAreaDataBuffer, UserAreaDataBuffer.Length);
5201 if (pFT_EE_UASize == IntPtr.Zero)
5203 throw new Exception(
"Failed to load function FT_EE_UASize.");
5205 if (pFT_EE_UAWrite == IntPtr.Zero)
5207 throw new Exception(
"Failed to load function FT_EE_UAWrite.");
5222 public FT_STATUS GetDeviceType(ref FT_DEVICE DeviceType)
5225 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5228 if (hFTD2XXDLL == IntPtr.Zero)
5232 if (pFT_GetDeviceInfo != IntPtr.Zero)
5234 tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5236 UInt32 DeviceID = 0;
5237 byte[] sernum =
new byte[16];
5238 byte[] desc =
new byte[64];
5240 DeviceType =
FT_DEVICE.FT_DEVICE_UNKNOWN;
5242 if (ftHandle != IntPtr.Zero)
5245 ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5250 if (pFT_GetDeviceInfo == IntPtr.Zero)
5252 throw new Exception(
"Failed to load function FT_GetDeviceInfo.");
5267 public FT_STATUS GetDeviceID(ref UInt32 DeviceID)
5270 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5273 if (hFTD2XXDLL == IntPtr.Zero)
5277 if (pFT_GetDeviceInfo != IntPtr.Zero)
5279 tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5282 byte[] sernum =
new byte[16];
5283 byte[] desc =
new byte[64];
5285 if (ftHandle != IntPtr.Zero)
5288 ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5293 if (pFT_GetDeviceInfo == IntPtr.Zero)
5295 throw new Exception(
"Failed to load function FT_GetDeviceInfo.");
5310 public FT_STATUS GetDescription(out
string Description)
5313 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5315 Description = String.Empty;
5318 if (hFTD2XXDLL == IntPtr.Zero)
5323 if (pFT_GetDeviceInfo != IntPtr.Zero)
5325 tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5327 UInt32 DeviceID = 0;
5329 byte[] sernum =
new byte[16];
5330 byte[] desc =
new byte[64];
5332 if (ftHandle != IntPtr.Zero)
5335 ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5336 Description = Encoding.ASCII.GetString(desc);
5337 Description = Description.Substring(0, Description.IndexOf(
"\0"));
5342 if (pFT_GetDeviceInfo == IntPtr.Zero)
5344 throw new Exception(
"Failed to load function FT_GetDeviceInfo.");
5359 public FT_STATUS GetSerialNumber(out
string SerialNumber)
5362 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5364 SerialNumber = String.Empty;
5367 if (hFTD2XXDLL == IntPtr.Zero)
5372 if (pFT_GetDeviceInfo != IntPtr.Zero)
5374 tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5376 UInt32 DeviceID = 0;
5378 byte[] sernum =
new byte[16];
5379 byte[] desc =
new byte[64];
5381 if (ftHandle != IntPtr.Zero)
5384 ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5385 SerialNumber = Encoding.ASCII.GetString(sernum);
5386 SerialNumber = SerialNumber.Substring(0, SerialNumber.IndexOf(
"\0"));
5391 if (pFT_GetDeviceInfo == IntPtr.Zero)
5393 throw new Exception(
"Failed to load function FT_GetDeviceInfo.");
5408 public FT_STATUS GetRxBytesAvailable(ref UInt32 RxQueue)
5411 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5414 if (hFTD2XXDLL == IntPtr.Zero)
5418 if (pFT_GetQueueStatus != IntPtr.Zero)
5420 tFT_GetQueueStatus FT_GetQueueStatus = (tFT_GetQueueStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetQueueStatus, typeof(tFT_GetQueueStatus));
5422 if (ftHandle != IntPtr.Zero)
5425 ftStatus = FT_GetQueueStatus(ftHandle, ref RxQueue);
5430 if (pFT_GetQueueStatus == IntPtr.Zero)
5432 throw new Exception(
"Failed to load function FT_GetQueueStatus.");
5447 public FT_STATUS GetTxBytesWaiting(ref UInt32 TxQueue)
5450 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5453 if (hFTD2XXDLL == IntPtr.Zero)
5457 if (pFT_GetStatus != IntPtr.Zero)
5459 tFT_GetStatus FT_GetStatus = (tFT_GetStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetStatus, typeof(tFT_GetStatus));
5462 UInt32 EventStatus = 0;
5464 if (ftHandle != IntPtr.Zero)
5467 ftStatus = FT_GetStatus(ftHandle, ref RxQueue, ref TxQueue, ref EventStatus);
5472 if (pFT_GetStatus == IntPtr.Zero)
5474 throw new Exception(
"Failed to load function FT_GetStatus.");
5489 public FT_STATUS GetEventType(ref UInt32 EventType)
5492 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5495 if (hFTD2XXDLL == IntPtr.Zero)
5499 if (pFT_GetStatus != IntPtr.Zero)
5501 tFT_GetStatus FT_GetStatus = (tFT_GetStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetStatus, typeof(tFT_GetStatus));
5506 if (ftHandle != IntPtr.Zero)
5509 ftStatus = FT_GetStatus(ftHandle, ref RxQueue, ref TxQueue, ref EventType);
5514 if (pFT_GetStatus == IntPtr.Zero)
5516 throw new Exception(
"Failed to load function FT_GetStatus.");
5531 public FT_STATUS GetModemStatus(ref byte ModemStatus)
5534 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5537 if (hFTD2XXDLL == IntPtr.Zero)
5541 if (pFT_GetModemStatus != IntPtr.Zero)
5543 tFT_GetModemStatus FT_GetModemStatus = (tFT_GetModemStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetModemStatus, typeof(tFT_GetModemStatus));
5545 UInt32 ModemLineStatus = 0;
5547 if (ftHandle != IntPtr.Zero)
5550 ftStatus = FT_GetModemStatus(ftHandle, ref ModemLineStatus);
5553 ModemStatus = Convert.ToByte(ModemLineStatus & 0x000000FF);
5557 if (pFT_GetModemStatus == IntPtr.Zero)
5559 throw new Exception(
"Failed to load function FT_GetModemStatus.");
5574 public FT_STATUS GetLineStatus(ref byte LineStatus)
5577 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5580 if (hFTD2XXDLL == IntPtr.Zero)
5584 if (pFT_GetModemStatus != IntPtr.Zero)
5586 tFT_GetModemStatus FT_GetModemStatus = (tFT_GetModemStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetModemStatus, typeof(tFT_GetModemStatus));
5588 UInt32 ModemLineStatus = 0;
5590 if (ftHandle != IntPtr.Zero)
5593 ftStatus = FT_GetModemStatus(ftHandle, ref ModemLineStatus);
5595 LineStatus = Convert.ToByte((ModemLineStatus >> 8) & 0x000000FF);
5599 if (pFT_GetModemStatus == IntPtr.Zero)
5601 throw new Exception(
"Failed to load function FT_GetModemStatus.");
5616 public FT_STATUS SetBaudRate(UInt32 BaudRate)
5619 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5622 if (hFTD2XXDLL == IntPtr.Zero)
5626 if (pFT_SetBaudRate != IntPtr.Zero)
5628 tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
5630 if (ftHandle != IntPtr.Zero)
5633 ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
5638 if (pFT_SetBaudRate == IntPtr.Zero)
5640 throw new Exception(
"Failed to load function FT_SetBaudRate.");
5657 public FT_STATUS SetDataCharacteristics(byte DataBits, byte StopBits, byte Parity)
5660 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5663 if (hFTD2XXDLL == IntPtr.Zero)
5667 if (pFT_SetDataCharacteristics != IntPtr.Zero)
5669 tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
5671 if (ftHandle != IntPtr.Zero)
5674 ftStatus = FT_SetDataCharacteristics(ftHandle, DataBits, StopBits, Parity);
5679 if (pFT_SetDataCharacteristics == IntPtr.Zero)
5681 throw new Exception(
"Failed to load function FT_SetDataCharacteristics.");
5698 public FT_STATUS SetFlowControl(UInt16 FlowControl, byte Xon, byte Xoff)
5701 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5704 if (hFTD2XXDLL == IntPtr.Zero)
5708 if (pFT_SetFlowControl != IntPtr.Zero)
5710 tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
5712 if (ftHandle != IntPtr.Zero)
5715 ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
5720 if (pFT_SetFlowControl == IntPtr.Zero)
5722 throw new Exception(
"Failed to load function FT_SetFlowControl.");
5737 public FT_STATUS SetRTS(
bool Enable)
5740 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5743 if (hFTD2XXDLL == IntPtr.Zero)
5747 if ((pFT_SetRts != IntPtr.Zero) & (pFT_ClrRts != IntPtr.Zero))
5749 tFT_SetRts FT_SetRts = (tFT_SetRts)Marshal.GetDelegateForFunctionPointer(pFT_SetRts, typeof(tFT_SetRts));
5750 tFT_ClrRts FT_ClrRts = (tFT_ClrRts)Marshal.GetDelegateForFunctionPointer(pFT_ClrRts, typeof(tFT_ClrRts));
5752 if (ftHandle != IntPtr.Zero)
5757 ftStatus = FT_SetRts(ftHandle);
5762 ftStatus = FT_ClrRts(ftHandle);
5768 if (pFT_SetRts == IntPtr.Zero)
5770 throw new Exception(
"Failed to load function FT_SetRts.");
5772 if (pFT_ClrRts == IntPtr.Zero)
5774 throw new Exception(
"Failed to load function FT_ClrRts.");
5789 public FT_STATUS SetDTR(
bool Enable)
5792 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5795 if (hFTD2XXDLL == IntPtr.Zero)
5799 if ((pFT_SetDtr != IntPtr.Zero) & (pFT_ClrDtr != IntPtr.Zero))
5801 tFT_SetDtr FT_SetDtr = (tFT_SetDtr)Marshal.GetDelegateForFunctionPointer(pFT_SetDtr, typeof(tFT_SetDtr));
5802 tFT_ClrDtr FT_ClrDtr = (tFT_ClrDtr)Marshal.GetDelegateForFunctionPointer(pFT_ClrDtr, typeof(tFT_ClrDtr));
5804 if (ftHandle != IntPtr.Zero)
5809 ftStatus = FT_SetDtr(ftHandle);
5814 ftStatus = FT_ClrDtr(ftHandle);
5820 if (pFT_SetDtr == IntPtr.Zero)
5822 throw new Exception(
"Failed to load function FT_SetDtr.");
5824 if (pFT_ClrDtr == IntPtr.Zero)
5826 throw new Exception(
"Failed to load function FT_ClrDtr.");
5842 public FT_STATUS SetTimeouts(UInt32 ReadTimeout, UInt32 WriteTimeout)
5845 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5848 if (hFTD2XXDLL == IntPtr.Zero)
5852 if (pFT_SetTimeouts != IntPtr.Zero)
5854 tFT_SetTimeouts FT_SetTimeouts = (tFT_SetTimeouts)Marshal.GetDelegateForFunctionPointer(pFT_SetTimeouts, typeof(tFT_SetTimeouts));
5856 if (ftHandle != IntPtr.Zero)
5859 ftStatus = FT_SetTimeouts(ftHandle, ReadTimeout, WriteTimeout);
5864 if (pFT_SetTimeouts == IntPtr.Zero)
5866 throw new Exception(
"Failed to load function FT_SetTimeouts.");
5881 public FT_STATUS SetBreak(
bool Enable)
5884 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5887 if (hFTD2XXDLL == IntPtr.Zero)
5891 if ((pFT_SetBreakOn != IntPtr.Zero) & (pFT_SetBreakOff != IntPtr.Zero))
5893 tFT_SetBreakOn FT_SetBreakOn = (tFT_SetBreakOn)Marshal.GetDelegateForFunctionPointer(pFT_SetBreakOn, typeof(tFT_SetBreakOn));
5894 tFT_SetBreakOff FT_SetBreakOff = (tFT_SetBreakOff)Marshal.GetDelegateForFunctionPointer(pFT_SetBreakOff, typeof(tFT_SetBreakOff));
5896 if (ftHandle != IntPtr.Zero)
5901 ftStatus = FT_SetBreakOn(ftHandle);
5906 ftStatus = FT_SetBreakOff(ftHandle);
5912 if (pFT_SetBreakOn == IntPtr.Zero)
5914 throw new Exception(
"Failed to load function FT_SetBreakOn.");
5916 if (pFT_SetBreakOff == IntPtr.Zero)
5918 throw new Exception(
"Failed to load function FT_SetBreakOff.");
5934 public FT_STATUS SetResetPipeRetryCount(UInt32 ResetPipeRetryCount)
5937 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5940 if (hFTD2XXDLL == IntPtr.Zero)
5944 if (pFT_SetResetPipeRetryCount != IntPtr.Zero)
5946 tFT_SetResetPipeRetryCount FT_SetResetPipeRetryCount = (tFT_SetResetPipeRetryCount)Marshal.GetDelegateForFunctionPointer(pFT_SetResetPipeRetryCount, typeof(tFT_SetResetPipeRetryCount));
5948 if (ftHandle != IntPtr.Zero)
5951 ftStatus = FT_SetResetPipeRetryCount(ftHandle, ResetPipeRetryCount);
5956 if (pFT_SetResetPipeRetryCount == IntPtr.Zero)
5958 throw new Exception(
"Failed to load function FT_SetResetPipeRetryCount.");
5973 public FT_STATUS GetDriverVersion(ref UInt32 DriverVersion)
5976 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5979 if (hFTD2XXDLL == IntPtr.Zero)
5983 if (pFT_GetDriverVersion != IntPtr.Zero)
5985 tFT_GetDriverVersion FT_GetDriverVersion = (tFT_GetDriverVersion)Marshal.GetDelegateForFunctionPointer(pFT_GetDriverVersion, typeof(tFT_GetDriverVersion));
5987 if (ftHandle != IntPtr.Zero)
5990 ftStatus = FT_GetDriverVersion(ftHandle, ref DriverVersion);
5995 if (pFT_GetDriverVersion == IntPtr.Zero)
5997 throw new Exception(
"Failed to load function FT_GetDriverVersion.");
6012 public FT_STATUS GetLibraryVersion(ref UInt32 LibraryVersion)
6015 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6018 if (hFTD2XXDLL == IntPtr.Zero)
6022 if (pFT_GetLibraryVersion != IntPtr.Zero)
6024 tFT_GetLibraryVersion FT_GetLibraryVersion = (tFT_GetLibraryVersion)Marshal.GetDelegateForFunctionPointer(pFT_GetLibraryVersion, typeof(tFT_GetLibraryVersion));
6027 ftStatus = FT_GetLibraryVersion(ref LibraryVersion);
6031 if (pFT_GetLibraryVersion == IntPtr.Zero)
6033 throw new Exception(
"Failed to load function FT_GetLibraryVersion.");
6048 public FT_STATUS SetDeadmanTimeout(UInt32 DeadmanTimeout)
6051 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6054 if (hFTD2XXDLL == IntPtr.Zero)
6058 if (pFT_SetDeadmanTimeout != IntPtr.Zero)
6060 tFT_SetDeadmanTimeout FT_SetDeadmanTimeout = (tFT_SetDeadmanTimeout)Marshal.GetDelegateForFunctionPointer(pFT_SetDeadmanTimeout, typeof(tFT_SetDeadmanTimeout));
6062 if (ftHandle != IntPtr.Zero)
6065 ftStatus = FT_SetDeadmanTimeout(ftHandle, DeadmanTimeout);
6070 if (pFT_SetDeadmanTimeout == IntPtr.Zero)
6072 throw new Exception(
"Failed to load function FT_SetDeadmanTimeout.");
6089 public FT_STATUS SetLatency(byte Latency)
6092 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6095 if (hFTD2XXDLL == IntPtr.Zero)
6099 if (pFT_SetLatencyTimer != IntPtr.Zero)
6101 tFT_SetLatencyTimer FT_SetLatencyTimer = (tFT_SetLatencyTimer)Marshal.GetDelegateForFunctionPointer(pFT_SetLatencyTimer, typeof(tFT_SetLatencyTimer));
6103 if (ftHandle != IntPtr.Zero)
6107 GetDeviceType(ref DeviceType);
6108 if ((DeviceType ==
FT_DEVICE.FT_DEVICE_BM) || (DeviceType ==
FT_DEVICE.FT_DEVICE_2232))
6117 ftStatus = FT_SetLatencyTimer(ftHandle, Latency);
6122 if (pFT_SetLatencyTimer == IntPtr.Zero)
6124 throw new Exception(
"Failed to load function FT_SetLatencyTimer.");
6139 public FT_STATUS GetLatency(ref byte Latency)
6142 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6145 if (hFTD2XXDLL == IntPtr.Zero)
6149 if (pFT_GetLatencyTimer != IntPtr.Zero)
6151 tFT_GetLatencyTimer FT_GetLatencyTimer = (tFT_GetLatencyTimer)Marshal.GetDelegateForFunctionPointer(pFT_GetLatencyTimer, typeof(tFT_GetLatencyTimer));
6153 if (ftHandle != IntPtr.Zero)
6156 ftStatus = FT_GetLatencyTimer(ftHandle, ref Latency);
6161 if (pFT_GetLatencyTimer == IntPtr.Zero)
6163 throw new Exception(
"Failed to load function FT_GetLatencyTimer.");
6178 public FT_STATUS InTransferSize(UInt32 InTransferSize)
6183 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6186 if (hFTD2XXDLL == IntPtr.Zero)
6190 if (pFT_SetUSBParameters != IntPtr.Zero)
6192 tFT_SetUSBParameters FT_SetUSBParameters = (tFT_SetUSBParameters)Marshal.GetDelegateForFunctionPointer(pFT_SetUSBParameters, typeof(tFT_SetUSBParameters));
6196 if (ftHandle != IntPtr.Zero)
6199 ftStatus = FT_SetUSBParameters(ftHandle, InTransferSize, OutTransferSize);
6204 if (pFT_SetUSBParameters == IntPtr.Zero)
6206 throw new Exception(
"Failed to load function FT_SetUSBParameters.");
6224 public FT_STATUS SetCharacters(byte EventChar,
bool EventCharEnable, byte ErrorChar,
bool ErrorCharEnable)
6227 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6230 if (hFTD2XXDLL == IntPtr.Zero)
6234 if (pFT_SetChars != IntPtr.Zero)
6236 tFT_SetChars FT_SetChars = (tFT_SetChars)Marshal.GetDelegateForFunctionPointer(pFT_SetChars, typeof(tFT_SetChars));
6238 if (ftHandle != IntPtr.Zero)
6241 ftStatus = FT_SetChars(ftHandle, EventChar, Convert.ToByte(EventCharEnable), ErrorChar, Convert.ToByte(ErrorCharEnable));
6246 if (pFT_SetChars == IntPtr.Zero)
6248 throw new Exception(
"Failed to load function FT_SetChars.");
6263 public FT_STATUS EEUserAreaSize(ref UInt32 UASize)
6266 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6269 if (hFTD2XXDLL == IntPtr.Zero)
6273 if (pFT_EE_UASize != IntPtr.Zero)
6275 tFT_EE_UASize FT_EE_UASize = (tFT_EE_UASize)Marshal.GetDelegateForFunctionPointer(pFT_EE_UASize, typeof(tFT_EE_UASize));
6277 if (ftHandle != IntPtr.Zero)
6279 ftStatus = FT_EE_UASize(ftHandle, ref UASize);
6284 if (pFT_EE_UASize == IntPtr.Zero)
6286 throw new Exception(
"Failed to load function FT_EE_UASize.");
6301 public FT_STATUS GetCOMPort(out
string ComPortName)
6304 FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6307 ComPortName =
string.Empty;
6310 if (hFTD2XXDLL == IntPtr.Zero)
6314 if (pFT_GetComPortNumber != IntPtr.Zero)
6316 tFT_GetComPortNumber FT_GetComPortNumber = (tFT_GetComPortNumber)Marshal.GetDelegateForFunctionPointer(pFT_GetComPortNumber, typeof(tFT_GetComPortNumber));
6318 Int32 ComPortNumber = -1;
6319 if (ftHandle != IntPtr.Zero)
6322 ftStatus = FT_GetComPortNumber(ftHandle, ref ComPortNumber);
6325 if (ComPortNumber == -1)
6328 ComPortName =
string.Empty;
6334 ComPortName =
"COM" + ComPortNumber.ToString();
6339 if (pFT_GetComPortNumber == IntPtr.Zero)
6341 throw new Exception(
"Failed to load function FT_GetComPortNumber.");
6354 #region PROPERTY_DEFINITIONS
6366 if (ftHandle == IntPtr.Zero)
6380 private string InterfaceIdentifier
6385 Identifier = String.Empty;
6389 GetDeviceType(ref deviceType);
6390 if ((deviceType ==
FT_DEVICE.FT_DEVICE_2232) | (deviceType ==
FT_DEVICE.FT_DEVICE_2232H) | (deviceType ==
FT_DEVICE.FT_DEVICE_4232H))
6393 GetDescription(out Description);
6394 Identifier = Description.Substring((Description.Length - 1));
6403 #region HELPER_METHODS
6405 public void ErrorHandler(FT_STATUS ftStatus)
6407 ErrorHandler(ftStatus, FT_ERROR.FT_NO_ERROR);
6416 private void ErrorHandler(FT_STATUS ftStatus, FT_ERROR ftErrorCondition)
6431 case FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_ERASE:
6433 throw new FT_EXCEPTION(
"FTDI device not opened for erase.");
6435 case FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_WRITE:
6437 throw new FT_EXCEPTION(
"FTDI device not opened for write.");
6441 throw new FT_EXCEPTION(
"Failed to erase FTDI device EEPROM.");
6445 throw new FT_EXCEPTION(
"No EEPROM fitted to FTDI device.");
6447 case FT_STATUS.FT_EEPROM_NOT_PROGRAMMED:
6449 throw new FT_EXCEPTION(
"FTDI device EEPROM not programmed.");
6453 throw new FT_EXCEPTION(
"Failed to read FTDI device EEPROM.");
6457 throw new FT_EXCEPTION(
"Failed to write FTDI device EEPROM.");
6459 case FT_STATUS.FT_FAILED_TO_WRITE_DEVICE:
6461 throw new FT_EXCEPTION(
"Failed to write to FTDI device.");
6463 case FT_STATUS.FT_INSUFFICIENT_RESOURCES:
6469 throw new FT_EXCEPTION(
"Invalid arguments for FTD2XX function call.");
6473 throw new FT_EXCEPTION(
"Invalid Baud rate for FTDI device.");
6477 throw new FT_EXCEPTION(
"Invalid handle for FTDI device.");
6481 throw new FT_EXCEPTION(
"Invalid parameter for FTD2XX function call.");
6489 throw new FT_EXCEPTION(
"An unexpected error has occurred when trying to communicate with the FTDI device.");
6495 if (ftErrorCondition != FT_ERROR.FT_NO_ERROR)
6498 switch (ftErrorCondition)
6500 case FT_ERROR.FT_INCORRECT_DEVICE:
6502 throw new FT_EXCEPTION(
"The current device type does not match the EEPROM structure.");
6504 case FT_ERROR.FT_INVALID_BITMODE:
6506 throw new FT_EXCEPTION(
"The requested bit mode is not valid for the current device.");
6508 case FT_ERROR.FT_BUFFER_SIZE:
6510 throw new FT_EXCEPTION(
"The supplied buffer is not big enough.");