none
Imprimir codigo de barra en una Zebra TLP 2844 por un puerto USB RRS feed

  • Pregunta

  • Hola todos los ejemplos que he encontrados son por LPT1 y  COM. pero necesito ocupar el puerto USB.

    el código que tengo es el siguiente, quiero enviar toda las información a través del puerto pero el problema que en el

    _hPort = CreateFile(printerPath, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)

    me devuelve -1

    el código completo es.

    Imports System.IO
    Imports System.Runtime.InteropServices
    Imports Microsoft.Win32.SafeHandles
    Public Class Window1
        Private Const GENERIC_WRITE As Integer = &H40000000
        Private Const OPEN_EXISTING As Integer = 3
        Private Const FILE_SHARE_WRITE As Integer = &H2
    
        Private _fileWriter As StreamWriter
        Private _outFile As FileStream
        Private _hPort As Integer
        Dim handle As SafeFileHandle
    
        <StructLayout(LayoutKind.Sequential)> Public Structure SECURITY_ATTRIBUTES
            Private nLength As Integer
            Private lpSecurityDescriptor As Integer
            Private bInheritHandle As Integer
        End Structure
    
        'Define Win32 functions
        Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
        Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer
    
        ''' <summary>
        ''' This function must be called first.  Printer path must be a COM Port or a UNC path.
        ''' </summary>
        Public Sub StartWrite(ByVal printerPath As String)
            Dim SA As SECURITY_ATTRIBUTES
            'Dim hPortP As IntPtr
            Dim hPortP As Integer
            'Dim retval As Integer
    
            'Create connection
            _hPort = CreateFile(printerPath, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
    
    
            'Get unsafe pointer
            hPortP = New IntPtr(_hPort) 'convert Integer to IntPtr 
            handle = New SafeFileHandle(New IntPtr(_hPort), True)
    
            'Create file stream
            _outFile = New FileStream(handle, FileAccess.Write)
    
            'Create stream writer
            _fileWriter = New StreamWriter(_outFile)
    
        End Sub
        ''' <summary>
        ''' This will write a command to the printer.
        ''' </summary>
        Public Sub Write(ByVal rawLine As String)
            _fileWriter.WriteLine(rawLine)
        End Sub
        ''' <summary>
        ''' This function must be called after writing to the zebra printer.
        ''' </summary>
        Public Sub EndWrite()
            'Clean up
            _fileWriter.Flush()
            _fileWriter.Close()
            _outFile.Close()
            CloseHandle(_hPort)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
            Dim print As New Window1
    
            'Print on the computer PC-0556 with printer name VantageT
            'print.StartWrite("\\pc-0556\\VantageT")
            print.StartWrite("\\192.160.0.120\ZDesigner TLP 2844 (Copiar 1)")
    
            'Do this because the zebra manual says so
            print.Write("")
            print.Write("N")
    
            'Write Text
            print.Write("A30,90,0,4,1,1,N,""" & "Hello" & """")
    
            'Write bar code
            print.Write("B30,20,0,1,2,5,50,N,""" & "World" & """")
    
            'Print a single copy
            print.Write("P1")
    
            'Clean up
            print.EndWrite()
        End Sub
    End Class
    
    

    Saludos y mucha gracias.

    martes, 10 de abril de 2012 18:19

Todas las respuestas

  • Yo tengo el mismo problema, alguien a hallado una solución ?
    jueves, 16 de agosto de 2012 17:24
  • En la WEB del fabricante tenéis el driver y bastante información sobre la impresora.

    ¿Por qué no imprimís como una impresora normal y corriente?

    Y para imprimir códigos de barras, hay fuentes que se ven como los códigos.


    MVP Visual C++ - Visita mi blog sobre desarrollo: http://geeks.ms/blogs/rfog/


    • Editado RFOG viernes, 31 de agosto de 2012 19:58
    viernes, 31 de agosto de 2012 19:57
  • Hola

    Cuando ejecuto el código me sale el siguiente aviso: 

    {"Identificador no válido.Nombre del parámetro: handle"}

    ¿Como podría solucionar eso?

    Saludos


    guillermo leon rea

    sábado, 17 de junio de 2017 17:39