WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
FTD2XX_NET.cs
Go to the documentation of this file.
1 /*
2 ** This code is based on FTD2XX_NET.cs as found on the FDTI website.
3 ** It has been modified to throw exceptions instead of showing messageboxes when problems occur.
4 ** In addition a proper event has been added.
5 **
6 ** The following lines contain the original comments as defined by FDTI.
7 **
8 ** FTD2XX_NET
9 **
10 ** Copyright © 2009-2012 Future Technology Devices International Limited
11 **
12 ** C# Source file for .NET wrapper of the Windows FTD2XX.dll API calls.
13 ** Main module
14 **
15 ** Author: FTDI
16 ** Project: CDM Windows Driver Package
17 ** Module: FTD2XX_NET Managed Wrapper
18 ** Requires:
19 ** Comments:
20 **
21 ** History:
22 ** 1.0.0 - Initial version
23 ** 1.0.12 - Included support for the FT232H device.
24 ** 1.0.14 - Included Support for the X-Series of devices.
25 **
26 */
27 using System;
28 using System.Collections.Generic;
29 using System.Text;
30 using System.Runtime.InteropServices;
31 using System.Threading;
32 using System.IO;
34 
35 namespace DirectOutput.Cab.Out.FTDIChip
36 {
40  public class FTDI
41  {
42  private AutoResetEvent receivedDataEvent;
43  private BackgroundWorker dataReceivedHandler;
44 
45  #region CONSTRUCTOR_DESTRUCTOR
46  // constructor
50  public FTDI()
51  {
52  // If FTD2XX.DLL is NOT loaded already, load it
53  if (hFTD2XXDLL == IntPtr.Zero)
54  {
55  // Load our FTD2XX.DLL library
56  hFTD2XXDLL = LoadLibrary(@"FTD2XX.DLL");
57  if (hFTD2XXDLL == IntPtr.Zero)
58  {
59  // Failed to load our FTD2XX.DLL library from System32 or the application directory
60  // Try the same directory that this FTD2XX_NET DLL is in
61 
62  hFTD2XXDLL = LoadLibrary(@Path.GetDirectoryName(GetType().Assembly.Location) + "\\FTD2XX.DLL");
63  }
64  }
65 
66  // If we have succesfully loaded the library, get the function pointers set up
67  if (hFTD2XXDLL != IntPtr.Zero)
68  {
69  // Set up our function pointers for use through our exported methods
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");
121  }
122  else
123  {
124  // Failed to load our DLL - alert the user
125  throw new Exception("Failed to load FTD2XX.DLL. Are the FTDI drivers installed?");
126  }
127 
128 
129  }
130 
131 
132  private void ReadData(object pSender, DoWorkEventArgs pEventArgs)
133  {
134  UInt32 nrOfBytesAvailable = 0;
135  while (true)
136  {
137  // wait until event is fired
138  this.receivedDataEvent.WaitOne();
139 
140  // try to recieve data now
141  FTDI.FT_STATUS status = GetRxBytesAvailable(ref nrOfBytesAvailable);
142  if (status != FTDI.FT_STATUS.FT_OK)
143  {
144  break;
145  }
146  if (nrOfBytesAvailable > 0)
147  {
148 
149  OnCharReceived();
150  }
151  }
152  }
153 
154 
155 
159  ~FTDI()
160  {
161  // FreeLibrary here - we should only do this if we are completely finished
162  FreeLibrary(hFTD2XXDLL);
163  hFTD2XXDLL = IntPtr.Zero;
164  }
165  #endregion
166 
167  #region LOAD_LIBRARIES
168  [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);
178  #endregion
179 
180  #region DELEGATES
181  // Definitions for FTD2XX functions
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);
186 
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);
195 
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);
200 
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);
239 
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);
242 
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);
261 
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);
272 
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);
279 
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);
286 
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);
291 
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);
296  #endregion
297 
298  #region CONSTANT_VALUES
299  // Constants for FT_STATUS
303  public enum FT_STATUS
304  {
308  FT_OK = 0,
312  FT_INVALID_HANDLE,
316  FT_DEVICE_NOT_FOUND,
320  FT_DEVICE_NOT_OPENED,
324  FT_IO_ERROR,
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,
372  FT_INVALID_ARGS,
376  FT_OTHER_ERROR
377  };
378 
379  // Constants for other error states internal to this class library
383  private enum FT_ERROR
384  {
385  FT_NO_ERROR = 0,
386  FT_INCORRECT_DEVICE,
387  FT_INVALID_BITMODE,
388  FT_BUFFER_SIZE
389  };
390 
391  // Flags for FT_OpenEx
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;
395 
396  // Word Lengths
400  public class FT_DATA_BITS
401  {
405  public const byte FT_BITS_8 = 0x08;
409  public const byte FT_BITS_7 = 0x07;
410  }
411 
412  // Stop Bits
416  public class FT_STOP_BITS
417  {
421  public const byte FT_STOP_BITS_1 = 0x00;
425  public const byte FT_STOP_BITS_2 = 0x02;
426  }
427 
428  // Parity
432  public class FT_PARITY
433  {
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;
454  }
455 
456  // Flow Control
460  public class FT_FLOW_CONTROL
461  {
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;
478  }
479 
480  // Purge Rx and Tx buffers
484  public class FT_PURGE
485  {
489  public const byte FT_PURGE_RX = 0x01;
493  public const byte FT_PURGE_TX = 0x02;
494  }
495 
496  // Modem Status bits
500  public class FT_MODEM_STATUS
501  {
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;
518  }
519 
520  // Line Status bits
524  public class FT_LINE_STATUS
525  {
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;
542  }
543 
544  // Events
548  public class FT_EVENTS
549  {
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;
562  }
563 
564  // Bit modes
568  public class FT_BIT_MODES
569  {
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;
602  }
603 
604  // FT232R CBUS Options
608  public class FT_CBUS_OPTIONS
609  {
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;
662  }
663 
664  // FT232H CBUS Options
668  public class FT_232H_CBUS_OPTIONS
669  {
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;
718  public const byte FT_CBUS_CLK7_5 = 0x0C;
721  }
722 
727  {
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;
816  }
817 
818  // Flag values for FT_GetDeviceInfoDetail and FT_GetDeviceInfo
822  public class FT_FLAGS
823  {
827  public const UInt32 FT_FLAGS_OPENED = 0x00000001;
831  public const UInt32 FT_FLAGS_HISPEED = 0x00000002;
832  }
833 
834  // Valid drive current values for FT2232H, FT4232H and FT232H devices
838  public class FT_DRIVE_CURRENT
839  {
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;
856  }
857 
858  // Device type identifiers for FT_GetDeviceInfoDetail and FT_GetDeviceInfo
862  public enum FT_DEVICE
863  {
867  FT_DEVICE_BM = 0,
871  FT_DEVICE_AM,
875  FT_DEVICE_100AX,
879  FT_DEVICE_UNKNOWN,
883  FT_DEVICE_2232,
887  FT_DEVICE_232R,
891  FT_DEVICE_2232H,
895  FT_DEVICE_4232H,
899  FT_DEVICE_232H,
903  FT_DEVICE_X_SERIES
904  };
905  #endregion
906 
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;
915  #endregion
916 
917  #region VARIABLES
918  // Create private variables for the device within the class
919  private IntPtr ftHandle = IntPtr.Zero;
920  #endregion
921 
922  #region TYPEDEFS
923  public class FT_DEVICE_INFO_NODE
928  {
932  public UInt32 Flags;
936  public FT_DEVICE Type;
940  public UInt32 ID;
944  public UInt32 LocId;
948  public string SerialNumber;
952  public string Description;
957  public IntPtr ftHandle;
958  }
959  #endregion
960 
961  #region EEPROM_STRUCTURES
962  // Internal structure for reading and writing EEPROM contents
963  // NOTE: NEED Pack=1 for byte alignment! Without this, data is garbage
964  [StructLayout(LayoutKind.Sequential, Pack = 4)]
965  private class FT_PROGRAM_DATA
966  {
967  public UInt32 Signature1;
968  public UInt32 Signature2;
969  public UInt32 Version;
970  public UInt16 VendorID;
971  public UInt16 ProductID;
972 
973  public IntPtr Manufacturer;
974  public IntPtr ManufacturerID;
975  public IntPtr Description;
976  public IntPtr SerialNumber;
977 
978  public UInt16 MaxPower;
979  public UInt16 PnP;
980  public UInt16 SelfPowered;
981  public UInt16 RemoteWakeup;
982  // FT232B extensions
983  public byte Rev4;
984  public byte IsoIn;
985  public byte IsoOut;
986  public byte PullDownEnable;
987  public byte SerNumEnable;
988  public byte USBVersionEnable;
989  public UInt16 USBVersion;
990  // FT2232D extensions
991  public byte Rev5;
992  public byte IsoInA;
993  public byte IsoInB;
994  public byte IsoOutA;
995  public byte IsoOutB;
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;
1005  public byte AIsVCP;
1006  public byte IFBIsFifo;
1007  public byte IFBIsFifoTar;
1008  public byte IFBIsFastSer;
1009  public byte BIsVCP;
1010  // FT232R extensions
1011  public byte UseExtOsc;
1012  public byte HighDriveIOs;
1013  public byte EndpointSize;
1014  public byte PullDownEnableR;
1015  public byte SerNumEnableR;
1016  public byte InvertTXD; // non-zero if invert TXD
1017  public byte InvertRXD; // non-zero if invert RXD
1018  public byte InvertRTS; // non-zero if invert RTS
1019  public byte InvertCTS; // non-zero if invert CTS
1020  public byte InvertDTR; // non-zero if invert DTR
1021  public byte InvertDSR; // non-zero if invert DSR
1022  public byte InvertDCD; // non-zero if invert DCD
1023  public byte InvertRI; // non-zero if invert RI
1024  public byte Cbus0; // Cbus Mux control - Ignored for FT245R
1025  public byte Cbus1; // Cbus Mux control - Ignored for FT245R
1026  public byte Cbus2; // Cbus Mux control - Ignored for FT245R
1027  public byte Cbus3; // Cbus Mux control - Ignored for FT245R
1028  public byte Cbus4; // Cbus Mux control - Ignored for FT245R
1029  public byte RIsD2XX; // Default to loading VCP
1030  // FT2232H extensions
1031  public byte PullDownEnable7;
1032  public byte SerNumEnable7;
1033  public byte ALSlowSlew; // non-zero if AL pins have slow slew
1034  public byte ALSchmittInput; // non-zero if AL pins are Schmitt input
1035  public byte ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1036  public byte AHSlowSlew; // non-zero if AH pins have slow slew
1037  public byte AHSchmittInput; // non-zero if AH pins are Schmitt input
1038  public byte AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1039  public byte BLSlowSlew; // non-zero if BL pins have slow slew
1040  public byte BLSchmittInput; // non-zero if BL pins are Schmitt input
1041  public byte BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1042  public byte BHSlowSlew; // non-zero if BH pins have slow slew
1043  public byte BHSchmittInput; // non-zero if BH pins are Schmitt input
1044  public byte BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1045  public byte IFAIsFifo7; // non-zero if interface is 245 FIFO
1046  public byte IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
1047  public byte IFAIsFastSer7; // non-zero if interface is Fast serial
1048  public byte AIsVCP7; // non-zero if interface is to use VCP drivers
1049  public byte IFBIsFifo7; // non-zero if interface is 245 FIFO
1050  public byte IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
1051  public byte IFBIsFastSer7; // non-zero if interface is Fast serial
1052  public byte BIsVCP7; // non-zero if interface is to use VCP drivers
1053  public byte PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs
1054  // FT4232H extensions
1055  public byte PullDownEnable8;
1056  public byte SerNumEnable8;
1057  public byte ASlowSlew; // non-zero if AL pins have slow slew
1058  public byte ASchmittInput; // non-zero if AL pins are Schmitt input
1059  public byte ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1060  public byte BSlowSlew; // non-zero if AH pins have slow slew
1061  public byte BSchmittInput; // non-zero if AH pins are Schmitt input
1062  public byte BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1063  public byte CSlowSlew; // non-zero if BL pins have slow slew
1064  public byte CSchmittInput; // non-zero if BL pins are Schmitt input
1065  public byte CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1066  public byte DSlowSlew; // non-zero if BH pins have slow slew
1067  public byte DSchmittInput; // non-zero if BH pins are Schmitt input
1068  public byte DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1069  public byte ARIIsTXDEN;
1070  public byte BRIIsTXDEN;
1071  public byte CRIIsTXDEN;
1072  public byte DRIIsTXDEN;
1073  public byte AIsVCP8; // non-zero if interface is to use VCP drivers
1074  public byte BIsVCP8; // non-zero if interface is to use VCP drivers
1075  public byte CIsVCP8; // non-zero if interface is to use VCP drivers
1076  public byte DIsVCP8; // non-zero if interface is to use VCP drivers
1077  // FT232H extensions
1078  public byte PullDownEnableH; // non-zero if pull down enabled
1079  public byte SerNumEnableH; // non-zero if serial number to be used
1080  public byte ACSlowSlewH; // non-zero if AC pins have slow slew
1081  public byte ACSchmittInputH; // non-zero if AC pins are Schmitt input
1082  public byte ACDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA
1083  public byte ADSlowSlewH; // non-zero if AD pins have slow slew
1084  public byte ADSchmittInputH; // non-zero if AD pins are Schmitt input
1085  public byte ADDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA
1086  public byte Cbus0H; // Cbus Mux control
1087  public byte Cbus1H; // Cbus Mux control
1088  public byte Cbus2H; // Cbus Mux control
1089  public byte Cbus3H; // Cbus Mux control
1090  public byte Cbus4H; // Cbus Mux control
1091  public byte Cbus5H; // Cbus Mux control
1092  public byte Cbus6H; // Cbus Mux control
1093  public byte Cbus7H; // Cbus Mux control
1094  public byte Cbus8H; // Cbus Mux control
1095  public byte Cbus9H; // Cbus Mux control
1096  public byte IsFifoH; // non-zero if interface is 245 FIFO
1097  public byte IsFifoTarH; // non-zero if interface is 245 FIFO CPU target
1098  public byte IsFastSerH; // non-zero if interface is Fast serial
1099  public byte IsFT1248H; // non-zero if interface is FT1248
1100  public byte FT1248CpolH; // FT1248 clock polarity
1101  public byte FT1248LsbH; // FT1248 data is LSB (1) or MSB (0)
1102  public byte FT1248FlowControlH; // FT1248 flow control enable
1103  public byte IsVCPH; // non-zero if interface is to use VCP drivers
1104  public byte PowerSaveEnableH; // non-zero if using ACBUS7 to save power for self-powered designs
1105  }
1106 
1107  [StructLayout(LayoutKind.Sequential, Pack = 4)]
1108  struct FT_EEPROM_HEADER
1109  {
1110  public UInt32 deviceType; // FTxxxx device type to be programmed
1111  // Device descriptor options
1112  public UInt16 VendorId; // 0x0403
1113  public UInt16 ProductId; // 0x6001
1114  public byte SerNumEnable; // non-zero if serial number to be used
1115  // Config descriptor options
1116  public UInt16 MaxPower; // 0 < MaxPower <= 500
1117  public byte SelfPowered; // 0 = bus powered, 1 = self powered
1118  public byte RemoteWakeup; // 0 = not capable, 1 = capable
1119  // Hardware options
1120  public byte PullDownEnable; // non-zero if pull down in suspend enabled
1121  }
1122 
1123  [StructLayout(LayoutKind.Sequential, Pack = 4)]
1124  struct FT_XSERIES_DATA
1125  {
1126  public FT_EEPROM_HEADER common;
1127 
1128  public byte ACSlowSlew; // non-zero if AC bus pins have slow slew
1129  public byte ACSchmittInput; // non-zero if AC bus pins are Schmitt input
1130  public byte ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1131  public byte ADSlowSlew; // non-zero if AD bus pins have slow slew
1132  public byte ADSchmittInput; // non-zero if AD bus pins are Schmitt input
1133  public byte ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
1134  // CBUS options
1135  public byte Cbus0; // Cbus Mux control
1136  public byte Cbus1; // Cbus Mux control
1137  public byte Cbus2; // Cbus Mux control
1138  public byte Cbus3; // Cbus Mux control
1139  public byte Cbus4; // Cbus Mux control
1140  public byte Cbus5; // Cbus Mux control
1141  public byte Cbus6; // Cbus Mux control
1142  // UART signal options
1143  public byte InvertTXD; // non-zero if invert TXD
1144  public byte InvertRXD; // non-zero if invert RXD
1145  public byte InvertRTS; // non-zero if invert RTS
1146  public byte InvertCTS; // non-zero if invert CTS
1147  public byte InvertDTR; // non-zero if invert DTR
1148  public byte InvertDSR; // non-zero if invert DSR
1149  public byte InvertDCD; // non-zero if invert DCD
1150  public byte InvertRI; // non-zero if invert RI
1151  // Battery Charge Detect options
1152  public byte BCDEnable; // Enable Battery Charger Detection
1153  public byte BCDForceCbusPWREN; // asserts the power enable signal on CBUS when charging port detected
1154  public byte BCDDisableSleep; // forces the device never to go into sleep mode
1155  // I2C options
1156  public UInt16 I2CSlaveAddress; // I2C slave device address
1157  public UInt32 I2CDeviceId; // I2C device ID
1158  public byte I2CDisableSchmitt; // Disable I2C Schmitt trigger
1159  // FT1248 options
1160  public byte FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0)
1161  public byte FT1248Lsb; // FT1248 data is LSB (1) or MSB (0)
1162  public byte FT1248FlowControl; // FT1248 flow control enable
1163  // Hardware options
1164  public byte RS485EchoSuppress; //
1165  public byte PowerSaveEnable; //
1166  // Driver option
1167  public byte DriverType; //
1168  }
1169 
1170  // Base class for EEPROM structures - these elements are common to all devices
1174  public class FT_EEPROM_DATA
1175  {
1176  //private const UInt32 Signature1 = 0x00000000;
1177  //private const UInt32 Signature2 = 0xFFFFFFFF;
1178  //private const UInt32 Version = 0x00000002;
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;
1207  //private bool PnP = true;
1211  public bool SelfPowered = false;
1215  public bool RemoteWakeup = false;
1216  }
1217 
1218  // EEPROM class for FT232B and FT245B
1224  {
1225  //private bool Rev4 = true;
1226  //private bool IsoIn = false;
1227  //private bool IsoOut = false;
1231  public bool PullDownEnable = false;
1235  public bool SerNumEnable = true;
1239  public bool USBVersionEnable = true;
1243  public UInt16 USBVersion = 0x0200;
1244  }
1245 
1246  // EEPROM class for FT2232C, FT2232L and FT2232D
1252  {
1253  //private bool Rev5 = true;
1254  //private bool IsoInA = false;
1255  //private bool IsoInB = false;
1256  //private bool IsoOutA = false;
1257  //private bool IsoOutB = false;
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;
1314  }
1315 
1316  // EEPROM class for FT232R and FT245R
1322  {
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;
1382  public byte Cbus0 = FT_CBUS_OPTIONS.FT_CBUS_SLEEP;
1389  public byte Cbus1 = FT_CBUS_OPTIONS.FT_CBUS_SLEEP;
1396  public byte Cbus2 = FT_CBUS_OPTIONS.FT_CBUS_SLEEP;
1403  public byte Cbus3 = FT_CBUS_OPTIONS.FT_CBUS_SLEEP;
1410  public byte Cbus4 = FT_CBUS_OPTIONS.FT_CBUS_SLEEP;
1414  public bool RIsD2XX = false;
1415  }
1416 
1417  // EEPROM class for FT2232H
1423  {
1427  public bool PullDownEnable = false;
1431  public bool SerNumEnable = true;
1435  public bool ALSlowSlew = false;
1439  public bool ALSchmittInput = false;
1443  public byte ALDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1447  public bool AHSlowSlew = false;
1451  public bool AHSchmittInput = false;
1455  public byte AHDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1459  public bool BLSlowSlew = false;
1463  public bool BLSchmittInput = false;
1467  public byte BLDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1471  public bool BHSlowSlew = false;
1475  public bool BHSchmittInput = false;
1479  public byte BHDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
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;
1516  }
1517 
1518  // EEPROM class for FT4232H
1524  {
1528  public bool PullDownEnable = false;
1532  public bool SerNumEnable = true;
1536  public bool ASlowSlew = false;
1540  public bool ASchmittInput = false;
1544  public byte ADriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1548  public bool BSlowSlew = false;
1552  public bool BSchmittInput = false;
1556  public byte BDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1560  public bool CSlowSlew = false;
1564  public bool CSchmittInput = false;
1568  public byte CDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1572  public bool DSlowSlew = false;
1576  public bool DSchmittInput = false;
1580  public byte DDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
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;
1613  }
1614  // EEPROM class for FT232H
1620  {
1624  public bool PullDownEnable = false;
1628  public bool SerNumEnable = true;
1632  public bool ACSlowSlew = false;
1636  public bool ACSchmittInput = false;
1640  public byte ACDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
1644  public bool ADSlowSlew = false;
1648  public bool ADSchmittInput = false;
1652  public byte ADDriveCurrent = FT_DRIVE_CURRENT.FT_DRIVE_CURRENT_4MA;
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;
1754  }
1755 
1761  {
1765  public bool PullDownEnable = false;
1769  public bool SerNumEnable = true;
1773  public bool USBVersionEnable = true;
1777  public UInt16 USBVersion = 0x0200;
1781  public byte ACSlowSlew;
1785  public byte ACSchmittInput;
1789  public byte ACDriveCurrent;
1793  public byte ADSlowSlew;
1797  public byte ADSchmittInput;
1801  public byte ADDriveCurrent;
1809  public byte Cbus0;
1817  public byte Cbus1;
1825  public byte Cbus2;
1833  public byte Cbus3;
1841  public byte Cbus4;
1849  public byte Cbus5;
1857  public byte Cbus6;
1861  public byte InvertTXD;
1865  public byte InvertRXD;
1869  public byte InvertRTS;
1873  public byte InvertCTS;
1877  public byte InvertDTR;
1881  public byte InvertDSR;
1885  public byte InvertDCD;
1889  public byte InvertRI;
1893  public byte BCDEnable;
1897  public byte BCDForceCbusPWREN;
1901  public byte BCDDisableSleep;
1905  public ushort I2CSlaveAddress;
1909  public UInt32 I2CDeviceId;
1913  public byte I2CDisableSchmitt;
1917  public byte FT1248Cpol;
1921  public byte FT1248Lsb;
1925  public byte FT1248FlowControl;
1929  public byte RS485EchoSuppress;
1933  public byte PowerSaveEnable;
1937  public byte IsVCP;
1938  }
1939 
1940  #endregion
1941 
1942  #region EXCEPTION_HANDLING
1943  [global::System.Serializable]
1947  public class FT_EXCEPTION : Exception
1948  {
1952  public FT_EXCEPTION() { }
1957  public FT_EXCEPTION(string message) : base(message) { }
1963  public FT_EXCEPTION(string message, Exception inner) : base(message, inner) { }
1969  protected FT_EXCEPTION(
1970  System.Runtime.Serialization.SerializationInfo info,
1971  System.Runtime.Serialization.StreamingContext context)
1972  : base(info, context) { }
1973  }
1974  #endregion
1975 
1976  #region FUNCTION_IMPORTS_FTD2XX.DLL
1977  // Handle to our DLL - used with GetProcAddress to load all of our functions
1978  IntPtr hFTD2XXDLL = IntPtr.Zero;
1979  // Declare pointers to each of the functions we are going to use in FT2DXX.DLL
1980  // These are assigned in our constructor and freed in our destructor.
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;
2032  #endregion
2033 
2034  #region METHOD_DEFINITIONS
2035  //**************************************************************************
2036  // GetNumberOfDevices
2037  //**************************************************************************
2038  // Intellisense comments
2044  public FT_STATUS GetNumberOfDevices(ref UInt32 devcount)
2045  {
2046  // Initialise ftStatus to something other than FT_OK
2047  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2048 
2049  // If the DLL hasn't been loaded, just return here
2050  if (hFTD2XXDLL == IntPtr.Zero)
2051  return ftStatus;
2052 
2053  // Check for our required function pointers being set up
2054  if (pFT_CreateDeviceInfoList != IntPtr.Zero)
2055  {
2056  tFT_CreateDeviceInfoList FT_CreateDeviceInfoList = (tFT_CreateDeviceInfoList)Marshal.GetDelegateForFunctionPointer(pFT_CreateDeviceInfoList, typeof(tFT_CreateDeviceInfoList));
2057 
2058  // Call FT_CreateDeviceInfoList
2059  ftStatus = FT_CreateDeviceInfoList(ref devcount);
2060  }
2061  else
2062  {
2063  throw new Exception("Failed to load function FT_CreateDeviceInfoList.");
2064  }
2065  return ftStatus;
2066 
2067  }
2068 
2069 
2070  //**************************************************************************
2071  // GetDeviceList
2072  //**************************************************************************
2073  // Intellisense comments
2081  {
2082  // Initialise ftStatus to something other than FT_OK
2083  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2084  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
2085 
2086  // If the DLL hasn't been loaded, just return here
2087  if (hFTD2XXDLL == IntPtr.Zero)
2088  return ftStatus;
2089 
2090  // Check for our required function pointers being set up
2091  if ((pFT_CreateDeviceInfoList != IntPtr.Zero) & (pFT_GetDeviceInfoDetail != IntPtr.Zero))
2092  {
2093  UInt32 devcount = 0;
2094 
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));
2097 
2098  // Call FT_CreateDeviceInfoList
2099  ftStatus = FT_CreateDeviceInfoList(ref devcount);
2100 
2101  // Allocate the required storage for our list
2102 
2103  byte[] sernum = new byte[16];
2104  byte[] desc = new byte[64];
2105 
2106  if (devcount > 0)
2107  {
2108  // Check the size of the buffer passed in is big enough
2109  if (devicelist.Length < devcount)
2110  {
2111  // Buffer not big enough
2112  ftErrorCondition = FT_ERROR.FT_BUFFER_SIZE;
2113  // Throw exception
2114  ErrorHandler(ftStatus, ftErrorCondition);
2115  }
2116 
2117  // Instantiate the array elements as FT_DEVICE_INFO_NODE
2118  for (UInt32 i = 0; i < devcount; i++)
2119  {
2120  devicelist[i] = new FT_DEVICE_INFO_NODE();
2121  // Call FT_GetDeviceInfoDetail
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);
2123  // Convert byte arrays to strings
2124  devicelist[i].SerialNumber = Encoding.ASCII.GetString(sernum);
2125  devicelist[i].Description = Encoding.ASCII.GetString(desc);
2126  // Trim strings to first occurrence of a null terminator character
2127  devicelist[i].SerialNumber = devicelist[i].SerialNumber.Substring(0, devicelist[i].SerialNumber.IndexOf("\0"));
2128  devicelist[i].Description = devicelist[i].Description.Substring(0, devicelist[i].Description.IndexOf("\0"));
2129  }
2130  }
2131  }
2132  else
2133  {
2134  if (pFT_CreateDeviceInfoList == IntPtr.Zero)
2135  {
2136  throw new Exception("Failed to load function FT_CreateDeviceInfoList.");
2137  }
2138  if (pFT_GetDeviceInfoDetail == IntPtr.Zero)
2139  {
2140  throw new Exception("Failed to load function FT_GetDeviceInfoListDetail.");
2141  }
2142  }
2143  return ftStatus;
2144  }
2145 
2146 
2147  //**************************************************************************
2148  // OpenByIndex
2149  //**************************************************************************
2150  // Intellisense comments
2158  public FT_STATUS OpenByIndex(UInt32 index)
2159  {
2160  // Initialise ftStatus to something other than FT_OK
2161  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2162 
2163  // If the DLL hasn't been loaded, just return here
2164  if (hFTD2XXDLL == IntPtr.Zero)
2165  return ftStatus;
2166 
2167  // Check for our required function pointers being set up
2168  if ((pFT_Open != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2169  {
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));
2174 
2175  // Call FT_Open
2176  ftStatus = FT_Open(index, ref ftHandle);
2177 
2178  // Appears that the handle value can be non-NULL on a fail, so set it explicitly
2179  if (ftStatus != FT_STATUS.FT_OK)
2180  ftHandle = IntPtr.Zero;
2181 
2182  if (ftHandle != IntPtr.Zero)
2183  {
2184  // Initialise port data characteristics
2185  byte WordLength = FT_DATA_BITS.FT_BITS_8;
2186  byte StopBits = FT_STOP_BITS.FT_STOP_BITS_1;
2187  byte Parity = FT_PARITY.FT_PARITY_NONE;
2188  ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2189  // Initialise to no flow control
2190  UInt16 FlowControl = FT_FLOW_CONTROL.FT_FLOW_NONE;
2191  byte Xon = 0x11;
2192  byte Xoff = 0x13;
2193  ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2194  // Initialise Baud rate
2195  UInt32 BaudRate = 9600;
2196  ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2197  }
2198  }
2199  else
2200  {
2201  if (pFT_Open == IntPtr.Zero)
2202  {
2203  throw new Exception("Failed to load function FT_Open.");
2204  }
2205  if (pFT_SetDataCharacteristics == IntPtr.Zero)
2206  {
2207  throw new Exception("Failed to load function FT_SetDataCharacteristics.");
2208  }
2209  if (pFT_SetFlowControl == IntPtr.Zero)
2210  {
2211  throw new Exception("Failed to load function FT_SetFlowControl.");
2212  }
2213  if (pFT_SetBaudRate == IntPtr.Zero)
2214  {
2215  throw new Exception("Failed to load function FT_SetBaudRate.");
2216  }
2217  }
2218 
2219  if (ftStatus == FT_STATUS.FT_OK)
2220  {
2221  SetupEvent();
2222  }
2223 
2224 
2225 
2226  return ftStatus;
2227  }
2228 
2229 
2230  //**************************************************************************
2231  // OpenBySerialNumber
2232  //**************************************************************************
2233  // Intellisense comments
2240  public FT_STATUS OpenBySerialNumber(string serialnumber)
2241  {
2242  // Initialise ftStatus to something other than FT_OK
2243  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2244 
2245  // If the DLL hasn't been loaded, just return here
2246  if (hFTD2XXDLL == IntPtr.Zero)
2247  return ftStatus;
2248 
2249  // Check for our required function pointers being set up
2250  if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2251  {
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));
2256 
2257  // Call FT_OpenEx
2258  ftStatus = FT_OpenEx(serialnumber, FT_OPEN_BY_SERIAL_NUMBER, ref ftHandle);
2259 
2260  // Appears that the handle value can be non-NULL on a fail, so set it explicitly
2261  if (ftStatus != FT_STATUS.FT_OK)
2262  ftHandle = IntPtr.Zero;
2263 
2264  if (ftHandle != IntPtr.Zero)
2265  {
2266  // Initialise port data characteristics
2267  byte WordLength = FT_DATA_BITS.FT_BITS_8;
2268  byte StopBits = FT_STOP_BITS.FT_STOP_BITS_1;
2269  byte Parity = FT_PARITY.FT_PARITY_NONE;
2270  ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2271  // Initialise to no flow control
2272  UInt16 FlowControl = FT_FLOW_CONTROL.FT_FLOW_NONE;
2273  byte Xon = 0x11;
2274  byte Xoff = 0x13;
2275  ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2276  // Initialise Baud rate
2277  UInt32 BaudRate = 9600;
2278  ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2279  }
2280  }
2281  else
2282  {
2283  if (pFT_OpenEx == IntPtr.Zero)
2284  {
2285  throw new Exception("Failed to load function FT_OpenEx.");
2286  }
2287  if (pFT_SetDataCharacteristics == IntPtr.Zero)
2288  {
2289  throw new Exception("Failed to load function FT_SetDataCharacteristics.");
2290  }
2291  if (pFT_SetFlowControl == IntPtr.Zero)
2292  {
2293  throw new Exception("Failed to load function FT_SetFlowControl.");
2294  }
2295  if (pFT_SetBaudRate == IntPtr.Zero)
2296  {
2297  throw new Exception("Failed to load function FT_SetBaudRate.");
2298  }
2299  }
2300 
2301  if (ftStatus == FT_STATUS.FT_OK)
2302  {
2303  SetupEvent();
2304  }
2305 
2306 
2307  return ftStatus;
2308  }
2309 
2310 
2311  //**************************************************************************
2312  // OpenByDescription
2313  //**************************************************************************
2314  // Intellisense comments
2321  public FT_STATUS OpenByDescription(string description)
2322  {
2323  // Initialise ftStatus to something other than FT_OK
2324  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2325 
2326  // If the DLL hasn't been loaded, just return here
2327  if (hFTD2XXDLL == IntPtr.Zero)
2328  return ftStatus;
2329 
2330  // Check for our required function pointers being set up
2331  if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2332  {
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));
2337 
2338  // Call FT_OpenEx
2339  ftStatus = FT_OpenEx(description, FT_OPEN_BY_DESCRIPTION, ref ftHandle);
2340 
2341  // Appears that the handle value can be non-NULL on a fail, so set it explicitly
2342  if (ftStatus != FT_STATUS.FT_OK)
2343  ftHandle = IntPtr.Zero;
2344 
2345  if (ftHandle != IntPtr.Zero)
2346  {
2347  // Initialise port data characteristics
2348  byte WordLength = FT_DATA_BITS.FT_BITS_8;
2349  byte StopBits = FT_STOP_BITS.FT_STOP_BITS_1;
2350  byte Parity = FT_PARITY.FT_PARITY_NONE;
2351  ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2352  // Initialise to no flow control
2353  UInt16 FlowControl = FT_FLOW_CONTROL.FT_FLOW_NONE;
2354  byte Xon = 0x11;
2355  byte Xoff = 0x13;
2356  ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2357  // Initialise Baud rate
2358  UInt32 BaudRate = 9600;
2359  ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2360  }
2361  }
2362  else
2363  {
2364  if (pFT_OpenEx == IntPtr.Zero)
2365  {
2366  throw new Exception("Failed to load function FT_OpenEx.");
2367  }
2368  if (pFT_SetDataCharacteristics == IntPtr.Zero)
2369  {
2370  throw new Exception("Failed to load function FT_SetDataCharacteristics.");
2371  }
2372  if (pFT_SetFlowControl == IntPtr.Zero)
2373  {
2374  throw new Exception("Failed to load function FT_SetFlowControl.");
2375  }
2376  if (pFT_SetBaudRate == IntPtr.Zero)
2377  {
2378  throw new Exception("Failed to load function FT_SetBaudRate.");
2379  }
2380  }
2381 
2382  if (ftStatus == FT_STATUS.FT_OK)
2383  {
2384  SetupEvent();
2385  }
2386  return ftStatus;
2387  }
2388 
2389 
2390  //**************************************************************************
2391  // OpenByLocation
2392  //**************************************************************************
2393  // Intellisense comments
2400  public FT_STATUS OpenByLocation(UInt32 location)
2401  {
2402  // Initialise ftStatus to something other than FT_OK
2403  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2405  // If the DLL hasn't been loaded, just return here
2406  if (hFTD2XXDLL == IntPtr.Zero)
2407  return ftStatus;
2408 
2409  // Check for our required function pointers being set up
2410  if ((pFT_OpenEx != IntPtr.Zero) & (pFT_SetDataCharacteristics != IntPtr.Zero) & (pFT_SetFlowControl != IntPtr.Zero) & (pFT_SetBaudRate != IntPtr.Zero))
2411  {
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));
2416 
2417  // Call FT_OpenEx
2418  ftStatus = FT_OpenEx(location, FT_OPEN_BY_LOCATION, ref ftHandle);
2419 
2420  // Appears that the handle value can be non-NULL on a fail, so set it explicitly
2421  if (ftStatus != FT_STATUS.FT_OK)
2422  ftHandle = IntPtr.Zero;
2423 
2424  if (ftHandle != IntPtr.Zero)
2425  {
2426  // Initialise port data characteristics
2427  byte WordLength = FT_DATA_BITS.FT_BITS_8;
2428  byte StopBits = FT_STOP_BITS.FT_STOP_BITS_1;
2429  byte Parity = FT_PARITY.FT_PARITY_NONE;
2430  ftStatus = FT_SetDataCharacteristics(ftHandle, WordLength, StopBits, Parity);
2431  // Initialise to no flow control
2432  UInt16 FlowControl = FT_FLOW_CONTROL.FT_FLOW_NONE;
2433  byte Xon = 0x11;
2434  byte Xoff = 0x13;
2435  ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
2436  // Initialise Baud rate
2437  UInt32 BaudRate = 9600;
2438  ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
2439  }
2440  }
2441  else
2442  {
2443  if (pFT_OpenEx == IntPtr.Zero)
2444  {
2445  throw new Exception("Failed to load function FT_OpenEx.");
2446  }
2447  if (pFT_SetDataCharacteristics == IntPtr.Zero)
2448  {
2449  throw new Exception("Failed to load function FT_SetDataCharacteristics.");
2450  }
2451  if (pFT_SetFlowControl == IntPtr.Zero)
2452  {
2453  throw new Exception("Failed to load function FT_SetFlowControl.");
2454  }
2455  if (pFT_SetBaudRate == IntPtr.Zero)
2456  {
2457  throw new Exception("Failed to load function FT_SetBaudRate.");
2458  }
2459  }
2460 
2461  if (ftStatus == FT_STATUS.FT_OK)
2462  {
2463  SetupEvent();
2464  }
2465 
2466 
2467  return ftStatus;
2468  }
2469 
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);
2474 
2475  dataReceivedHandler = new BackgroundWorker();
2476  dataReceivedHandler.DoWork += ReadData;
2477  if (!dataReceivedHandler.IsBusy)
2478  {
2479  dataReceivedHandler.RunWorkerAsync();
2480  }
2481 
2482  }
2483 
2487  public event EventHandler<EventArgs> CharReceived;
2491  private void OnCharReceived()
2492  {
2493  if (CharReceived != null)
2494  {
2495  CharReceived(this, new EventArgs());
2496  }
2497  }
2498 
2499 
2500  //**************************************************************************
2501  // Close
2502  //**************************************************************************
2503  // Intellisense comments
2508  public FT_STATUS Close()
2509  {
2510  // Initialise ftStatus to something other than FT_OK
2511  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2513  // If the DLL hasn't been loaded, just return here
2514  if (hFTD2XXDLL == IntPtr.Zero)
2515  return ftStatus;
2516 
2517  // Check for our required function pointers being set up
2518  if (pFT_Close != IntPtr.Zero)
2519  {
2520  tFT_Close FT_Close = (tFT_Close)Marshal.GetDelegateForFunctionPointer(pFT_Close, typeof(tFT_Close));
2521 
2522  // Call FT_Close
2523  ftStatus = FT_Close(ftHandle);
2524 
2525  if (ftStatus == FT_STATUS.FT_OK)
2526  {
2527  ftHandle = IntPtr.Zero;
2528  }
2529  }
2530  else
2531  {
2532  if (pFT_Close == IntPtr.Zero)
2533  {
2534  throw new Exception("Failed to load function FT_Close.");
2535  }
2536  }
2537  return ftStatus;
2538  }
2539 
2540 
2541  //**************************************************************************
2542  // Read
2543  //**************************************************************************
2544  // Intellisense comments
2552  public FT_STATUS Read(byte[] dataBuffer, UInt32 numBytesToRead, ref UInt32 numBytesRead)
2553  {
2554  // Initialise ftStatus to something other than FT_OK
2555  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2557  // If the DLL hasn't been loaded, just return here
2558  if (hFTD2XXDLL == IntPtr.Zero)
2559  return ftStatus;
2560 
2561  // Check for our required function pointers being set up
2562  if (pFT_Read != IntPtr.Zero)
2563  {
2564 
2565  tFT_Read FT_Read = (tFT_Read)Marshal.GetDelegateForFunctionPointer(pFT_Read, typeof(tFT_Read));
2566 
2567  // If the buffer is not big enough to receive the amount of data requested, adjust the number of bytes to read
2568  if (dataBuffer.Length < numBytesToRead)
2569  {
2570  numBytesToRead = (uint)dataBuffer.Length;
2571  }
2572 
2573  if (ftHandle != IntPtr.Zero)
2574  {
2575  // Call FT_Read
2576  ftStatus = FT_Read(ftHandle, dataBuffer, numBytesToRead, ref numBytesRead);
2577  }
2578  }
2579  else
2580  {
2581  if (pFT_Read == IntPtr.Zero)
2582  {
2583  throw new Exception("Failed to load function FT_Read.");
2584  }
2585  }
2586  return ftStatus;
2587  }
2588 
2589  // Intellisense comments
2597  public FT_STATUS Read(out string dataBuffer, UInt32 numBytesToRead, ref UInt32 numBytesRead)
2598  {
2599  // Initialise ftStatus to something other than FT_OK
2600  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2602  // As dataBuffer is an OUT parameter, needs to be assigned before returning
2603  dataBuffer = string.Empty;
2604 
2605  // If the DLL hasn't been loaded, just return here
2606  if (hFTD2XXDLL == IntPtr.Zero)
2607  return ftStatus;
2608 
2609  // Check for our required function pointers being set up
2610  if (pFT_Read != IntPtr.Zero)
2611  {
2612  tFT_Read FT_Read = (tFT_Read)Marshal.GetDelegateForFunctionPointer(pFT_Read, typeof(tFT_Read));
2613 
2614  byte[] byteDataBuffer = new byte[numBytesToRead];
2615 
2616  if (ftHandle != IntPtr.Zero)
2617  {
2618  // Call FT_Read
2619  ftStatus = FT_Read(ftHandle, byteDataBuffer, numBytesToRead, ref numBytesRead);
2620 
2621  // Convert ASCII byte array back to Unicode string for passing back
2622  dataBuffer = Encoding.ASCII.GetString(byteDataBuffer);
2623  // Trim buffer to actual bytes read
2624  dataBuffer = dataBuffer.Substring(0, (int)numBytesRead);
2625  }
2626  }
2627  else
2628  {
2629  if (pFT_Read == IntPtr.Zero)
2630  {
2631  throw new Exception("Failed to load function FT_Read.");
2632  }
2633  }
2634  return ftStatus;
2635  }
2636 
2637  //**************************************************************************
2638  // Write
2639  //**************************************************************************
2640  // Intellisense comments
2648  public FT_STATUS Write(byte[] dataBuffer, Int32 numBytesToWrite, ref UInt32 numBytesWritten)
2649  {
2650  // Initialise ftStatus to something other than FT_OK
2651  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2653  // If the DLL hasn't been loaded, just return here
2654  if (hFTD2XXDLL == IntPtr.Zero)
2655  return ftStatus;
2656 
2657  // Check for our required function pointers being set up
2658  if (pFT_Write != IntPtr.Zero)
2659  {
2660  tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2661 
2662  if (ftHandle != IntPtr.Zero)
2663  {
2664  // Call FT_Write
2665  ftStatus = FT_Write(ftHandle, dataBuffer, (UInt32)numBytesToWrite, ref numBytesWritten);
2666  }
2667  }
2668  else
2669  {
2670  if (pFT_Write == IntPtr.Zero)
2671  {
2672  throw new Exception("Failed to load function FT_Write.");
2673  }
2674  }
2675  return ftStatus;
2676  }
2677 
2678  // Intellisense comments
2686  public FT_STATUS Write(byte[] dataBuffer, UInt32 numBytesToWrite, ref UInt32 numBytesWritten)
2687  {
2688  // Initialise ftStatus to something other than FT_OK
2689  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2691  // If the DLL hasn't been loaded, just return here
2692  if (hFTD2XXDLL == IntPtr.Zero)
2693  return ftStatus;
2694 
2695  // Check for our required function pointers being set up
2696  if (pFT_Write != IntPtr.Zero)
2697  {
2698  tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2699 
2700  if (ftHandle != IntPtr.Zero)
2701  {
2702  // Call FT_Write
2703  ftStatus = FT_Write(ftHandle, dataBuffer, numBytesToWrite, ref numBytesWritten);
2704  }
2705  }
2706  else
2707  {
2708  if (pFT_Write == IntPtr.Zero)
2709  {
2710  throw new Exception("Failed to load function FT_Write.");
2711  }
2712  }
2713  return ftStatus;
2714  }
2715 
2716  // Intellisense comments
2724  public FT_STATUS Write(string dataBuffer, Int32 numBytesToWrite, ref UInt32 numBytesWritten)
2725  {
2726  // Initialise ftStatus to something other than FT_OK
2727  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2729  // If the DLL hasn't been loaded, just return here
2730  if (hFTD2XXDLL == IntPtr.Zero)
2731  return ftStatus;
2732 
2733  // Check for our required function pointers being set up
2734  if (pFT_Write != IntPtr.Zero)
2735  {
2736  tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2737 
2738  // Convert Unicode string to ASCII byte array
2739  byte[] byteDataBuffer = Encoding.ASCII.GetBytes(dataBuffer);
2740 
2741  if (ftHandle != IntPtr.Zero)
2742  {
2743  // Call FT_Write
2744  ftStatus = FT_Write(ftHandle, byteDataBuffer, (UInt32)numBytesToWrite, ref numBytesWritten);
2745  }
2746  }
2747  else
2748  {
2749  if (pFT_Write == IntPtr.Zero)
2750  {
2751  throw new Exception("Failed to load function FT_Write.");
2752  }
2753  }
2754  return ftStatus;
2755  }
2756 
2757  // Intellisense comments
2765  public FT_STATUS Write(string dataBuffer, UInt32 numBytesToWrite, ref UInt32 numBytesWritten)
2766  {
2767  // Initialise ftStatus to something other than FT_OK
2768  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2770  // If the DLL hasn't been loaded, just return here
2771  if (hFTD2XXDLL == IntPtr.Zero)
2772  return ftStatus;
2773 
2774  // Check for our required function pointers being set up
2775  if (pFT_Write != IntPtr.Zero)
2776  {
2777  tFT_Write FT_Write = (tFT_Write)Marshal.GetDelegateForFunctionPointer(pFT_Write, typeof(tFT_Write));
2778 
2779  // Convert Unicode string to ASCII byte array
2780  byte[] byteDataBuffer = Encoding.ASCII.GetBytes(dataBuffer);
2781 
2782  if (ftHandle != IntPtr.Zero)
2783  {
2784  // Call FT_Write
2785  ftStatus = FT_Write(ftHandle, byteDataBuffer, numBytesToWrite, ref numBytesWritten);
2786  }
2787  }
2788  else
2789  {
2790  if (pFT_Write == IntPtr.Zero)
2791  {
2792  throw new Exception("Failed to load function FT_Write.");
2793  }
2794  }
2795  return ftStatus;
2796  }
2797 
2798  //**************************************************************************
2799  // ResetDevice
2800  //**************************************************************************
2801  // Intellisense comments
2806  public FT_STATUS ResetDevice()
2807  {
2808  // Initialise ftStatus to something other than FT_OK
2809  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2811  // If the DLL hasn't been loaded, just return here
2812  if (hFTD2XXDLL == IntPtr.Zero)
2813  return ftStatus;
2814 
2815  // Check for our required function pointers being set up
2816  if (pFT_ResetDevice != IntPtr.Zero)
2817  {
2818  tFT_ResetDevice FT_ResetDevice = (tFT_ResetDevice)Marshal.GetDelegateForFunctionPointer(pFT_ResetDevice, typeof(tFT_ResetDevice));
2819 
2820  if (ftHandle != IntPtr.Zero)
2821  {
2822  // Call FT_ResetDevice
2823  ftStatus = FT_ResetDevice(ftHandle);
2824  }
2825  }
2826  else
2827  {
2828  if (pFT_ResetDevice == IntPtr.Zero)
2829  {
2830  throw new Exception("Failed to load function FT_ResetDevice.");
2831  }
2832  }
2833  return ftStatus;
2834  }
2835 
2836  //**************************************************************************
2837  // Purge
2838  //**************************************************************************
2839  // Intellisense comments
2845  public FT_STATUS Purge(UInt32 purgemask)
2846  {
2847  // Initialise ftStatus to something other than FT_OK
2848  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2850  // If the DLL hasn't been loaded, just return here
2851  if (hFTD2XXDLL == IntPtr.Zero)
2852  return ftStatus;
2853 
2854  // Check for our required function pointers being set up
2855  if (pFT_Purge != IntPtr.Zero)
2856  {
2857  tFT_Purge FT_Purge = (tFT_Purge)Marshal.GetDelegateForFunctionPointer(pFT_Purge, typeof(tFT_Purge));
2858 
2859  if (ftHandle != IntPtr.Zero)
2860  {
2861  // Call FT_Purge
2862  ftStatus = FT_Purge(ftHandle, purgemask);
2863  }
2864  }
2865  else
2866  {
2867  if (pFT_Purge == IntPtr.Zero)
2868  {
2869  throw new Exception("Failed to load function FT_Purge.");
2870  }
2871  }
2872  return ftStatus;
2873  }
2874 
2875  //**************************************************************************
2876  // SetEventNotification
2877  //**************************************************************************
2878  // Intellisense comments
2886  private FT_STATUS SetEventNotification(UInt32 eventmask, EventWaitHandle eventhandle)
2887  {
2888  // Initialise ftStatus to something other than FT_OK
2889  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2890 
2891  // If the DLL hasn't been loaded, just return here
2892  if (hFTD2XXDLL == IntPtr.Zero)
2893  return ftStatus;
2894 
2895  // Check for our required function pointers being set up
2896  if (pFT_SetEventNotification != IntPtr.Zero)
2897  {
2898  tFT_SetEventNotification FT_SetEventNotification = (tFT_SetEventNotification)Marshal.GetDelegateForFunctionPointer(pFT_SetEventNotification, typeof(tFT_SetEventNotification));
2899 
2900  if (ftHandle != IntPtr.Zero)
2901  {
2902  // Call FT_SetSetEventNotification
2903  ftStatus = FT_SetEventNotification(ftHandle, eventmask, eventhandle.SafeWaitHandle);
2904  }
2905  }
2906  else
2907  {
2908  if (pFT_SetEventNotification == IntPtr.Zero)
2909  {
2910  throw new Exception("Failed to load function FT_SetEventNotification.");
2911  }
2912  }
2913  return ftStatus;
2914  }
2915 
2916  //**************************************************************************
2917  // StopInTask
2918  //**************************************************************************
2919  // Intellisense comments
2924  public FT_STATUS StopInTask()
2925  {
2926  // Initialise ftStatus to something other than FT_OK
2927  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2928 
2929  // If the DLL hasn't been loaded, just return here
2930  if (hFTD2XXDLL == IntPtr.Zero)
2931  return ftStatus;
2932 
2933  // Check for our required function pointers being set up
2934  if (pFT_StopInTask != IntPtr.Zero)
2935  {
2936  tFT_StopInTask FT_StopInTask = (tFT_StopInTask)Marshal.GetDelegateForFunctionPointer(pFT_StopInTask, typeof(tFT_StopInTask));
2937 
2938  if (ftHandle != IntPtr.Zero)
2939  {
2940  // Call FT_StopInTask
2941  ftStatus = FT_StopInTask(ftHandle);
2942  }
2943  }
2944  else
2945  {
2946  if (pFT_StopInTask == IntPtr.Zero)
2947  {
2948  throw new Exception("Failed to load function FT_StopInTask.");
2949  }
2950  }
2951  return ftStatus;
2952  }
2953 
2954  //**************************************************************************
2955  // RestartInTask
2956  //**************************************************************************
2957  // Intellisense comments
2962  public FT_STATUS RestartInTask()
2963  {
2964  // Initialise ftStatus to something other than FT_OK
2965  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
2966 
2967  // If the DLL hasn't been loaded, just return here
2968  if (hFTD2XXDLL == IntPtr.Zero)
2969  return ftStatus;
2970 
2971  // Check for our required function pointers being set up
2972  if (pFT_RestartInTask != IntPtr.Zero)
2973  {
2974  tFT_RestartInTask FT_RestartInTask = (tFT_RestartInTask)Marshal.GetDelegateForFunctionPointer(pFT_RestartInTask, typeof(tFT_RestartInTask));
2975 
2976  if (ftHandle != IntPtr.Zero)
2977  {
2978  // Call FT_RestartInTask
2979  ftStatus = FT_RestartInTask(ftHandle);
2980  }
2981  }
2982  else
2983  {
2984  if (pFT_RestartInTask == IntPtr.Zero)
2985  {
2986  throw new Exception("Failed to load function FT_RestartInTask.");
2987  }
2988  }
2989  return ftStatus;
2990  }
2991 
2992  //**************************************************************************
2993  // ResetPort
2994  //**************************************************************************
2995  // Intellisense comments
3000  public FT_STATUS ResetPort()
3001  {
3002  // Initialise ftStatus to something other than FT_OK
3003  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3004 
3005  // If the DLL hasn't been loaded, just return here
3006  if (hFTD2XXDLL == IntPtr.Zero)
3007  return ftStatus;
3008 
3009  // Check for our required function pointers being set up
3010  if (pFT_ResetPort != IntPtr.Zero)
3011  {
3012  tFT_ResetPort FT_ResetPort = (tFT_ResetPort)Marshal.GetDelegateForFunctionPointer(pFT_ResetPort, typeof(tFT_ResetPort));
3013 
3014  if (ftHandle != IntPtr.Zero)
3015  {
3016  // Call FT_ResetPort
3017  ftStatus = FT_ResetPort(ftHandle);
3018  }
3019  }
3020  else
3021  {
3022  if (pFT_ResetPort == IntPtr.Zero)
3023  {
3024  throw new Exception("Failed to load function FT_ResetPort.");
3025  }
3026  }
3027  return ftStatus;
3028  }
3029 
3030  //**************************************************************************
3031  // CyclePort
3032  //**************************************************************************
3033  // Intellisense comments
3039  public FT_STATUS CyclePort()
3040  {
3041  // Initialise ftStatus to something other than FT_OK
3042  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3043 
3044  // If the DLL hasn't been loaded, just return here
3045  if (hFTD2XXDLL == IntPtr.Zero)
3046  return ftStatus;
3047 
3048  // Check for our required function pointers being set up
3049  if ((pFT_CyclePort != IntPtr.Zero) & (pFT_Close != IntPtr.Zero))
3050  {
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));
3053 
3054  if (ftHandle != IntPtr.Zero)
3055  {
3056  // Call FT_CyclePort
3057  ftStatus = FT_CyclePort(ftHandle);
3058  if (ftStatus == FT_STATUS.FT_OK)
3059  {
3060  // If successful, call FT_Close
3061  ftStatus = FT_Close(ftHandle);
3062  if (ftStatus == FT_STATUS.FT_OK)
3063  {
3064  ftHandle = IntPtr.Zero;
3065  }
3066  }
3067  }
3068  }
3069  else
3070  {
3071  if (pFT_CyclePort == IntPtr.Zero)
3072  {
3073  throw new Exception("Failed to load function FT_CyclePort.");
3074  }
3075  if (pFT_Close == IntPtr.Zero)
3076  {
3077  throw new Exception("Failed to load function FT_Close.");
3078  }
3079  }
3080  return ftStatus;
3081  }
3082 
3083  //**************************************************************************
3084  // Rescan
3085  //**************************************************************************
3086  // Intellisense comments
3091  public FT_STATUS Rescan()
3092  {
3093  // Initialise ftStatus to something other than FT_OK
3094  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3095 
3096  // If the DLL hasn't been loaded, just return here
3097  if (hFTD2XXDLL == IntPtr.Zero)
3098  return ftStatus;
3099 
3100  // Check for our required function pointers being set up
3101  if (pFT_Rescan != IntPtr.Zero)
3102  {
3103  tFT_Rescan FT_Rescan = (tFT_Rescan)Marshal.GetDelegateForFunctionPointer(pFT_Rescan, typeof(tFT_Rescan));
3104 
3105  // Call FT_Rescan
3106  ftStatus = FT_Rescan();
3107  }
3108  else
3109  {
3110  if (pFT_Rescan == IntPtr.Zero)
3111  {
3112  throw new Exception("Failed to load function FT_Rescan.");
3113  }
3114  }
3115  return ftStatus;
3116  }
3117 
3118  //**************************************************************************
3119  // Reload
3120  //**************************************************************************
3121  // Intellisense comments
3129  public FT_STATUS Reload(UInt16 VendorID, UInt16 ProductID)
3130  {
3131  // Initialise ftStatus to something other than FT_OK
3132  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3133 
3134  // If the DLL hasn't been loaded, just return here
3135  if (hFTD2XXDLL == IntPtr.Zero)
3136  return ftStatus;
3137 
3138  // Check for our required function pointers being set up
3139  if (pFT_Reload != IntPtr.Zero)
3140  {
3141  tFT_Reload FT_Reload = (tFT_Reload)Marshal.GetDelegateForFunctionPointer(pFT_Reload, typeof(tFT_Reload));
3142 
3143  // Call FT_Reload
3144  ftStatus = FT_Reload(VendorID, ProductID);
3145  }
3146  else
3147  {
3148  if (pFT_Reload == IntPtr.Zero)
3149  {
3150  throw new Exception("Failed to load function FT_Reload.");
3151  }
3152  }
3153  return ftStatus;
3154  }
3155 
3156  //**************************************************************************
3157  // SetBitMode
3158  //**************************************************************************
3159  // Intellisense comments
3174  public FT_STATUS SetBitMode(byte Mask, byte BitMode)
3175  {
3176  // Initialise ftStatus to something other than FT_OK
3177  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3178  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3179 
3180  // If the DLL hasn't been loaded, just return here
3181  if (hFTD2XXDLL == IntPtr.Zero)
3182  return ftStatus;
3183 
3184  // Check for our required function pointers being set up
3185  if (pFT_SetBitMode != IntPtr.Zero)
3186  {
3187  tFT_SetBitMode FT_SetBitMode = (tFT_SetBitMode)Marshal.GetDelegateForFunctionPointer(pFT_SetBitMode, typeof(tFT_SetBitMode));
3188 
3189  if (ftHandle != IntPtr.Zero)
3190  {
3191 
3192  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3193  // Set Bit Mode does not apply to FT8U232AM, FT8U245AM or FT8U100AX devices
3194  GetDeviceType(ref DeviceType);
3195  if (DeviceType == FT_DEVICE.FT_DEVICE_AM)
3196  {
3197  // Throw an exception
3198  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3199  ErrorHandler(ftStatus, ftErrorCondition);
3200  }
3201  else if (DeviceType == FT_DEVICE.FT_DEVICE_100AX)
3202  {
3203  // Throw an exception
3204  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3205  ErrorHandler(ftStatus, ftErrorCondition);
3206  }
3207  else if ((DeviceType == FT_DEVICE.FT_DEVICE_BM) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3208  {
3209  if ((BitMode & (FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG)) == 0)
3210  {
3211  // Throw an exception
3212  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3213  ErrorHandler(ftStatus, ftErrorCondition);
3214  }
3215  }
3216  else if ((DeviceType == FT_DEVICE.FT_DEVICE_2232) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3217  {
3219  {
3220  // Throw an exception
3221  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3222  ErrorHandler(ftStatus, ftErrorCondition);
3223  }
3224  if ((BitMode == FT_BIT_MODES.FT_BIT_MODE_MPSSE) & (InterfaceIdentifier != "A"))
3225  {
3226  // MPSSE mode is only available on channel A
3227  // Throw an exception
3228  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3229  ErrorHandler(ftStatus, ftErrorCondition);
3230  }
3231  }
3232  else if ((DeviceType == FT_DEVICE.FT_DEVICE_232R) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3233  {
3235  {
3236  // Throw an exception
3237  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3238  ErrorHandler(ftStatus, ftErrorCondition);
3239  }
3240  }
3241  else if ((DeviceType == FT_DEVICE.FT_DEVICE_2232H) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3242  {
3244  {
3245  // Throw an exception
3246  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3247  ErrorHandler(ftStatus, ftErrorCondition);
3248  }
3249  if (((BitMode == FT_BIT_MODES.FT_BIT_MODE_MCU_HOST) | (BitMode == FT_BIT_MODES.FT_BIT_MODE_SYNC_FIFO)) & (InterfaceIdentifier != "A"))
3250  {
3251  // MCU Host Emulation and Single channel synchronous 245 FIFO mode is only available on channel A
3252  // Throw an exception
3253  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3254  ErrorHandler(ftStatus, ftErrorCondition);
3255  }
3256  }
3257  else if ((DeviceType == FT_DEVICE.FT_DEVICE_4232H) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3258  {
3260  {
3261  // Throw an exception
3262  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3263  ErrorHandler(ftStatus, ftErrorCondition);
3264  }
3265  if ((BitMode == FT_BIT_MODES.FT_BIT_MODE_MPSSE) & ((InterfaceIdentifier != "A") & (InterfaceIdentifier != "B")))
3266  {
3267  // MPSSE mode is only available on channel A and B
3268  // Throw an exception
3269  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3270  ErrorHandler(ftStatus, ftErrorCondition);
3271  }
3272  }
3273  else if ((DeviceType == FT_DEVICE.FT_DEVICE_232H) && (BitMode != FT_BIT_MODES.FT_BIT_MODE_RESET))
3274  {
3275  // FT232H supports all current bit modes!
3276  if (BitMode > FT_BIT_MODES.FT_BIT_MODE_SYNC_FIFO)
3277  {
3278  // Throw an exception
3279  ftErrorCondition = FT_ERROR.FT_INVALID_BITMODE;
3280  ErrorHandler(ftStatus, ftErrorCondition);
3281  }
3282  }
3283 
3284  // Requested bit mode is supported
3285  // Note FT_BIT_MODES.FT_BIT_MODE_RESET falls through to here - no bits set so cannot check for AND
3286  // Call FT_SetBitMode
3287  ftStatus = FT_SetBitMode(ftHandle, Mask, BitMode);
3288  }
3289  }
3290  else
3291  {
3292  if (pFT_SetBitMode == IntPtr.Zero)
3293  {
3294  throw new Exception("Failed to load function FT_SetBitMode.");
3295  }
3296  }
3297  return ftStatus;
3298  }
3299 
3300  //**************************************************************************
3301  // GetPinStates
3302  //**************************************************************************
3303  // Intellisense comments
3309  public FT_STATUS GetPinStates(ref byte BitMode)
3310  {
3311  // Initialise ftStatus to something other than FT_OK
3312  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3313 
3314  // If the DLL hasn't been loaded, just return here
3315  if (hFTD2XXDLL == IntPtr.Zero)
3316  return ftStatus;
3317 
3318  // Check for our required function pointers being set up
3319  if (pFT_GetBitMode != IntPtr.Zero)
3320  {
3321  tFT_GetBitMode FT_GetBitMode = (tFT_GetBitMode)Marshal.GetDelegateForFunctionPointer(pFT_GetBitMode, typeof(tFT_GetBitMode));
3322 
3323  if (ftHandle != IntPtr.Zero)
3324  {
3325  // Call FT_GetBitMode
3326  ftStatus = FT_GetBitMode(ftHandle, ref BitMode);
3327  }
3328  }
3329  else
3330  {
3331  if (pFT_GetBitMode == IntPtr.Zero)
3332  {
3333  throw new Exception("Failed to load function FT_GetBitMode.");
3334  }
3335  }
3336  return ftStatus;
3337  }
3338 
3339  //**************************************************************************
3340  // ReadEEPROMLocation
3341  //**************************************************************************
3342  // Intellisense comments
3349  public FT_STATUS ReadEEPROMLocation(UInt32 Address, ref UInt16 EEValue)
3350  {
3351  // Initialise ftStatus to something other than FT_OK
3352  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3353 
3354  // If the DLL hasn't been loaded, just return here
3355  if (hFTD2XXDLL == IntPtr.Zero)
3356  return ftStatus;
3357 
3358  // Check for our required function pointers being set up
3359  if (pFT_ReadEE != IntPtr.Zero)
3360  {
3361  tFT_ReadEE FT_ReadEE = (tFT_ReadEE)Marshal.GetDelegateForFunctionPointer(pFT_ReadEE, typeof(tFT_ReadEE));
3362 
3363  if (ftHandle != IntPtr.Zero)
3364  {
3365  // Call FT_ReadEE
3366  ftStatus = FT_ReadEE(ftHandle, Address, ref EEValue);
3367  }
3368  }
3369  else
3370  {
3371  if (pFT_ReadEE == IntPtr.Zero)
3372  {
3373  throw new Exception("Failed to load function FT_ReadEE.");
3374  }
3375  }
3376  return ftStatus;
3377  }
3378 
3379  //**************************************************************************
3380  // WriteEEPROMLocation
3381  //**************************************************************************
3382  // Intellisense comments
3389  public FT_STATUS WriteEEPROMLocation(UInt32 Address, UInt16 EEValue)
3390  {
3391  // Initialise ftStatus to something other than FT_OK
3392  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3393 
3394  // If the DLL hasn't been loaded, just return here
3395  if (hFTD2XXDLL == IntPtr.Zero)
3396  return ftStatus;
3397 
3398  // Check for our required function pointers being set up
3399  if (pFT_WriteEE != IntPtr.Zero)
3400  {
3401  tFT_WriteEE FT_WriteEE = (tFT_WriteEE)Marshal.GetDelegateForFunctionPointer(pFT_WriteEE, typeof(tFT_WriteEE));
3402 
3403  if (ftHandle != IntPtr.Zero)
3404  {
3405  // Call FT_WriteEE
3406  ftStatus = FT_WriteEE(ftHandle, Address, EEValue);
3407  }
3408  }
3409  else
3410  {
3411  if (pFT_WriteEE == IntPtr.Zero)
3412  {
3413  throw new Exception("Failed to load function FT_WriteEE.");
3414  }
3415  }
3416  return ftStatus;
3417  }
3418 
3419  //**************************************************************************
3420  // EraseEEPROM
3421  //**************************************************************************
3422  // Intellisense comments
3428  public FT_STATUS EraseEEPROM()
3429  {
3430  // Initialise ftStatus to something other than FT_OK
3431  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3432  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3433 
3434  // If the DLL hasn't been loaded, just return here
3435  if (hFTD2XXDLL == IntPtr.Zero)
3436  return ftStatus;
3437 
3438  // Check for our required function pointers being set up
3439  if (pFT_EraseEE != IntPtr.Zero)
3440  {
3441  tFT_EraseEE FT_EraseEE = (tFT_EraseEE)Marshal.GetDelegateForFunctionPointer(pFT_EraseEE, typeof(tFT_EraseEE));
3442 
3443  if (ftHandle != IntPtr.Zero)
3444  {
3445  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3446  // Check that it is not an FT232R or FT245R that we are trying to erase
3447  GetDeviceType(ref DeviceType);
3448  if (DeviceType == FT_DEVICE.FT_DEVICE_232R)
3449  {
3450  // If it is a device with an internal EEPROM, throw an exception
3451  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3452  ErrorHandler(ftStatus, ftErrorCondition);
3453  }
3454 
3455  // Call FT_EraseEE
3456  ftStatus = FT_EraseEE(ftHandle);
3457  }
3458  }
3459  else
3460  {
3461  if (pFT_EraseEE == IntPtr.Zero)
3462  {
3463  throw new Exception("Failed to load function FT_EraseEE.");
3464  }
3465  }
3466  return ftStatus;
3467  }
3468 
3469  //**************************************************************************
3470  // ReadFT232BEEPROM
3471  //**************************************************************************
3472  // Intellisense comments
3479  public FT_STATUS ReadFT232BEEPROM(FT232B_EEPROM_STRUCTURE ee232b)
3480  {
3481  // Initialise ftStatus to something other than FT_OK
3482  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3483  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3484 
3485  // If the DLL hasn't been loaded, just return here
3486  if (hFTD2XXDLL == IntPtr.Zero)
3487  return ftStatus;
3488 
3489  // Check for our required function pointers being set up
3490  if (pFT_EE_Read != IntPtr.Zero)
3491  {
3492  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3493 
3494  if (ftHandle != IntPtr.Zero)
3495  {
3496  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3497  // Check that it is an FT232B or FT245B that we are trying to read
3498  GetDeviceType(ref DeviceType);
3499  if (DeviceType != FT_DEVICE.FT_DEVICE_BM)
3500  {
3501  // If it is not, throw an exception
3502  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3503  ErrorHandler(ftStatus, ftErrorCondition);
3504  }
3505 
3506  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
3507 
3508  // Set up structure headers
3509  eedata.Signature1 = 0x00000000;
3510  eedata.Signature2 = 0xFFFFFFFF;
3511  eedata.Version = 2;
3512 
3513  // Allocate space from unmanaged heap
3514  eedata.Manufacturer = Marshal.AllocHGlobal(32);
3515  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3516  eedata.Description = Marshal.AllocHGlobal(64);
3517  eedata.SerialNumber = Marshal.AllocHGlobal(16);
3518 
3519  // Call FT_EE_Read
3520  ftStatus = FT_EE_Read(ftHandle, eedata);
3521 
3522  // Retrieve string values
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);
3527 
3528  // Free unmanaged buffers
3529  Marshal.FreeHGlobal(eedata.Manufacturer);
3530  Marshal.FreeHGlobal(eedata.ManufacturerID);
3531  Marshal.FreeHGlobal(eedata.Description);
3532  Marshal.FreeHGlobal(eedata.SerialNumber);
3533 
3534  // Map non-string elements to structure to be returned
3535  // Standard elements
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);
3541  // B specific fields
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;
3546  }
3547  }
3548  else
3549  {
3550  if (pFT_EE_Read == IntPtr.Zero)
3551  {
3552  throw new Exception("Failed to load function FT_EE_Read.");
3553  }
3554  }
3555  return ftStatus;
3556  }
3557 
3558  //**************************************************************************
3559  // ReadFT2232EEPROM
3560  //**************************************************************************
3561  // Intellisense comments
3568  public FT_STATUS ReadFT2232EEPROM(FT2232_EEPROM_STRUCTURE ee2232)
3569  {
3570  // Initialise ftStatus to something other than FT_OK
3571  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3572  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3573 
3574  // If the DLL hasn't been loaded, just return here
3575  if (hFTD2XXDLL == IntPtr.Zero)
3576  return ftStatus;
3577 
3578  // Check for our required function pointers being set up
3579  if (pFT_EE_Read != IntPtr.Zero)
3580  {
3581  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3582 
3583  if (ftHandle != IntPtr.Zero)
3584  {
3585  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3586  // Check that it is an FT2232 that we are trying to read
3587  GetDeviceType(ref DeviceType);
3588  if (DeviceType != FT_DEVICE.FT_DEVICE_2232)
3589  {
3590  // If it is not, throw an exception
3591  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3592  ErrorHandler(ftStatus, ftErrorCondition);
3593  }
3594 
3595  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
3596 
3597  // Set up structure headers
3598  eedata.Signature1 = 0x00000000;
3599  eedata.Signature2 = 0xFFFFFFFF;
3600  eedata.Version = 2;
3601 
3602  // Allocate space from unmanaged heap
3603  eedata.Manufacturer = Marshal.AllocHGlobal(32);
3604  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3605  eedata.Description = Marshal.AllocHGlobal(64);
3606  eedata.SerialNumber = Marshal.AllocHGlobal(16);
3607 
3608  // Call FT_EE_Read
3609  ftStatus = FT_EE_Read(ftHandle, eedata);
3610 
3611  // Retrieve string values
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);
3616 
3617  // Free unmanaged buffers
3618  Marshal.FreeHGlobal(eedata.Manufacturer);
3619  Marshal.FreeHGlobal(eedata.ManufacturerID);
3620  Marshal.FreeHGlobal(eedata.Description);
3621  Marshal.FreeHGlobal(eedata.SerialNumber);
3622 
3623  // Map non-string elements to structure to be returned
3624  // Standard elements
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);
3630  // 2232 specific fields
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);
3645  }
3646  }
3647  else
3648  {
3649  if (pFT_EE_Read == IntPtr.Zero)
3650  {
3651  throw new Exception("Failed to load function FT_EE_Read.");
3652  }
3653  }
3654  return ftStatus;
3655  }
3656 
3657  //**************************************************************************
3658  // ReadFT232REEPROM
3659  //**************************************************************************
3660  // Intellisense comments
3667  public FT_STATUS ReadFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
3668  {
3669  // Initialise ftStatus to something other than FT_OK
3670  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3671  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3672 
3673  // If the DLL hasn't been loaded, just return here
3674  if (hFTD2XXDLL == IntPtr.Zero)
3675  return ftStatus;
3676 
3677  // Check for our required function pointers being set up
3678  if (pFT_EE_Read != IntPtr.Zero)
3679  {
3680  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3681 
3682  if (ftHandle != IntPtr.Zero)
3683  {
3684  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3685  // Check that it is an FT232R or FT245R that we are trying to read
3686  GetDeviceType(ref DeviceType);
3687  if (DeviceType != FT_DEVICE.FT_DEVICE_232R)
3688  {
3689  // If it is not, throw an exception
3690  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3691  ErrorHandler(ftStatus, ftErrorCondition);
3692  }
3693 
3694  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
3695 
3696  // Set up structure headers
3697  eedata.Signature1 = 0x00000000;
3698  eedata.Signature2 = 0xFFFFFFFF;
3699  eedata.Version = 2;
3700 
3701  // Allocate space from unmanaged heap
3702  eedata.Manufacturer = Marshal.AllocHGlobal(32);
3703  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3704  eedata.Description = Marshal.AllocHGlobal(64);
3705  eedata.SerialNumber = Marshal.AllocHGlobal(16);
3706 
3707  // Call FT_EE_Read
3708  ftStatus = FT_EE_Read(ftHandle, eedata);
3709 
3710  // Retrieve string values
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);
3715 
3716  // Free unmanaged buffers
3717  Marshal.FreeHGlobal(eedata.Manufacturer);
3718  Marshal.FreeHGlobal(eedata.ManufacturerID);
3719  Marshal.FreeHGlobal(eedata.Description);
3720  Marshal.FreeHGlobal(eedata.SerialNumber);
3721 
3722  // Map non-string elements to structure to be returned
3723  // Standard elements
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);
3729  // 232R specific fields
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);
3749  }
3750  }
3751  else
3752  {
3753  if (pFT_EE_Read == IntPtr.Zero)
3754  {
3755  throw new Exception("Failed to load function FT_EE_Read.");
3756  }
3757  }
3758  return ftStatus;
3759  }
3760 
3761  //**************************************************************************
3762  // ReadFT2232HEEPROM
3763  //**************************************************************************
3764  // Intellisense comments
3771  public FT_STATUS ReadFT2232HEEPROM(FT2232H_EEPROM_STRUCTURE ee2232h)
3772  {
3773  // Initialise ftStatus to something other than FT_OK
3774  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3775  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3776 
3777  // If the DLL hasn't been loaded, just return here
3778  if (hFTD2XXDLL == IntPtr.Zero)
3779  return ftStatus;
3780 
3781  // Check for our required function pointers being set up
3782  if (pFT_EE_Read != IntPtr.Zero)
3783  {
3784  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3785 
3786  if (ftHandle != IntPtr.Zero)
3787  {
3788  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3789  // Check that it is an FT2232H that we are trying to read
3790  GetDeviceType(ref DeviceType);
3791  if (DeviceType != FT_DEVICE.FT_DEVICE_2232H)
3792  {
3793  // If it is not, throw an exception
3794  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3795  ErrorHandler(ftStatus, ftErrorCondition);
3796  }
3797 
3798  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
3799 
3800  // Set up structure headers
3801  eedata.Signature1 = 0x00000000;
3802  eedata.Signature2 = 0xFFFFFFFF;
3803  eedata.Version = 3;
3804 
3805  // Allocate space from unmanaged heap
3806  eedata.Manufacturer = Marshal.AllocHGlobal(32);
3807  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3808  eedata.Description = Marshal.AllocHGlobal(64);
3809  eedata.SerialNumber = Marshal.AllocHGlobal(16);
3810 
3811  // Call FT_EE_Read
3812  ftStatus = FT_EE_Read(ftHandle, eedata);
3813 
3814  // Retrieve string values
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);
3819 
3820  // Free unmanaged buffers
3821  Marshal.FreeHGlobal(eedata.Manufacturer);
3822  Marshal.FreeHGlobal(eedata.ManufacturerID);
3823  Marshal.FreeHGlobal(eedata.Description);
3824  Marshal.FreeHGlobal(eedata.SerialNumber);
3825 
3826  // Map non-string elements to structure to be returned
3827  // Standard elements
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);
3833  // 2232H specific fields
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);
3857  }
3858  }
3859  else
3860  {
3861  if (pFT_EE_Read == IntPtr.Zero)
3862  {
3863  throw new Exception("Failed to load function FT_EE_Read.");
3864  }
3865  }
3866  return ftStatus;
3867  }
3868 
3869  //**************************************************************************
3870  // ReadFT4232HEEPROM
3871  //**************************************************************************
3872  // Intellisense comments
3879  public FT_STATUS ReadFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
3880  {
3881  // Initialise ftStatus to something other than FT_OK
3882  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3883  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3884 
3885  // If the DLL hasn't been loaded, just return here
3886  if (hFTD2XXDLL == IntPtr.Zero)
3887  return ftStatus;
3888 
3889  // Check for our required function pointers being set up
3890  if (pFT_EE_Read != IntPtr.Zero)
3891  {
3892  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
3893 
3894  if (ftHandle != IntPtr.Zero)
3895  {
3896  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
3897  // Check that it is an FT4232H that we are trying to read
3898  GetDeviceType(ref DeviceType);
3899  if (DeviceType != FT_DEVICE.FT_DEVICE_4232H)
3900  {
3901  // If it is not, throw an exception
3902  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
3903  ErrorHandler(ftStatus, ftErrorCondition);
3904  }
3905 
3906  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
3907 
3908  // Set up structure headers
3909  eedata.Signature1 = 0x00000000;
3910  eedata.Signature2 = 0xFFFFFFFF;
3911  eedata.Version = 4;
3912 
3913  // Allocate space from unmanaged heap
3914  eedata.Manufacturer = Marshal.AllocHGlobal(32);
3915  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
3916  eedata.Description = Marshal.AllocHGlobal(64);
3917  eedata.SerialNumber = Marshal.AllocHGlobal(16);
3918 
3919  // Call FT_EE_Read
3920  ftStatus = FT_EE_Read(ftHandle, eedata);
3921 
3922  // Retrieve string values
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);
3927 
3928  // Free unmanaged buffers
3929  Marshal.FreeHGlobal(eedata.Manufacturer);
3930  Marshal.FreeHGlobal(eedata.ManufacturerID);
3931  Marshal.FreeHGlobal(eedata.Description);
3932  Marshal.FreeHGlobal(eedata.SerialNumber);
3933 
3934  // Map non-string elements to structure to be returned
3935  // Standard elements
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);
3941  // 4232H specific fields
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);
3964  }
3965  }
3966  else
3967  {
3968  if (pFT_EE_Read == IntPtr.Zero)
3969  {
3970  throw new Exception("Failed to load function FT_EE_Read.");
3971  }
3972  }
3973  return ftStatus;
3974  }
3975 
3976  //**************************************************************************
3977  // ReadFT232HEEPROM
3978  //**************************************************************************
3979  // Intellisense comments
3986  public FT_STATUS ReadFT232HEEPROM(FT232H_EEPROM_STRUCTURE ee232h)
3987  {
3988  // Initialise ftStatus to something other than FT_OK
3989  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
3990  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
3991 
3992  // If the DLL hasn't been loaded, just return here
3993  if (hFTD2XXDLL == IntPtr.Zero)
3994  return ftStatus;
3995 
3996  // Check for our required function pointers being set up
3997  if (pFT_EE_Read != IntPtr.Zero)
3998  {
3999  tFT_EE_Read FT_EE_Read = (tFT_EE_Read)Marshal.GetDelegateForFunctionPointer(pFT_EE_Read, typeof(tFT_EE_Read));
4000 
4001  if (ftHandle != IntPtr.Zero)
4002  {
4003  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4004  // Check that it is an FT232H that we are trying to read
4005  GetDeviceType(ref DeviceType);
4006  if (DeviceType != FT_DEVICE.FT_DEVICE_232H)
4007  {
4008  // If it is not, throw an exception
4009  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4010  ErrorHandler(ftStatus, ftErrorCondition);
4011  }
4012 
4013  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4014 
4015  // Set up structure headers
4016  eedata.Signature1 = 0x00000000;
4017  eedata.Signature2 = 0xFFFFFFFF;
4018  eedata.Version = 5;
4019 
4020  // Allocate space from unmanaged heap
4021  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4022  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4023  eedata.Description = Marshal.AllocHGlobal(64);
4024  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4025 
4026  // Call FT_EE_Read
4027  ftStatus = FT_EE_Read(ftHandle, eedata);
4028 
4029  // Retrieve string values
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);
4034 
4035  // Free unmanaged buffers
4036  Marshal.FreeHGlobal(eedata.Manufacturer);
4037  Marshal.FreeHGlobal(eedata.ManufacturerID);
4038  Marshal.FreeHGlobal(eedata.Description);
4039  Marshal.FreeHGlobal(eedata.SerialNumber);
4040 
4041  // Map non-string elements to structure to be returned
4042  // Standard elements
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);
4048  // 232H specific fields
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);
4076  }
4077  }
4078  else
4079  {
4080  if (pFT_EE_Read == IntPtr.Zero)
4081  {
4082  throw new Exception("Failed to load function FT_EE_Read.");
4083  }
4084  }
4085  return ftStatus;
4086  }
4087 
4088  //**************************************************************************
4089  // ReadXSeriesEEPROM
4090  //**************************************************************************
4091  // Intellisense comments
4098  public FT_STATUS ReadXSeriesEEPROM(FT_XSERIES_EEPROM_STRUCTURE eeX)
4099  {
4100  // Initialise ftStatus to something other than FT_OK
4101  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4102  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4103 
4104  // If the DLL hasn't been loaded, just return here
4105  if (hFTD2XXDLL == IntPtr.Zero)
4106  return ftStatus;
4107 
4108  // Check for our required function pointers being set up
4109  if (pFT_EEPROM_Read != IntPtr.Zero)
4110  {
4111  tFT_EEPROM_Read FT_EEPROM_Read = (tFT_EEPROM_Read)Marshal.GetDelegateForFunctionPointer(pFT_EEPROM_Read, typeof(tFT_EEPROM_Read));
4112 
4113  if (ftHandle != IntPtr.Zero)
4114  {
4115  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4116  // Check that it is an FT232H that we are trying to read
4117  GetDeviceType(ref DeviceType);
4118  if (DeviceType != FT_DEVICE.FT_DEVICE_X_SERIES)
4119  {
4120  // If it is not, throw an exception
4121  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4122  ErrorHandler(ftStatus, ftErrorCondition);
4123  }
4124 
4125  FT_XSERIES_DATA eeData = new FT_XSERIES_DATA();
4126  FT_EEPROM_HEADER eeHeader = new FT_EEPROM_HEADER();
4127 
4128  byte[] manufacturer = new byte[32];
4129  byte[] manufacturerID = new byte[16];
4130  byte[] description = new byte[64];
4131  byte[] serialNumber = new byte[16];
4132 
4133  eeHeader.deviceType = (uint)FT_DEVICE.FT_DEVICE_X_SERIES;
4134  eeData.common = eeHeader;
4135 
4136  // Calculate the size of our data structure...
4137  int size = Marshal.SizeOf(eeData);
4138 
4139  // Allocate space for our pointer...
4140  IntPtr eeDataMarshal = Marshal.AllocHGlobal(size);
4141  Marshal.StructureToPtr(eeData, eeDataMarshal, false);
4142 
4143  // Call FT_EEPROM_Read
4144  ftStatus = FT_EEPROM_Read(ftHandle, eeDataMarshal, (uint)size, manufacturer, manufacturerID, description, serialNumber);
4145 
4146  if (ftStatus == FT_STATUS.FT_OK)
4147  {
4148  // Get the data back from the pointer...
4149  eeData = (FT_XSERIES_DATA)Marshal.PtrToStructure(eeDataMarshal, typeof(FT_XSERIES_DATA));
4150 
4151  // Retrieve string values
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);
4157  // Map non-string elements to structure to be returned
4158  // Standard elements
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);
4166  // X-Series specific fields
4167  // CBUS
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;
4175  // Drive Options
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;
4182  // BCD
4183  eeX.BCDDisableSleep = eeData.BCDDisableSleep;
4184  eeX.BCDEnable = eeData.BCDEnable;
4185  eeX.BCDForceCbusPWREN = eeData.BCDForceCbusPWREN;
4186  // FT1248
4187  eeX.FT1248Cpol = eeData.FT1248Cpol;
4188  eeX.FT1248FlowControl = eeData.FT1248FlowControl;
4189  eeX.FT1248Lsb = eeData.FT1248Lsb;
4190  // I2C
4191  eeX.I2CDeviceId = eeData.I2CDeviceId;
4192  eeX.I2CDisableSchmitt = eeData.I2CDisableSchmitt;
4193  eeX.I2CSlaveAddress = eeData.I2CSlaveAddress;
4194  // RS232 Signals
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;
4203  // Hardware Options
4204  eeX.PowerSaveEnable = eeData.PowerSaveEnable;
4205  eeX.RS485EchoSuppress = eeData.RS485EchoSuppress;
4206  // Driver Option
4207  eeX.IsVCP = eeData.DriverType;
4208  }
4209  }
4210  }
4211  else
4212  {
4213  if (pFT_EE_Read == IntPtr.Zero)
4214  {
4215  throw new Exception("Failed to load function FT_EE_Read.");
4216  }
4217  }
4218  return ftStatus;
4219  }
4220 
4221  //**************************************************************************
4222  // WriteFT232BEEPROM
4223  //**************************************************************************
4224  // Intellisense comments
4232  public FT_STATUS WriteFT232BEEPROM(FT232B_EEPROM_STRUCTURE ee232b)
4233  {
4234  // Initialise ftStatus to something other than FT_OK
4235  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4236  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4237 
4238  // If the DLL hasn't been loaded, just return here
4239  if (hFTD2XXDLL == IntPtr.Zero)
4240  return ftStatus;
4241 
4242  // Check for our required function pointers being set up
4243  if (pFT_EE_Program != IntPtr.Zero)
4244  {
4245  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4246 
4247  if (ftHandle != IntPtr.Zero)
4248  {
4249  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4250  // Check that it is an FT232B or FT245B that we are trying to write
4251  GetDeviceType(ref DeviceType);
4252  if (DeviceType != FT_DEVICE.FT_DEVICE_BM)
4253  {
4254  // If it is not, throw an exception
4255  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4256  ErrorHandler(ftStatus, ftErrorCondition);
4257  }
4258 
4259  // Check for VID and PID of 0x0000
4260  if ((ee232b.VendorID == 0x0000) | (ee232b.ProductID == 0x0000))
4261  {
4262  // Do not allow users to program the device with VID or PID of 0x0000
4263  return FT_STATUS.FT_INVALID_PARAMETER;
4264  }
4265 
4266  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4267 
4268  // Set up structure headers
4269  eedata.Signature1 = 0x00000000;
4270  eedata.Signature2 = 0xFFFFFFFF;
4271  eedata.Version = 2;
4272 
4273  // Allocate space from unmanaged heap
4274  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4275  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4276  eedata.Description = Marshal.AllocHGlobal(64);
4277  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4278 
4279  // Check lengths of strings to make sure that they are within our limits
4280  // If not, trim them to make them our maximum length
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);
4289 
4290  // Set string values
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);
4295 
4296  // Map non-string elements to structure
4297  // Standard elements
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);
4303  // B specific fields
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;
4309 
4310  // Call FT_EE_Program
4311  ftStatus = FT_EE_Program(ftHandle, eedata);
4312 
4313  // Free unmanaged buffers
4314  Marshal.FreeHGlobal(eedata.Manufacturer);
4315  Marshal.FreeHGlobal(eedata.ManufacturerID);
4316  Marshal.FreeHGlobal(eedata.Description);
4317  Marshal.FreeHGlobal(eedata.SerialNumber);
4318  }
4319  }
4320  else
4321  {
4322  if (pFT_EE_Program == IntPtr.Zero)
4323  {
4324  throw new Exception("Failed to load function FT_EE_Program.");
4325  }
4326  }
4327  return ftStatus;
4328  }
4329 
4330  //**************************************************************************
4331  // WriteFT2232EEPROM
4332  //**************************************************************************
4333  // Intellisense comments
4342  public FT_STATUS WriteFT2232EEPROM(FT2232_EEPROM_STRUCTURE ee2232)
4343  {
4344  // Initialise ftStatus to something other than FT_OK
4345  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4346  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4347 
4348  // If the DLL hasn't been loaded, just return here
4349  if (hFTD2XXDLL == IntPtr.Zero)
4350  return ftStatus;
4351 
4352  // Check for our required function pointers being set up
4353  if (pFT_EE_Program != IntPtr.Zero)
4354  {
4355  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4356 
4357  if (ftHandle != IntPtr.Zero)
4358  {
4359  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4360  // Check that it is an FT2232 that we are trying to write
4361  GetDeviceType(ref DeviceType);
4362  if (DeviceType != FT_DEVICE.FT_DEVICE_2232)
4363  {
4364  // If it is not, throw an exception
4365  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4366  ErrorHandler(ftStatus, ftErrorCondition);
4367  }
4368 
4369  // Check for VID and PID of 0x0000
4370  if ((ee2232.VendorID == 0x0000) | (ee2232.ProductID == 0x0000))
4371  {
4372  // Do not allow users to program the device with VID or PID of 0x0000
4373  return FT_STATUS.FT_INVALID_PARAMETER;
4374  }
4375 
4376  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4377 
4378  // Set up structure headers
4379  eedata.Signature1 = 0x00000000;
4380  eedata.Signature2 = 0xFFFFFFFF;
4381  eedata.Version = 2;
4382 
4383  // Allocate space from unmanaged heap
4384  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4385  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4386  eedata.Description = Marshal.AllocHGlobal(64);
4387  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4388 
4389  // Check lengths of strings to make sure that they are within our limits
4390  // If not, trim them to make them our maximum length
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);
4399 
4400  // Set string values
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);
4405 
4406  // Map non-string elements to structure
4407  // Standard elements
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);
4413  // 2232 specific fields
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);
4429 
4430  // Call FT_EE_Program
4431  ftStatus = FT_EE_Program(ftHandle, eedata);
4432 
4433  // Free unmanaged buffers
4434  Marshal.FreeHGlobal(eedata.Manufacturer);
4435  Marshal.FreeHGlobal(eedata.ManufacturerID);
4436  Marshal.FreeHGlobal(eedata.Description);
4437  Marshal.FreeHGlobal(eedata.SerialNumber);
4438  }
4439  }
4440  else
4441  {
4442  if (pFT_EE_Program == IntPtr.Zero)
4443  {
4444  throw new Exception("Failed to load function FT_EE_Program.");
4445  }
4446  }
4447  return ftStatus;
4448  }
4449 
4450  //**************************************************************************
4451  // WriteFT232REEPROM
4452  //**************************************************************************
4453  // Intellisense comments
4462  public FT_STATUS WriteFT232REEPROM(FT232R_EEPROM_STRUCTURE ee232r)
4463  {
4464  // Initialise ftStatus to something other than FT_OK
4465  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4466  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4467 
4468  // If the DLL hasn't been loaded, just return here
4469  if (hFTD2XXDLL == IntPtr.Zero)
4470  return ftStatus;
4472  // Check for our required function pointers being set up
4473  if (pFT_EE_Program != IntPtr.Zero)
4474  {
4475  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4476 
4477  if (ftHandle != IntPtr.Zero)
4478  {
4479  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4480  // Check that it is an FT232R or FT245R that we are trying to write
4481  GetDeviceType(ref DeviceType);
4482  if (DeviceType != FT_DEVICE.FT_DEVICE_232R)
4483  {
4484  // If it is not, throw an exception
4485  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4486  ErrorHandler(ftStatus, ftErrorCondition);
4487  }
4488 
4489  // Check for VID and PID of 0x0000
4490  if ((ee232r.VendorID == 0x0000) | (ee232r.ProductID == 0x0000))
4491  {
4492  // Do not allow users to program the device with VID or PID of 0x0000
4493  return FT_STATUS.FT_INVALID_PARAMETER;
4494  }
4495 
4496  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4497 
4498  // Set up structure headers
4499  eedata.Signature1 = 0x00000000;
4500  eedata.Signature2 = 0xFFFFFFFF;
4501  eedata.Version = 2;
4502 
4503  // Allocate space from unmanaged heap
4504  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4505  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4506  eedata.Description = Marshal.AllocHGlobal(64);
4507  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4508 
4509  // Check lengths of strings to make sure that they are within our limits
4510  // If not, trim them to make them our maximum length
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);
4519 
4520  // Set string values
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);
4525 
4526  // Map non-string elements to structure
4527  // Standard elements
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);
4533  // 232R specific fields
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);
4538  // Override any endpoint size the user has selected and force 64 bytes
4539  // Some users have been known to wreck devices by setting 0 here...
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);
4557 
4558  // Call FT_EE_Program
4559  ftStatus = FT_EE_Program(ftHandle, eedata);
4560 
4561  // Free unmanaged buffers
4562  Marshal.FreeHGlobal(eedata.Manufacturer);
4563  Marshal.FreeHGlobal(eedata.ManufacturerID);
4564  Marshal.FreeHGlobal(eedata.Description);
4565  Marshal.FreeHGlobal(eedata.SerialNumber);
4566  }
4567  }
4568  else
4569  {
4570  if (pFT_EE_Program == IntPtr.Zero)
4571  {
4572  throw new Exception("Failed to load function FT_EE_Program.");
4573  }
4574  }
4575  return ftStatus;
4576  }
4577 
4578  //**************************************************************************
4579  // WriteFT2232HEEPROM
4580  //**************************************************************************
4581  // Intellisense comments
4590  public FT_STATUS WriteFT2232HEEPROM(FT2232H_EEPROM_STRUCTURE ee2232h)
4591  {
4592  // Initialise ftStatus to something other than FT_OK
4593  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4594  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4595 
4596  // If the DLL hasn't been loaded, just return here
4597  if (hFTD2XXDLL == IntPtr.Zero)
4598  return ftStatus;
4599 
4600  // Check for our required function pointers being set up
4601  if (pFT_EE_Program != IntPtr.Zero)
4602  {
4603  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4604 
4605  if (ftHandle != IntPtr.Zero)
4606  {
4607  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4608  // Check that it is an FT2232H that we are trying to write
4609  GetDeviceType(ref DeviceType);
4610  if (DeviceType != FT_DEVICE.FT_DEVICE_2232H)
4611  {
4612  // If it is not, throw an exception
4613  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4614  ErrorHandler(ftStatus, ftErrorCondition);
4615  }
4616 
4617  // Check for VID and PID of 0x0000
4618  if ((ee2232h.VendorID == 0x0000) | (ee2232h.ProductID == 0x0000))
4619  {
4620  // Do not allow users to program the device with VID or PID of 0x0000
4621  return FT_STATUS.FT_INVALID_PARAMETER;
4622  }
4623 
4624  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4625 
4626  // Set up structure headers
4627  eedata.Signature1 = 0x00000000;
4628  eedata.Signature2 = 0xFFFFFFFF;
4629  eedata.Version = 3;
4630 
4631  // Allocate space from unmanaged heap
4632  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4633  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4634  eedata.Description = Marshal.AllocHGlobal(64);
4635  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4636 
4637  // Check lengths of strings to make sure that they are within our limits
4638  // If not, trim them to make them our maximum length
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);
4647 
4648  // Set string values
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);
4653 
4654  // Map non-string elements to structure
4655  // Standard elements
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);
4661  // 2232H specific fields
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);
4685 
4686  // Call FT_EE_Program
4687  ftStatus = FT_EE_Program(ftHandle, eedata);
4688 
4689  // Free unmanaged buffers
4690  Marshal.FreeHGlobal(eedata.Manufacturer);
4691  Marshal.FreeHGlobal(eedata.ManufacturerID);
4692  Marshal.FreeHGlobal(eedata.Description);
4693  Marshal.FreeHGlobal(eedata.SerialNumber);
4694  }
4695  }
4696  else
4697  {
4698  if (pFT_EE_Program == IntPtr.Zero)
4699  {
4700  throw new Exception("Failed to load function FT_EE_Program.");
4701  }
4702  }
4703  return ftStatus;
4704  }
4705 
4706  //**************************************************************************
4707  // WriteFT4232HEEPROM
4708  //**************************************************************************
4709  // Intellisense comments
4718  public FT_STATUS WriteFT4232HEEPROM(FT4232H_EEPROM_STRUCTURE ee4232h)
4719  {
4720  // Initialise ftStatus to something other than FT_OK
4721  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4722  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4723 
4724  // If the DLL hasn't been loaded, just return here
4725  if (hFTD2XXDLL == IntPtr.Zero)
4726  return ftStatus;
4727 
4728  // Check for our required function pointers being set up
4729  if (pFT_EE_Program != IntPtr.Zero)
4730  {
4731  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4732 
4733  if (ftHandle != IntPtr.Zero)
4734  {
4735  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4736  // Check that it is an FT4232H that we are trying to write
4737  GetDeviceType(ref DeviceType);
4738  if (DeviceType != FT_DEVICE.FT_DEVICE_4232H)
4739  {
4740  // If it is not, throw an exception
4741  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4742  ErrorHandler(ftStatus, ftErrorCondition);
4743  }
4744 
4745  // Check for VID and PID of 0x0000
4746  if ((ee4232h.VendorID == 0x0000) | (ee4232h.ProductID == 0x0000))
4747  {
4748  // Do not allow users to program the device with VID or PID of 0x0000
4749  return FT_STATUS.FT_INVALID_PARAMETER;
4750  }
4751 
4752  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4753 
4754  // Set up structure headers
4755  eedata.Signature1 = 0x00000000;
4756  eedata.Signature2 = 0xFFFFFFFF;
4757  eedata.Version = 4;
4758 
4759  // Allocate space from unmanaged heap
4760  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4761  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4762  eedata.Description = Marshal.AllocHGlobal(64);
4763  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4764 
4765  // Check lengths of strings to make sure that they are within our limits
4766  // If not, trim them to make them our maximum length
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);
4775 
4776  // Set string values
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);
4781 
4782  // Map non-string elements to structure
4783  // Standard elements
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);
4789  // 4232H specific fields
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);
4812 
4813  // Call FT_EE_Program
4814  ftStatus = FT_EE_Program(ftHandle, eedata);
4815 
4816  // Free unmanaged buffers
4817  Marshal.FreeHGlobal(eedata.Manufacturer);
4818  Marshal.FreeHGlobal(eedata.ManufacturerID);
4819  Marshal.FreeHGlobal(eedata.Description);
4820  Marshal.FreeHGlobal(eedata.SerialNumber);
4821  }
4822  }
4823  else
4824  {
4825  if (pFT_EE_Program == IntPtr.Zero)
4826  {
4827  throw new Exception("Failed to load function FT_EE_Program.");
4828  }
4829  }
4830  return ftStatus;
4831  }
4832 
4833  //**************************************************************************
4834  // WriteFT232HEEPROM
4835  //**************************************************************************
4836  // Intellisense comments
4845  public FT_STATUS WriteFT232HEEPROM(FT232H_EEPROM_STRUCTURE ee232h)
4846  {
4847  // Initialise ftStatus to something other than FT_OK
4848  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4849  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4850 
4851  // If the DLL hasn't been loaded, just return here
4852  if (hFTD2XXDLL == IntPtr.Zero)
4853  return ftStatus;
4854 
4855  // Check for our required function pointers being set up
4856  if (pFT_EE_Program != IntPtr.Zero)
4857  {
4858  tFT_EE_Program FT_EE_Program = (tFT_EE_Program)Marshal.GetDelegateForFunctionPointer(pFT_EE_Program, typeof(tFT_EE_Program));
4859 
4860  if (ftHandle != IntPtr.Zero)
4861  {
4862  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4863  // Check that it is an FT232H that we are trying to write
4864  GetDeviceType(ref DeviceType);
4865  if (DeviceType != FT_DEVICE.FT_DEVICE_232H)
4866  {
4867  // If it is not, throw an exception
4868  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
4869  ErrorHandler(ftStatus, ftErrorCondition);
4870  }
4871 
4872  // Check for VID and PID of 0x0000
4873  if ((ee232h.VendorID == 0x0000) | (ee232h.ProductID == 0x0000))
4874  {
4875  // Do not allow users to program the device with VID or PID of 0x0000
4876  return FT_STATUS.FT_INVALID_PARAMETER;
4877  }
4878 
4879  FT_PROGRAM_DATA eedata = new FT_PROGRAM_DATA();
4880 
4881  // Set up structure headers
4882  eedata.Signature1 = 0x00000000;
4883  eedata.Signature2 = 0xFFFFFFFF;
4884  eedata.Version = 5;
4885 
4886  // Allocate space from unmanaged heap
4887  eedata.Manufacturer = Marshal.AllocHGlobal(32);
4888  eedata.ManufacturerID = Marshal.AllocHGlobal(16);
4889  eedata.Description = Marshal.AllocHGlobal(64);
4890  eedata.SerialNumber = Marshal.AllocHGlobal(16);
4891 
4892  // Check lengths of strings to make sure that they are within our limits
4893  // If not, trim them to make them our maximum length
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);
4902 
4903  // Set string values
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);
4908 
4909  // Map non-string elements to structure
4910  // Standard elements
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);
4916  // 232H specific fields
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);
4944 
4945  // Call FT_EE_Program
4946  ftStatus = FT_EE_Program(ftHandle, eedata);
4947 
4948  // Free unmanaged buffers
4949  Marshal.FreeHGlobal(eedata.Manufacturer);
4950  Marshal.FreeHGlobal(eedata.ManufacturerID);
4951  Marshal.FreeHGlobal(eedata.Description);
4952  Marshal.FreeHGlobal(eedata.SerialNumber);
4953  }
4954  }
4955  else
4956  {
4957  if (pFT_EE_Program == IntPtr.Zero)
4958  {
4959  throw new Exception("Failed to load function FT_EE_Program.");
4960  }
4961  }
4962  return ftStatus;
4963  }
4964 
4965  //**************************************************************************
4966  // WriteXSeriesEEPROM
4967  //**************************************************************************
4968  // Intellisense comments
4977  public FT_STATUS WriteXSeriesEEPROM(FT_XSERIES_EEPROM_STRUCTURE eeX)
4978  {
4979  // Initialise ftStatus to something other than FT_OK
4980  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
4981  FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;
4982 
4983  byte[] manufacturer, manufacturerID, description, serialNumber;
4984 
4985  // If the DLL hasn't been loaded, just return here
4986  if (hFTD2XXDLL == IntPtr.Zero)
4987  return ftStatus;
4988 
4989  // Check for our required function pointers being set up
4990  if (pFT_EEPROM_Program != IntPtr.Zero)
4991  {
4992  tFT_EEPROM_Program FT_EEPROM_Program = (tFT_EEPROM_Program)Marshal.GetDelegateForFunctionPointer(pFT_EEPROM_Program, typeof(tFT_EEPROM_Program));
4993 
4994  if (ftHandle != IntPtr.Zero)
4995  {
4996  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
4997  // Check that it is an FT232H that we are trying to write
4998  GetDeviceType(ref DeviceType);
4999  if (DeviceType != FT_DEVICE.FT_DEVICE_X_SERIES)
5000  {
5001  // If it is not, throw an exception
5002  ftErrorCondition = FT_ERROR.FT_INCORRECT_DEVICE;
5003  ErrorHandler(ftStatus, ftErrorCondition);
5004  }
5005 
5006  // Check for VID and PID of 0x0000
5007  if ((eeX.VendorID == 0x0000) | (eeX.ProductID == 0x0000))
5008  {
5009  // Do not allow users to program the device with VID or PID of 0x0000
5010  return FT_STATUS.FT_INVALID_PARAMETER;
5011  }
5012 
5013  FT_XSERIES_DATA eeData = new FT_XSERIES_DATA();
5014 
5015  // String manipulation...
5016  // Allocate space from unmanaged heap
5017  manufacturer = new byte[32];
5018  manufacturerID = new byte[16];
5019  description = new byte[64];
5020  serialNumber = new byte[16];
5021 
5022  // Check lengths of strings to make sure that they are within our limits
5023  // If not, trim them to make them our maximum length
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);
5032 
5033  // Set string values
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);
5039 
5040  // Map non-string elements to structure to be returned
5041  // Standard elements
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);
5050  // X-Series specific fields
5051  // CBUS
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;
5059  // Drive Options
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;
5066  // BCD
5067  eeData.BCDDisableSleep = eeX.BCDDisableSleep;
5068  eeData.BCDEnable = eeX.BCDEnable;
5069  eeData.BCDForceCbusPWREN = eeX.BCDForceCbusPWREN;
5070  // FT1248
5071  eeData.FT1248Cpol = eeX.FT1248Cpol;
5072  eeData.FT1248FlowControl = eeX.FT1248FlowControl;
5073  eeData.FT1248Lsb = eeX.FT1248Lsb;
5074  // I2C
5075  eeData.I2CDeviceId = eeX.I2CDeviceId;
5076  eeData.I2CDisableSchmitt = eeX.I2CDisableSchmitt;
5077  eeData.I2CSlaveAddress = eeX.I2CSlaveAddress;
5078  // RS232 Signals
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;
5087  // Hardware Options
5088  eeData.PowerSaveEnable = eeX.PowerSaveEnable;
5089  eeData.RS485EchoSuppress = eeX.RS485EchoSuppress;
5090  // Driver Option
5091  eeData.DriverType = eeX.IsVCP;
5092 
5093  // Check the size of the structure...
5094  int size = Marshal.SizeOf(eeData);
5095  // Allocate space for our pointer...
5096  IntPtr eeDataMarshal = Marshal.AllocHGlobal(size);
5097  Marshal.StructureToPtr(eeData, eeDataMarshal, false);
5098 
5099  ftStatus = FT_EEPROM_Program(ftHandle, eeDataMarshal, (uint)size, manufacturer, manufacturerID, description, serialNumber);
5100  }
5101  }
5102 
5103  return FT_STATUS.FT_DEVICE_NOT_FOUND;
5104  }
5105 
5106  //**************************************************************************
5107  // EEReadUserArea
5108  //**************************************************************************
5109  // Intellisense comments
5116  public FT_STATUS EEReadUserArea(byte[] UserAreaDataBuffer, ref UInt32 numBytesRead)
5117  {
5118  // Initialise ftStatus to something other than FT_OK
5119  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5120 
5121  // If the DLL hasn't been loaded, just return here
5122  if (hFTD2XXDLL == IntPtr.Zero)
5123  return ftStatus;
5124 
5125  // Check for our required function pointers being set up
5126  if ((pFT_EE_UASize != IntPtr.Zero) & (pFT_EE_UARead != IntPtr.Zero))
5127  {
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));
5130 
5131  if (ftHandle != IntPtr.Zero)
5132  {
5133  UInt32 UASize = 0;
5134  // Get size of user area to allocate an array of the correct size.
5135  // The application must also get the UA size for its copy
5136  ftStatus = FT_EE_UASize(ftHandle, ref UASize);
5137 
5138  // Make sure we have enough storage for the whole user area
5139  if (UserAreaDataBuffer.Length >= UASize)
5140  {
5141  // Call FT_EE_UARead
5142  ftStatus = FT_EE_UARead(ftHandle, UserAreaDataBuffer, UserAreaDataBuffer.Length, ref numBytesRead);
5143  }
5144  }
5145  }
5146  else
5147  {
5148  if (pFT_EE_UASize == IntPtr.Zero)
5149  {
5150  throw new Exception("Failed to load function FT_EE_UASize.");
5151  }
5152  if (pFT_EE_UARead == IntPtr.Zero)
5153  {
5154  throw new Exception("Failed to load function FT_EE_UARead.");
5155  }
5156  }
5157  return ftStatus;
5158  }
5159 
5160  //**************************************************************************
5161  // EEWriteUserArea
5162  //**************************************************************************
5163  // Intellisense comments
5169  public FT_STATUS EEWriteUserArea(byte[] UserAreaDataBuffer)
5170  {
5171  // Initialise ftStatus to something other than FT_OK
5172  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5173 
5174  // If the DLL hasn't been loaded, just return here
5175  if (hFTD2XXDLL == IntPtr.Zero)
5176  return ftStatus;
5177 
5178  // Check for our required function pointers being set up
5179  if ((pFT_EE_UASize != IntPtr.Zero) & (pFT_EE_UAWrite != IntPtr.Zero))
5180  {
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));
5183 
5184  if (ftHandle != IntPtr.Zero)
5185  {
5186  UInt32 UASize = 0;
5187  // Get size of user area to allocate an array of the correct size.
5188  // The application must also get the UA size for its copy
5189  ftStatus = FT_EE_UASize(ftHandle, ref UASize);
5190 
5191  // Make sure we have enough storage for all the data in the EEPROM
5192  if (UserAreaDataBuffer.Length <= UASize)
5193  {
5194  // Call FT_EE_UAWrite
5195  ftStatus = FT_EE_UAWrite(ftHandle, UserAreaDataBuffer, UserAreaDataBuffer.Length);
5196  }
5197  }
5198  }
5199  else
5200  {
5201  if (pFT_EE_UASize == IntPtr.Zero)
5202  {
5203  throw new Exception("Failed to load function FT_EE_UASize.");
5204  }
5205  if (pFT_EE_UAWrite == IntPtr.Zero)
5206  {
5207  throw new Exception("Failed to load function FT_EE_UAWrite.");
5208  }
5209  }
5210  return ftStatus;
5211  }
5212 
5213  //**************************************************************************
5214  // GetDeviceType
5215  //**************************************************************************
5216  // Intellisense comments
5222  public FT_STATUS GetDeviceType(ref FT_DEVICE DeviceType)
5223  {
5224  // Initialise ftStatus to something other than FT_OK
5225  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5226 
5227  // If the DLL hasn't been loaded, just return here
5228  if (hFTD2XXDLL == IntPtr.Zero)
5229  return ftStatus;
5230 
5231  // Check for our required function pointers being set up
5232  if (pFT_GetDeviceInfo != IntPtr.Zero)
5233  {
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];
5239 
5240  DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
5241 
5242  if (ftHandle != IntPtr.Zero)
5243  {
5244  // Call FT_GetDeviceInfo
5245  ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5246  }
5247  }
5248  else
5249  {
5250  if (pFT_GetDeviceInfo == IntPtr.Zero)
5251  {
5252  throw new Exception("Failed to load function FT_GetDeviceInfo.");
5253  }
5254  }
5255  return ftStatus;
5256  }
5257 
5258  //**************************************************************************
5259  // GetDeviceID
5260  //**************************************************************************
5261  // Intellisense comments
5267  public FT_STATUS GetDeviceID(ref UInt32 DeviceID)
5268  {
5269  // Initialise ftStatus to something other than FT_OK
5270  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5271 
5272  // If the DLL hasn't been loaded, just return here
5273  if (hFTD2XXDLL == IntPtr.Zero)
5274  return ftStatus;
5275 
5276  // Check for our required function pointers being set up
5277  if (pFT_GetDeviceInfo != IntPtr.Zero)
5278  {
5279  tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5281  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
5282  byte[] sernum = new byte[16];
5283  byte[] desc = new byte[64];
5284 
5285  if (ftHandle != IntPtr.Zero)
5286  {
5287  // Call FT_GetDeviceInfo
5288  ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
5289  }
5290  }
5291  else
5292  {
5293  if (pFT_GetDeviceInfo == IntPtr.Zero)
5294  {
5295  throw new Exception("Failed to load function FT_GetDeviceInfo.");
5296  }
5297  }
5298  return ftStatus;
5299  }
5300 
5301  //**************************************************************************
5302  // GetDescription
5303  //**************************************************************************
5304  // Intellisense comments
5310  public FT_STATUS GetDescription(out string Description)
5311  {
5312  // Initialise ftStatus to something other than FT_OK
5313  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5314 
5315  Description = String.Empty;
5316 
5317  // If the DLL hasn't been loaded, just return here
5318  if (hFTD2XXDLL == IntPtr.Zero)
5319  return ftStatus;
5320 
5321 
5322  // Check for our required function pointers being set up
5323  if (pFT_GetDeviceInfo != IntPtr.Zero)
5324  {
5325  tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5326 
5327  UInt32 DeviceID = 0;
5328  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
5329  byte[] sernum = new byte[16];
5330  byte[] desc = new byte[64];
5331 
5332  if (ftHandle != IntPtr.Zero)
5333  {
5334  // Call FT_GetDeviceInfo
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"));
5338  }
5339  }
5340  else
5341  {
5342  if (pFT_GetDeviceInfo == IntPtr.Zero)
5343  {
5344  throw new Exception("Failed to load function FT_GetDeviceInfo.");
5345  }
5346  }
5347  return ftStatus;
5348  }
5349 
5350  //**************************************************************************
5351  // GetSerialNumber
5352  //**************************************************************************
5353  // Intellisense comments
5359  public FT_STATUS GetSerialNumber(out string SerialNumber)
5360  {
5361  // Initialise ftStatus to something other than FT_OK
5362  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5363 
5364  SerialNumber = String.Empty;
5365 
5366  // If the DLL hasn't been loaded, just return here
5367  if (hFTD2XXDLL == IntPtr.Zero)
5368  return ftStatus;
5369 
5370 
5371  // Check for our required function pointers being set up
5372  if (pFT_GetDeviceInfo != IntPtr.Zero)
5373  {
5374  tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
5375 
5376  UInt32 DeviceID = 0;
5377  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
5378  byte[] sernum = new byte[16];
5379  byte[] desc = new byte[64];
5380 
5381  if (ftHandle != IntPtr.Zero)
5382  {
5383  // Call FT_GetDeviceInfo
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"));
5387  }
5388  }
5389  else
5390  {
5391  if (pFT_GetDeviceInfo == IntPtr.Zero)
5392  {
5393  throw new Exception("Failed to load function FT_GetDeviceInfo.");
5394  }
5395  }
5396  return ftStatus;
5397  }
5398 
5399  //**************************************************************************
5400  // GetRxBytesAvailable
5401  //**************************************************************************
5402  // Intellisense comments
5408  public FT_STATUS GetRxBytesAvailable(ref UInt32 RxQueue)
5409  {
5410  // Initialise ftStatus to something other than FT_OK
5411  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5412 
5413  // If the DLL hasn't been loaded, just return here
5414  if (hFTD2XXDLL == IntPtr.Zero)
5415  return ftStatus;
5416 
5417  // Check for our required function pointers being set up
5418  if (pFT_GetQueueStatus != IntPtr.Zero)
5419  {
5420  tFT_GetQueueStatus FT_GetQueueStatus = (tFT_GetQueueStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetQueueStatus, typeof(tFT_GetQueueStatus));
5422  if (ftHandle != IntPtr.Zero)
5423  {
5424  // Call FT_GetQueueStatus
5425  ftStatus = FT_GetQueueStatus(ftHandle, ref RxQueue);
5426  }
5427  }
5428  else
5429  {
5430  if (pFT_GetQueueStatus == IntPtr.Zero)
5431  {
5432  throw new Exception("Failed to load function FT_GetQueueStatus.");
5433  }
5434  }
5435  return ftStatus;
5436  }
5437 
5438  //**************************************************************************
5439  // GetTxBytesWaiting
5440  //**************************************************************************
5441  // Intellisense comments
5447  public FT_STATUS GetTxBytesWaiting(ref UInt32 TxQueue)
5448  {
5449  // Initialise ftStatus to something other than FT_OK
5450  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5451 
5452  // If the DLL hasn't been loaded, just return here
5453  if (hFTD2XXDLL == IntPtr.Zero)
5454  return ftStatus;
5455 
5456  // Check for our required function pointers being set up
5457  if (pFT_GetStatus != IntPtr.Zero)
5458  {
5459  tFT_GetStatus FT_GetStatus = (tFT_GetStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetStatus, typeof(tFT_GetStatus));
5461  UInt32 RxQueue = 0;
5462  UInt32 EventStatus = 0;
5463 
5464  if (ftHandle != IntPtr.Zero)
5465  {
5466  // Call FT_GetStatus
5467  ftStatus = FT_GetStatus(ftHandle, ref RxQueue, ref TxQueue, ref EventStatus);
5468  }
5469  }
5470  else
5471  {
5472  if (pFT_GetStatus == IntPtr.Zero)
5473  {
5474  throw new Exception("Failed to load function FT_GetStatus.");
5475  }
5476  }
5477  return ftStatus;
5478  }
5479 
5480  //**************************************************************************
5481  // GetEventType
5482  //**************************************************************************
5483  // Intellisense comments
5489  public FT_STATUS GetEventType(ref UInt32 EventType)
5490  {
5491  // Initialise ftStatus to something other than FT_OK
5492  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5493 
5494  // If the DLL hasn't been loaded, just return here
5495  if (hFTD2XXDLL == IntPtr.Zero)
5496  return ftStatus;
5497 
5498  // Check for our required function pointers being set up
5499  if (pFT_GetStatus != IntPtr.Zero)
5500  {
5501  tFT_GetStatus FT_GetStatus = (tFT_GetStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetStatus, typeof(tFT_GetStatus));
5503  UInt32 RxQueue = 0;
5504  UInt32 TxQueue = 0;
5505 
5506  if (ftHandle != IntPtr.Zero)
5507  {
5508  // Call FT_GetStatus
5509  ftStatus = FT_GetStatus(ftHandle, ref RxQueue, ref TxQueue, ref EventType);
5510  }
5511  }
5512  else
5513  {
5514  if (pFT_GetStatus == IntPtr.Zero)
5515  {
5516  throw new Exception("Failed to load function FT_GetStatus.");
5517  }
5518  }
5519  return ftStatus;
5520  }
5521 
5522  //**************************************************************************
5523  // GetModemStatus
5524  //**************************************************************************
5525  // Intellisense comments
5531  public FT_STATUS GetModemStatus(ref byte ModemStatus)
5532  {
5533  // Initialise ftStatus to something other than FT_OK
5534  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5535 
5536  // If the DLL hasn't been loaded, just return here
5537  if (hFTD2XXDLL == IntPtr.Zero)
5538  return ftStatus;
5539 
5540  // Check for our required function pointers being set up
5541  if (pFT_GetModemStatus != IntPtr.Zero)
5542  {
5543  tFT_GetModemStatus FT_GetModemStatus = (tFT_GetModemStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetModemStatus, typeof(tFT_GetModemStatus));
5545  UInt32 ModemLineStatus = 0;
5546 
5547  if (ftHandle != IntPtr.Zero)
5548  {
5549  // Call FT_GetModemStatus
5550  ftStatus = FT_GetModemStatus(ftHandle, ref ModemLineStatus);
5551 
5552  }
5553  ModemStatus = Convert.ToByte(ModemLineStatus & 0x000000FF);
5554  }
5555  else
5556  {
5557  if (pFT_GetModemStatus == IntPtr.Zero)
5558  {
5559  throw new Exception("Failed to load function FT_GetModemStatus.");
5560  }
5561  }
5562  return ftStatus;
5563  }
5564 
5565  //**************************************************************************
5566  // GetLineStatus
5567  //**************************************************************************
5568  // Intellisense comments
5574  public FT_STATUS GetLineStatus(ref byte LineStatus)
5575  {
5576  // Initialise ftStatus to something other than FT_OK
5577  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5578 
5579  // If the DLL hasn't been loaded, just return here
5580  if (hFTD2XXDLL == IntPtr.Zero)
5581  return ftStatus;
5582 
5583  // Check for our required function pointers being set up
5584  if (pFT_GetModemStatus != IntPtr.Zero)
5585  {
5586  tFT_GetModemStatus FT_GetModemStatus = (tFT_GetModemStatus)Marshal.GetDelegateForFunctionPointer(pFT_GetModemStatus, typeof(tFT_GetModemStatus));
5588  UInt32 ModemLineStatus = 0;
5589 
5590  if (ftHandle != IntPtr.Zero)
5591  {
5592  // Call FT_GetModemStatus
5593  ftStatus = FT_GetModemStatus(ftHandle, ref ModemLineStatus);
5594  }
5595  LineStatus = Convert.ToByte((ModemLineStatus >> 8) & 0x000000FF);
5596  }
5597  else
5598  {
5599  if (pFT_GetModemStatus == IntPtr.Zero)
5600  {
5601  throw new Exception("Failed to load function FT_GetModemStatus.");
5602  }
5603  }
5604  return ftStatus;
5605  }
5606 
5607  //**************************************************************************
5608  // SetBaudRate
5609  //**************************************************************************
5610  // Intellisense comments
5616  public FT_STATUS SetBaudRate(UInt32 BaudRate)
5617  {
5618  // Initialise ftStatus to something other than FT_OK
5619  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5620 
5621  // If the DLL hasn't been loaded, just return here
5622  if (hFTD2XXDLL == IntPtr.Zero)
5623  return ftStatus;
5624 
5625  // Check for our required function pointers being set up
5626  if (pFT_SetBaudRate != IntPtr.Zero)
5627  {
5628  tFT_SetBaudRate FT_SetBaudRate = (tFT_SetBaudRate)Marshal.GetDelegateForFunctionPointer(pFT_SetBaudRate, typeof(tFT_SetBaudRate));
5630  if (ftHandle != IntPtr.Zero)
5631  {
5632  // Call FT_SetBaudRate
5633  ftStatus = FT_SetBaudRate(ftHandle, BaudRate);
5634  }
5635  }
5636  else
5637  {
5638  if (pFT_SetBaudRate == IntPtr.Zero)
5639  {
5640  throw new Exception("Failed to load function FT_SetBaudRate.");
5641  }
5642  }
5643  return ftStatus;
5644  }
5645 
5646  //**************************************************************************
5647  // SetDataCharacteristics
5648  //**************************************************************************
5649  // Intellisense comments
5657  public FT_STATUS SetDataCharacteristics(byte DataBits, byte StopBits, byte Parity)
5658  {
5659  // Initialise ftStatus to something other than FT_OK
5660  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5661 
5662  // If the DLL hasn't been loaded, just return here
5663  if (hFTD2XXDLL == IntPtr.Zero)
5664  return ftStatus;
5665 
5666  // Check for our required function pointers being set up
5667  if (pFT_SetDataCharacteristics != IntPtr.Zero)
5668  {
5669  tFT_SetDataCharacteristics FT_SetDataCharacteristics = (tFT_SetDataCharacteristics)Marshal.GetDelegateForFunctionPointer(pFT_SetDataCharacteristics, typeof(tFT_SetDataCharacteristics));
5671  if (ftHandle != IntPtr.Zero)
5672  {
5673  // Call FT_SetDataCharacteristics
5674  ftStatus = FT_SetDataCharacteristics(ftHandle, DataBits, StopBits, Parity);
5675  }
5676  }
5677  else
5678  {
5679  if (pFT_SetDataCharacteristics == IntPtr.Zero)
5680  {
5681  throw new Exception("Failed to load function FT_SetDataCharacteristics.");
5682  }
5683  }
5684  return ftStatus;
5685  }
5686 
5687  //**************************************************************************
5688  // SetFlowControl
5689  //**************************************************************************
5690  // Intellisense comments
5698  public FT_STATUS SetFlowControl(UInt16 FlowControl, byte Xon, byte Xoff)
5699  {
5700  // Initialise ftStatus to something other than FT_OK
5701  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5702 
5703  // If the DLL hasn't been loaded, just return here
5704  if (hFTD2XXDLL == IntPtr.Zero)
5705  return ftStatus;
5706 
5707  // Check for our required function pointers being set up
5708  if (pFT_SetFlowControl != IntPtr.Zero)
5709  {
5710  tFT_SetFlowControl FT_SetFlowControl = (tFT_SetFlowControl)Marshal.GetDelegateForFunctionPointer(pFT_SetFlowControl, typeof(tFT_SetFlowControl));
5712  if (ftHandle != IntPtr.Zero)
5713  {
5714  // Call FT_SetFlowControl
5715  ftStatus = FT_SetFlowControl(ftHandle, FlowControl, Xon, Xoff);
5716  }
5717  }
5718  else
5719  {
5720  if (pFT_SetFlowControl == IntPtr.Zero)
5721  {
5722  throw new Exception("Failed to load function FT_SetFlowControl.");
5723  }
5724  }
5725  return ftStatus;
5726  }
5727 
5728  //**************************************************************************
5729  // SetRTS
5730  //**************************************************************************
5731  // Intellisense comments
5737  public FT_STATUS SetRTS(bool Enable)
5738  {
5739  // Initialise ftStatus to something other than FT_OK
5740  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5741 
5742  // If the DLL hasn't been loaded, just return here
5743  if (hFTD2XXDLL == IntPtr.Zero)
5744  return ftStatus;
5745 
5746  // Check for our required function pointers being set up
5747  if ((pFT_SetRts != IntPtr.Zero) & (pFT_ClrRts != IntPtr.Zero))
5748  {
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));
5751 
5752  if (ftHandle != IntPtr.Zero)
5753  {
5754  if (Enable)
5755  {
5756  // Call FT_SetRts
5757  ftStatus = FT_SetRts(ftHandle);
5758  }
5759  else
5760  {
5761  // Call FT_ClrRts
5762  ftStatus = FT_ClrRts(ftHandle);
5763  }
5764  }
5765  }
5766  else
5767  {
5768  if (pFT_SetRts == IntPtr.Zero)
5769  {
5770  throw new Exception("Failed to load function FT_SetRts.");
5771  }
5772  if (pFT_ClrRts == IntPtr.Zero)
5773  {
5774  throw new Exception("Failed to load function FT_ClrRts.");
5775  }
5776  }
5777  return ftStatus;
5778  }
5779 
5780  //**************************************************************************
5781  // SetDTR
5782  //**************************************************************************
5783  // Intellisense comments
5789  public FT_STATUS SetDTR(bool Enable)
5790  {
5791  // Initialise ftStatus to something other than FT_OK
5792  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5793 
5794  // If the DLL hasn't been loaded, just return here
5795  if (hFTD2XXDLL == IntPtr.Zero)
5796  return ftStatus;
5797 
5798  // Check for our required function pointers being set up
5799  if ((pFT_SetDtr != IntPtr.Zero) & (pFT_ClrDtr != IntPtr.Zero))
5800  {
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));
5803 
5804  if (ftHandle != IntPtr.Zero)
5805  {
5806  if (Enable)
5807  {
5808  // Call FT_SetDtr
5809  ftStatus = FT_SetDtr(ftHandle);
5810  }
5811  else
5812  {
5813  // Call FT_ClrDtr
5814  ftStatus = FT_ClrDtr(ftHandle);
5815  }
5816  }
5817  }
5818  else
5819  {
5820  if (pFT_SetDtr == IntPtr.Zero)
5821  {
5822  throw new Exception("Failed to load function FT_SetDtr.");
5823  }
5824  if (pFT_ClrDtr == IntPtr.Zero)
5825  {
5826  throw new Exception("Failed to load function FT_ClrDtr.");
5827  }
5828  }
5829  return ftStatus;
5830  }
5831 
5832  //**************************************************************************
5833  // SetTimeouts
5834  //**************************************************************************
5835  // Intellisense comments
5842  public FT_STATUS SetTimeouts(UInt32 ReadTimeout, UInt32 WriteTimeout)
5843  {
5844  // Initialise ftStatus to something other than FT_OK
5845  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5846 
5847  // If the DLL hasn't been loaded, just return here
5848  if (hFTD2XXDLL == IntPtr.Zero)
5849  return ftStatus;
5850 
5851  // Check for our required function pointers being set up
5852  if (pFT_SetTimeouts != IntPtr.Zero)
5853  {
5854  tFT_SetTimeouts FT_SetTimeouts = (tFT_SetTimeouts)Marshal.GetDelegateForFunctionPointer(pFT_SetTimeouts, typeof(tFT_SetTimeouts));
5856  if (ftHandle != IntPtr.Zero)
5857  {
5858  // Call FT_SetTimeouts
5859  ftStatus = FT_SetTimeouts(ftHandle, ReadTimeout, WriteTimeout);
5860  }
5861  }
5862  else
5863  {
5864  if (pFT_SetTimeouts == IntPtr.Zero)
5865  {
5866  throw new Exception("Failed to load function FT_SetTimeouts.");
5867  }
5868  }
5869  return ftStatus;
5870  }
5871 
5872  //**************************************************************************
5873  // SetBreak
5874  //**************************************************************************
5875  // Intellisense comments
5881  public FT_STATUS SetBreak(bool Enable)
5882  {
5883  // Initialise ftStatus to something other than FT_OK
5884  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5885 
5886  // If the DLL hasn't been loaded, just return here
5887  if (hFTD2XXDLL == IntPtr.Zero)
5888  return ftStatus;
5889 
5890  // Check for our required function pointers being set up
5891  if ((pFT_SetBreakOn != IntPtr.Zero) & (pFT_SetBreakOff != IntPtr.Zero))
5892  {
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));
5895 
5896  if (ftHandle != IntPtr.Zero)
5897  {
5898  if (Enable)
5899  {
5900  // Call FT_SetBreakOn
5901  ftStatus = FT_SetBreakOn(ftHandle);
5902  }
5903  else
5904  {
5905  // Call FT_SetBreakOff
5906  ftStatus = FT_SetBreakOff(ftHandle);
5907  }
5908  }
5909  }
5910  else
5911  {
5912  if (pFT_SetBreakOn == IntPtr.Zero)
5913  {
5914  throw new Exception("Failed to load function FT_SetBreakOn.");
5915  }
5916  if (pFT_SetBreakOff == IntPtr.Zero)
5917  {
5918  throw new Exception("Failed to load function FT_SetBreakOff.");
5919  }
5920  }
5921  return ftStatus;
5922  }
5923 
5924  //**************************************************************************
5925  // SetResetPipeRetryCount
5926  //**************************************************************************
5927  // Intellisense comments
5934  public FT_STATUS SetResetPipeRetryCount(UInt32 ResetPipeRetryCount)
5935  {
5936  // Initialise ftStatus to something other than FT_OK
5937  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5938 
5939  // If the DLL hasn't been loaded, just return here
5940  if (hFTD2XXDLL == IntPtr.Zero)
5941  return ftStatus;
5942 
5943  // Check for our required function pointers being set up
5944  if (pFT_SetResetPipeRetryCount != IntPtr.Zero)
5945  {
5946  tFT_SetResetPipeRetryCount FT_SetResetPipeRetryCount = (tFT_SetResetPipeRetryCount)Marshal.GetDelegateForFunctionPointer(pFT_SetResetPipeRetryCount, typeof(tFT_SetResetPipeRetryCount));
5948  if (ftHandle != IntPtr.Zero)
5949  {
5950  // Call FT_SetResetPipeRetryCount
5951  ftStatus = FT_SetResetPipeRetryCount(ftHandle, ResetPipeRetryCount);
5952  }
5953  }
5954  else
5955  {
5956  if (pFT_SetResetPipeRetryCount == IntPtr.Zero)
5957  {
5958  throw new Exception("Failed to load function FT_SetResetPipeRetryCount.");
5959  }
5960  }
5961  return ftStatus;
5962  }
5963 
5964  //**************************************************************************
5965  // GetDriverVersion
5966  //**************************************************************************
5967  // Intellisense comments
5973  public FT_STATUS GetDriverVersion(ref UInt32 DriverVersion)
5974  {
5975  // Initialise ftStatus to something other than FT_OK
5976  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
5977 
5978  // If the DLL hasn't been loaded, just return here
5979  if (hFTD2XXDLL == IntPtr.Zero)
5980  return ftStatus;
5981 
5982  // Check for our required function pointers being set up
5983  if (pFT_GetDriverVersion != IntPtr.Zero)
5984  {
5985  tFT_GetDriverVersion FT_GetDriverVersion = (tFT_GetDriverVersion)Marshal.GetDelegateForFunctionPointer(pFT_GetDriverVersion, typeof(tFT_GetDriverVersion));
5987  if (ftHandle != IntPtr.Zero)
5988  {
5989  // Call FT_GetDriverVersion
5990  ftStatus = FT_GetDriverVersion(ftHandle, ref DriverVersion);
5991  }
5992  }
5993  else
5994  {
5995  if (pFT_GetDriverVersion == IntPtr.Zero)
5996  {
5997  throw new Exception("Failed to load function FT_GetDriverVersion.");
5998  }
5999  }
6000  return ftStatus;
6001  }
6002 
6003  //**************************************************************************
6004  // GetLibraryVersion
6005  //**************************************************************************
6006  // Intellisense comments
6012  public FT_STATUS GetLibraryVersion(ref UInt32 LibraryVersion)
6013  {
6014  // Initialise ftStatus to something other than FT_OK
6015  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6016 
6017  // If the DLL hasn't been loaded, just return here
6018  if (hFTD2XXDLL == IntPtr.Zero)
6019  return ftStatus;
6020 
6021  // Check for our required function pointers being set up
6022  if (pFT_GetLibraryVersion != IntPtr.Zero)
6023  {
6024  tFT_GetLibraryVersion FT_GetLibraryVersion = (tFT_GetLibraryVersion)Marshal.GetDelegateForFunctionPointer(pFT_GetLibraryVersion, typeof(tFT_GetLibraryVersion));
6026  // Call FT_GetLibraryVersion
6027  ftStatus = FT_GetLibraryVersion(ref LibraryVersion);
6028  }
6029  else
6030  {
6031  if (pFT_GetLibraryVersion == IntPtr.Zero)
6032  {
6033  throw new Exception("Failed to load function FT_GetLibraryVersion.");
6034  }
6035  }
6036  return ftStatus;
6037  }
6038 
6039  //**************************************************************************
6040  // SetDeadmanTimeout
6041  //**************************************************************************
6042  // Intellisense comments
6048  public FT_STATUS SetDeadmanTimeout(UInt32 DeadmanTimeout)
6049  {
6050  // Initialise ftStatus to something other than FT_OK
6051  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6052 
6053  // If the DLL hasn't been loaded, just return here
6054  if (hFTD2XXDLL == IntPtr.Zero)
6055  return ftStatus;
6056 
6057  // Check for our required function pointers being set up
6058  if (pFT_SetDeadmanTimeout != IntPtr.Zero)
6059  {
6060  tFT_SetDeadmanTimeout FT_SetDeadmanTimeout = (tFT_SetDeadmanTimeout)Marshal.GetDelegateForFunctionPointer(pFT_SetDeadmanTimeout, typeof(tFT_SetDeadmanTimeout));
6062  if (ftHandle != IntPtr.Zero)
6063  {
6064  // Call FT_SetDeadmanTimeout
6065  ftStatus = FT_SetDeadmanTimeout(ftHandle, DeadmanTimeout);
6066  }
6067  }
6068  else
6069  {
6070  if (pFT_SetDeadmanTimeout == IntPtr.Zero)
6071  {
6072  throw new Exception("Failed to load function FT_SetDeadmanTimeout.");
6073  }
6074  }
6075  return ftStatus;
6076  }
6077 
6078  //**************************************************************************
6079  // SetLatency
6080  //**************************************************************************
6081  // Intellisense comments
6089  public FT_STATUS SetLatency(byte Latency)
6090  {
6091  // Initialise ftStatus to something other than FT_OK
6092  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6093 
6094  // If the DLL hasn't been loaded, just return here
6095  if (hFTD2XXDLL == IntPtr.Zero)
6096  return ftStatus;
6097 
6098  // Check for our required function pointers being set up
6099  if (pFT_SetLatencyTimer != IntPtr.Zero)
6100  {
6101  tFT_SetLatencyTimer FT_SetLatencyTimer = (tFT_SetLatencyTimer)Marshal.GetDelegateForFunctionPointer(pFT_SetLatencyTimer, typeof(tFT_SetLatencyTimer));
6103  if (ftHandle != IntPtr.Zero)
6104  {
6105  FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
6106  // Set Bit Mode does not apply to FT8U232AM, FT8U245AM or FT8U100AX devices
6107  GetDeviceType(ref DeviceType);
6108  if ((DeviceType == FT_DEVICE.FT_DEVICE_BM) || (DeviceType == FT_DEVICE.FT_DEVICE_2232))
6109  {
6110  // Do not allow latency of 1ms or 0ms for older devices
6111  // since this can cause problems/lock up due to buffering mechanism
6112  if (Latency < 2)
6113  Latency = 2;
6114  }
6115 
6116  // Call FT_SetLatencyTimer
6117  ftStatus = FT_SetLatencyTimer(ftHandle, Latency);
6118  }
6119  }
6120  else
6121  {
6122  if (pFT_SetLatencyTimer == IntPtr.Zero)
6123  {
6124  throw new Exception("Failed to load function FT_SetLatencyTimer.");
6125  }
6126  }
6127  return ftStatus;
6128  }
6129 
6130  //**************************************************************************
6131  // GetLatency
6132  //**************************************************************************
6133  // Intellisense comments
6139  public FT_STATUS GetLatency(ref byte Latency)
6140  {
6141  // Initialise ftStatus to something other than FT_OK
6142  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6143 
6144  // If the DLL hasn't been loaded, just return here
6145  if (hFTD2XXDLL == IntPtr.Zero)
6146  return ftStatus;
6147 
6148  // Check for our required function pointers being set up
6149  if (pFT_GetLatencyTimer != IntPtr.Zero)
6150  {
6151  tFT_GetLatencyTimer FT_GetLatencyTimer = (tFT_GetLatencyTimer)Marshal.GetDelegateForFunctionPointer(pFT_GetLatencyTimer, typeof(tFT_GetLatencyTimer));
6153  if (ftHandle != IntPtr.Zero)
6154  {
6155  // Call FT_GetLatencyTimer
6156  ftStatus = FT_GetLatencyTimer(ftHandle, ref Latency);
6157  }
6158  }
6159  else
6160  {
6161  if (pFT_GetLatencyTimer == IntPtr.Zero)
6162  {
6163  throw new Exception("Failed to load function FT_GetLatencyTimer.");
6164  }
6165  }
6166  return ftStatus;
6167  }
6168 
6169  //**************************************************************************
6170  // SetUSBTransferSizes
6171  //**************************************************************************
6172  // Intellisense comments
6178  public FT_STATUS InTransferSize(UInt32 InTransferSize)
6179  // Only support IN transfer sizes at the moment
6180  //public UInt32 InTransferSize(UInt32 InTransferSize, UInt32 OutTransferSize)
6181  {
6182  // Initialise ftStatus to something other than FT_OK
6183  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6184 
6185  // If the DLL hasn't been loaded, just return here
6186  if (hFTD2XXDLL == IntPtr.Zero)
6187  return ftStatus;
6188 
6189  // Check for our required function pointers being set up
6190  if (pFT_SetUSBParameters != IntPtr.Zero)
6191  {
6192  tFT_SetUSBParameters FT_SetUSBParameters = (tFT_SetUSBParameters)Marshal.GetDelegateForFunctionPointer(pFT_SetUSBParameters, typeof(tFT_SetUSBParameters));
6193 
6194  UInt32 OutTransferSize = InTransferSize;
6195 
6196  if (ftHandle != IntPtr.Zero)
6197  {
6198  // Call FT_SetUSBParameters
6199  ftStatus = FT_SetUSBParameters(ftHandle, InTransferSize, OutTransferSize);
6200  }
6201  }
6202  else
6203  {
6204  if (pFT_SetUSBParameters == IntPtr.Zero)
6205  {
6206  throw new Exception("Failed to load function FT_SetUSBParameters.");
6207  }
6208  }
6209  return ftStatus;
6210  }
6211 
6212  //**************************************************************************
6213  // SetCharacters
6214  //**************************************************************************
6215  // Intellisense comments
6224  public FT_STATUS SetCharacters(byte EventChar, bool EventCharEnable, byte ErrorChar, bool ErrorCharEnable)
6225  {
6226  // Initialise ftStatus to something other than FT_OK
6227  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6228 
6229  // If the DLL hasn't been loaded, just return here
6230  if (hFTD2XXDLL == IntPtr.Zero)
6231  return ftStatus;
6232 
6233  // Check for our required function pointers being set up
6234  if (pFT_SetChars != IntPtr.Zero)
6235  {
6236  tFT_SetChars FT_SetChars = (tFT_SetChars)Marshal.GetDelegateForFunctionPointer(pFT_SetChars, typeof(tFT_SetChars));
6238  if (ftHandle != IntPtr.Zero)
6239  {
6240  // Call FT_SetChars
6241  ftStatus = FT_SetChars(ftHandle, EventChar, Convert.ToByte(EventCharEnable), ErrorChar, Convert.ToByte(ErrorCharEnable));
6242  }
6243  }
6244  else
6245  {
6246  if (pFT_SetChars == IntPtr.Zero)
6247  {
6248  throw new Exception("Failed to load function FT_SetChars.");
6249  }
6250  }
6251  return ftStatus;
6252  }
6253 
6254  //**************************************************************************
6255  // GetEEUserAreaSize
6256  //**************************************************************************
6257  // Intellisense comments
6263  public FT_STATUS EEUserAreaSize(ref UInt32 UASize)
6264  {
6265  // Initialise ftStatus to something other than FT_OK
6266  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6267 
6268  // If the DLL hasn't been loaded, just return here
6269  if (hFTD2XXDLL == IntPtr.Zero)
6270  return ftStatus;
6271 
6272  // Check for our required function pointers being set up
6273  if (pFT_EE_UASize != IntPtr.Zero)
6274  {
6275  tFT_EE_UASize FT_EE_UASize = (tFT_EE_UASize)Marshal.GetDelegateForFunctionPointer(pFT_EE_UASize, typeof(tFT_EE_UASize));
6277  if (ftHandle != IntPtr.Zero)
6278  {
6279  ftStatus = FT_EE_UASize(ftHandle, ref UASize);
6280  }
6281  }
6282  else
6283  {
6284  if (pFT_EE_UASize == IntPtr.Zero)
6285  {
6286  throw new Exception("Failed to load function FT_EE_UASize.");
6287  }
6288  }
6289  return ftStatus;
6290  }
6291 
6292  //**************************************************************************
6293  // GetCOMPort
6294  //**************************************************************************
6295  // Intellisense comments
6301  public FT_STATUS GetCOMPort(out string ComPortName)
6302  {
6303  // Initialise ftStatus to something other than FT_OK
6304  FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
6305 
6306  // As ComPortName is an OUT paremeter, has to be assigned before returning
6307  ComPortName = string.Empty;
6308 
6309  // If the DLL hasn't been loaded, just return here
6310  if (hFTD2XXDLL == IntPtr.Zero)
6311  return ftStatus;
6312 
6313  // Check for our required function pointers being set up
6314  if (pFT_GetComPortNumber != IntPtr.Zero)
6315  {
6316  tFT_GetComPortNumber FT_GetComPortNumber = (tFT_GetComPortNumber)Marshal.GetDelegateForFunctionPointer(pFT_GetComPortNumber, typeof(tFT_GetComPortNumber));
6317 
6318  Int32 ComPortNumber = -1;
6319  if (ftHandle != IntPtr.Zero)
6320  {
6321  // Call FT_GetComPortNumber
6322  ftStatus = FT_GetComPortNumber(ftHandle, ref ComPortNumber);
6323  }
6324 
6325  if (ComPortNumber == -1)
6326  {
6327  // If no COM port installed, return an empty string
6328  ComPortName = string.Empty;
6329  }
6330  else
6331  {
6332  // If installed, return full COM string
6333  // This can then be passed to an instance of the SerialPort class to assign the port number.
6334  ComPortName = "COM" + ComPortNumber.ToString();
6335  }
6336  }
6337  else
6338  {
6339  if (pFT_GetComPortNumber == IntPtr.Zero)
6340  {
6341  throw new Exception("Failed to load function FT_GetComPortNumber.");
6342  }
6343  }
6344  return ftStatus;
6345  }
6346  #endregion
6347 
6348 
6349 
6350 
6351 
6352 
6353 
6354  #region PROPERTY_DEFINITIONS
6355  //**************************************************************************
6356  // IsOpen
6357  //**************************************************************************
6358  // Intellisense comments
6362  public bool IsOpen
6363  {
6364  get
6365  {
6366  if (ftHandle == IntPtr.Zero)
6367  return false;
6368  else
6369  return true;
6370  }
6371  }
6372 
6373  //**************************************************************************
6374  // InterfaceIdentifier
6375  //**************************************************************************
6376  // Intellisense comments
6380  private string InterfaceIdentifier
6381  {
6382  get
6383  {
6384  string Identifier;
6385  Identifier = String.Empty;
6386  if (IsOpen)
6387  {
6388  FT_DEVICE deviceType = FT_DEVICE.FT_DEVICE_BM;
6389  GetDeviceType(ref deviceType);
6390  if ((deviceType == FT_DEVICE.FT_DEVICE_2232) | (deviceType == FT_DEVICE.FT_DEVICE_2232H) | (deviceType == FT_DEVICE.FT_DEVICE_4232H))
6391  {
6392  string Description;
6393  GetDescription(out Description);
6394  Identifier = Description.Substring((Description.Length - 1));
6395  return Identifier;
6396  }
6397  }
6398  return Identifier;
6399  }
6400  }
6401  #endregion
6402 
6403  #region HELPER_METHODS
6404 
6405  public void ErrorHandler(FT_STATUS ftStatus)
6406  {
6407  ErrorHandler(ftStatus, FT_ERROR.FT_NO_ERROR);
6408  }
6409 
6410  //**************************************************************************
6411  // ErrorHandler
6412  //**************************************************************************
6416  private void ErrorHandler(FT_STATUS ftStatus, FT_ERROR ftErrorCondition)
6417  {
6418  if (ftStatus != FT_STATUS.FT_OK)
6419  {
6420  // Check FT_STATUS values returned from FTD2XX DLL calls
6421  switch (ftStatus)
6422  {
6423  case FT_STATUS.FT_DEVICE_NOT_FOUND:
6424  {
6425  throw new FT_EXCEPTION("FTDI device not found.");
6426  }
6427  case FT_STATUS.FT_DEVICE_NOT_OPENED:
6428  {
6429  throw new FT_EXCEPTION("FTDI device not opened.");
6430  }
6431  case FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_ERASE:
6432  {
6433  throw new FT_EXCEPTION("FTDI device not opened for erase.");
6434  }
6435  case FT_STATUS.FT_DEVICE_NOT_OPENED_FOR_WRITE:
6436  {
6437  throw new FT_EXCEPTION("FTDI device not opened for write.");
6438  }
6439  case FT_STATUS.FT_EEPROM_ERASE_FAILED:
6440  {
6441  throw new FT_EXCEPTION("Failed to erase FTDI device EEPROM.");
6442  }
6443  case FT_STATUS.FT_EEPROM_NOT_PRESENT:
6444  {
6445  throw new FT_EXCEPTION("No EEPROM fitted to FTDI device.");
6446  }
6447  case FT_STATUS.FT_EEPROM_NOT_PROGRAMMED:
6448  {
6449  throw new FT_EXCEPTION("FTDI device EEPROM not programmed.");
6450  }
6451  case FT_STATUS.FT_EEPROM_READ_FAILED:
6452  {
6453  throw new FT_EXCEPTION("Failed to read FTDI device EEPROM.");
6454  }
6455  case FT_STATUS.FT_EEPROM_WRITE_FAILED:
6456  {
6457  throw new FT_EXCEPTION("Failed to write FTDI device EEPROM.");
6458  }
6459  case FT_STATUS.FT_FAILED_TO_WRITE_DEVICE:
6460  {
6461  throw new FT_EXCEPTION("Failed to write to FTDI device.");
6462  }
6463  case FT_STATUS.FT_INSUFFICIENT_RESOURCES:
6464  {
6465  throw new FT_EXCEPTION("Insufficient resources.");
6466  }
6467  case FT_STATUS.FT_INVALID_ARGS:
6468  {
6469  throw new FT_EXCEPTION("Invalid arguments for FTD2XX function call.");
6470  }
6471  case FT_STATUS.FT_INVALID_BAUD_RATE:
6472  {
6473  throw new FT_EXCEPTION("Invalid Baud rate for FTDI device.");
6474  }
6475  case FT_STATUS.FT_INVALID_HANDLE:
6476  {
6477  throw new FT_EXCEPTION("Invalid handle for FTDI device.");
6478  }
6479  case FT_STATUS.FT_INVALID_PARAMETER:
6480  {
6481  throw new FT_EXCEPTION("Invalid parameter for FTD2XX function call.");
6482  }
6483  case FT_STATUS.FT_IO_ERROR:
6484  {
6485  throw new FT_EXCEPTION("FTDI device IO error.");
6486  }
6487  case FT_STATUS.FT_OTHER_ERROR:
6488  {
6489  throw new FT_EXCEPTION("An unexpected error has occurred when trying to communicate with the FTDI device.");
6490  }
6491  default:
6492  break;
6493  }
6494  }
6495  if (ftErrorCondition != FT_ERROR.FT_NO_ERROR)
6496  {
6497  // Check for other error conditions not handled by FTD2XX DLL
6498  switch (ftErrorCondition)
6499  {
6500  case FT_ERROR.FT_INCORRECT_DEVICE:
6501  {
6502  throw new FT_EXCEPTION("The current device type does not match the EEPROM structure.");
6503  }
6504  case FT_ERROR.FT_INVALID_BITMODE:
6505  {
6506  throw new FT_EXCEPTION("The requested bit mode is not valid for the current device.");
6507  }
6508  case FT_ERROR.FT_BUFFER_SIZE:
6509  {
6510  throw new FT_EXCEPTION("The supplied buffer is not big enough.");
6511  }
6512 
6513  default:
6514  break;
6515  }
6516 
6517  }
6518 
6519  return;
6520  }
6521  #endregion
6522  }
6523 }
const byte FT_BIT_MODE_SYNC_FIFO
Single channel synchronous 245 FIFO mode - only available on FT2232H channel A and FT232H ...
Definition: FTD2XX_NET.cs:601
Permitted stop bits for FTDI devices
Definition: FTD2XX_NET.cs:416
byte ACSlowSlew
Determines if AC pins have a slow slew rate
Definition: FTD2XX_NET.cs:1781
byte InvertDCD
Inverts the sense of the DCD line
Definition: FTD2XX_NET.cs:1885
const byte FT_DRIVE_CURRENT_4MA
4mA drive current
Definition: FTD2XX_NET.cs:843
const byte FT_CBUS_SLEEP
FT232R CBUS EEPROM options - Sleep
Definition: FTD2XX_NET.cs:633
byte Cbus0
Sets the function of the CBUS0 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_GPIO, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1809
FT_STATUS
Status values for FTDI devices.
Definition: FTD2XX_NET.cs:303
byte InvertRXD
Inverts the sense of the RXD line
Definition: FTD2XX_NET.cs:1865
byte InvertCTS
Inverts the sense of the CTS line
Definition: FTD2XX_NET.cs:1873
FT_EXCEPTION(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
Definition: FTD2XX_NET.cs:1969
byte Cbus1
Sets the function of the CBUS1 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_GPIO, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1817
Flags that provide information on the FTDI device state
Definition: FTD2XX_NET.cs:822
byte Cbus4
Sets the function of the CBUS4 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1841
FT_STATUS GetNumberOfDevices(ref UInt32 devcount)
Gets the number of FTDI devices available.
Definition: FTD2XX_NET.cs:2044
Permitted parity values for FTDI devices
Definition: FTD2XX_NET.cs:432
FT_EXCEPTION(string message, Exception inner)
Definition: FTD2XX_NET.cs:1963
UInt32 ID
The Vendor ID and Product ID of the device
Definition: FTD2XX_NET.cs:940
byte BCDEnable
Determines whether the Battery Charge Detection option is enabled.
Definition: FTD2XX_NET.cs:1893
FT_STATUS GetDeviceList(FT_DEVICE_INFO_NODE[] devicelist)
Gets information on all of the FTDI devices available.
Definition: FTD2XX_NET.cs:2080
FTDI device event types that can be monitored
Definition: FTD2XX_NET.cs:548
byte ACSchmittInput
Determines if the AC pins have a Schmitt input
Definition: FTD2XX_NET.cs:1785
IntPtr ftHandle
The device handle. This value is not used externally and is provided for information only...
Definition: FTD2XX_NET.cs:957
const byte FT_BIT_MODE_SYNC_BITBANG
Synchronous bit-bang mode
Definition: FTD2XX_NET.cs:585
byte InvertDSR
Inverts the sense of the DSR line
Definition: FTD2XX_NET.cs:1881
EEPROM structure specific to FT232R and FT245R devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1321
byte ADSlowSlew
Determines if AD pins have a slow slew rate
Definition: FTD2XX_NET.cs:1793
Available functions for the FT232R CBUS pins. Controlled by FT232R EEPROM settings ...
Definition: FTD2XX_NET.cs:608
string SerialNumber
The device serial number
Definition: FTD2XX_NET.cs:948
FTDI()
Constructor for the FTDI class.
Definition: FTD2XX_NET.cs:50
const byte FT_BIT_MODE_RESET
Reset bit mode
Definition: FTD2XX_NET.cs:573
byte FT1248Cpol
FT1248 clock polarity - clock idle high (1) or clock idle low (0)
Definition: FTD2XX_NET.cs:1917
UInt32 LocId
The physical location identifier of the device
Definition: FTD2XX_NET.cs:944
byte BCDDisableSleep
Forces the device never to go into sleep mode.
Definition: FTD2XX_NET.cs:1901
EEPROM structure specific to X-Series devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1760
Common EEPROM elements for all devices. Inherited to specific device type EEPROMs.
Definition: FTD2XX_NET.cs:1174
UInt32 Flags
Indicates device state. Can be any combination of the following: FT_FLAGS_OPENED, FT_FLAGS_HISPEED ...
Definition: FTD2XX_NET.cs:932
byte InvertRTS
Inverts the sense of the RTS line
Definition: FTD2XX_NET.cs:1869
const byte FT_BIT_MODE_ASYNC_BITBANG
Asynchronous bit-bang mode
Definition: FTD2XX_NET.cs:577
EEPROM structure specific to FT232H devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1619
byte BCDForceCbusPWREN
Asserts the power enable signal on CBUS when charging port detected.
Definition: FTD2XX_NET.cs:1897
Purge buffer constant definitions
Definition: FTD2XX_NET.cs:484
EEPROM structure specific to FT2232 devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1251
byte FT1248Lsb
FT1248 data is LSB (1) or MSB (0)
Definition: FTD2XX_NET.cs:1921
byte ADSchmittInput
Determines if AD pins have a schmitt input
Definition: FTD2XX_NET.cs:1797
Permitted flow control values for FTDI devices
Definition: FTD2XX_NET.cs:460
byte ACDriveCurrent
Determines the AC pins drive current in mA. Valid values are FT_DRIVE_CURRENT_4MA, FT_DRIVE_CURRENT_8MA, FT_DRIVE_CURRENT_12MA or FT_DRIVE_CURRENT_16MA
Definition: FTD2XX_NET.cs:1789
Exceptions thrown by errors within the FTDI class.
Definition: FTD2XX_NET.cs:1947
EEPROM structure specific to FT4232H devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1523
FT_DEVICE Type
Indicates the device type. Can be one of the following: FT_DEVICE_232R, FT_DEVICE_2232C, FT_DEVICE_BM, FT_DEVICE_AM, FT_DEVICE_100AX or FT_DEVICE_UNKNOWN
Definition: FTD2XX_NET.cs:936
byte Cbus2
Sets the function of the CBUS2 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_GPIO, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1825
Type that holds device information for GetDeviceInformation method. Used with FT_GetDeviceInfo and FT...
Definition: FTD2XX_NET.cs:927
FT_DEVICE
List of FTDI device types
Definition: FTD2XX_NET.cs:862
byte Cbus3
Sets the function of the CBUS3 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_GPIO, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1833
byte Cbus5
Sets the function of the CBUS5 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1849
const byte FT_BIT_MODE_FAST_SERIAL
Fast opto-isolated serial mode - only available on FT2232, FT2232H, FT4232H and FT232H ...
Definition: FTD2XX_NET.cs:593
Available functions for the FT232H CBUS pins. Controlled by FT232H EEPROM settings ...
Definition: FTD2XX_NET.cs:668
Available functions for the X-Series CBUS pins. Controlled by X-Series EEPROM settings ...
Definition: FTD2XX_NET.cs:726
const byte FT_BIT_MODE_MPSSE
MPSSE bit mode - only available on FT2232, FT2232H, FT4232H and FT232H
Definition: FTD2XX_NET.cs:581
Permitted data bits for FTDI devices
Definition: FTD2XX_NET.cs:400
const byte FT_BIT_MODE_MCU_HOST
MCU host bus emulation mode - only available on FT2232, FT2232H, FT4232H and FT232H ...
Definition: FTD2XX_NET.cs:589
const byte FT_CBUS_TRISTATE
FT232H CBUS EEPROM options - Tristate
Definition: FTD2XX_NET.cs:673
Permitted bit mode values for FTDI devices. For use with SetBitMode
Definition: FTD2XX_NET.cs:568
Class wrapper for FTD2XX.DLL
Definition: FTD2XX_NET.cs:40
byte ADDriveCurrent
Determines the AD pins drive current in mA. Valid values are FT_DRIVE_CURRENT_4MA, FT_DRIVE_CURRENT_8MA, FT_DRIVE_CURRENT_12MA or FT_DRIVE_CURRENT_16MA
Definition: FTD2XX_NET.cs:1801
EEPROM structure specific to FT2232H devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1422
byte InvertDTR
Inverts the sense of the DTR line
Definition: FTD2XX_NET.cs:1877
EEPROM structure specific to FT232B and FT245B devices. Inherits from FT_EEPROM_DATA.
Definition: FTD2XX_NET.cs:1223
byte InvertTXD
Inverts the sense of the TXD line
Definition: FTD2XX_NET.cs:1861
byte Cbus6
Sets the function of the CBUS6 pin for FT232H devices. Valid values are FT_CBUS_TRISTATE, FT_CBUS_RXLED, FT_CBUS_TXLED, FT_CBUS_TXRXLED, FT_CBUS_PWREN, FT_CBUS_SLEEP, FT_CBUS_DRIVE_0, FT_CBUS_DRIVE_1, FT_CBUS_TXDEN, FT_CBUS_CLK24, FT_CBUS_CLK12, FT_CBUS_CLK6, FT_CBUS_BCD_CHARGER, FT_CBUS_BCD_CHARGER_N, FT_CBUS_VBUS_SENSE, FT_CBUS_BITBANG_WR, FT_CBUS_BITBANG_RD, FT_CBUS_TIME_STAMP, FT_CBUS_KEEP_AWAKE
Definition: FTD2XX_NET.cs:1857
byte IsVCP
Determines whether the VCP driver is loaded.
Definition: FTD2XX_NET.cs:1937
const byte FT_BIT_MODE_CBUS_BITBANG
CBUS bit-bang mode - only available on FT232R and FT232H
Definition: FTD2XX_NET.cs:597
Valid values for drive current options on FT2232H, FT4232H and FT232H devices.
Definition: FTD2XX_NET.cs:838