zebra Printer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • id10t error

    zebra Printer

    Hello,

    I am going to be using a Symbol WT4090 to scan items. I need to
    printer a tag from the Zebra ql320 plus. I am trying to do this is
    Visual basic 2005. Does anyone know and good site to find out how to
    do this. I have looked everywhere i know with no luck. Thank you in
    advance for your help.
  • ReneMarxis

    #2
    Re: zebra Printer

    On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
    Hello,
    >
    I am going to be using a Symbol WT4090 to scan items. I need to
    printer a tag from the Zebra ql320 plus. I am trying to do this is
    Visual basic 2005. Does anyone know and good site to find out how to
    do this.  I have looked everywhere i know with no luck. Thank you in
    advance for your help.
    After you scaned an item you need to print it on an Printer?
    Depends on how you can connect to the printer. If the printer is
    connected to one PC you have to send Raw Bytes to the Printer. But
    therefore you need to have one template written in ZPL (or what
    language your printer 'speaks')

    Comment

    • ReneMarxis

      #3
      Re: zebra Printer

      On 28 Apr., 15:08, ReneMarxis <rene.mar...@ya hoo.dewrote:
      On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
      >
      Hello,
      >
      I am going to be using a Symbol WT4090 to scan items. I need to
      printer a tag from the Zebra ql320 plus. I am trying to do this is
      Visual basic 2005. Does anyone know and good site to find out how to
      do this.  I have looked everywhere i know with no luck. Thank you in
      advance for your help.
      >
      After you scaned an item you need to print it on an Printer?
      Depends on how you can connect to the printer. If the printer is
      connected to one PC you have to send Raw Bytes to the Printer. But
      therefore you need to have one template written in ZPL (or what
      language your printer 'speaks')


      You can use CPCL, EPL2, ZPL2 .... to print

      Comment

      • id10t error

        #4
        Re: zebra Printer

        On Apr 28, 9:11 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
        On 28 Apr., 15:08, ReneMarxis <rene.mar...@ya hoo.dewrote:
        >
        On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
        >
        Hello,
        >
        I am going to be using a Symbol WT4090 to scan items. I need to
        printer a tag from the Zebra ql320 plus. I am trying to do this is
        Visual basic 2005. Does anyone know and good site to find out how to
        do this.  I have looked everywhere i know with no luck. Thank you in
        advance for your help.
        >
        After you scaned an item you need to print it on an Printer?
        Depends on how you can connect to the printer. If the printer is
        connected to one PC you have to send Raw Bytes to the Printer. But
        therefore you need to have one template written in ZPL (or what
        language your printer 'speaks')
        >
        http://www.zebra.com/id/zebra/na/en/...ters/mobile/ql...
        >
        You can use CPCL, EPL2, ZPL2 .... to print
        It will be connected wireless over network. That is the problem I am
        having. I am not sure how to communicate to it.
        This is the code I have if it connect with a com port. I can print
        with this code if the printer is connected to the com port

        Dim Texxxt As String
        Dim SA As SECURITY_ATTRIB UTES
        Dim hPortP As IntPtr, outfile As FileStream
        LPTPORT = "Com1"
        Texxxt = Me.RichTextBox1 .Text
        hPort = CreateFile(LPTP ORT, GENERIC_WRITE, FILE_SHARE_WRIT E,
        SA, OPEN_EXISTING, 0, 0)
        hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
        'Dim outfile As FileStream = File.Create(hPo rtP,
        FileAccess.Writ e, False) 'Create FileStream using Handle
        outfile = New FileStream(hPor tP, FileAccess.Writ e, False)
        Dim fileWriter As New StreamWriter(ou tfile)
        'fileWriter.Wri teLine("! 0 200 200 240 1")
        'fileWriter.Wri teLine("Journal ")
        'fileWriter.Wri teLine("VB 128 0 0 50 100 157 123456789")
        'fileWriter.Wri teLine("T 7 0 24 171 Barcode Value is
        123456789")
        'fileWriter.Wri teLine("FORM")
        'fileWriter.Wri teLine("PRINT")
        Dim copies As String = 1
        'fileWriter.Wri teLine("! 0 200 200 325 " & copies)
        fileWriter.Writ eLine("! 0 200 200 200 " & copies)
        fileWriter.Writ eLine("LABEL")
        fileWriter.Writ eLine("CONTRAST 0")
        fileWriter.Writ eLine("TONE 0")
        fileWriter.Writ eLine("SPEED 3")
        fileWriter.Writ eLine("PAGE-WIDTH 250")
        fileWriter.Writ eLine("BAR-SENSE")
        fileWriter.Writ eLine("COUNTRY USA")
        fileWriter.Writ eLine(";// PAGE 000000000250032 5")
        'Store Number in upperleft Corner
        'fileWriter.Wri teLine("TEXT90 5 0 25 3 003")
        fileWriter.Writ eLine("TEXT90 5 0 25 200 003")
        'SKU in upper right Corner
        fileWriter.Writ eLine("TEXT90 5 0 25 100 5580154")
        ''Prints barcode on second line
        fileWriter.Writ eLine("VB 128 1 3 40 50 200 0005580154")
        ''Prints Long SKU on line 3
        fileWriter.Writ eLine("TEXT90 0 2 100 200
        0211-90979-3600-010-1000")
        ''Prints UPC on Line 4
        fileWriter.Writ eLine("TEXT90 0 3 120 200 UPC-188371")
        ''Prints Date Code
        fileWriter.Writ eLine("TEXT90 0 2 140 200 308")
        ''Prints Store Number
        fileWriter.Writ eLine("TEXT90 5 0 160 200 009")
        ''Prints White Tag
        fileWriter.Writ eLine("TEXT90 5 0 150 100 29.99")
        ''Prints Speical Name
        fileWriter.Writ eLine("TEXT90 5 0 190 200 Store Special")
        ''Prints Red Tag
        fileWriter.Writ eLine("TEXT90 5 1 210 150 24.99")
        fileWriter.Writ eLine("CUT")
        fileWriter.Writ eLine("FORM")
        fileWriter.Writ eLine("PRINT")
        fileWriter.Flus h()
        fileWriter.Clos e()
        outfile.Close()
        retval = CloseHandle(hPo rt)
        End Sub

        Comment

        • ReneMarxis

          #5
          Re: zebra Printer

          I am using winspool.Drv to print to the printer. In this case i don't
          care if the printer is on Network or not. It is configured on my
          server-machine which does the printing.

          I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
          WritePrinter... . from that windows-library to send the Text to the
          printer.

          I am sorry i can't tell you how to connect directly to an network
          printer. But probably there is some alike method on windows mobile

          Comment

          • id10t error

            #6
            Re: zebra Printer

            On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
            I am using winspool.Drv to print to the printer. In this case i don't
            care if the printer is on Network or not. It is configured on my
            server-machine which does the printing.
            >
            I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
            WritePrinter... . from that windows-library to send the Text to the
            printer.
            >
            I am sorry i can't tell you how to connect directly to an network
            printer. But probably there is some alike method on windows mobile
            do you have any sample code i could look at?

            Comment

            • ReneMarxis

              #7
              Re: zebra Printer

              On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
              On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
              >
              I am using winspool.Drv to print to the printer. In this case i don't
              care if the printer is on Network or not. It is configured on my
              server-machine which does the printing.
              >
              I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
              WritePrinter... . from that windows-library to send the Text to the
              printer.
              >
              I am sorry i can't tell you how to connect directly to an network
              printer. But probably there is some alike method on windows mobile
              >
              do you have any sample code i could look at?
              'Option Explicit On
              Option Strict Off

              Imports System.IO
              Imports System.Runtime. InteropServices

              Public Class RawPrinterHelpe r
              ' Structure and API declarions:
              <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
              Structure DOCINFOW
              <MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
              <MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
              <MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
              End Structure

              'UP: Geändert wegen unbalanced stack fehlermeldung
              <DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function OpenPrinter(ByV al src As String, ByRef
              hPrinter As IntPtr, ByVal pd As Integer) As Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
              Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
              ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
              Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
              As Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
              Boolean
              End Function
              <DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
              SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
              ExactSpelling:= True,
              CallingConventi on:=CallingConv ention.StdCall) _
              Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
              ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
              Int32) As Boolean
              End Function


              Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
              hPrinter As _
              IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
              cbBuf _
              As Integer, ByRef pcbNeeded As Integer) As Boolean

              ' SendBytesToPrin ter()
              ' When the function is given a printer name and an unmanaged array
              of
              ' bytes, the function sends those bytes to the print queue.
              ' Returns True on success or False on failure.
              Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
              String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
              Dim hPrinter As IntPtr ' The printer handle.
              Dim dwError As Int32 ' Last error - in case there
              was trouble.
              Dim di As DOCINFOW = Nothing ' Describes your document
              (name, port, data type).
              Dim dwWritten As Int32 ' The number of bytes written
              by WritePrinter().
              Dim bSuccess As Boolean ' Your success code.

              ' Set up the DOCINFO structure.
              With di
              .pDocName = "My Visual Basic .NET RAW Document"
              .pDataType = "RAW"
              End With
              ' Assume failure unless you specifically succeed.
              bSuccess = False
              If OpenPrinter(szP rinterName, hPrinter, 0) Then

              Dim ByteBuf As Integer
              Dim BytesNeeded As Int32
              Dim PrinterInfo2 As New PRINTER_INFO_2
              Dim PrinterInfo() As Byte
              Dim result As Boolean

              'Determine the buffer size that is required to obtain the
              printer information.
              result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
              'Display the error message that you receive when you call
              the GetPrinter function,
              'and then close the printer handle.
              dwError = Marshal.GetLast Win32Error()
              If dwError <ERROR_INSUFFIC IENT_BUFFER And _
              dwError <0 Then
              Try
              ClosePrinter(hP rinter)
              Catch ex As Exception
              End Try
              Throw New MESPopupExcepti on("DCS-1031",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
              End If

              ReDim PrinterInfo(Byt esNeeded)
              ByteBuf = BytesNeeded

              'Call the GetPrinter function to obtain the status.
              result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
              BytesNeeded)
              'Check for any errors.
              If Not result Then
              'Get the error.
              dwError = Marshal.GetLast Win32Error()
              Try
              ClosePrinter(hP rinter)
              Catch ex As Exception
              End Try
              Throw New MESPopupExcepti on("DCS-1031",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
              End If


              PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
              GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
              If PrinterInfo2.St atus <0 Then
              Throw New MESPopupExcepti on("DCS-1032",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName,
              GetPrinterStatu sText(PrinterIn fo2.Status))
              Exit Function
              End If

              ' Im Falle, dass der Drucker ohne Spooler konfiguriert
              wurde,
              ' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
              Rückmeldung vom Betriebssystem
              ' und die Methode EndDocPrinter bleibt hängen. Dazu wird
              diese Methode mittels eines
              ' zusätzlichen Threads mit Timeout von 20s gestartet

              ' Um Übergabeparamet er an den Thread übergeben zu können,
              wird ein Objekt der Klasse
              ' "PrinterThr ead" angelegt und die Property pHandle
              gesetzt
              Dim myPrinterThread Obj As New PrinterThread
              myPrinterThread Obj.m_pHandle = hPrinter
              myPrinterThread Obj.m_DocInfo = di
              Dim myThread As System.Threadin g.Thread

              myThread = New System.Threadin g.Thread(Addres sOf
              myPrinterThread Obj.StartDocPri nter)
              myThread.Start( )
              Dim retBool As Boolean = myThread.Join(1 0000)
              If Not retBool Then
              myThread.Abort( )
              Throw New MESPopupExcepti on("DCS-1030",
              MESPopup.Meldun gsTypen.Fehler, "Timeout")
              End If
              bSuccess = myPrinterThread Obj.retVal

              If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
              ' Write your printer-specific bytes to the printer.
              If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
              dwCount, dwWritten)
              If bSuccess Then bSuccess = EndPagePrinter( hPrinter)


              'If StartDocPrinter (hPrinter, 1, di) Then
              ' If StartPagePrinte r(hPrinter) Then
              ' ' Write your printer-specific bytes to the
              printer.
              ' bSuccess = WritePrinter(hP rinter, pBytes,
              dwCount, dwWritten)
              ' bSuccess = EndPagePrinter( hPrinter)
              ' End If

              If bSuccess Then
              myThread = New System.Threadin g.Thread(Addres sOf
              myPrinterThread Obj.EndDocPrint er)
              myThread.Start( )
              retBool = myThread.Join(1 0000)
              If Not retBool Then
              myThread.Abort( )
              Throw New MESPopupExcepti on("DCS-1030",
              MESPopup.Meldun gsTypen.Fehler, "Timeout")
              End If
              End If

              'bSuccess = EndDocPrinter(h Printer)
              'End If

              ClosePrinter(hP rinter)
              End If
              ' If you did not succeed, GetLastError may give more
              information
              ' about why not.
              If bSuccess = False Then
              dwError = Marshal.GetLast Win32Error()
              Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
              Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
              Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
              Const ERROR_INVALID_P RINTER_STATE As Int32 = 1906
              Const ERROR_PRINTER_N OT_FOUND As Int32 = 3012

              Select Case dwError
              Case ERROR_INVALID_P RINTER_NAME
              'DCS-1025 = Drucker {0} ist unter Windows nicht
              bekannt!
              Throw New MESPopupExcepti on("DCS-1025",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName)
              Case ERROR_INVALID_P RINTER_COMMAND
              'DCS-1026 = Druckkommando {0} ist ungültig!
              Throw New MESPopupExcepti on("DCS-1026",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName)
              Case ERROR_PRINTER_O UT_OF_PAPER
              'DCS-1027 = Drucker {0} hat kein Papier!
              Throw New MESPopupExcepti on("DCS-1027",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName)
              Case ERROR_INVALID_P RINTER_STATE
              'DCS-1028 = Drucker {0} ist nicht bereit!
              Throw New MESPopupExcepti on("DCS-1028",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName)
              Case ERROR_PRINTER_N OT_FOUND
              'DCS-1029 = Drucker {0} nicht gefunden!
              Throw New MESPopupExcepti on("DCS-1029",
              MESPopup.Meldun gsTypen.Fehler, szPrinterName)
              Case Else
              'DCS-1030 = Unbekannter Fehler beim Ausdruck des
              Etiketts! Fehlercode: {1}
              Throw New MESPopupExcepti on("DCS-1030",
              MESPopup.Meldun gsTypen.Fehler, dwError.ToStrin g)
              End Select

              End If
              Return bSuccess
              End Function ' SendBytesToPrin ter()

              ' SendFileToPrint er()
              ' When the function is given a file name and a printer name,
              ' the function reads the contents of the file and sends the
              ' contents to the printer.
              ' Presumes that the file contains printer-ready data.
              ' Shows how to use the SendBytesToPrin ter function.
              ' Returns True on success or False on failure.
              Public Shared Function SendFileToPrint er(ByVal szPrinterName As
              String, ByVal szFileName As String) As Boolean
              ' Open the file.
              Dim fs As New FileStream(szFi leName, FileMode.Open)
              ' Create a BinaryReader on the file.
              Dim br As New BinaryReader(fs )
              ' Dim an array of bytes large enough to hold the file's
              contents.
              Dim bytes(CInt(fs.L ength)) As Byte
              Dim bSuccess As Boolean
              ' Your unmanaged pointer.
              Dim pUnmanagedBytes As IntPtr

              ' Read the contents of the file into the array.
              bytes = br.ReadBytes(CI nt(fs.Length))
              ' Allocate some unmanaged memory for those bytes.
              pUnmanagedBytes = Marshal.AllocCo TaskMem(CInt(fs .Length))
              ' Copy the managed byte array into the unmanaged array.
              Marshal.Copy(by tes, 0, pUnmanagedBytes , CInt(fs.Length) )
              ' Send the unmanaged bytes to the printer.
              bSuccess = SendBytesToPrin ter(szPrinterNa me, pUnmanagedBytes ,
              CInt(fs.Length) )
              ' Free the unmanaged memory that you allocated earlier.
              Marshal.FreeCoT askMem(pUnmanag edBytes)
              Return bSuccess
              End Function ' SendFileToPrint er()

              ' When the function is given a string and a printer name,
              ' the function sends the string to the printer as raw bytes.
              Public Shared Sub SendStringToPri nter(ByVal szPrinterName As
              String, ByVal szString As String)
              Dim pBytes As IntPtr
              Dim dwCount As Int32

              szString = System.Text.Enc oding.Default.G etString( _

              System.Text.Enc oding.GetEncodi ng(850).GetByte s(szString))

              ' How many characters are in the string?
              dwCount = szString.Length ()
              ' Assume that the printer is expecting ANSI text, and then
              convert
              ' the string to ANSI text.
              pBytes = Marshal.StringT oCoTaskMemAnsi( szString)
              ' Send the converted ANSI string to the printer.
              SendBytesToPrin ter(szPrinterNa me, pBytes, dwCount)
              Marshal.FreeCoT askMem(pBytes)
              End Sub
              End Class

              Module CheckPrinterSta tus

              <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)>
              Structure PRINTER_INFO_2
              Public pServerName As Integer
              Public pPrinterName As Integer
              Public pShareName As Integer
              Public pPortName As Integer
              Public pDriverName As Integer
              Public pComment As Integer
              Public pLocation As Integer
              Public pDevMode As Integer
              Public pSepFile As Integer
              Public pPrintProcessor As Integer
              Public pDatatype As Integer
              Public pParameters As Integer
              Public pSecurityDescri ptor As Integer
              Public Attributes As Integer
              Public Priority As Integer
              Public DefaultPriority As Integer
              Public StartTime As Integer
              Public UntilTime As Integer
              Public Status As Integer
              Public cJobs As Integer
              Public AveragePPM As Integer
              End Structure

              Public Function DatatoDeserial( ByVal datas() As Byte, ByVal
              type_to_change As Type, _
              ByVal NumJub As Long) As Object
              'Returns the size of the JOB_INFO_2 structure
              'HACK: Changed Long to integer
              Dim Data_to_Size As Integer = Marshal.SizeOf( type_to_change)
              If Data_to_Size datas.Length Then
              Return Nothing
              End If

              Dim buffer As IntPtr = Marshal.AllocHG lobal(Data_to_S ize)
              Dim startindex As Long
              Dim i As Integer
              For i = 0 To NumJub - 1
              If i = 0 Then
              startindex = 0
              Else
              startindex = startindex + Data_to_Size
              End If
              Next
              'Copy data from the datas array to the unmanaged memory
              pointer.
              Marshal.Copy(da tas, startindex, buffer, Data_to_Size)

              'Marshal data from the buffer pointer to a managed object.
              Dim result_obj As Object = Marshal.PtrToSt ructure(buffer,
              type_to_change)
              'Free the memory that is allocated from the unmanaged memory.
              Marshal.FreeHGl obal(buffer)
              Return result_obj
              End Function

              'Define the printer status constants.
              Public Const ERROR_INSUFFICI ENT_BUFFER As Integer = 122
              Public Const PRINTER_STATUS_ BUSY As Integer = &H200
              Public Const PRINTER_STATUS_ DOOR_OPEN As Integer = &H400000
              Public Const PRINTER_STATUS_ ERROR As Integer = &H2
              Public Const PRINTER_STATUS_ INITIALIZING As Integer = &H8000
              Public Const PRINTER_STATUS_ IO_ACTIVE As Integer = &H100
              Public Const PRINTER_STATUS_ MANUAL_FEED As Integer = &H20
              Public Const PRINTER_STATUS_ NO_TONER As Integer = &H40000
              Public Const PRINTER_STATUS_ NOT_AVAILABLE As Integer = &H1000
              Public Const PRINTER_STATUS_ OFFLINE As Integer = &H80
              Public Const PRINTER_STATUS_ OUT_OF_MEMORY As Integer = &H200000
              Public Const PRINTER_STATUS_ OUTPUT_BIN_FULL As Integer = &H800
              Public Const PRINTER_STATUS_ PAGE_PUNT As Integer = &H80000
              Public Const PRINTER_STATUS_ PAPER_JAM As Integer = &H8
              Public Const PRINTER_STATUS_ PAPER_OUT As Integer = &H10
              Public Const PRINTER_STATUS_ PAPER_PROBLEM As Integer = &H40
              Public Const PRINTER_STATUS_ PAUSED As Integer = &H1
              Public Const PRINTER_STATUS_ PENDING_DELETIO N As Integer = &H4
              Public Const PRINTER_STATUS_ PRINTING As Integer = &H400
              Public Const PRINTER_STATUS_ PROCESSING As Integer = &H4000
              Public Const PRINTER_STATUS_ TONER_LOW As Integer = &H20000
              Public Const PRINTER_STATUS_ USER_INTERVENTI ON As Integer =
              &H100000
              Public Const PRINTER_STATUS_ WAITING As Integer = &H2000
              Public Const PRINTER_STATUS_ WARMING_UP As Integer = &H10000

              Public Function GetPrinterStatu sText(ByVal PI2Status As Long) As
              String
              Dim tempStr As String
              If PI2Status = 0 Then ' Return the "Ready" status.
              GetPrinterStatu sText = "Ready"
              Else
              tempStr = ""
              'Determine the printer state.
              If (PI2Status And PRINTER_STATUS_ BUSY) Then
              tempStr = tempStr & "Busy"
              End If
              If (PI2Status And PRINTER_STATUS_ DOOR_OPEN) Then
              tempStr = tempStr & "Printer Door Open"
              End If
              If (PI2Status And PRINTER_STATUS_ ERROR) Then
              tempStr = tempStr & "Printer Error"
              End If
              If (PI2Status And PRINTER_STATUS_ INITIALIZING) Then
              tempStr = tempStr & "Initializi ng"
              End If
              If (PI2Status And PRINTER_STATUS_ IO_ACTIVE) Then
              tempStr = tempStr & "I/O Active"
              End If
              If (PI2Status And PRINTER_STATUS_ MANUAL_FEED) Then
              tempStr = tempStr & "Manual Feed"
              End If
              If (PI2Status And PRINTER_STATUS_ NO_TONER) Then
              tempStr = tempStr & "No Toner"
              End If
              If (PI2Status And PRINTER_STATUS_ NOT_AVAILABLE) Then
              tempStr = tempStr & "Not Available"
              End If
              If (PI2Status And PRINTER_STATUS_ OFFLINE) Then
              tempStr = tempStr & "Off Line"
              End If
              If (PI2Status And PRINTER_STATUS_ OUT_OF_MEMORY) Then
              tempStr = tempStr & "Out of Memory"
              End If
              If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
              tempStr = tempStr & "Output Bin Full"
              End If
              If (PI2Status And PRINTER_STATUS_ PAGE_PUNT) Then
              tempStr = tempStr & "Page Punt"
              End If
              If (PI2Status And PRINTER_STATUS_ PAPER_JAM) Then
              tempStr = tempStr & "Paper Jam"
              End If
              If (PI2Status And PRINTER_STATUS_ PAPER_OUT) Then
              tempStr = tempStr & "Paper Out"
              End If
              If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
              tempStr = tempStr & "Output Bin Full"
              End If
              If (PI2Status And PRINTER_STATUS_ PAPER_PROBLEM) Then
              tempStr = tempStr & "Page Problem"
              End If
              If (PI2Status And PRINTER_STATUS_ PAUSED) Then
              tempStr = tempStr & "Paused"
              End If
              If (PI2Status And PRINTER_STATUS_ PENDING_DELETIO N) Then
              tempStr = tempStr & "Pending Deletion"
              End If
              If (PI2Status And PRINTER_STATUS_ PRINTING) Then
              tempStr = tempStr & "Printing"
              End If
              If (PI2Status And PRINTER_STATUS_ PROCESSING) Then
              tempStr = tempStr & "Processing "
              End If
              If (PI2Status And PRINTER_STATUS_ TONER_LOW) Then
              tempStr = tempStr & "Toner Low"
              End If
              If (PI2Status And PRINTER_STATUS_ USER_INTERVENTI ON) Then
              tempStr = tempStr & "User Intervention"
              End If
              If (PI2Status And PRINTER_STATUS_ WAITING) Then
              tempStr = tempStr & "Waiting"
              End If
              If (PI2Status And PRINTER_STATUS_ WARMING_UP) Then
              tempStr = tempStr & "Warming Up"
              End If
              If Len(tempStr) = 0 Then
              tempStr = "Unknown Status of " & PI2Status
              End If
              'Return the status.
              GetPrinterStatu sText = tempStr
              End If
              End Function
              End Module

              Public Class PrinterThread
              Public m_pHandle As System.IntPtr
              Public m_DocInfo As RawPrinterHelpe r.DOCINFOW ' Describes
              your document (name, port, data type).
              Public retVal As Boolean

              Public Sub EndDocPrinter()
              retVal = RawPrinterHelpe r.EndDocPrinter (m_pHandle)
              End Sub
              Public Sub StartDocPrinter ()
              retVal = RawPrinterHelpe r.StartDocPrint er(m_pHandle, 1,
              m_DocInfo)
              End Sub
              End Class

              Comment

              • Simon Anderson

                #8
                Re: zebra Printer

                Hi, just to chuck my views on this topic

                We also have this problem, im sure the code works to the winspool.drv

                but a more "noddy" approach we came up with, which also seems to work, we
                scan and print to zebras on networks

                Set up the printer on a server so that can print to it the same as below

                execute a cmdprompt bur hidden, so the user has no idea that this is
                happening then

                1) delete a net use command to lpt6
                2) create a net use mapping lpt6 to the printer (we've set that as an
                configurable option in the application)
                3) save the zpl codes to a text file
                4) use a type command to print to LPT6




                "ReneMarxis " <rene.marxis@ya hoo.dewrote in message
                news:a29a0c3a-fca4-4a8f-848e-b537eca07b71@c6 5g2000hsa.googl egroups.com...
                On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
                On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
                >
                I am using winspool.Drv to print to the printer. In this case i don't
                care if the printer is on Network or not. It is configured on my
                server-machine which does the printing.
                >
                I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
                WritePrinter... . from that windows-library to send the Text to the
                printer.
                >
                I am sorry i can't tell you how to connect directly to an network
                printer. But probably there is some alike method on windows mobile
                >
                do you have any sample code i could look at?
                'Option Explicit On
                Option Strict Off

                Imports System.IO
                Imports System.Runtime. InteropServices

                Public Class RawPrinterHelpe r
                ' Structure and API declarions:
                <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
                Structure DOCINFOW
                <MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
                <MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
                <MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
                End Structure

                'UP: Geändert wegen unbalanced stack fehlermeldung
                <DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function OpenPrinter(ByV al src As String, ByRef
                hPrinter As IntPtr, ByVal pd As Integer) As Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
                Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
                ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
                Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
                As Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
                Boolean
                End Function
                <DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
                SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                ExactSpelling:= True,
                CallingConventi on:=CallingConv ention.StdCall) _
                Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
                ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
                Int32) As Boolean
                End Function


                Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
                hPrinter As _
                IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
                cbBuf _
                As Integer, ByRef pcbNeeded As Integer) As Boolean

                ' SendBytesToPrin ter()
                ' When the function is given a printer name and an unmanaged array
                of
                ' bytes, the function sends those bytes to the print queue.
                ' Returns True on success or False on failure.
                Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
                String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
                Dim hPrinter As IntPtr ' The printer handle.
                Dim dwError As Int32 ' Last error - in case there
                was trouble.
                Dim di As DOCINFOW = Nothing ' Describes your document
                (name, port, data type).
                Dim dwWritten As Int32 ' The number of bytes written
                by WritePrinter().
                Dim bSuccess As Boolean ' Your success code.

                ' Set up the DOCINFO structure.
                With di
                .pDocName = "My Visual Basic .NET RAW Document"
                .pDataType = "RAW"
                End With
                ' Assume failure unless you specifically succeed.
                bSuccess = False
                If OpenPrinter(szP rinterName, hPrinter, 0) Then

                Dim ByteBuf As Integer
                Dim BytesNeeded As Int32
                Dim PrinterInfo2 As New PRINTER_INFO_2
                Dim PrinterInfo() As Byte
                Dim result As Boolean

                'Determine the buffer size that is required to obtain the
                printer information.
                result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
                'Display the error message that you receive when you call
                the GetPrinter function,
                'and then close the printer handle.
                dwError = Marshal.GetLast Win32Error()
                If dwError <ERROR_INSUFFIC IENT_BUFFER And _
                dwError <0 Then
                Try
                ClosePrinter(hP rinter)
                Catch ex As Exception
                End Try
                Throw New MESPopupExcepti on("DCS-1031",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
                End If

                ReDim PrinterInfo(Byt esNeeded)
                ByteBuf = BytesNeeded

                'Call the GetPrinter function to obtain the status.
                result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
                BytesNeeded)
                'Check for any errors.
                If Not result Then
                'Get the error.
                dwError = Marshal.GetLast Win32Error()
                Try
                ClosePrinter(hP rinter)
                Catch ex As Exception
                End Try
                Throw New MESPopupExcepti on("DCS-1031",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
                End If


                PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
                GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
                If PrinterInfo2.St atus <0 Then
                Throw New MESPopupExcepti on("DCS-1032",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName,
                GetPrinterStatu sText(PrinterIn fo2.Status))
                Exit Function
                End If

                ' Im Falle, dass der Drucker ohne Spooler konfiguriert
                wurde,
                ' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
                Rückmeldung vom Betriebssystem
                ' und die Methode EndDocPrinter bleibt hängen. Dazu wird
                diese Methode mittels eines
                ' zusätzlichen Threads mit Timeout von 20s gestartet

                ' Um Übergabeparamet er an den Thread übergeben zu können,
                wird ein Objekt der Klasse
                ' "PrinterThr ead" angelegt und die Property pHandle
                gesetzt
                Dim myPrinterThread Obj As New PrinterThread
                myPrinterThread Obj.m_pHandle = hPrinter
                myPrinterThread Obj.m_DocInfo = di
                Dim myThread As System.Threadin g.Thread

                myThread = New System.Threadin g.Thread(Addres sOf
                myPrinterThread Obj.StartDocPri nter)
                myThread.Start( )
                Dim retBool As Boolean = myThread.Join(1 0000)
                If Not retBool Then
                myThread.Abort( )
                Throw New MESPopupExcepti on("DCS-1030",
                MESPopup.Meldun gsTypen.Fehler, "Timeout")
                End If
                bSuccess = myPrinterThread Obj.retVal

                If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
                ' Write your printer-specific bytes to the printer.
                If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
                dwCount, dwWritten)
                If bSuccess Then bSuccess = EndPagePrinter( hPrinter)


                'If StartDocPrinter (hPrinter, 1, di) Then
                ' If StartPagePrinte r(hPrinter) Then
                ' ' Write your printer-specific bytes to the
                printer.
                ' bSuccess = WritePrinter(hP rinter, pBytes,
                dwCount, dwWritten)
                ' bSuccess = EndPagePrinter( hPrinter)
                ' End If

                If bSuccess Then
                myThread = New System.Threadin g.Thread(Addres sOf
                myPrinterThread Obj.EndDocPrint er)
                myThread.Start( )
                retBool = myThread.Join(1 0000)
                If Not retBool Then
                myThread.Abort( )
                Throw New MESPopupExcepti on("DCS-1030",
                MESPopup.Meldun gsTypen.Fehler, "Timeout")
                End If
                End If

                'bSuccess = EndDocPrinter(h Printer)
                'End If

                ClosePrinter(hP rinter)
                End If
                ' If you did not succeed, GetLastError may give more
                information
                ' about why not.
                If bSuccess = False Then
                dwError = Marshal.GetLast Win32Error()
                Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
                Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
                Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
                Const ERROR_INVALID_P RINTER_STATE As Int32 = 1906
                Const ERROR_PRINTER_N OT_FOUND As Int32 = 3012

                Select Case dwError
                Case ERROR_INVALID_P RINTER_NAME
                'DCS-1025 = Drucker {0} ist unter Windows nicht
                bekannt!
                Throw New MESPopupExcepti on("DCS-1025",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName)
                Case ERROR_INVALID_P RINTER_COMMAND
                'DCS-1026 = Druckkommando {0} ist ungültig!
                Throw New MESPopupExcepti on("DCS-1026",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName)
                Case ERROR_PRINTER_O UT_OF_PAPER
                'DCS-1027 = Drucker {0} hat kein Papier!
                Throw New MESPopupExcepti on("DCS-1027",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName)
                Case ERROR_INVALID_P RINTER_STATE
                'DCS-1028 = Drucker {0} ist nicht bereit!
                Throw New MESPopupExcepti on("DCS-1028",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName)
                Case ERROR_PRINTER_N OT_FOUND
                'DCS-1029 = Drucker {0} nicht gefunden!
                Throw New MESPopupExcepti on("DCS-1029",
                MESPopup.Meldun gsTypen.Fehler, szPrinterName)
                Case Else
                'DCS-1030 = Unbekannter Fehler beim Ausdruck des
                Etiketts! Fehlercode: {1}
                Throw New MESPopupExcepti on("DCS-1030",
                MESPopup.Meldun gsTypen.Fehler, dwError.ToStrin g)
                End Select

                End If
                Return bSuccess
                End Function ' SendBytesToPrin ter()

                ' SendFileToPrint er()
                ' When the function is given a file name and a printer name,
                ' the function reads the contents of the file and sends the
                ' contents to the printer.
                ' Presumes that the file contains printer-ready data.
                ' Shows how to use the SendBytesToPrin ter function.
                ' Returns True on success or False on failure.
                Public Shared Function SendFileToPrint er(ByVal szPrinterName As
                String, ByVal szFileName As String) As Boolean
                ' Open the file.
                Dim fs As New FileStream(szFi leName, FileMode.Open)
                ' Create a BinaryReader on the file.
                Dim br As New BinaryReader(fs )
                ' Dim an array of bytes large enough to hold the file's
                contents.
                Dim bytes(CInt(fs.L ength)) As Byte
                Dim bSuccess As Boolean
                ' Your unmanaged pointer.
                Dim pUnmanagedBytes As IntPtr

                ' Read the contents of the file into the array.
                bytes = br.ReadBytes(CI nt(fs.Length))
                ' Allocate some unmanaged memory for those bytes.
                pUnmanagedBytes = Marshal.AllocCo TaskMem(CInt(fs .Length))
                ' Copy the managed byte array into the unmanaged array.
                Marshal.Copy(by tes, 0, pUnmanagedBytes , CInt(fs.Length) )
                ' Send the unmanaged bytes to the printer.
                bSuccess = SendBytesToPrin ter(szPrinterNa me, pUnmanagedBytes ,
                CInt(fs.Length) )
                ' Free the unmanaged memory that you allocated earlier.
                Marshal.FreeCoT askMem(pUnmanag edBytes)
                Return bSuccess
                End Function ' SendFileToPrint er()

                ' When the function is given a string and a printer name,
                ' the function sends the string to the printer as raw bytes.
                Public Shared Sub SendStringToPri nter(ByVal szPrinterName As
                String, ByVal szString As String)
                Dim pBytes As IntPtr
                Dim dwCount As Int32

                szString = System.Text.Enc oding.Default.G etString( _

                System.Text.Enc oding.GetEncodi ng(850).GetByte s(szString))

                ' How many characters are in the string?
                dwCount = szString.Length ()
                ' Assume that the printer is expecting ANSI text, and then
                convert
                ' the string to ANSI text.
                pBytes = Marshal.StringT oCoTaskMemAnsi( szString)
                ' Send the converted ANSI string to the printer.
                SendBytesToPrin ter(szPrinterNa me, pBytes, dwCount)
                Marshal.FreeCoT askMem(pBytes)
                End Sub
                End Class

                Module CheckPrinterSta tus

                <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)>
                Structure PRINTER_INFO_2
                Public pServerName As Integer
                Public pPrinterName As Integer
                Public pShareName As Integer
                Public pPortName As Integer
                Public pDriverName As Integer
                Public pComment As Integer
                Public pLocation As Integer
                Public pDevMode As Integer
                Public pSepFile As Integer
                Public pPrintProcessor As Integer
                Public pDatatype As Integer
                Public pParameters As Integer
                Public pSecurityDescri ptor As Integer
                Public Attributes As Integer
                Public Priority As Integer
                Public DefaultPriority As Integer
                Public StartTime As Integer
                Public UntilTime As Integer
                Public Status As Integer
                Public cJobs As Integer
                Public AveragePPM As Integer
                End Structure

                Public Function DatatoDeserial( ByVal datas() As Byte, ByVal
                type_to_change As Type, _
                ByVal NumJub As Long) As Object
                'Returns the size of the JOB_INFO_2 structure
                'HACK: Changed Long to integer
                Dim Data_to_Size As Integer = Marshal.SizeOf( type_to_change)
                If Data_to_Size datas.Length Then
                Return Nothing
                End If

                Dim buffer As IntPtr = Marshal.AllocHG lobal(Data_to_S ize)
                Dim startindex As Long
                Dim i As Integer
                For i = 0 To NumJub - 1
                If i = 0 Then
                startindex = 0
                Else
                startindex = startindex + Data_to_Size
                End If
                Next
                'Copy data from the datas array to the unmanaged memory
                pointer.
                Marshal.Copy(da tas, startindex, buffer, Data_to_Size)

                'Marshal data from the buffer pointer to a managed object.
                Dim result_obj As Object = Marshal.PtrToSt ructure(buffer,
                type_to_change)
                'Free the memory that is allocated from the unmanaged memory.
                Marshal.FreeHGl obal(buffer)
                Return result_obj
                End Function

                'Define the printer status constants.
                Public Const ERROR_INSUFFICI ENT_BUFFER As Integer = 122
                Public Const PRINTER_STATUS_ BUSY As Integer = &H200
                Public Const PRINTER_STATUS_ DOOR_OPEN As Integer = &H400000
                Public Const PRINTER_STATUS_ ERROR As Integer = &H2
                Public Const PRINTER_STATUS_ INITIALIZING As Integer = &H8000
                Public Const PRINTER_STATUS_ IO_ACTIVE As Integer = &H100
                Public Const PRINTER_STATUS_ MANUAL_FEED As Integer = &H20
                Public Const PRINTER_STATUS_ NO_TONER As Integer = &H40000
                Public Const PRINTER_STATUS_ NOT_AVAILABLE As Integer = &H1000
                Public Const PRINTER_STATUS_ OFFLINE As Integer = &H80
                Public Const PRINTER_STATUS_ OUT_OF_MEMORY As Integer = &H200000
                Public Const PRINTER_STATUS_ OUTPUT_BIN_FULL As Integer = &H800
                Public Const PRINTER_STATUS_ PAGE_PUNT As Integer = &H80000
                Public Const PRINTER_STATUS_ PAPER_JAM As Integer = &H8
                Public Const PRINTER_STATUS_ PAPER_OUT As Integer = &H10
                Public Const PRINTER_STATUS_ PAPER_PROBLEM As Integer = &H40
                Public Const PRINTER_STATUS_ PAUSED As Integer = &H1
                Public Const PRINTER_STATUS_ PENDING_DELETIO N As Integer = &H4
                Public Const PRINTER_STATUS_ PRINTING As Integer = &H400
                Public Const PRINTER_STATUS_ PROCESSING As Integer = &H4000
                Public Const PRINTER_STATUS_ TONER_LOW As Integer = &H20000
                Public Const PRINTER_STATUS_ USER_INTERVENTI ON As Integer =
                &H100000
                Public Const PRINTER_STATUS_ WAITING As Integer = &H2000
                Public Const PRINTER_STATUS_ WARMING_UP As Integer = &H10000

                Public Function GetPrinterStatu sText(ByVal PI2Status As Long) As
                String
                Dim tempStr As String
                If PI2Status = 0 Then ' Return the "Ready" status.
                GetPrinterStatu sText = "Ready"
                Else
                tempStr = ""
                'Determine the printer state.
                If (PI2Status And PRINTER_STATUS_ BUSY) Then
                tempStr = tempStr & "Busy"
                End If
                If (PI2Status And PRINTER_STATUS_ DOOR_OPEN) Then
                tempStr = tempStr & "Printer Door Open"
                End If
                If (PI2Status And PRINTER_STATUS_ ERROR) Then
                tempStr = tempStr & "Printer Error"
                End If
                If (PI2Status And PRINTER_STATUS_ INITIALIZING) Then
                tempStr = tempStr & "Initializi ng"
                End If
                If (PI2Status And PRINTER_STATUS_ IO_ACTIVE) Then
                tempStr = tempStr & "I/O Active"
                End If
                If (PI2Status And PRINTER_STATUS_ MANUAL_FEED) Then
                tempStr = tempStr & "Manual Feed"
                End If
                If (PI2Status And PRINTER_STATUS_ NO_TONER) Then
                tempStr = tempStr & "No Toner"
                End If
                If (PI2Status And PRINTER_STATUS_ NOT_AVAILABLE) Then
                tempStr = tempStr & "Not Available"
                End If
                If (PI2Status And PRINTER_STATUS_ OFFLINE) Then
                tempStr = tempStr & "Off Line"
                End If
                If (PI2Status And PRINTER_STATUS_ OUT_OF_MEMORY) Then
                tempStr = tempStr & "Out of Memory"
                End If
                If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
                tempStr = tempStr & "Output Bin Full"
                End If
                If (PI2Status And PRINTER_STATUS_ PAGE_PUNT) Then
                tempStr = tempStr & "Page Punt"
                End If
                If (PI2Status And PRINTER_STATUS_ PAPER_JAM) Then
                tempStr = tempStr & "Paper Jam"
                End If
                If (PI2Status And PRINTER_STATUS_ PAPER_OUT) Then
                tempStr = tempStr & "Paper Out"
                End If
                If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
                tempStr = tempStr & "Output Bin Full"
                End If
                If (PI2Status And PRINTER_STATUS_ PAPER_PROBLEM) Then
                tempStr = tempStr & "Page Problem"
                End If
                If (PI2Status And PRINTER_STATUS_ PAUSED) Then
                tempStr = tempStr & "Paused"
                End If
                If (PI2Status And PRINTER_STATUS_ PENDING_DELETIO N) Then
                tempStr = tempStr & "Pending Deletion"
                End If
                If (PI2Status And PRINTER_STATUS_ PRINTING) Then
                tempStr = tempStr & "Printing"
                End If
                If (PI2Status And PRINTER_STATUS_ PROCESSING) Then
                tempStr = tempStr & "Processing "
                End If
                If (PI2Status And PRINTER_STATUS_ TONER_LOW) Then
                tempStr = tempStr & "Toner Low"
                End If
                If (PI2Status And PRINTER_STATUS_ USER_INTERVENTI ON) Then
                tempStr = tempStr & "User Intervention"
                End If
                If (PI2Status And PRINTER_STATUS_ WAITING) Then
                tempStr = tempStr & "Waiting"
                End If
                If (PI2Status And PRINTER_STATUS_ WARMING_UP) Then
                tempStr = tempStr & "Warming Up"
                End If
                If Len(tempStr) = 0 Then
                tempStr = "Unknown Status of " & PI2Status
                End If
                'Return the status.
                GetPrinterStatu sText = tempStr
                End If
                End Function
                End Module

                Public Class PrinterThread
                Public m_pHandle As System.IntPtr
                Public m_DocInfo As RawPrinterHelpe r.DOCINFOW ' Describes
                your document (name, port, data type).
                Public retVal As Boolean

                Public Sub EndDocPrinter()
                retVal = RawPrinterHelpe r.EndDocPrinter (m_pHandle)
                End Sub
                Public Sub StartDocPrinter ()
                retVal = RawPrinterHelpe r.StartDocPrint er(m_pHandle, 1,
                m_DocInfo)
                End Sub
                End Class

                Comment

                • mcnews

                  #9
                  Re: zebra Printer

                  On Jun 22, 6:06 am, "Simon Anderson"
                  <simon.ander... @newlinecomputi ng.comwrote:
                  Hi, just to chuck my views on this topic
                  >
                  We also have this problem, im sure the code works to the winspool.drv
                  >
                  but a more "noddy" approach we came up with, which also seems to work, we
                  scan and print to zebras on networks
                  >
                  Set up the printer on a server so that can print to it the same as below
                  >
                  execute a cmdprompt bur hidden, so the user has no idea that this is
                  happening then
                  >
                  1) delete a net use command to lpt6
                  2) create a net use mapping lpt6 to the printer (we've set that as an
                  configurable option in the application)
                  3) save the zpl codes to a text file
                  4) use a type command to print to LPT6
                  >
                  "ReneMarxis " <rene.mar...@ya hoo.dewrote in message
                  >
                  news:a29a0c3a-fca4-4a8f-848e-b537eca07b71@c6 5g2000hsa.googl egroups.com...
                  On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
                  >
                  On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
                  >
                  I am using winspool.Drv to print to the printer. In this case i don't
                  care if the printer is on Network or not. It is configured on my
                  server-machine which does the printing.
                  >
                  I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
                  WritePrinter... . from that windows-library to send the Text to the
                  printer.
                  >
                  I am sorry i can't tell you how to connect directly to an network
                  printer. But probably there is some alike method on windows mobile
                  >
                  do you have any sample code i could look at?
                  >
                  'Option Explicit On
                  Option Strict Off
                  >
                  Imports System.IO
                  Imports System.Runtime. InteropServices
                  >
                  Public Class RawPrinterHelpe r
                  ' Structure and API declarions:
                  <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
                  Structure DOCINFOW
                  <MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
                  <MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
                  <MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
                  End Structure
                  >
                  'UP: Geändert wegen unbalanced stack fehlermeldung
                  <DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function OpenPrinter(ByV al src As String, ByRef
                  hPrinter As IntPtr, ByVal pd As Integer) As Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
                  Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
                  ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
                  Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
                  As Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
                  Boolean
                  End Function
                  <DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
                  SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
                  ExactSpelling:= True,
                  CallingConventi on:=CallingConv ention.StdCall) _
                  Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
                  ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
                  Int32) As Boolean
                  End Function
                  >
                  Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
                  hPrinter As _
                  IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
                  cbBuf _
                  As Integer, ByRef pcbNeeded As Integer) As Boolean
                  >
                  ' SendBytesToPrin ter()
                  ' When the function is given a printer name and an unmanaged array
                  of
                  ' bytes, the function sends those bytes to the print queue.
                  ' Returns True on success or False on failure.
                  Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
                  String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
                  Dim hPrinter As IntPtr ' The printer handle.
                  Dim dwError As Int32 ' Last error - in case there
                  was trouble.
                  Dim di As DOCINFOW = Nothing ' Describes your document
                  (name, port, data type).
                  Dim dwWritten As Int32 ' The number of bytes written
                  by WritePrinter().
                  Dim bSuccess As Boolean ' Your success code.
                  >
                  ' Set up the DOCINFO structure.
                  With di
                  .pDocName = "My Visual Basic .NET RAW Document"
                  .pDataType = "RAW"
                  End With
                  ' Assume failure unless you specifically succeed.
                  bSuccess = False
                  If OpenPrinter(szP rinterName, hPrinter, 0) Then
                  >
                  Dim ByteBuf As Integer
                  Dim BytesNeeded As Int32
                  Dim PrinterInfo2 As New PRINTER_INFO_2
                  Dim PrinterInfo() As Byte
                  Dim result As Boolean
                  >
                  'Determine the buffer size that is required to obtain the
                  printer information.
                  result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
                  'Display the error message that you receive when you call
                  the GetPrinter function,
                  'and then close the printer handle.
                  dwError = Marshal.GetLast Win32Error()
                  If dwError <ERROR_INSUFFIC IENT_BUFFER And _
                  dwError <0 Then
                  Try
                  ClosePrinter(hP rinter)
                  Catch ex As Exception
                  End Try
                  Throw New MESPopupExcepti on("DCS-1031",
                  MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
                  End If
                  >
                  ReDim PrinterInfo(Byt esNeeded)
                  ByteBuf = BytesNeeded
                  >
                  'Call the GetPrinter function to obtain the status.
                  result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
                  BytesNeeded)
                  'Check for any errors.
                  If Not result Then
                  'Get the error.
                  dwError = Marshal.GetLast Win32Error()
                  Try
                  ClosePrinter(hP rinter)
                  Catch ex As Exception
                  End Try
                  Throw New MESPopupExcepti on("DCS-1031",
                  MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
                  End If
                  >
                  PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
                  GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
                  If PrinterInfo2.St atus <0 Then
                  Throw New MESPopupExcepti on("DCS-1032",
                  MESPopup.Meldun gsTypen.Fehler, szPrinterName,
                  GetPrinterStatu sText(PrinterIn fo2.Status))
                  Exit Function
                  End If
                  >
                  ' Im Falle, dass der Drucker ohne Spooler konfiguriert
                  wurde,
                  ' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
                  Rückmeldung vom Betriebssystem
                  ' und die Methode EndDocPrinter bleibt hängen. Dazu wird
                  diese Methode mittels eines
                  ' zusätzlichen Threads mit Timeout von 20s gestartet
                  >
                  ' Um Übergabeparamet er an den Thread übergeben zu können,
                  wird ein Objekt der Klasse
                  ' "PrinterThr ead" angelegt und die Property pHandle
                  gesetzt
                  Dim myPrinterThread Obj As New PrinterThread
                  myPrinterThread Obj.m_pHandle = hPrinter
                  myPrinterThread Obj.m_DocInfo = di
                  Dim myThread As System.Threadin g.Thread
                  >
                  myThread = New System.Threadin g.Thread(Addres sOf
                  myPrinterThread Obj.StartDocPri nter)
                  myThread.Start( )
                  Dim retBool As Boolean = myThread.Join(1 0000)
                  If Not retBool Then
                  myThread.Abort( )
                  Throw New MESPopupExcepti on("DCS-1030",
                  MESPopup.Meldun gsTypen.Fehler, "Timeout")
                  End If
                  bSuccess = myPrinterThread Obj.retVal
                  >
                  If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
                  ' Write your printer-specific bytes to the printer.
                  If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
                  dwCount, dwWritten)
                  If bSuccess Then bSuccess = EndPagePrinter( hPrinter)
                  >
                  'If StartDocPrinter (hPrinter, 1, di) Then
                  ' If StartPagePrinte r(hPrinter) Then
                  ' ' Write your printer-specific bytes to the
                  printer.
                  ' bSuccess = WritePrinter(hP rinter, pBytes,
                  dwCount, dwWritten)
                  ' bSuccess = EndPagePrinter( hPrinter)
                  ' End If
                  >
                  If bSuccess Then
                  myThread = New System.Threadin g.Thread(Addres sOf
                  myPrinterThread Obj.EndDocPrint er)
                  myThread.Start( )
                  retBool = myThread.Join(1 0000)
                  If Not retBool Then
                  myThread.Abort( )
                  Throw New MESPopupExcepti on("DCS-1030",
                  MESPopup.Meldun gsTypen.Fehler, "Timeout")
                  End If
                  End If
                  >
                  'bSuccess = EndDocPrinter(h Printer)
                  'End If
                  >
                  ClosePrinter(hP rinter)
                  End If
                  ' If you did not succeed, GetLastError may give more
                  information
                  ' about why not.
                  If bSuccess = False Then
                  dwError = Marshal.GetLast Win32Error()
                  Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
                  Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
                  Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
                  Const ERROR_INVALID_P RINTER_STATE As Int32 =
                  ...
                  >
                  read more »
                  i've done this with zebras and eltrons included printers attached via
                  USB.
                  the sharing then mapping an unused LPT port is the trick.

                  Comment

                  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                    #10
                    Re: zebra Printer

                    id10t error wrote:
                    Hello,
                    >
                    I am going to be using a Symbol WT4090 to scan items. I need to
                    printer a tag from the Zebra ql320 plus. I am trying to do this is
                    Visual basic 2005. Does anyone know and good site to find out how to
                    do this. I have looked everywhere i know with no luck. Thank you in
                    advance for your help.
                    I while back I had to make one of our applications print on a Zebra
                    label printer (much larger than the sleak QL 320 Plus). What I did was
                    to produce the labels as a PDF document, and then let the user click on
                    the print icon in Adobe Reader to print the labels via the Windows
                    driver for the printer.

                    Using PDF might not be practical in your case, but there are Windows
                    drivers for the printer, so you should be able to print to it like any
                    other printer.

                    --
                    Göran Andersson
                    _____
                    Göran Anderssons privata hemsida.

                    Comment

                    Working...