Spanish Impresion QR CODE Bluetooth ESC/POS Printer Class

elsanto1970

Member
Licensed User
Buenas gente : agregue unas funciones para imprimir codigos QR en un Impresora Epson TM-P20 , a la clase https://www.b4x.com/android/forum/threads/bluetooth-esc-pos-printer-class.106553/




Funciones agregadas a la clase original:
'**************************************************
' QR CODE EPSON TM-P20
 
'**************************************************

Public Sub ModelQrCode(modeloqr As Int)
    ' QR Code: Select the model
    ' Funcion 165
    ' [Format]    ASCII  GS     (      k     pL     pH     cn     fn     n1     n2
    '            Hex   1D  28    6B    04    00    31    41    n1    n2
    '         Decimal  29  40    107 4    0    49    65    n1    n2
    '[Range]
    '(pL + pH × 256) = 4
    'cn = 49
    'fn = 65
    'n2 = 0
    'n1: different depending on the printers
    'TM-P20:
    'n1 = 49, 50
    '[Default]
    'n1 = 50, n2 = 0
    ' modeloqr = n1 (49 - 50 - 51)
    
    ' https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=140
    
    ' GS ( k PL = 4 PH = 0 cn =49 fn=65 n1 = 49 o 50(p20) n2 = 0
    Dim pL As Int
    Dim pH As Int
    Dim cn As Int
    Dim fn As Int
    Dim n1 As Int
    Dim n2 As Int
    
    pL = 4
    pH = 0
    cn = 49 ' (qr = 49 pfd417 = 48 etc)= cn
    fn = 65   
    n1 = modeloqr ' 50 para p20
    n2 = 0
    '****************************
    'String Comun del Mensaje
    WriteString(GS & "(" & "k")
    '****************************
    Dim params(6) As Byte
    params(0) = pL
    params(1) = pH
    params(2) = cn
    params(3) = fn
    params(4) = n1
    params(5) = n2
    WriteBytes(params)
    
End Sub
Public Sub SizeQrCode(sizeqr As Int)
    '     QR Code: Set the size of module
    '     Funcion 167
    '     sizeqr = n1 (1-16)  n1 = 3 para p20
    '     https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=141
    '     [Format]    ASCII     GS  (     k    pL    pH    cn    fn    n
    '                Hex    1D    28    6B    03    00    31    43    n
    '              Decimal    29    40    107    3    0    49    67    n

    ' GS ( k PL = 3 PH = 0 cn =49 fn=67 n = 1-16  n=3 para p20
    
    Dim pL As Int
    Dim pH As Int
    Dim cn As Int
    Dim fn As Int
    Dim n1 As Int

    
    pL = 3
    pH = 0
    cn = 49 ' (qr = 49 pfd417 = 48)= cn
    fn = 67  'fn
    n1 = sizeqr '(1-16)
    '****************************
    'String Comun del Mensaje
    WriteString(GS & "(" & "k")
    '****************************
    Dim params(5) As Byte
    params(0) = pL
    params(1) = pH
    params(2) = cn
    params(3) = fn
    params(4) = n1
    
    WriteBytes(params)
    
End Sub
Public Sub ErrorQcode(errorqr As Int )
    ' QR Code: Select the error correction level
    ' Funcion 169
    ' https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=142
    ' [Format]    ASCII    GS    (    k    pL    pH    cn    fn    n   
    '            Hex    1D    28    6B    03    00    31    45    n
    '         Decimal    29    40    107    3    0    49    69    n
    '[Range]
    '(pL + pH × 256) = 3
    'cn = 49
    'fn = 69
    'n = 48 – 51
    '[Default]
    'n = 48
    ' GS ( k PL = 3 PH = 0 cn =49 fn=69 n = 48-51
    
    
    Dim pL As Int
    Dim pH As Int
    Dim cn As Int
    Dim fn As Int
    Dim n1 As Int

    
    pL = 3
    pH = 0
    cn = 49 ' (qr = 49 pfd417 = 48)= cn
    fn = 69  'fn
    n1 = errorqr '(48-51)
    
    '****************************
    'String Comun del Mensaje
    WriteString(GS & "(" & "k")
    '****************************
    Dim params(5) As Byte
    params(0) = pL
    params(1) = pH
    params(2) = cn
    params(3) = fn
    params(4) = n1
    
    WriteBytes(params)
    
End Sub
Public Sub StoreQrCode(data As String)
    '  QR Code: Store the data in the symbol storage area
    '  Funcion 180
    '  https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=143

    '[Format]    ASCII    GS    (    k    pL    pH    cn    fn    m    d1...dk
    '           Hex     1D    28    6B    pL    pH    31    50    30    d1...dk
    '           Decimal    29    40    107    pL    pH    49    80    48    d1...dk
    '[Range]
    '(pL + pH × 256) = 4 – 7092
    'cn = 49
    'fn = 80
    'm = 48
    'd = 0 – 255
    'k = (pL + pH × 256) − 3
    
    '[Description]
    'Stores the QR Code symbol data (d1...dk) in the symbol storage area.
    'd...dk es el data a imprimir
    
    Dim databytes() As Byte = data.GetBytes("ISO-8859-1")
    Dim store_len As Int = databytes.Length + 3
    Dim pH        As Int = store_len / 256
    
    Log("ph" & pH)
    
    Dim pL As Int = store_len Mod 256
    Log("pH" &  pL)
    

    Dim cn As Int
    Dim fn As Int
    Dim m As Int
  
    
    cn = 49 ' (qr = 49 pfd417 = 48)= cn
    fn = 80  'fn
    m =  48  '
    
    '****************************
    'String Comun del Mensaje
    WriteString(GS & "(" & "k")
    '****************************   
    
    Dim params(5) As Byte
    params(0) = pL
    params(1) = pH
    params(2) = cn
    params(3) = fn
    params(4) = m
    '
    WriteBytes(params)
    '
    WriteBytes(databytes)
    
End Sub
Public Sub PrintQrCode
    '     QR Code: Print the symbol data in the symbol storage area
    '     Funcion 181
    '     https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=144
    '[Format]    ASCII       GS    (    k    pL    pH    cn    fn    m
    '            Hex         1D    28     6B     03     00    31     51     m
    '           Decimal      29     40     107 3      0     49     81     m
    '[Range]
    '(pL + pH × 256) = 3
    'cn = 49
    'fn = 81
    'm = 48
    
    Dim pL As Int
    Dim pH As Int
    Dim cn As Int
    Dim fn As Int
    Dim m As Int
    pL = 3
    pH = 0
    cn = 49
    fn = 81
    m =  48 'tm-p20
    
    '****************************
    'String Comun del Mensaje
    WriteString(GS & "(" & "k")
    '****************************
    
    Dim params(5) As Byte
    params(0) = pL
    params(1) = pH
    params(2) = cn
    params(3) = fn
    params(4) = m
    WriteBytes(params)
    
End Sub
'*******FIN QR CODE EPSON TM-P20 *********************
Ejemplo de impresion foto y lineas desde un boton
B4X:
Sub btnQrCodeNew_Click
    
    Printer1.Reset
    Printer1.ModelQrCode(50) ' 49-51 valores permitidos
    Printer1.SizeQrCode(6)  '1-16 valores permitidos
    Printer1.ErrorQcode(48)  '48-51 valores permitidos
    If TxtQrcode.Text = "" Then
        ToastMessageShow("Error necesito el texto" , True)
        Return
    End If
    Dim TextoImprimir As String
    TextoImprimir =  TxtQrcode.Text
    Printer1.StoreQrCode(TextoImprimir)
    Printer1.PrintQrCode
    Printer1.WriteString(TextoImprimir & CRLF)
    '****************************************************************************
    
    Printer1.WriteString(Chr(27) & "d" & Chr(3)) 'avanza 3 lineas para el corte
End Sub
WhatsApp Image 2020-09-25 at 15.49.10.jpeg
 
Top