Spanish [SOLUCIONADO] Imprimir código de barras en impresora etiquetas (CPCL)

TILogistic

Expert
Licensed User
Longtime User
si desea sube un ejemplo para revisar que estas haciendo.

he visto el demo y utiliza un sdk CPCL_SDK_V1.11 y he visto como imprime, es igual que todas las demás impresora que usan CPCL.

saludos.
 

vecino

Well-Known Member
Licensed User
Longtime User
Sí, voy a preparar una pequeña demo y la subo, porque es extraño, cuando envío a imprimir se activa la impresora si está "dormida", o sea, que la impresora detecta que se han conectado y se ha enviado algo.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hola, amigos, aquí subo un proyecto de pruebas que estoy usando, a ver si podéis ver en qué me equivoco.
Gracias.
 

Attachments

  • testprintermovil.zip
    10.3 KB · Views: 158

vecino

Well-Known Member
Licensed User
Longtime User
¿Alguien ha podido probar el proyecto demo en alguna impresora similar?
Es por descartar que sea problema de la impresora.
Gracias.
 

vecino

Well-Known Member
Licensed User
Longtime User
Gracias, f0raster0, ahora sí que estoy perdido o_O
A ver si consigo otra impresora y pruebo, porque esta no me da ningún error al conectar. Aunque luego no imprime.
 

vecino

Well-Known Member
Licensed User
Longtime User
Perfecto, es que en el ejemplo no he puesto ningún código de barras para probar, solamente texto.
Pues entonces va a ser algún problema de esta impresora.

Aunque ahora que lo pienso, el programa demo (.apk) que trae sí que imprime también.
No encuentro lógica alguna :confused:
 

TILogistic

Expert
Licensed User
Longtime User
estimado su impresora imprime los comandos CPCL en bytes.

si usted envía a imprimir texto eso imprime y desea dar formato como tipo de letras, margenes, code de barras, debe utilizar comandos CPCL.

vea este ejemplo:

 

vecino

Well-Known Member
Licensed User
Longtime User
estimado su impresora imprime los comandos CPCL en bytes.
si usted envía a imprimir texto eso imprime y desea dar formato como tipo de letras, margenes, code de barras, debe utilizar comandos CPCL.
vea este ejemplo:

Hola, oparra, pero el demo que he puesto es cpcl, según tus indicaciones en la ayuda que me has dado. A "f0raster0" le funciona y a mí no.
Seguramente no he entendido lo que has dicho.
Pruebo también tu enlace y comento...
 

TILogistic

Expert
Licensed User
Longtime User
Si vi lo que post "f0raster0" es una clase para impresora de comandos ESC.

puedes usarla si tu impresora emula ESC, pero los manuales que has publicado solo emula CPCL.

puedes usar esa clase el método WriteString que convierte texto a bytes y envía a la impresora.

B4X:
' Send the contents of an array of bytes to the printer

' Remember that if the printer is expecting text the bytes will be printed as characters in the current code page

Public Sub WriteBytes(data() As Byte)

    If Connected Then

        Astream.Write(data)

    End If

End Sub



' Send the string to the printer in IBM437 encoding which is the original PC DOS codepage

' This is usually the default codepage for a printer and is CodePage = 0

' Beware of using WriteString with Chr() to send numeric values as they may be affected by Unicode to codepage translations

' Most character level operations are pre-defined as UPPERCASE string variables for easy concatenation with other string data

Public Sub WriteString(data As String)

    WriteString2(data, "IBM437")

End Sub



' Send the string to the printer in the specified encoding

' You also need to set the printer to a  matching encoding using the CodePage property

' Beware of using WriteString2 with Chr() to send numeric values as they may be affected by codepage substitutions

' Most character level operations are pre-defined as UPPERCASE string variables for easy concatenatipon with other string data

Public Sub WriteString2(data As String, encoding As String)

    Try

        If Connected Then

            Astream.Write(data.GetBytes(encoding))

        End If

    Catch

        Log("Printer error : " & LastException.Message)

        AStream_Error

    End Try

End Sub

tu SDK del demo es este:

1623839053788.png
 

vecino

Well-Known Member
Licensed User
Longtime User
Vale, he probado la demo de f0raster0 y muestra texto, pero no los códigos de barras.
Oparra, entonces el ejemplo/demo que he puesto yo debería de funcionar porque usa CPCL, ¿no?, y ese es el problema, que no me funciona.
 

TILogistic

Expert
Licensed User
Longtime User
Agrega esta rutina al demo de "f0raster0" y ejecútala debería imprimir el código de barra.

segun el SDK el encoding es "gb2312"

public static String LanguageEncode = "gb2312";

B4X:
Private Sub PrintCodeBarCPCL

    Dim CPCLcomand As String

    CPCLcomand = "! 0 200 200 210 1"
    Printer1.WriteString2(CPCLcomand, "gb2312")

    CPCLcomand = "BARCODE 128 1 1 50 150 10 HORIZ."
    Printer1.WriteString2(CPCLcomand, "gb2312")

    CPCLcomand = "TEXT 7 0 210 60 HORIZ."
    Printer1.WriteString2(CPCLcomand, "gb2312")

    CPCLcomand = "FORM"
    Printer1.WriteString2(CPCLcomand, "gb2312")

    CPCLcomand = "PRINT"
    Printer1.WriteString2(CPCLcomand, "gb2312")
End Sub

Usar método WriteString2 de clase Bluetooth ESC/POS Printer Class

B4X:
' Send the string to the printer in the specified encoding
' You also need to set the printer to a  matching encoding using the CodePage property
' Beware of using WriteString2 with Chr() to send numeric values as they may be affected by codepage substitutions
' Most character level operations are pre-defined as UPPERCASE string variables for easy concatenatipon with other string data
Public Sub WriteString2(data As String, encoding As String)
    Try
        If Connected Then
            Astream.Write(data.GetBytes(encoding))
        End If
    Catch
        Log("Printer error : " & LastException.Message)
        AStream_Error
    End Try
End Sub
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
correcion falto CRLF

B4X:
Private Sub PrintCodeBarCPCL
    
    Dim CPCLcomand As String
    
    CPCLcomand = "! 0 200 200 210 1" & CRLF
    Printer1.WriteString2(CPCLcomand, "gb2312")
    
    CPCLcomand = "BARCODE 128 1 1 50 150 10 HORIZ." & CRLF
    Printer1.WriteString2(CPCLcomand, "gb2312")
    
    CPCLcomand = "TEXT 7 0 210 60 HORIZ." & CRLF
    Printer1.WriteString2(CPCLcomand, "gb2312")
    
    CPCLcomand = "FORM" & CRLF
    Printer1.WriteString2(CPCLcomand, "gb2312")
    
    CPCLcomand = "PRINT" & CRLF
    Printer1.WriteString2(CPCLcomand, "gb2312")
End Sub
 

vecino

Well-Known Member
Licensed User
Longtime User
No existe "Astream" en esa demo.
Astream.Write(data.GetBytes(encoding))
 

vecino

Well-Known Member
Licensed User
Longtime User
Bien, lo he probado y solamente imprime texto, nada de códigos de barras :/

pru.jpg
 

TILogistic

Expert
Licensed User
Longtime User
según tu print setup dice esto CPCL, puedes publicar el setup de la impresora nuevamente, pero mas completo y visible

1623841816750.png
 

TILogistic

Expert
Licensed User
Longtime User
este demo de la documentación que publicaste, funciona con tu impresora
 

Attachments

  • Screenshot_20210616-074357.png
    Screenshot_20210616-074357.png
    51.8 KB · Views: 133
Top