C#调用FT245RL接口函数

    技术2022-07-10  134

    FT245RL是一款USB芯片,本文主要介绍将FT245RL的函数引用到C#的类中。

    #region AID_dll文件 [DllImport("AID.dll")] static extern uint FT_ListDevices(); #endregion #region FTD2XX_dll文件 [DllImport("FTD2XX.dll")] public static extern FT_STATUS FT_Read(uint ftHandle, [MarshalAs(UnmanagedType.LPArray)] byte[] p_data, uint nBufferSize, ref uint lpBytesReturned); [DllImport("FTD2XX.dll")] public static extern FT_STATUS FT_Write(uint ftHandle, [MarshalAs(UnmanagedType.LPArray)] byte[] p_data, uint nBufferSize, ref uint lpBytesReturned); [DllImport("FTD2XX.dll")] public static extern FT_STATUS FT_Open(int deviceNumber, ref uint pHandle); [DllImport("FTD2XX.dll")] public static extern FT_STATUS FT_Close(uint ftHandle); [DllImport("FTD2XX.dll")] public static extern FT_STATUS FT_GetStatus(uint ftHandle, ref uint dwRxBytes, ref uint dwTxBytes, ref uint dwEventDWord); public partial class NativeConstants { /// FTD2XX_H -> /// Error generating expression: 值不能为空。 ///参数名: node public const string FTD2XX_H = ""; /// FTD2XX_API -> __declspec(dllimport) /// Error generating expression: Error generating function call. Operation not implemented public const string FTD2XX_API = "__declspec(dllimport)"; /// Warning: Generation of Method Macros is not supported at this time /// FT_SUCCESS -> "(status) ((status) == FT_OK)" public const string FT_SUCCESS = "(status) ((status) == FT_OK)"; /// FT_BAUD_300 -> 0x0000 public const int FT_BAUD_300 = 0; /// FT_BAUD_600 -> 0x0000 public const int FT_BAUD_600 = 0; /// FT_BAUD_1200 -> 0x0000 public const int FT_BAUD_1200 = 0; /// FT_BAUD_2400 -> 0x0000 public const int FT_BAUD_2400 = 0; /// FT_BAUD_4800 -> 0x0000 public const int FT_BAUD_4800 = 0; /// FT_BAUD_9600 -> 0x0000 public const int FT_BAUD_9600 = 0; /// FT_BAUD_14400 -> 0x0000 public const int FT_BAUD_14400 = 0; /// FT_BAUD_19200 -> 0x0000 public const int FT_BAUD_19200 = 0; /// FT_BAUD_38400 -> 0x0000 public const int FT_BAUD_38400 = 0; /// FT_BAUD_57600 -> 0x0000 public const int FT_BAUD_57600 = 0; /// FT_BAUD_115200 -> 0x0000 public const int FT_BAUD_115200 = 0; /// FT_BAUD_230400 -> 0x0000 public const int FT_BAUD_230400 = 0; /// FT_BAUD_460800 -> 0x0000 public const int FT_BAUD_460800 = 0; /// FT_BAUD_921600 -> 0x0000 public const int FT_BAUD_921600 = 0; /// Warning: Generation of Method Macros is not supported at this time /// FT_BITS_8 -> "(UCHAR) 8" public const string FT_BITS_8 = "(UCHAR) 8"; /// Warning: Generation of Method Macros is not supported at this time /// FT_BITS_7 -> "(UCHAR) 7" public const string FT_BITS_7 = "(UCHAR) 7"; /// Warning: Generation of Method Macros is not supported at this time /// FT_BITS_6 -> "(UCHAR) 6" public const string FT_BITS_6 = "(UCHAR) 6"; /// Warning: Generation of Method Macros is not supported at this time /// FT_BITS_5 -> "(UCHAR) 5" public const string FT_BITS_5 = "(UCHAR) 5"; /// Warning: Generation of Method Macros is not supported at this time /// FT_STOP_BITS_1 -> "(UCHAR) 0" public const string FT_STOP_BITS_1 = "(UCHAR) 0"; /// Warning: Generation of Method Macros is not supported at this time /// FT_STOP_BITS_1_5 -> "(UCHAR) 1" public const string FT_STOP_BITS_1_5 = "(UCHAR) 1"; /// Warning: Generation of Method Macros is not supported at this time /// FT_STOP_BITS_2 -> "(UCHAR) 2" public const string FT_STOP_BITS_2 = "(UCHAR) 2"; /// Warning: Generation of Method Macros is not supported at this time /// FT_PARITY_NONE -> "(UCHAR) 0" public const string FT_PARITY_NONE = "(UCHAR) 0"; /// Warning: Generation of Method Macros is not supported at this time /// FT_PARITY_ODD -> "(UCHAR) 1" public const string FT_PARITY_ODD = "(UCHAR) 1"; /// Warning: Generation of Method Macros is not supported at this time /// FT_PARITY_EVEN -> "(UCHAR) 2" public const string FT_PARITY_EVEN = "(UCHAR) 2"; /// Warning: Generation of Method Macros is not supported at this time /// FT_PARITY_MARK -> "(UCHAR) 3" public const string FT_PARITY_MARK = "(UCHAR) 3"; /// Warning: Generation of Method Macros is not supported at this time /// FT_PARITY_SPACE -> "(UCHAR) 4" public const string FT_PARITY_SPACE = "(UCHAR) 4"; /// FT_FLOW_NONE -> 0x0000 public const int FT_FLOW_NONE = 0; /// FT_FLOW_RTS_CTS -> 0x0100 public const int FT_FLOW_RTS_CTS = 256; /// FT_FLOW_DTR_DSR -> 0x0200 public const int FT_FLOW_DTR_DSR = 512; /// FT_FLOW_XON_XOFF -> 0x0400 public const int FT_FLOW_XON_XOFF = 1024; /// FT_PURGE_RX -> 1 public const int FT_PURGE_RX = 1; /// FT_PURGE_TX -> 2 public const int FT_PURGE_TX = 2; /// FT_EVENT_RXCHAR -> 1 public const int FT_EVENT_RXCHAR = 1; /// FT_EVENT_MODEM_STATUS -> 2 public const int FT_EVENT_MODEM_STATUS = 2; /// FT_DEFAULT_RX_TIMEOUT -> 300 public const int FT_DEFAULT_RX_TIMEOUT = 300; /// FT_DEFAULT_TX_TIMEOUT -> 300 public const int FT_DEFAULT_TX_TIMEOUT = 300; } public enum FT_STATUS { FT_OK, FT_INVALID_HANDLE, FT_DEVICE_NOT_FOUND, FT_DEVICE_NOT_OPENED, FT_IO_ERROR, FT_INSUFFICIENT_RESOURCES, } /// Return Type: void ///param0: DWORD->unsigned int ///param1: DWORD->unsigned int public delegate void PFT_EVENT_HANDLER(uint param0, uint param1); [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public struct OVERLAPPED { /// ULONG_PTR->unsigned int public uint Internal; /// ULONG_PTR->unsigned int public uint InternalHigh; /// Anonymous_7416d31a_1ce9_4e50_b1e1_0f2ad25c0196 public Anonymous1 Union1; /// HANDLE->void* public System.IntPtr hEvent; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)] public struct Anonymous1 { /// Anonymous_ac6e4301_4438_458f_96dd_e86faeeca2a6 [System.Runtime.InteropServices.FieldOffsetAttribute(0)] public Anonymous2 Struct1; /// PVOID->void* [System.Runtime.InteropServices.FieldOffsetAttribute(0)] public System.IntPtr Pointer; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public struct Anonymous2 { /// DWORD->unsigned int public uint Offset; /// DWORD->unsigned int public uint OffsetHigh; } public partial class NativeMethods { /// Return Type: FT_STATUS ///deviceNumber: int ///pHandle: FT_HANDLE* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_Open")] public static extern FT_STATUS FT_Open(int deviceNumber, ref uint pHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_Close")] public static extern FT_STATUS FT_Close(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///lpBuffer: LPVOID->void* ///nBufferSize: DWORD->unsigned int ///lpBytesReturned: LPDWORD->DWORD* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_Read")] public static extern FT_STATUS FT_Read(uint ftHandle, System.IntPtr lpBuffer, uint nBufferSize, ref uint lpBytesReturned); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///lpBuffer: LPVOID->void* ///nBufferSize: DWORD->unsigned int ///lpBytesWritten: LPDWORD->DWORD* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_Write")] public static extern FT_STATUS FT_Write(uint ftHandle, System.IntPtr lpBuffer, uint nBufferSize, ref uint lpBytesWritten); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///dwIoControlCode: DWORD->unsigned int ///lpInBuf: LPVOID->void* ///nInBufSize: DWORD->unsigned int ///lpOutBuf: LPVOID->void* ///nOutBufSize: DWORD->unsigned int ///lpBytesReturned: LPDWORD->DWORD* ///lpOverlapped: LPOVERLAPPED->_OVERLAPPED* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_IoCtl")] public static extern FT_STATUS FT_IoCtl(uint ftHandle, uint dwIoControlCode, System.IntPtr lpInBuf, uint nInBufSize, System.IntPtr lpOutBuf, uint nOutBufSize, ref uint lpBytesReturned, ref OVERLAPPED lpOverlapped); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///BaudRate: ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetBaudRate")] public static extern FT_STATUS FT_SetBaudRate(uint ftHandle, uint BaudRate); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///WordLength: UCHAR->unsigned char ///StopBits: UCHAR->unsigned char ///Parity: UCHAR->unsigned char [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetDataCharacteristics")] public static extern FT_STATUS FT_SetDataCharacteristics(uint ftHandle, byte WordLength, byte StopBits, byte Parity); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///FlowControl: USHORT->unsigned short ///XonChar: UCHAR->unsigned char ///XoffChar: UCHAR->unsigned char [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetFlowControl")] public static extern FT_STATUS FT_SetFlowControl(uint ftHandle, ushort FlowControl, byte XonChar, byte XoffChar); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_ResetDevice")] public static extern FT_STATUS FT_ResetDevice(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetDtr")] public static extern FT_STATUS FT_SetDtr(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_ClrDtr")] public static extern FT_STATUS FT_ClrDtr(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetRts")] public static extern FT_STATUS FT_SetRts(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_ClrRts")] public static extern FT_STATUS FT_ClrRts(uint ftHandle); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///pModemStatus: ULONG* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_GetModemStatus")] public static extern FT_STATUS FT_GetModemStatus(uint ftHandle, ref uint pModemStatus); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///EventChar: UCHAR->unsigned char ///EventCharEnabled: UCHAR->unsigned char ///ErrorChar: UCHAR->unsigned char ///ErrorCharEnabled: UCHAR->unsigned char [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetChars")] public static extern FT_STATUS FT_SetChars(uint ftHandle, byte EventChar, byte EventCharEnabled, byte ErrorChar, byte ErrorCharEnabled); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///Mask: ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_Purge")] public static extern FT_STATUS FT_Purge(uint ftHandle, uint Mask); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///ReadTimeout: ULONG->unsigned int ///WriteTimeout: ULONG->unsigned int [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetTimeouts")] public static extern FT_STATUS FT_SetTimeouts(uint ftHandle, uint ReadTimeout, uint WriteTimeout); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///dwRxBytes: DWORD* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_GetQueueStatus")] public static extern FT_STATUS FT_GetQueueStatus(uint ftHandle, ref uint dwRxBytes); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///Mask: DWORD->unsigned int ///Fun: PFT_EVENT_HANDLER [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_SetEventNotification")] public static extern FT_STATUS FT_SetEventNotification(uint ftHandle, uint Mask, PFT_EVENT_HANDLER Fun); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///dwEventDWord: DWORD* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_GetEventStatus")] public static extern FT_STATUS FT_GetEventStatus(uint ftHandle, ref uint dwEventDWord); /// Return Type: FT_STATUS ///ftHandle: FT_HANDLE->ULONG->unsigned int ///dwRxBytes: DWORD* ///dwTxBytes: DWORD* ///dwEventDWord: DWORD* [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "FT_GetStatus")] public static extern FT_STATUS FT_GetStatus(uint ftHandle, ref uint dwRxBytes, ref uint dwTxBytes, ref uint dwEventDWord); } #endregion
    Processed: 0.010, SQL: 9