C
cmdolcet69
I have the code below that uses the LPT port of the printer. This
communication works great how can I get a USB port to work like the
code below!
'Interface Calls for Configuration of LPT Port with Zebra Printer
'******************************************************************************
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING = 3
Public Const FILE_SHARE_WRITE = &H2
Dim LPTPORT As String
Dim hPort As Integer
Public Declare Function CreateFile Lib "kernel32" Alias
"CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As
Integer, ByVal dwShareMode As Integer, _
<MarshalAs(UnmanagedType.Struct)> ByRef lpSecurityAttributes As
SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, ByVal
dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" Alias
"CloseHandle" (ByVal hObject As Integer) As Integer
Dim retval As Integer
<StructLayout(LayoutKind.Sequential)> Public Structure
SECURITY_ATTRIBUTES
Private nLength As Integer
Private lpSecurityDescriptor As Integer
Private bInheritHandle As Integer
End Structure
'***************************************************************************
LPTPORT = "LPT1"
hPort = CreateFile(LPTPORT, GENERIC_WRITE,
FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
outFile = New FileStream(hPortP, FileAccess.Write, False)
'Create FileStream using Handle
Dim fileWriter As New StreamWriter(outFile)
'^XA- start the communication with the Thermal Printer
'^XZ- end the communcation with the Thermal Printer
fileWriter.Write("^XA")
fileWriter.Write("^LH0,0")
fileWriter.Write("^LL480")
fileWriter.Write("^FO50,50^AF40,30^FD Fit Gate^FS" &
"^FO230,50^AF40,30^FD" & CStr(_strPVI) & "^FS" &
"^FO450,50^AF40,30^FD" & Date.Now & "^FS")
fileWriter.Write("^FO50,85^AF40,30^FD" & _strModelName &
"^FS^")
fileWriter.Write
("^FO50,110^AF40,30^FD----------------------------------------^FS")
communication works great how can I get a USB port to work like the
code below!
'Interface Calls for Configuration of LPT Port with Zebra Printer
'******************************************************************************
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING = 3
Public Const FILE_SHARE_WRITE = &H2
Dim LPTPORT As String
Dim hPort As Integer
Public Declare Function CreateFile Lib "kernel32" Alias
"CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As
Integer, ByVal dwShareMode As Integer, _
<MarshalAs(UnmanagedType.Struct)> ByRef lpSecurityAttributes As
SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, ByVal
dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" Alias
"CloseHandle" (ByVal hObject As Integer) As Integer
Dim retval As Integer
<StructLayout(LayoutKind.Sequential)> Public Structure
SECURITY_ATTRIBUTES
Private nLength As Integer
Private lpSecurityDescriptor As Integer
Private bInheritHandle As Integer
End Structure
'***************************************************************************
LPTPORT = "LPT1"
hPort = CreateFile(LPTPORT, GENERIC_WRITE,
FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
outFile = New FileStream(hPortP, FileAccess.Write, False)
'Create FileStream using Handle
Dim fileWriter As New StreamWriter(outFile)
'^XA- start the communication with the Thermal Printer
'^XZ- end the communcation with the Thermal Printer
fileWriter.Write("^XA")
fileWriter.Write("^LH0,0")
fileWriter.Write("^LL480")
fileWriter.Write("^FO50,50^AF40,30^FD Fit Gate^FS" &
"^FO230,50^AF40,30^FD" & CStr(_strPVI) & "^FS" &
"^FO450,50^AF40,30^FD" & Date.Now & "^FS")
fileWriter.Write("^FO50,85^AF40,30^FD" & _strModelName &
"^FS^")
fileWriter.Write
("^FO50,110^AF40,30^FD----------------------------------------^FS")