00001 /** 00002 * \file UsbDirect.h 00003 * Routines for sending and receiving with a usb - rs485 adapter accessed directly 00004 * through driver. These are basically convenience routines for calling FTD2XX.dll 00005 * 00006 * The device numbers of usb devices are dependant on startup / installation order. 00007 * The only reliable way to open a particular usb dongle is to look at all devices 00008 * to determine the one with the correct serial number (which is unique) 00009 * 00010 * Normally you would use UsbDirect_DeviceCount and then UsbDirect_GetDeviceSerialNumber 00011 * to give a user a list of USB devices. The serial numbers can then be passed to AAComms_Init 00012 * 00013 * NOTE: Any open connections cannot be discovered using this library, so close all connections 00014 * before trying to enumerate the available Usb connections 00015 * 00016 * Copyright (C) 2006 RMSD Ltd 00017 */ 00018 #ifndef __USB_DIRECT_H 00019 #define __USB_DIRECT_H 00020 00021 //! Indicates the status of the USB connection 00022 typedef enum { 00023 udOK, //! No error 00024 udTIMEOUT, //! Function timed out 00025 udFAILED, //! Function failed 00026 udIOERROR, //! There was an IO error. Usually this occurs when the USB->RS485 00027 //! adapter is unplugged by a user 00028 udDEVICE_NOT_FOUND //! The specified USB device was not found 00029 } UD_STATUS; 00030 00031 // If you want to build these routines into a dll, then make sure __USBDIRECT_EXPORTS is defined 00032 #if defined(__USBDIRECT_EXPORTS) 00033 #define __DLL_EXPORT __export 00034 #elif defined(__USBDIRECT_IMPORTS) 00035 #define __DLL_EXPORT __import 00036 #else 00037 #define __DLL_EXPORT 00038 #endif 00039 00040 /** 00041 This routine writes the provided data to a serial port 00042 00043 \param handle Handle to the serial port 00044 \param lpBuf Pointer to data to transmit 00045 \param dwToWrite Size of data to send 00046 */ 00047 UD_STATUS __DLL_EXPORT UsbDirect_WriteBuffer( HANDLE handle, char *lpBuf, DWORD dwToWrite ); 00048 00049 /** 00050 This routine checks to see if a character has been received on the serial port. 00051 00052 \param handle Handle to the serial port 00053 \param lpBuf Pointer to memory to store received character (left unchanged if no data avaiable) 00054 \param WaitMsec The maximum amount of time (in milli seconds) to wait for a character 00055 */ 00056 UD_STATUS __DLL_EXPORT UsbDirect_WaitForChar( HANDLE handle, char *lpBuf, DWORD WaitMsec ); 00057 00058 /** 00059 This routine opens a usb - rs485 interface 00060 00061 \param devId This is the device number of the usb port. Use UsbDirect_SerialNumToDevNum to 00062 discover this number 00063 \param baud Baud rate to open port at 00064 00065 \returns INVALID_HANDLE_VALUE on error, otherwise the handle of the usb - 485 interface port 00066 */ 00067 HANDLE __DLL_EXPORT UsbDirect_Open( DWORD devId, int baud ); 00068 00069 /** 00070 Closes a previosly opened port 00071 00072 \param handle The value returned by a call to UsbDirect_Open 00073 */ 00074 void __DLL_EXPORT UsbDirect_Close( HANDLE handle ); 00075 00076 /** 00077 Finds the number of connected usb devices 00078 */ 00079 DWORD __DLL_EXPORT UsbDirect_DeviceCount( void ); 00080 00081 /** 00082 Description: Finds the serial number of a particular usb device 00083 00084 \param Index The index of the usb device. Must be less than UsbDirect_DeviceCount 00085 \param buf Storage for serial number. Must be at least 10 characters long 00086 */ 00087 UD_STATUS __DLL_EXPORT UsbDirect_GetDeviceSerialNumber( DWORD Index, char *buf ); 00088 00089 /** 00090 Gets the description of a particular usb device 00091 00092 \param Index The index of the usb device. Must be less than UsbDirect_DeviceCount 00093 \param buf Storage for serial number. Must be at least 10 characters long 00094 */ 00095 UD_STATUS __DLL_EXPORT UsbDirect_GetDeviceDescription( DWORD Index, char *buf ); 00096 00097 /** 00098 Finds a usb device that has the specified serial number 00099 00100 \param serialNum The serial number of the wanted usb device 00101 \param devNum Place to store the device number of the usb device (if it is found) 00102 */ 00103 UD_STATUS __DLL_EXPORT UsbDirect_SerialNumToDevNum( char *serialNum, DWORD *devNum ); 00104 00105 #endif 00106