Android Question ESC/POS COMMAND TAB

Discussion in 'Android Questions' started by MarcoRome, Feb 13, 2016.

  1. MarcoRome

    MarcoRome Expert Licensed User

    Hi All. I'm trying to make some prints with a POS that supports Epson (ESC / POS) command.
    I have this code:

    Code:
    'Qui inserisco l'intestazione delle colonne   
        Dim d_qta As String = "QTY"
        
    Dim d_desc As String = "ITEM"
        
    Dim d_price As String = "U/PRICE"

        astreams1.Write(d_qta.GetBytes(
    "UTF8"))
        astreams1.Write(
    Array As Byte(27,101,0,9)) 'Tab

        astreams1.Write(d_desc.GetBytes(
    "UTF8"))
        astreams1.Write(
    Array As Byte(27,101,0,9)) 'Tab

        astreams1.Write(d_price.GetBytes(
    "UTF8"))
    But i have this result:
    2016-02-13 19.10.33.jpg

    As you can see the first TAB is present ( QTY + TAB + ITEM ) but the second TAB isnt present ( ITEMU/PRICE ).

    I try also this code :
    Code:
    astreams1.Write(Array As Byte(27,101,0,9)) 'Tab
    but dont change nothing

    Any idea ??
    Thank you
     
  2. imbault

    imbault Well-Known Member Licensed User

    Hi @MarcoRome, i'm trying the same (about) with a bluetooth label printer
    Can you, please give a code snippet of a print routine ( your astream1 init etc...)

    BTW, try to remove the / in your U/PRICE just to see


    Thanks
     
  3. MarcoRome

    MarcoRome Expert Licensed User

    Thank you Imbault but also if insert only QTY, ITEM, PRICE ( without / ) dont change nothing.
    About a astream i try Initialize and InitializePrefix ( with BigEndian True / False ) same thing.

    I try in all mode also this:

    Code:
    dim onetab as string = Chr(27) & (101) & Chr(0) & Chr(9)
    astreams1.Write(onetab.GetBytes(
    "UTF8"))
    'Or
    astreams1.Write(Array As Byte(27,101,0,9)) 'Tab
    Also this

    Code:
    dim onetab as string = Chr(27) & (68) &  Chr(9)
    astreams1.Write(onetab.GetBytes(
    "UTF8"))
    'Or
    astreams1.Write(Array As Byte(27,689)) 'Tab
    But dont change nothing.
    Anyway if i do Test i see that Command Support is ESPON(ESC/POS), and in test as you see TAB work without problem :confused::confused:

    2016-02-14 08.57.13.jpg
     
  4. mc73

    mc73 Well-Known Member Licensed User

    Tab is 9, no other escape codes. 27-101-48-n is for setting the (n)umber of characters of the tab.
     
  5. MarcoRome

    MarcoRome Expert Licensed User

    Hi mc73, thank you for response
    i try this code:

    Code:
    Dim d_qta As String = "QTY"
        
    Dim d_desc As String = "ITEM"
        
    Dim d_price As String = "U/PRICE"
        
    Dim d_total As String = "TOTAL"
        astreams1.Write(d_qta.GetBytes(
    "UTF8"))
        astreams1.Write(
    Array As Byte(27,101,48,1)) 'Number Chars Tab
        astreams1.Write(Array As Byte(9)) 'Tab Char
        astreams1.Write(d_desc.GetBytes("UTF8"))
        astreams1.Write(
    Array As Byte(27,101,48,2)) 'Number Chars Tab
        astreams1.Write(Array As Byte(9)) 'Tab Char
        astreams1.Write(d_price.GetBytes("UTF8"))
    but i have print this result:

     
  6. mc73

    mc73 Well-Known Member Licensed User

    Suppose your columns are of fixed length, which I suppose is the case here. Say, first column has to have 5 characters, then second column, say, 10 characters, and then a third column.
    This means, that the first tab should try to go to position 5, the second tab should go to position 5+10=15. So, the tab settings we need, is 5 and 15, that is the points of line at which we need the columns to be separated.
    This should be written as
    Code:
    dim myString as string=chr(27) & "D" & chr(5) & chr(15) & chr(0) & "tab1" & chr(9) & "tab2" & chr(9) & "tab3"
    . Then write to stream, the bytes of the string and hopefully it'll work.
     
    fabricio, f0raster0, Don Oso and 3 others like this.
  7. MarcoRome

    MarcoRome Expert Licensed User

    Yes mc73 ;) work very well.
    Thank you very much
     
    mc73 likes this.
  8. MarcoRome

    MarcoRome Expert Licensed User

    As requested by some colleagues, i share the code create for example above, hoping that it will be of help.
    Libraries : RandomAccessFile - UsbSerial
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

        
    Dim usb1 As UsbSerial
        
    Dim astreams1 As AsyncStreams

    End Sub

    #Region EXAMPLE POSPRINTER
    Sub aprostampante
        
    If usb1.UsbPresent(1) = usb1.USB_NONE Then    ' Ver_2.4
            Log("Msgbox - no device")
            
    Msgbox("No USB device or accessory detected!""Error")
            
    Log("Msgbox - returned")
            
    Return
        
    End If
        
    Log("Checking permission 1")
        
    If (usb1.HasPermission(1)) Then    ' Ver_2.4
            'Msgbox(usb1.DeviceInfo(1), "Device Information 1")    ' Ver_2.4
            Log(usb1.DeviceInfo(1))
            
    'Questo è importante
            usb1.SetCustomDevice(usb1.DRIVER_SILABS, 0x4930x8760)
            
    'usb1.SetParameters(19200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)

            
    Dim dev As Int
          
            dev = usb1.Open(
    192001'STMicroeletronics
            'dev = usb1.Open(4800, 1)
            'dev = usb1.Open(115200, 1)        ' Ver_2.4
            'dev = usb1.Open(9600, 1)        ' Ver_2.4
            If dev <> usb1.USB_NONE Then
                
    Log("Connected successfully! 1")
                astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, 
    "astreams1")
                
    'THIS IS VERY IMPORTANT- PARAMETER
                usb1.SetParameters(19200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)
                
    'START PRINT
                stampafattura
            
    Else
                
    Log("Error opening USB port 1")
            
    End If
        
    Else
            usb1.RequestPermission(
    1)  ' Ver_2.4
        End If
    End Sub

    Sub stampafattura
        
    'astreams1.Write("By Devil-App".GetBytes("UTF8"))
        'astreams1.Write("Welcome To USB Receiver" & Chr(10) & Chr(13))
        'astreams1.Write("By Devil-App" & Chr(10) & Chr(13))
      
        
    '***** START DEMO

        
    Dim SendMsg As String

       
      
        SendMsg = 
    "HOUSE FOOD & ROOMS"  'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "LOCATION: TAKE AWAY" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        SendMsg = 
    "TEL: 0302-774477, 0302-773399, 024-4145444" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
          
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "CASHIER: TAKE AWAY PM" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        
    'Print Date and Time
        SendMsg = DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        
    'Qui inserisco il numero di ordine       
        SendMsg = "ORDER NO:" & ordine_consegna 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
          
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        
    'Here Receipt no:   
        SendMsg = "RECEIPT NO: XXXXXXXXX"  'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))


        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        
    'COLUMN HEADER  
        Dim d_qta As String = "QTY"
        
    Dim d_desc As String = "ITEM"
        
    Dim d_price As String = "U/PRICE"
        
    Dim d_total As String = "TOTAL"
      
        
    'QTY++ITEM++++++++U/PRICE+++TOTAL
        Dim myString As String=Chr(27) & "D" & Chr(4) & Chr(17) & Chr(27) & Chr(0) & d_qta & Chr(9) & d_desc & Chr(9) & d_price & Chr(9) & d_total
        astreams1.Write(myString.GetBytes(
    "UTF8"))

        astreams1.Write(
    Array As Byte(1310))'Line feed
      
        
    'LOOP EXAMPLE
        For i = 0 To 3
            
    Dim qta As String = i
            
    Dim ii As Int = Rnd(01000)
            
    Dim descrizione As String = "Descrizione " & i & ii
            descrizione = descrizione.SubString2(
    0,13)
            
    Dim price As String = "30.14"

            
    '0++++Descrizione 0
            astreams1.Write(Array As Byte(1310))'Line feed
            Dim mydetails As String=Chr(27) & "D" & Chr(4) & Chr(19) & Chr(26) & Chr(0) & qta & Chr(9) & descrizione & Chr(9) & price & Chr(9) & price
            astreams1.Write(mydetails.GetBytes(
    "UTF8"))

             
                  
        
    Next
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        
    'Qui inserisco i paramtri per NHIS e VAT in modo da detrarre il totale
        Dim contototale As Double = 121.60
        
    Dim totalenhis As Double = contototale *  0.0244  
        
    Dim totalevat As Double = contototale *  0.1275
      
        
    Dim subtotale As Double = contototale - totalenhis - totalevat
        
    'Fine calcolo
      
        SendMsg = 
    "SUB - TOTAL:             " & NumberFormat2(subtotale, 022True'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))


        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        
    'NHIS
        SendMsg = "NHIS:                    " &  NumberFormat2(totalenhis, 022True'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      

        
    'VAT
        SendMsg = "VAT:                     " &  NumberFormat2(totalevat, 022True'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        
    'TOTAL 2
        SendMsg = "AMOUNT DUE:               " & NumberFormat2(contototale, 022True'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))

        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))


        SendMsg = 
    "PAID:                     " & NumberFormat2(contototale, 022True'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
      
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "VAT NO: 221V44449" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "PHONE ORDERS: 11:00AM - 10:00PM" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "COME AGAIN" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    "*******************************" 'Send this line to the EPSON printer
        astreams1.Write(SendMsg.GetBytes("UTF8"))
      
        SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
          
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
         SendMsg = 
    Chr(13) & Chr(10)'Line feed
        astreams1.Write(SendMsg.GetBytes("UTF8"))
        
    '****** END PRINT
    End Sub

    Sub Astreams1_NewData (Buffer() As Byte)
        
    ' You must check for DeviceInfo or analyze Buffer data to know what is connected to the USB
        ' The order of the USB could change as you plug them and could change when changing the hub port they are connected to
        Log("NewData 1")
        
    Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
    End Sub

    Sub AStreams1_Error
        
    Log("Error: " & LastException)
        astreams1.Close
    End Sub
    Sub Astreams1_Terminated
        
    Log("Terminated")
        astreams1.Close
    End Sub

    #End Region EXAMPLE POSPRINTER
    bye
    Marco
     
  9. rboeck

    rboeck Well-Known Member Licensed User

    Here for all interested: replace or insert this lines in the upper demo (after ***** START DEMO )and see how to switch to diffent font sizes and styles...

    Code:
    SendMsg = "This is  Font A" & CRLF  
        astreams1.write (SendMsg.GetBytes(
    "UTF8"))
     
        SendMsg = 
    Chr(27) & "!" &Chr(1) & "Character Font B"CRLF 
        astreams1.Write(SendMsg.GetBytes(
    "UTF8"))
     
        SendMsg = 
    Chr(27) & "!" &Chr(8+1) & "Character Font B emphasized" & CRLF
        astreams1.Write(SendMsg.GetBytes(
    "UTF8"))
       
        SendMsg = 
    Chr(27) & "!" &Chr(8) & "Character Font A emphasized" & CRLF
        astreams1.Write(SendMsg.GetBytes(
    "UTF8"))
       
        SendMsg = 
    Chr(27) & "!" &Chr(8+16) & "Character Font A emphasized and double height" & CRLF
        astreams1.Write(SendMsg.GetBytes(
    "UTF8"))
       
        SendMsg = 
    Chr(27) & "!" &Chr(8+16+32) & "Font A emphasized and double height/width" & CRLF
        astreams1.Write(SendMsg.GetBytes(
    "UTF8"))
       
        SendMsg = 
    Chr(27) & "!" &Chr(8) & Chr(29) & "B" &Chr(1) & "Font A emphasized and reverse" & CRLF'
        astreams1.Write(SendMsg.GetBytes("UTF8"))
    I think, thats this few codes are recognized by the most thermal printers.
     
    f0raster0, Dadaista and MarcoRome like this.
  10. jahswani

    jahswani Active Member Licensed User

    Why do you write immmediately.Me i create a buffer and write once ...Is there some advantage of writing immediately ?
     
    Dadaista likes this.
  11. Dadaista

    Dadaista Member Licensed User

    I was trying the example from MarcoRome
    My printer prints ramdomly. Sometimes only prints the first line.... or until the line that prints "order no..."... sometimes until the second description. I don't know why

    with a break point (debug mode) in the call of the sub it happens several things. If I push F8 (step by step) prints whole ticket.. obviously
    if I push F9 Key, whole ticket prints too but, if I press F5 key, only the first line is printed. I don't know why this is happening.:(:confused::confused:

    I solved it, like jahswani said above... concatenating all in a buffer and only write once :D

    I hope this be useful for the users...;)

    Regards and sorry for my english :oops:
     
    Last edited: Jun 9, 2016
    DonManfred and Don Oso like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice