⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siusbxp.pas

📁 用DELPHI编写的与C8051F32X进行USB通讯程序
💻 PAS
字号:
unit SIUSBXP;
{**************************************************************************}
{                                                                          }
{    This C DLL header file first (automatic) conversion generated by:     }
{    HeadConv 4.0 (c) 2000 by Bob Swart (aka Dr.Bob - www.drbob42.com)     }
{      Final Delphi-Jedi (Darth) command-line units edition                }
{                                                                          }
{    Generated Date:  2008-3-14                                            }
{    Generated var Time: M 08:08:45                                              }
{                                                                          }
{**************************************************************************}

interface
uses
{$IFDEF WIN32}
  Windows;
{$ELSE}
  Wintypes, WinProcs;
{$ENDIF}


{/// The following ifdef block is the standard way of creating macros which make exporting }
{/// from a DLL simpler. All files within this DLL are compiled with the SISiUSB_EXPORTS }
{/// symbol defined on the command line. this symbol should not be defined on any project }
{/// that uses this DLL. This way any other project whose source files include this file see }
{/// functions as being imported from a DLL, wheras this DLL sees symbols }
{/// defined with this macro as being exported. }


{/// GetProductString() function flags }
const
  SI_RETURN_SERIAL_NUMBER = $00;
const
  SI_RETURN_DESCRIPTION = $01;
const
  SI_RETURN_LINK_NAME = $02;
const
  SI_RETURN_VID = $03;
const
  SI_RETURN_PID = $04;


{/// Return codes }
const
  SI_SUCCESS = $00;
const
  SI_DEVICE_NOT_FOUND = $F;
const
  SI_INVALID_HANDLE = $01;
const
  SI_READ_ERROR = $02;
const
  SI_RX_QUEUE_NOT_READY = $03;
const
  SI_WRITE_ERROR = $04;
const
  SI_RESET_ERROR = $05;
const
  SI_INVALID_PARAMETER = $06;
const
  SI_INVALID_REQUEST_LENGTH = $07;
const
  SI_DEVICE_IO_FAILED = $08;
const
  SI_INVALID_BAUDRATE = $09;
const
  SI_FUNCTION_NOT_SUPPORTED = $0a;
const
  SI_GLOBAL_DATA_ERROR = $0b;
const
  SI_SYSTEM_ERROR_CODE = $0c;
const
  SI_READ_TIMED_OUT = $0d;
const
  SI_WRITE_TIMED_OUT = $0e;

{/// RX Queue status flags }
const
  SI_RX_NO_OVERRUN = $00;
{/// 7/27/05 }
{/// added SI_RX_EMPTY (same as SI_RX_NO_OVERRUN) }
const
  SI_RX_EMPTY = $00;
const
  SI_RX_OVERRUN = $01;
const
  SI_RX_READY = $02;

{/// Buffer size limits }
const
  SI_MAX_DEVICE_STRLEN = 256;
const
  SI_MAX_READ_SIZE = 4096*16;
const
  SI_MAX_WRITE_SIZE = 4096;

{/// Type definitions }
{/// Type definitions }
type
  SI_STATUS = Integer;
  SI_DEVICE_STRING = array[0..SI_MAX_DEVICE_STRLEN] of char;
  LPVOID = Pointer;

{/// Input and Output pin Characteristics }
const
  SI_HELD_INACTIVE = $00;
const
  SI_HELD_ACTIVE = $01;
const
  SI_FIRMWARE_CONTROLLED = $02;
const
  SI_RECEIVE_FLOW_CONTROL = $02;
const
  SI_TRANSMIT_ACTIVE_SIGNAL = $03;

const
  SI_STATUS_INPUT = $00;
const
  SI_HANDSHAKE_LINE = $01; {// 01}


{/// Mask and Latch value bit definitions }
const
  SI_GPIO_0 = $01;
const
  SI_GPIO_1 = $02;
const
  SI_GPIO_2 = $04;
const
  SI_GPIO_3 = $08;

{/// GetDeviceVersion() return codes }
const
  SI_CP2101_VERSION = $01;
const
  SI_CP2102_VERSION = $02;
const
  SI_CP2103_VERSION = $03;



var
  SI_GetNumDevices: function(lpdwNumDevices: LPDWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_GetProductString: function(dwDeviceNum: DWORD;
                                lpvDeviceString: LPVOID;
                                dwFlags: DWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_Open: function(dwDevice: DWORD;
                    cyHandle: PHandle): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_Close: function(var cyHandle: THandle): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_Read: function(cyHandle: THandle; 
                    lpBuffer: LPVOID;
                    dwBytesToRead: DWORD;
                    lpdwBytesReturned: LPDWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_Write: function(cyHandle: THandle; 
                     lpBuffer: LPVOID;
                     dwBytesToWrite: DWORD;
                     lpdwBytesWritten: LPDWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_DeviceIOControl: function(cyHandle: THandle; 
                               dwIoControlCode: DWORD;
                               lpInBuffer: LPVOID;
                               dwBytesToRead: DWORD;
                               lpOutBuffer: LPVOID;
                               dwBytesToWrite: DWORD;
                               lpdwBytesSucceeded: LPDWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_FlushBuffers: function(cyHandle: THandle; 
                            FlushTransmit: BYTE; 
                            FlushReceive: BYTE): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetTimeouts: function(dwReadTimeout: DWORD;
                           dwWriteTimeout: DWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_GetTimeouts: function(lpdwReadTimeout: PLongInt;
                           lpdwWriteTimeout: PLongInt): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_CheckRXQueue: function(cyHandle: THandle; 
                            lpdwNumBytesInQueue: LPDWORD;
                            lpdwQueueStatus: LPDWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetBaudRate: function(cyHandle: THandle; 
                           dwBaudRate: DWORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetBaudDivisor: function(cyHandle: THandle; 
                              wBaudDivisor: WORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetLineControl: function(cyHandle: THandle; 
                              wLineControl: WORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetFlowControl: function(cyHandle: THandle; 
                              bCTS_MaskCode: BYTE; 
                              bRTS_MaskCode: BYTE; 
                              bDTR_MaskCode: BYTE; 
                              bDSR_MaskCode: BYTE; 
                              bDCD_MaskCode: BYTE; 
                              bFlowXonXoff: Bool): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_GetModemStatus: function(cyHandle: THandle; 
                              ModemStatus: PBYTE): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_SetBreak: function(cyHandle: THandle; 
                        wBreakState: WORD): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_ReadLatch: function(cyHandle: THandle; 
                         lpbLatch: PBYTE): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};


var
  SI_WriteLatch: function(cyHandle: THandle; 
                          bMask: BYTE; 
                          bLatch: BYTE): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF};



var
  SI_GetPartNumber: function(cyHandle: THandle; 
                             lpbPartNum: PBYTE): SI_STATUS {$IFDEF WIN32} stdcall {$ENDIF}; 


var
  DLLLoaded: Boolean { is DLL (dynamically) loaded already? }
    {$IFDEF WIN32} = False; {$ENDIF}

implementation

var
  SaveExit: pointer;
  DLLHandle: THandle;
{$IFNDEF MSDOS}
  ErrorMode: Integer;
{$ENDIF}

  procedure NewExit; far;
  begin
    ExitProc := SaveExit;
    FreeLibrary(DLLHandle)
  end {NewExit};

procedure LoadDLL;
begin
  if DLLLoaded then Exit;
{$IFNDEF MSDOS}
  ErrorMode := SetErrorMode($8000{SEM_NoOpenFileErrorBox});
{$ENDIF}
  DLLHandle := LoadLibrary('SIUSBXP.DLL');
  if DLLHandle >= 32 then
  begin
    DLLLoaded := True;
    SaveExit := ExitProc;
    ExitProc := @NewExit;
    @SI_GetNumDevices := GetProcAddress(DLLHandle,'SI_GetNumDevices');
  {$IFDEF WIN32}
    Assert(@SI_GetNumDevices <> nil);
  {$ENDIF}
    @SI_GetProductString := GetProcAddress(DLLHandle,'SI_GetProductString');
  {$IFDEF WIN32}
    Assert(@SI_GetProductString <> nil);
  {$ENDIF}
    @SI_Open := GetProcAddress(DLLHandle,'SI_Open');
  {$IFDEF WIN32}
    Assert(@SI_Open <> nil);
  {$ENDIF}
    @SI_Close := GetProcAddress(DLLHandle,'SI_Close');
  {$IFDEF WIN32}
    Assert(@SI_Close <> nil);
  {$ENDIF}
    @SI_Read := GetProcAddress(DLLHandle,'SI_Read');
  {$IFDEF WIN32}
    Assert(@SI_Read <> nil);
  {$ENDIF}
    @SI_Write := GetProcAddress(DLLHandle,'SI_Write');
  {$IFDEF WIN32}
    Assert(@SI_Write <> nil);
  {$ENDIF}
    @SI_DeviceIOControl := GetProcAddress(DLLHandle,'SI_DeviceIOControl');
  {$IFDEF WIN32}
    Assert(@SI_DeviceIOControl <> nil);
  {$ENDIF}
    @SI_FlushBuffers := GetProcAddress(DLLHandle,'SI_FlushBuffers');
  {$IFDEF WIN32}
    Assert(@SI_FlushBuffers <> nil);
  {$ENDIF}
    @SI_SetTimeouts := GetProcAddress(DLLHandle,'SI_SetTimeouts');
  {$IFDEF WIN32}
    Assert(@SI_SetTimeouts <> nil);
  {$ENDIF}
    @SI_GetTimeouts := GetProcAddress(DLLHandle,'SI_GetTimeouts');
  {$IFDEF WIN32}
    Assert(@SI_GetTimeouts <> nil);
  {$ENDIF}
    @SI_CheckRXQueue := GetProcAddress(DLLHandle,'SI_CheckRXQueue');
  {$IFDEF WIN32}
    Assert(@SI_CheckRXQueue <> nil);
  {$ENDIF}
    @SI_SetBaudRate := GetProcAddress(DLLHandle,'SI_SetBaudRate');
  {$IFDEF WIN32}
    Assert(@SI_SetBaudRate <> nil);
  {$ENDIF}
    @SI_SetBaudDivisor := GetProcAddress(DLLHandle,'SI_SetBaudDivisor');
  {$IFDEF WIN32}
    Assert(@SI_SetBaudDivisor <> nil);
  {$ENDIF}
    @SI_SetLineControl := GetProcAddress(DLLHandle,'SI_SetLineControl');
  {$IFDEF WIN32}
    Assert(@SI_SetLineControl <> nil);
  {$ENDIF}
    @SI_SetFlowControl := GetProcAddress(DLLHandle,'SI_SetFlowControl');
  {$IFDEF WIN32}
    Assert(@SI_SetFlowControl <> nil);
  {$ENDIF}
    @SI_GetModemStatus := GetProcAddress(DLLHandle,'SI_GetModemStatus');
  {$IFDEF WIN32}
    Assert(@SI_GetModemStatus <> nil);
  {$ENDIF}
    @SI_SetBreak := GetProcAddress(DLLHandle,'SI_SetBreak');
  {$IFDEF WIN32}
    Assert(@SI_SetBreak <> nil);
  {$ENDIF}
    @SI_ReadLatch := GetProcAddress(DLLHandle,'SI_ReadLatch');
  {$IFDEF WIN32}
    Assert(@SI_ReadLatch <> nil);
  {$ENDIF}
    @SI_WriteLatch := GetProcAddress(DLLHandle,'SI_WriteLatch');
  {$IFDEF WIN32}
    Assert(@SI_WriteLatch <> nil);
  {$ENDIF}
    @SI_GetPartNumber := GetProcAddress(DLLHandle,'SI_GetPartNumber');
  {$IFDEF WIN32}
    Assert(@SI_GetPartNumber <> nil);
  {$ENDIF}
  end
  else
  begin
    DLLLoaded := False;
    { Error: SIUSBXP.DLL could not be loaded !! }
  end;
{$IFNDEF MSDOS}
  SetErrorMode(ErrorMode)
{$ENDIF}
end {LoadDLL};

begin
  LoadDLL;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -