USB Zebra Printer Communication


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")
 
Ad

Advertisements

D

DickGrier

Hi,

I think you need to use this approach:
http://support.microsoft.com/kb/322090

Dick

--
Richard Grier (Microsoft MVP - Visual Basic) Hard & Software 12962 West
Louisiana Avenue Lakewood, CO 80228 303-986-2179 (voice) Homepage:
www.hardandsoftware.net Author of Visual Basic Programmer's Guide to Serial
Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July
2004, Revised July 2006.
 
J

Jarek Mielcarek

I can send you module which allow you to print on any printer installed
in system. Just email me, jarekmie[]wp.pl
Jarek

cmdolcet69 pisze:
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
-- cut --
 
C

cmdolcet69

I can send you module which allow you to print on any printer installed
in system. Just email me, jarekmie[]wp.pl
Jarek

cmdolcet69 pisze:> 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

-- cut --


the code i posted below, works however it takes a long time to try and
get a sheet printed out... How can I speed this up?


'Interface Calls for Configuration of USB001 Port with Zebra Printer

'****************************************************************************
Public Class RawPrinterHelper
' Structure and API declarions:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)
Structure DOCINFOW
<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As
String
<MarshalAs(UnmanagedType.LPWStr)> Public pOutputFile As
String
<MarshalAs(UnmanagedType.LPWStr)> Public pDataType As
String
End Structure

<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal src As String, ByRef
hPrinter As IntPtr, ByVal pd As Long) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartDocPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(ByVal hPrinter As
IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(ByVal hPrinter As
IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(ByVal hPrinter As
IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="WritePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function WritePrinter(ByVal hPrinter As IntPtr,
ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
Int32) As Boolean
End Function

pd.PrinterSettings = New PrinterSettings
Dim labelposition As Integer = 140

RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^XA")
RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^LH0,0")
RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^LL480")
 
Ad

Advertisements

C

cmdolcet69

Hi,

I think you need to use this approach:http://support.microsoft.com/kb/322090

Dick

--
Richard Grier (Microsoft MVP - Visual Basic) Hard & Software 12962 West
Louisiana Avenue Lakewood, CO 80228 303-986-2179 (voice) Homepage:www.hardandsoftware.netAuthor of Visual Basic Programmer's Guide to Serial
Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July
2004, Revised July 2006.



the code i posted below, works however it takes a long time to try and
get a sheet printed out... How can I speed this up?

'Interface Calls for Configuration of USB001 Port with Zebra Printer

'****************************************************************************
Public Class RawPrinterHelper
' Structure and API declarions:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)

Structure DOCINFOW
<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As
String
<MarshalAs(UnmanagedType.LPWStr)> Public pOutputFile As
String
<MarshalAs(UnmanagedType.LPWStr)> Public pDataType As
String
End Structure

<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal src As String, ByRef
hPrinter As IntPtr, ByVal pd As Long) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartDocPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(ByVal hPrinter As
IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(ByVal hPrinter As
IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(ByVal hPrinter As
IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="WritePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function WritePrinter(ByVal hPrinter As IntPtr,
ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
Int32) As Boolean
End Function

pd.PrinterSettings = New PrinterSettings
Dim labelposition As Integer = 140

RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^XA")
RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^LH0,0")
RawPrinterHelper.SendStringToPrinter
(pd.PrinterSettings.PrinterName, "^LL480")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top