From: cmdolcet69 on 29 Sep 2009 12:39 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")
From: Jarek Mielcarek on 30 Sep 2009 03:12 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 --
From: cmdolcet69 on 15 Oct 2009 16:11 On Sep 30, 3:12 am, Jarek Mielcarek <jarek...(a)brak.mi.wp.pl> wrote: > 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")
|
Pages: 1 Prev: Control arrays and FormN.Label31 Next: learning resources |