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

vecino

Well-Known Member
Licensed User
Longtime User
Hola, amigos, espero que estén todos bien.
De nuevo estoy aquí con mis dudas existenciales. En este hilo recibí una ayuda muy importante para resolver un problema con la impresora bluetooth, básicamente el código que estoy usando es el de este otro hilo adaptado con los consejos que recibí en el hilo anterior, y gracias a ello funciona perfectamente.
Solamente imprimo texto, pero ahora me piden que también imprima códigos de barras y... esa es mi duda.
Según el hilo que he indicado se ve un código de barras, así que debe poderse.
En ese hilo que inicié, elsanto1970, indicó una clase que utiliza para imprimir y veo que también tiene para códigos de barras, pero no estoy usando esa clase, por lo que no sé si se puede adaptar el procedimiento/Sub a la opción que estoy usando yo.

Resumiendo, que no sé qué camino tomar, ando bastante perdido, ¿podéis echarme una mano con este tema?
Gracias a todos.

Las impresoras que van a usar son de esas chinas, aquí va una foto:
impre.jpg
 

TILogistic

Expert
Licensed User
Longtime User
Debe revisar el manual y ver las especificaciones de la impresora.

Si permite imprimir código de barra y cuales son sus comandos.

Consejo:
Para entender bien que debe desarrollar debe separar las especificaciones en:.

1. tipo de conexión wifi, bluetooth, Serial, USB, RJ45, RS232, etc.
2. tipo de emulación de comandos ESC, ESC/P, ZPL, etc.

Saludos,
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
Hola, oparra, la impresora es bluetooth y sin haber configurado nada, he probado a imprimir una factura desde mi programa de ventas android y ha salido bien.
Sí imprime códigos de barras normales y 2D también, según la documentación.
No sé qué otra información puede hacer falta, así que enlazo aquí a un archivo zip donde está toda la documentación.
No es exactamente de este modelo, sino de otro posterior, pero son prácticamente iguales.
Documentación impresora móvil bluetooth.
Gracias.
 

vecino

Well-Known Member
Licensed User
Longtime User
No veo nada de ZPL, lo que sí pone es CPCL, que no sé qué es.
 

TILogistic

Expert
Licensed User
Longtime User
Revise los manuales del modelo HM-Z3 y solo emula comandos CPCL ( "Lenguaje de control de impresión Comtec" ).

usted indica que esta imprimiendo, podría indicar como esta imprimiendo actualmente el modelo que estas usando.

Suba un pequeño código.

Saludos.
 

TILogistic

Expert
Licensed User
Longtime User
si lo he visto pero son secuencias de escape no CPCL.

Ahora bien todavía no indica como imprime, ese link da un ejemplo de comandos escape
PrintBuffer=Chr(27)&"t"&Chr(16)&"Hello öäüßéèê" 'Set codepage 1252

comandos CPCL

// This example prints "This is a CPCL test." near the top of the label.
String cpclData = "! 0 200 200 210 1\r\n"
+ "TEXT 4 0 30 40 This is a CPCL test.\r\n"
+ "FORM\r\n"
+ "PRINT\r\n";

// Send the data to printer as a byte array.
thePrinterConn.write(cpclData.getBytes());


Saludos.
 

TILogistic

Expert
Licensed User
Longtime User
No entiendo todavía que esta emulando su impresora modelo M35.

Primero revise si esta emulando comandos ESC o CPCL, la mayoría de las impresora vienen con una emulación de comandos por defecto, revise cual es.

Modelo HMZ3
1623614528293.png


comandos CPCL
 

Attachments

  • HPRT HMZ3 HMT3_Programming Manual_Rev.1.5.zip
    453.9 KB · Views: 206

vecino

Well-Known Member
Licensed User
Longtime User
Imprimo tal y como indicas, ejemplo:
B4X:
Printer.Initialize2(BTConnection.OutputStream,"windows-1252")
PrintBuffer="Hola, mundo"
Printer.WriteLine(PrintBuffer)
Printer.Flush
En cuanto a CPCL, la verdad es que jamás había oido hablar sobre ese lenguaje.
¿Puedo enviar una cadena/string tal y como has descrito?
B4X:
Printer.Initialize2(BTConnection.OutputStream,"windows-1252")
String cpclData = "! 0 200 200 210 1\r\n"
                                  + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
                                  + "FORM\r\n"
                                  + "PRINT\r\n";
Printer.WriteLine(cpclData)
Printer.Flush
Gracias, y disculpa mi torpeza con este tema.
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
Parece que usa CPCL, sin embargo tal y como he comentado antes puedo imprimir normalmente, pero no uso letras grandes, negritas, condensadas, imágenes ni nada, solamente texto.
Lo que necesito es eso, imprimir códigos de barras.
He sacado una impresión de la configuración de la impresora:
cpcl.jpg
 

TILogistic

Expert
Licensed User
Longtime User
ok, para imprimir codigos de barras solo debes usar comandos CPCL o ESC

comando cpcl
Pagina 14 del manual
! 0 200 200 210 1
BARCODE 128 1 1 50 150 10 HORIZ.
TEXT 7 0 210 60 HORIZ.
VBARCODE 128 1 1 50 10 200 VERT.
VTEXT 7 0 60 140 VERT.
FORM
PRINT

Output:

1623617633681.png
 

TILogistic

Expert
Licensed User
Longtime User
Imprimo tal y como indicas, ejemplo:
B4X:
Printer.Initialize2(BTConnection.OutputStream,"windows-1252")
PrintBuffer="Hola, mundo"
Printer.WriteLine(PrintBuffer)
Printer.Flush
En cuanto a CPCL, la verdad es que jamás había oido hablar sobre ese lenguaje.
¿Puedo enviar una cadena/string tal y como has descrito?
B4X:
Printer.Initialize2(BTConnection.OutputStream,"windows-1252")
String cpclData = "! 0 200 200 210 1\r\n"
                                  + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
                                  + "FORM\r\n"
                                  + "PRINT\r\n";
Printer.WriteLine(cpclData)
Printer.Flush
Gracias, y disculpa mi torpeza con este tema.
si

B4X:
    Dim PrintBuffer As String
    PrintBuffer = "! 0 200 200 210 1" & Chr(13) & Chr(10)
    PrintBuffer = PrintBuffer & "TEXT 4 0 30 40 This is a CPCL test." & Chr(13) & Chr(10)
    PrintBuffer = PrintBuffer & "FORM" & Chr(13) & Chr(10)
    PrintBuffer = PrintBuffer & "PRINT" & Chr(13) & Chr(10)
 

TILogistic

Expert
Licensed User
Longtime User
Parece que usa CPCL, sin embargo tal y como he comentado antes puedo imprimir normalmente, pero no uso letras grandes, negritas, condensadas, imágenes ni nada, solamente texto.
Lo que necesito es eso, imprimir códigos de barras.
He sacado una impresión de la configuración de la impresora:
View attachment 114867
cuando imprimes la configuración no aparece que emulación de comandos que esta usando ??
 

TILogistic

Expert
Licensed User
Longtime User
si es CPCL lea el manual es simple de entender:

"! 0 200 200 210 1

Printer Commands
Format:
<!> {offset} <200> <200> {height} {qty}
where:
<!>: Use ‘!’ to begin a control session.
{offset}:The horizontal offset for the entire label. This value causes all fields to be offset horizontally by
the specified number of UNITS.
<200>:Horizontal resolution (in dots-per-inch).
<200>:Vertical resolution (in dots-per-inch).
{height}:The maximum height of the label.
The maximum label height is calculated by measuring from the bottom of the first black bar (or label
gap) to the top of the next black bar (or label gap). Then 1/16” [1.5mm] is subtracted from this distance
to obtain the maximum height. (In dots: subtract 12 dots on 203 d.p.i printers; 18 dots on 306 d.p.i.
printers)
{qty}: Quantity of labels to be printed. Maximum = 1024.
Printer Command Example
Input
! 0 200 200 210 1
TEXT 4 0 30 40 Hello World
FORM
PRINT
Output
1623618654062.png
 

TILogistic

Expert
Licensed User
Longtime User
ok, para imprimir codigos de barras solo debes usar comandos CPCL o ESC

comando cpcl
Pagina 14 del manual


Output:

View attachment 114871

B4X:
    Dim Printer As TextWriter
    Printer.Initialize2(serial1.OutputStream, "windows-1252")
    
    Dim CPCLcomand As String
    CPCLcomand = "! 0 200 200 210 1"
    Printer.Write(CPCLcomand)
    
    CPCLcomand = "BARCODE 128 1 1 50 150 10 HORIZ."
    Printer.Write(CPCLcomand)
    
    CPCLcomand = "TEXT 7 0 210 60 HORIZ."
    Printer.Write(CPCLcomand)
    
    CPCLcomand = "FORM"
    Printer.Write(CPCLcomand)
    
    CPCLcomand = "PRINT"
    Printer.Write(CPCLcomand)
    
    Printer.Flush


1623619609943.png
 

TILogistic

Expert
Licensed User
Longtime User
opcion 2 impresion en Bytes:

Libreria ByteConverter
B4X:
'    https://www.b4x.com/android/forum/threads/byteconverter-library.6787/#content
    Dim BConv As ByteConverter
   
    Dim Printer2 As OutputStream
    Printer2 = Serial1.OutputStream
   
    Dim CPCLcomand() As Byte
       
    CPCLcomand = BConv.StringToBytes("! 0 200 200 210 1")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
   
    CPCLcomand = BConv.StringToBytes("BARCODE 128 1 1 50 150 10 HORIZ.")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
   
    CPCLcomand = BConv.StringToBytes("TEXT 7 0 210 60 HORIZ.")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
   
    CPCLcomand = BConv.StringToBytes("FORM")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
   
   
    CPCLcomand = BConv.StringToBytes("PRINT")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
   
    Printer2.Flush

1623620578709.png
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
opcion 3

B4X:
    Dim Printer2 As OutputStream
    Printer2 = Serial1.OutputStream
    
    Dim CPCLcomand() As Byte
    
    CPCLcomand = "! 0 200 200 210 1".GetBytes("UTF8")
    Printer2.WriteBytes(CPCLcomand2, 0, CPCLcomand.Length)
    
    CPCLcomand = "BARCODE 128 1 1 50 150 10 HORIZ.".GetBytes("UTF8")
    Printer2.WriteBytes(CPCLcomand2, 0, CPCLcomand.Length)
    
    CPCLcomand = "TEXT 7 0 210 60 HORIZ.".GetBytes("UTF8")
    Printer2.WriteBytes(CPCLcomand2, 0, CPCLcomand.Length)
    
    CPCLcomand = "FORM".GetBytes("UTF8")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
    
    CPCLcomand = "PRINT".GetBytes("UTF8")
    Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
    
    Printer2.Flush
 

vecino

Well-Known Member
Licensed User
Longtime User
Amigo, me dejas asombrado, está claro que todos los días se aprende algo nuevo.
Lo pruebo en un rato y comento.
Muchísimas gracias.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hola, he probado todas las opciones que propones y se ejecuta sin ningún tipo de error, sin embargo, no imprime, la impresora no se inmuta.
Y ya digo, compila y ejecuta correctamente.
¿Esos ejemplos que has puesto los has impreso en alguna impresora similar?
 

vecino

Well-Known Member
Licensed User
Longtime User
He instalado una demo que trae la documentación que he subido antes y esa imprime bien.
Ni idea del motivo.
 
Top