OSDN Git Service

FX2/FX2.h: WAKEUPCS; FX2: PORTxCFG moved to FX2.h
[stock/stock.osdn.git] / FTDI / FTDI_win.h
1 // FTDI class, header file
2
3 #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
4 #include <windows.h>
5
6 #include "FTD2XX.h"
7
8 class FTDI
9 {
10 private:
11   FT_HANDLE handle;
12   FT_STATUS status;
13
14 public:
15   FTDI() : handle(NULL), status(FT_OK) {}
16
17   FT_STATUS list_devices(VOID * arg1, VOID * arg2, DWORD flags) {
18      status = FT_ListDevices(arg1, arg2, flags);
19      return status;
20   }
21   FT_STATUS open(int index) {
22      status = FT_Open(index, &handle);
23      return status;
24   }
25   FT_STATUS open_ex();  //OpenEx(PVOID, DWORD);
26   FT_STATUS close() {
27      status = FT_Close(handle);
28      handle = NULL;
29      return status;
30   }
31   bool get_device_info(FT_DEVICE * type, DWORD * id, char * SerialNumber, char * Description) {
32      status = FT_GetDeviceInfo(handle, type, id, SerialNumber, Description, NULL);
33      return (status == FT_OK);
34   }
35   inline int read(void * buffer, unsigned length) {
36      DWORD done_w;
37      status = FT_Read(handle, buffer, length, &done_w);
38      if (status == FT_OK)
39         return done_w;
40      return -1;
41   }
42   inline int write(const void * buffer, unsigned length) {
43      DWORD done_w;
44      status = FT_Write(handle, (void *)buffer, length, &done_w);
45      if (status == FT_OK)
46         return done_w;
47      return -1;
48   }
49 #if 0  // obsolete versions
50   inline FT_STATUS read_old(void * buffer, unsigned len, unsigned & done) {
51      DWORD done_w;
52      status = FT_Read(handle, buffer, len, &done_w);
53      done = done_w;
54      return status;
55   }
56   inline FT_STATUS write_old(const void * buffer, unsigned len, unsigned & done) {
57      DWORD done_w;
58      status = FT_Write(handle, (void *)buffer, len, &done_w);
59      done = done_w;
60      return status;
61   }
62 #endif
63   FT_STATUS reset_device() {
64      status = FT_ResetDevice(handle);
65      return status;
66   }
67   FT_STATUS reset_port() {
68      status = FT_ResetPort(handle);
69      return status;
70   }
71   FT_STATUS cycle_port() {
72      status = FT_CyclePort(handle);
73      return status;
74   }
75   FT_STATUS purge(ULONG mode) {
76      status = FT_Purge(handle, mode);
77      return status;
78   }
79   UCHAR     get_bit_mode() {
80      UCHAR byte;
81      status = FT_GetBitMode(handle, &byte);
82      return byte;
83   }
84   bool set_bit_mode(UCHAR mask, UCHAR mode) {
85      status = FT_SetBitMode(handle, mask, mode);
86      return (status == FT_OK);
87   }
88   // Rx, Tx timeout duration in ms
89   FT_STATUS set_timeouts(ULONG rx, ULONG tx) {
90      status = FT_SetTimeouts(handle, rx, tx);
91      return status;
92   }
93   DWORD     get_queue_status() { // get number of bytes in rx queue
94      DWORD rx_bytes;
95      status = FT_GetQueueStatus(handle, &rx_bytes);
96      return rx_bytes;
97   }
98   FT_STATUS get_status(DWORD * RxBytes, DWORD * TxBytes, DWORD * Event) {
99      status = FT_GetStatus(handle, RxBytes, TxBytes, Event);
100      return status;
101   }
102   bool set_baud_rate(unsigned long baud_rate) {
103      status = FT_SetBaudRate(handle, baud_rate);
104      return (status == FT_OK);
105   }
106   FT_STATUS set_divisor(USHORT divisor) {
107      status = FT_SetDivisor(handle, divisor);
108      return status;
109   }
110   FT_STATUS set_latency_timer(UCHAR latency) {
111      status = FT_SetLatencyTimer(handle, latency);
112      return status;
113   }
114   UCHAR     get_latency_timer() {
115      UCHAR latency;
116      status = FT_GetLatencyTimer(handle, &latency);
117      if (status != FT_OK)
118         latency = 0;
119      return latency;
120   }
121   DWORD     get_library_version() {
122      DWORD version;
123      status = FT_GetLibraryVersion(&version);
124      if (status != FT_OK)
125         version = 0;
126      return version;
127   }
128   DWORD     get_driver_version() {
129      DWORD version;
130      status = FT_GetDriverVersion(handle, &version);
131      if (status != FT_OK)
132         version = 0;
133      return version;
134   }
135   FT_STATUS set_usb_parameters(ULONG InTransferSize, ULONG OutTransferSize) {
136      status = FT_SetUSBParameters(handle, InTransferSize, OutTransferSize);
137      return status;
138   }
139   FT_STATUS set_event_notification(DWORD EventMask, PVOID hEvent) {
140      status = FT_SetEventNotification(handle, EventMask, hEvent);
141      return status;
142   }
143   FT_STATUS set_reset_pipe_retry_count(DWORD count) {
144      status = FT_SetResetPipeRetryCount(handle, count);
145      return status;
146   }
147   FT_STATUS set_flow_control(USHORT usFlowControl, UCHAR uXon, UCHAR uXoff) {
148      status = FT_SetFlowControl(handle, usFlowControl, uXon, uXoff);
149      return status;
150   }
151   bool set_flow_control_off() {
152      status = FT_SetFlowControl(handle, FT_FLOW_NONE, 0, 0);
153      return (status == FT_OK);
154   }
155   bool set_flow_control_RTS_CTS() {
156      status = FT_SetFlowControl(handle, FT_FLOW_RTS_CTS, 0, 0);
157      return (status == FT_OK);
158   }
159   FT_STATUS set_data_characteristics(UCHAR uWordLength, UCHAR uStopBits, UCHAR uParity) {
160      status = FT_SetDataCharacteristics(handle, uWordLength, uStopBits, uParity);
161      return status;
162   }
163   bool set_serial(int data_bits, char parity, int stop_bits) {
164      UCHAR e_data;
165      switch (data_bits) {
166         case 7:  e_data = FT_BITS_7; break;
167         case 8:  e_data = FT_BITS_8; break;
168         default: return false;
169      }
170      UCHAR e_stop;
171      switch (stop_bits) {
172         case 1:  e_stop = FT_STOP_BITS_1;  break;
173         case 2:  e_stop = FT_STOP_BITS_2;  break;
174         default: return false;
175      }
176      UCHAR e_parity;
177      switch (parity) {
178         case 'N': e_parity = FT_PARITY_NONE;  break;
179         case 'O': e_parity = FT_PARITY_ODD;   break;
180         case 'E': e_parity = FT_PARITY_EVEN;  break;
181         case 'M': e_parity = FT_PARITY_MARK;  break;
182         case 'S': e_parity = FT_PARITY_SPACE; break;
183         default: return false;
184      }
185      status = FT_SetDataCharacteristics(handle, e_data, e_stop, e_parity);
186      return (status == FT_OK);
187   }
188   unsigned  get_modem_status() {
189      DWORD ModemStatus;
190      status = FT_GetModemStatus(handle, &ModemStatus);
191      return ModemStatus;
192   }
193   bool set_dtr(bool on) {
194      if (on)
195         status = FT_SetDtr(handle);
196      else
197         status = FT_ClrDtr(handle);
198      return (status == FT_OK);
199   }
200   bool set_rts(bool on) {
201      if (on)
202         status = FT_SetRts(handle);
203      else
204         status = FT_ClrRts(handle);
205      return (status == FT_OK);
206   }
207   // raw EEPROM interface
208   int eeprom_read(unsigned addr) {
209      WORD value;
210      status = FT_ReadEE(handle, addr, &value);
211      if (status == FT_OK)
212         return value;
213      else
214         return -1;
215   }
216   bool eeprom_write(unsigned addr, unsigned short value) {
217      status = FT_WriteEE(handle, addr, value);
218      return (status == FT_OK);
219   }
220   // old EEPROM interface
221   bool eeprom_read_parse(PFT_PROGRAM_DATA pData) {
222      status = FT_EE_Read(handle, pData);
223      return (status == FT_OK);
224   }
225   bool eeprom_write(const PFT_PROGRAM_DATA pData) {
226      status = FT_EE_Program(handle, pData);
227      return (status == FT_OK);
228   }
229   // new EEPROM interface
230   bool eeprom_read(void * data, unsigned data_size, char * Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber) {
231      status = FT_EEPROM_Read(handle, data, data_size, Manufacturer, ManufacturerId, Description, SerialNumber);
232      return (status == FT_OK);
233   }
234   bool eeprom_write(void * data, unsigned data_size, char * Manufacturer, char *ManufacturerId, char *Description, char *SerialNumber) {
235      status = FT_EEPROM_Program(handle, data, data_size, Manufacturer, ManufacturerId, Description, SerialNumber);
236      return (status == FT_OK);
237   }
238   // EEPROM User Area
239   int eeprom_ua_size() {
240      DWORD value;
241      status = FT_EE_UASize(handle, &value);
242      if (status == FT_OK)
243         return value;
244      else
245         return -1;
246   }
247   int eeprom_ua_read(unsigned char * data, unsigned length) {
248      DWORD len;
249      status = FT_EE_UARead(handle, data, length, &len);
250      if (status == FT_OK)
251         return len;
252      else
253         return -1;
254   }
255   bool eeprom_ua_write(const unsigned char * data, unsigned length) {
256      status = FT_EE_UAWrite(handle, (PUCHAR)data, length);
257      return (status == FT_OK);
258   }
259
260
261
262 #if 0 // these functions hang FTDI version > 2.8 on Vista/W7
263 FT_STATUS FTDI::purge_rx()
264 {
265   for(unsigned i = 0; i < 100; ++i)
266     if (FT_StopInTask(handle) == FT_OK)
267       break;
268
269   status = FT_Purge(handle, FT_PURGE_RX);
270
271   for(unsigned i = 0; i < 100; ++i)
272     if (FT_RestartInTask(handle) == FT_OK)
273       break;
274
275   return status;
276 }
277 FT_STATUS stop_rx()
278 {
279   status = FT_StopInTask(handle);
280   return status;
281 }
282 FT_STATUS restart_rx()
283 {
284   status = FT_RestartInTask(handle);
285   return status;
286 }
287 #endif
288   
289
290 public:
291   operator bool() const { return (status == FT_OK); }
292   // returns a short description of the status
293   const char * status_msg() const
294   {
295      const char * mesg;
296      switch(status)
297      {
298      case FT_OK:
299         mesg = "OK"; break;
300      case FT_INVALID_HANDLE:
301         mesg = "INVALID_HANDLE"; break;
302      case FT_DEVICE_NOT_FOUND:
303         mesg = "DEVICE_NOT_FOUND"; break;
304      case FT_DEVICE_NOT_OPENED:
305         mesg = "DEVICE_NOT_OPENED"; break;
306      case FT_IO_ERROR:
307         mesg = "IO_ERROR"; break;
308      case FT_INSUFFICIENT_RESOURCES:
309         mesg = "INSUFFICIENT_RESOURCES"; break;
310      case FT_INVALID_PARAMETER:
311         mesg = "INVALID_PARAMETER"; break;
312      case FT_INVALID_BAUD_RATE:
313         mesg = "INVALID_BAUD_RATE"; break;
314      case FT_DEVICE_NOT_OPENED_FOR_ERASE:
315         mesg = "DEVICE_NOT_OPENED_FOR_ERASE"; break;
316      case FT_DEVICE_NOT_OPENED_FOR_WRITE:
317         mesg = "DEVICE_NOT_OPENED_FOR_WRITE"; break;
318      case FT_FAILED_TO_WRITE_DEVICE:
319         mesg = "FAILED_TO_WRITE_DEVICE"; break;
320      case FT_EEPROM_READ_FAILED:
321         mesg = "EEPROM_READ_FAILED"; break;
322      case FT_EEPROM_WRITE_FAILED:
323         mesg = "EEPROM_ERASE_FAILED"; break;
324      case FT_EEPROM_ERASE_FAILED:
325         mesg = "EEPROM_ERASE_FAILED"; break;
326      case FT_EEPROM_NOT_PRESENT:
327         mesg = "EEPROM_NOT_PRESENT"; break;
328      case FT_EEPROM_NOT_PROGRAMMED:
329         mesg = "EEPROM_NOT_PROGRAMMED"; break;
330      case FT_INVALID_ARGS:
331         mesg = "INVALID_ARGS"; break;
332      case FT_NOT_SUPPORTED:
333         mesg = "NOT_SUPPORTED"; break;
334      case FT_OTHER_ERROR:
335         mesg = "OTHER_ERROR"; break;
336      default:
337         mesg = NULL;
338      }
339      return mesg;
340   }
341   static const char * device_type(FT_DEVICE type) {
342      switch (type) {
343         case FT_DEVICE_232H:  return "FT232H";
344         case FT_DEVICE_4232H: return "FT4232H";
345         case FT_DEVICE_2232H: return "FT2232H";
346         case FT_DEVICE_232R:  return "FT232R";
347         case FT_DEVICE_2232C: return "FT2232C/L/D";
348         case FT_DEVICE_BM:    return "FT232BM";
349         case FT_DEVICE_AM:    return "FT8U232AM";
350         case FT_DEVICE_X_SERIES:  return "FT X";
351         default: return NULL;
352      }
353   }
354   bool is_open() const {
355      return (handle != NULL);
356   }
357 };
358
359 /*
360 FT_STATUS
361 FT_OK = 0
362 FT_INVALID_HANDLE = 1
363 FT_DEVICE_NOT_FOUND = 2
364 FT_DEVICE_NOT_OPENED = 3
365 FT_IO_ERROR = 4
366 FT_INSUFFICIENT_RESOURCES = 5
367 FT_INVALID_PARAMETER = 6
368 Flags (see FT_OpenEx)
369 FT_OPEN_BY_SERIAL_NUMBER = 1
370 FT_OPEN_BY_DESCRIPTION = 2
371 Flags (see FT_ListDevices)
372 FT_LIST_NUMBER_ONLY = 0x80000000
373 FT_LIST_BY_INDEX = 0x40000000
374 FT_LIST_ALL = 0x20000000
375 Word Length (see FT_SetDataCharacteristics)
376 FT_BITS_8 = 8
377 FT_BITS_7 = 7
378 Stop Bits (see FT_SetDataCharacteristics)
379 FT_STOP_BITS_1 = 0
380 FT_STOP_BITS_2 = 2
381 Parity (see FT_SetDataCharacteristics)
382 FT_PARITY_NONE = 0
383 FT_PARITY_ODD = 1
384 FT_PARITY_EVEN = 2
385 FT_PARITY_MARK = 3
386 FT_PARITY_SPACE = 4
387 Flow Control (see FT_SetFlowControl)
388 FT_FLOW_NONE = 0x0000
389 FT_FLOW_RTS_CTS = 0x0100
390 FT_FLOW_DTR_DSR = 0x0200
391 FT_FLOW_XON_XOFF = 0x0400
392 Purge RX and TX buffers (see FT_Purge)
393 FT_PURGE_RX = 1
394 FT_PURGE_TX = 2
395 FT_ListDevices
396 Description
397 Get information concerning the devices currently connected. This function can return
398 such information as the number of devices connected, and device strings such as serial
399 number and product description.
400 Syntax FT_STATUS FT_ListDevices ( PVOID pvArg1,PVOID pvArg2, DWORD dwFlags )
401 Parameters
402 pvArg1 PVOID: Meaning depends on dwFlags
403 pvArg2 PVOID: Meaning depends on dwFlags
404 dwFlags DWORD: Determines format of returned information
405 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
406 Remarks
407 This function can be used in a number of ways to return different types of information.
408 In its simplest form, it can be used to return the number of devices currently connected.
409 If FT_LIST_NUMBER_ONLY bit is set in dwFlags, the parameter pvArg1 is interpreted
410 as a pointer to a DWORD location to store the number of devices currently connected.
411 It can be used to return device string information. If FT_OPEN_BY_SERIAL_NUMBER
412 bit is set in dwFlags, the serial number string will be returned from this function. If
413 FT_OPEN_BY_DESCRIPTION bit is set in dwFlags, the product description string will
414 be returned from this function. If neither of these bits is set, the serial number string will
415 be returned by default.
416 It can be used to return device string information for a single device. If
417 FT_LIST_BY_INDEX bit is set in dwFlags, the parameter pvArg1 is interpreted as the
418 index of the device, and the parameter pvArg2 is interpreted as a pointer to a buffer to
419 contain the appropriate string. Indexes are zero-based, and the error code
420 FT_DEVICE_NOT_FOUND is returned for an invalid index.
421 It can be used to return device string information for all connected devices. If
422 FT_LIST_ALL bit is set in dwFlags, the parameter pvArg1 is interpreted as a pointer to an
423 array of pointers to buffers to contain the appropriate strings, and the parameter pvArg2 is
424 interpreted as a pointer to a DWORD location to store the number of devices currently
425 connected. Note that, for pvArg1, the last entry in the array of pointers to buffers should
426 be a NULL pointer so the array will contain one more location than the number of
427 devices connected.
428 Examples
429 Sample code shows how to get the number of devices currently connected.
430 FT_STATUS ftStatus;
431 DWORD numDevs;
432 ftStatus = FT_ListDevices(&numDevs,NULL,FT_LIST_NUMBER_ONLY);
433 if (ftStatus == FT_OK) {
434 // FT_ListDevices OK, number of devices connected is in numDevs
435 }
436 else {
437 // FT_ListDevices failed
438 }
439 This sample shows how to get the serial number of the first device found. Note that
440 indexes are zero-based. If more than one device is connected, incrementing devIndex
441 will get the serial number of each connected device in turn.
442 FT_STATUS ftStatus;
443 DWORD devIndex = 0;
444 char Buffer[16];
445 ftStatus =
446 FT_ListDevices((PVOID)devIndex,Buffer,FT_LIST_BY_INDEX|FT_OPEN_BY_SERIAL_N
447 UMBER);
448 if (FT_SUCCESS(ftStatus)) {
449 // FT_ListDevices OK, serial number is in Buffer
450 }
451 else {
452 // FT_ListDevices failed
453 }
454 This sample shows how to get the product descriptions of all the devices currently
455 connected.
456 FT_STATUS ftStatus;
457 char *BufPtrs[3]; // pointer to array of 3 pointers
458 char Buffer1[64]; // buffer for product description of first
459 device found
460 char Buffer2[64]; // buffer for product description of second
461 device
462 DWORD numDevs;
463 // initialize the array of pointers
464 BufPtrs[0] = Buffer1;
465 BufPtrs[1] = Buffer2;
466 BufPtrs[2] = NULL; // last entry should be NULL
467 ftStatus =
468 FT_ListDevices(BufPtrs,&numDevs,FT_LIST_ALL|FT_OPEN_BY_DESCRIPTION);
469 if (FT_SUCCESS(ftStatus)) {
470 // FT_ListDevices OK, product descriptions are in Buffer1 and Buffer2,
471 and
472 // numDevs contains the number of devices connected
473 }
474 else {
475 // FT_ListDevices failed
476 }
477 FT_Open
478 Description Open the device and return a handle which will be used for subsequent accesses.
479 Syntax FT_STATUS FT_Open ( PVOID pvDevice, FT_HANDLE *ftHandle )
480 Parameters
481 pvDevice ULONG: Must be 0 if only one device is attached. For multiple devices 1, 2 etc.
482 ftHandle FT_HANDLE *: Pointer to a variable of type FT_HANDLE where the handle will be
483 stored. This handle must be used to access the device.
484 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
485 Remarks
486 Although this function can be used to open multiple devices by setting pvDevice to 0, 1, 2
487 etc. there is no ability to open a specific device. To open named devices, use the function
488 FT_OpenEx.
489 Example
490 This sample shows how to open a device.
491 FT_HANDLE ftHandle;
492 FT_STATUS ftStatus;
493 ftStatus = FT_Open(0,&ftHandle);
494 if (ftStatus == FT_OK) {
495 // FT_Open OK, use ftHandle to access device
496 }
497 else {
498 // FT_Open failed
499 }
500 FT_OpenEx
501 Description
502 Open the named device and return a handle which will be used for subsequent accesses.
503 The device name can be its serial number or device description.
504 Syntax FT_STATUS FT_OpenEx ( PVOID pvArg1, DWORD dwFlags, FT_HANDLE
505 *ftHandle )
506 Parameters
507 pvArg1 PVOID: Meaning depends on dwFlags, but it will normally be interpreted as a pointer to
508 a null terminated string.
509 dwFlags DWORD: FT_OPEN_BY_SERIAL_NUMBER or FT_OPEN_BY_DESCRIPTION.
510 ftHandle FT_HANDLE *: Pointer to a variable of type FT_HANDLE where the handle will be
511 stored. This handle must be used to access the device.
512 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
513 Remarks
514 This function should be used to open multiple devices. Multiple devices can be opened at
515 the same time if they can be distinguished by serial number or device description.
516 Example
517 These samples show how to open two devices simultaneously.
518 Suppose one device has serial number "FT000001", and the other has serial number
519 "FT999999".
520 FT_STATUS ftStatus;
521 FT_HANDLE ftHandle1;
522 FT_HANDLE ftHandle2;
523 ftStatus = FT_OpenEx("FT000001",FT_OPEN_BY_SERIAL_NUMBER,&ftHandle1);
524 if (ftStatus == FT_OK) {
525 // FT_OpenEx OK, device with serial number "FT000001" is open
526 }
527 else {
528 // FT_OpenEx failed
529 }
530 ftStatus = FT_OpenEx("FT999999",FT_OPEN_BY_SERIAL_NUMBER,&ftHandle2);
531 if (ftStatus == FT_OK) {
532 // FT_OpenEx OK, device with serial number "FT999999" is open
533 }
534 else {
535 // FT_OpenEx failed
536 }
537 Suppose one device has description "USB HS SERIAL CONVERTER", and the other
538 has description "USB PUMP CONTROLLER".
539 FT_STATUS ftStatus;
540 FT_HANDLE ftHandle1;
541 FT_HANDLE ftHandle2;
542 ftStatus = FT_OpenEx("USB HS SERIAL
543 CONVERTER",FT_OPEN_BY_DESCRIPTION,&ftHandle1);
544 if (ftStatus == FT_OK) {
545 // FT_OpenEx OK, device with description "USB HS SERIAL CONVERTER"
546 is open
547 }
548 else {
549 // FT_OpenEx failed
550 }
551 ftStatus = FT_OpenEx("USB PUMP
552 CONTROLLER",FT_OPEN_BY_DESCRIPTION,&ftHandle2);
553 if (ftStatus == FT_OK) {
554 // FT_OpenEx OK, device with description "USB PUMP CONTROLLER" is
555 open
556 }
557 else {
558 // FT_OpenEx failed
559 }
560 FT_ResetDevice
561 Description This function sends a reset command to the device.
562 Syntax FT_STATUS FT_ResetDevice ( FT_HANDLE ftHandle )
563 Parameters
564 ftHandle FT_HANDLE: handle of the device to reset.
565 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
566 FT_SetBaudRate
567 Description This function sets the baud rate for the device.
568 Syntax FT_STATUS FT_SetBaudRate ( FT_HANDLE ftHandle, DWORD dwBaudRate )
569 Parameters
570 ftHandle FT_HANDLE: handle of the device.
571 dwBaudRate DWORD: Baud rate.
572 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
573 FT_SetDivisor
574 Description
575 This function sets the baud rate for the device. It is used to set non-standard baud rates.
576 Syntax FT_STATUS FT_SetDivisor ( FT_HANDLE ftHandle, USHORT usDivisor )
577 Parameters
578 ftHandle FT_HANDLE: handle of the device.
579 usDivisor USHORT: Divisor.
580 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
581 Remarks
582 The application note "Setting Baud rates for the FT8U232AM", which is available on our
583 web site
584 www.ftdi.co.uk , describes how to calculate the divisor for a non standard baud rate.
585 Example
586 Suppose we want to set a baud rate of 5787 baud. A simple calculation suggests that a
587 divisor of 4206 should work.
588 FT_HANDLE ftHandle; // handle of device obtained from FT_Open or
589 FT_OpenEx
590 FT_STATUS ftStatus;
591 ftStatus = FT_SetDivisor(ftHandle,0x4206);
592 if (ftStatus == FT_OK) {
593 // FT_SetDivisor OK, baud rate has been set to 5787 baud
594 }
595 else {
596 // FT_SetDivisor failed
597 }
598 FT_Purge
599 Description This function purges the receive and transmit buffers in the device.
600 Syntax FT_STATUS FT_Purge ( FT_HANDLE ftHandle, DWORD dwMask )
601 Parameters
602 ftHandle FT_HANDLE: handle of the device.
603 dwMask DWORD: Any combination of FT_PURGE_RX and FT_PURGE_TX.
604 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
605 FT_SetTimeouts
606 Description This function sets the read and write timeouts for the device.
607 Syntax FT_STATUS FT_SetTimeouts ( FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout )
608 Parameters
609 ftHandle FT_HANDLE: handle of the device.
610 dwReadTimeout DWORD: Read timeout in milliseconds.
611 dwWriteTimeout DWORD: Write timeout in milliseconds.
612 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
613 FT_GetQueueStatus
614 Description Gets the number of characters in the receive queue.
615 Syntax FT_STATUS FT_GetQueueStatus ( FT_HANDLE ftHandle, LPDWORD lpdwAmountInRxQueue )
616 Parameters
617 ftHandle FT_HANDLE: handle of the device to read.
618 lpdwAmountInRxQueue LPDWORD: Pointer to a variable of type DWORD which receives the
619 number of characters in the receive queue.
620 Return Value FT_STATUS: FT_OK if successful, otherwise the return value is an FT error code.
621 */