Android Question barcode

rogel a. tolentino

Member
Licensed User
CAn you help me to print a barcode in a thermal paper? I already know how to print alphanumeric characters via blueetooth thru thermal printer.
In vb.net the sample command is
oport.Write(Chr(27) + "Z1" + Chr(6) + "L" + "123456") '
to print 123456 with barcode
 

MarkusR

Well-Known Member
Licensed User
Longtime User
it looks like a Escape sequence, 27 is the decimal value of ascii escape control character.
the device catch it and do a special function.
u should look which sequences are supported in device manual, and make also sure u have a correct printer connection via usb direct or bluetooth library.
 
Last edited:
Upvote 0

rogel a. tolentino

Member
Licensed User
CAn you help me to print a barcode in a thermal paper? I already know how to print alphanumeric characters via blueetooth thru thermal printer.
In vb.net the sample command is
oport.Write(Chr(27) + "Z1" + Chr(6) + "L" + "123456") '
to print 123456 with barcode

What I mean is that how to print a barcode in b4a. The above sample code is for vb.net and is working. Thanks
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
if u will also print via bluetooth from b4a u need a library for it that u can connect to this device first.
then if u have a connection u can send this escape sequence to this printer and it should do the same as in .net
 
Upvote 0

rogel a. tolentino

Member
Licensed User
This is to inform you tha in Vb.net the syntax in printing bar code is as shown below:
oport.Write(Chr(27) + "Z1" + Chr(6) + "L" + "123456")

In b4a I tried this
B4X:
Printer.WriteLine(Chr(27) & "Z1" & Chr(6) & "L" & "123456")
and works. Thanks a lot
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
which library belongs Printer. ?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
please can u show how u define Printer, a bit more around Printer. ?
 
Upvote 0

rogel a. tolentino

Member
Licensed User
Code below is to connect to bluetooth printer

B4X:
Sub switch_Click
    If switch=0 Then 'FirstTime Then
        switch=1
        BtAdmin.Initialize("BlueTooth")
        BTConnection.Initialize("Printer")
        Dim paireddevices As Map
        paireddevices = BTConnection.GetPairedDevices
        Dim l As List
        Dim DeviceName, MacAddress As String
        l.Initialize
        For i = 0 To paireddevices.Size - 1 'Check all devices
            l.Add(paireddevices.GetKeyAt(i))
            DeviceName=paireddevices.Getkeyat(i)
            'Msgbox("qwe","rty")
            MacAddress=paireddevices.GetValueAt(i)
            Log(DeviceName & " -> " & MacAddress)
            If DeviceName.Contains("Thermal") Then 'Insert the BT-Name of the printer or use the MAC address
                Exit
            End If
        Next
        BTConnection.Connect(MacAddress)
    End If
End Sub

COde below is the printing process by calling printnew from the menu
B4X:
Sub printnew_Click
    Main.ResultSet1=Main.SQL1.ExecQuery("select * from newcon")
    Dim rr1,rr2,rr3,rr4 As String
    If Main.ResultSet1.RowCount>0 Then
        Printer.Initialize2(BTConnection.OutputStream,"windows-1252") 'important to print f.e. German/French chars
        PrintBuffer=Chr(27)&"t"&Chr(16)&"" '"Hello öäüßéèê" 'Set codepage 1252
        Printer.WriteLine(Chr(29)&""&Chr(13))
        Main.ResultSet1.Position=0
        Printer.WriteLine(Chr(29)&"Other Readings:"&Chr(13))
        For ii = 0 To Main.resultset1.rowcount-1
            Main.resultset1.Position=ii
            rr1=Main.resultset1.GetString2(0)
            rr2=Main.resultset1.GetString2(1)
            rr3=Main.resultset1.GetString2(2)
            rr4=Main.resultset1.GetString2(4)
            Printer.WriteLine(rr1&" "&rr2&" "&rr3&" "&rr4)
        Next
        Printer.WriteLine(Chr(27) & "Z1" & Chr(6) & "L" & "123456")  'sample to print in barcode the text 123456 chr(6) means 6 characters
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.Flush
    End If
End Sub
 
Upvote 0

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
Code below is to connect to bluetooth printer

B4X:
Sub switch_Click
    If switch=0 Then 'FirstTime Then
        switch=1
        BtAdmin.Initialize("BlueTooth")
        BTConnection.Initialize("Printer")
        Dim paireddevices As Map
        paireddevices = BTConnection.GetPairedDevices
        Dim l As List
        Dim DeviceName, MacAddress As String
        l.Initialize
        For i = 0 To paireddevices.Size - 1 'Check all devices
            l.Add(paireddevices.GetKeyAt(i))
            DeviceName=paireddevices.Getkeyat(i)
            'Msgbox("qwe","rty")
            MacAddress=paireddevices.GetValueAt(i)
            Log(DeviceName & " -> " & MacAddress)
            If DeviceName.Contains("Thermal") Then 'Insert the BT-Name of the printer or use the MAC address
                Exit
            End If
        Next
        BTConnection.Connect(MacAddress)
    End If
End Sub

COde below is the printing process by calling printnew from the menu
B4X:
Sub printnew_Click
    Main.ResultSet1=Main.SQL1.ExecQuery("select * from newcon")
    Dim rr1,rr2,rr3,rr4 As String
    If Main.ResultSet1.RowCount>0 Then
        Printer.Initialize2(BTConnection.OutputStream,"windows-1252") 'important to print f.e. German/French chars
        PrintBuffer=Chr(27)&"t"&Chr(16)&"" '"Hello öäüßéèê" 'Set codepage 1252
        Printer.WriteLine(Chr(29)&""&Chr(13))
        Main.ResultSet1.Position=0
        Printer.WriteLine(Chr(29)&"Other Readings:"&Chr(13))
        For ii = 0 To Main.resultset1.rowcount-1
            Main.resultset1.Position=ii
            rr1=Main.resultset1.GetString2(0)
            rr2=Main.resultset1.GetString2(1)
            rr3=Main.resultset1.GetString2(2)
            rr4=Main.resultset1.GetString2(4)
            Printer.WriteLine(rr1&" "&rr2&" "&rr3&" "&rr4)
        Next
        Printer.WriteLine(Chr(27) & "Z1" & Chr(6) & "L" & "123456")  'sample to print in barcode the text 123456 chr(6) means 6 characters
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.WriteLine("")
        Printer.Flush
    End If
End Sub


Could this be missing in the definitions part of the variables?

B4X:
Sub Process_Globals
    Dim PrintBuffer As String

    Dim BtAdmin As BluetoothAdmin
    Dim BTConnection As Serial
    Dim Printer As TextWriter
End Sub

https://www.b4x.com/android/forum/t...printer-with-matching-codepage.76831/#content
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
thank you for sharing :)
 
Upvote 0
Top