1,488
社区成员
发帖
与我相关
我的任务
分享
const int DEVNUM = 10;
const int PATHLEN = 200;
typedef struct
{
char strDevPath[PATHLEN];
}DEVPATH;
typedef struct
{
DEVPATH DevPath[DEVNUM];
int DevNum;
}DEVINFO;
int GetDevicePath(DEVINFO&);
bool Open(int PortNum);
bool Write(char *pBuf,DWORD nNumberOfBytesToWrite,DWORD &NumberOfBytesWritten);
void Close();
Public Const DevNum = 10
Public Const PATHLEN = 200
Public Type DEVPATH
strDevPath(0 To PATHLEN) As String
End Type
Public Type DEVINFO
iDevPath(0 To DevNum) As DEVPATH
DevNum As Integer
End Type
Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByRef sDevInfo As DEVINFO) _
As Long
Public Declare Function OpenUSB _
Lib "PrinterUsb.dll" Alias "Open" _
(ByVal PortNum As Integer) _
As Boolean
Public Declare Function WriteUSB _
Lib "PrinterUsb.dll" Alias "Write" _
(ByVal pBuf As String, _
ByVal nNumberOfBytesToWrite As Long, _
ByVal nNumberOfBytesWritten As Long) _
As Boolean
Public Declare Sub CloseUSB _
Lib "PrinterUsb.dll" Alias "Close" ()
'程序如下:
Private Sub cmdUSBTest_Click()
Dim MyDevInfo As DEVINFO
Dim ESC As String: ESC = Chr(27)
Dim strCmd As String
Dim nNumberOfBytesToWrite As Long: nNumberOfBytesToWrite = 0
Dim nNumberOfBytesWritten As Long: nNumberOfBytesWritten = 10
strCmd = "hello"
GetDevicePath MyDevInfo
If MyDevInfo.DevNum = 0 Then
MsgBox "未检测到USB设备!"
End
End If
If OpenUSB(0) = False Then
MsgBox "打开USB设备失败!"
End
End If
WriteUSB strCmd, nNumberOfBytesToWrite, nNumberOfBytesWritten
CloseUSB
End Sub
Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByRef sDevInfo As DEVINFO) _
As Long
Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByVal sDevInfo As DEVINFO) _
As Long
//#include "PrinterUsbDeclare.h"
#ifndef PRINTERUSB_H
#define PRINTERUSB_H
const int DEVNUM = 10;
const int PATHLEN = 200;
typedef struct
{
char strDevPath[PATHLEN];
}DEVPATH;
typedef struct
{
DEVPATH DevPath[DEVNUM];
int DevNum;
}DEVINFO;
#pragma comment(lib,"PrinterUsb.lib")
extern "C"_declspec(dllimport) int _stdcall GetDevicePath(DEVINFO&);
extern "C"_declspec(dllimport) bool _stdcall Open(int PortNum);
extern "C"_declspec(dllimport) bool _stdcall Write(char *pBuf,DWORD nNumberOfBytesToWrite,DWORD &NumberOfBytesWritten);
extern "C"_declspec(dllimport) bool _stdcall Read(char *pBuf,DWORD nNumberOfBytesToRead,DWORD &NumberOfBytesRead);
extern "C"_declspec(dllimport) void _stdcall Close();
#endif
Public Type DEVPATH
strDevPath(0 To PATHLEN - 1) As Byte
End Type
Public Type DEVINFO
iDevPath(0 To DEVNUM - 1) As DEVPATH
iDevNum As Integer
End Type
Public Declare Function GetUsbDevicePath _
Lib "PrinterUsb.dll" Alias "GetDevicePath" _
(sDevInfo As DEVINFO) _
As Long