Android Tutorial BlueTooth Printing via SPP

jahswant

Well-Known Member
Licensed User
Longtime User
I'm using an esc/pos printer connecting via Bluetooth.I'm wondering on how to send a logo or a bar code to that printer on my receipt.If you have an example it will be greatly appreciated...
 

timwil

Active Member
Licensed User
Longtime User
your printer should have a utility that would allow the download of the logo

then you would send the command sequence to print the logo

Chr(28) & "p" & Chr(1) & "0"

On a ESC/POS printer the above string prints the logo set as NV graphic 0
 

metzeller_2013

Member
Licensed User
Longtime User
@kris A
Have made your printer work already? If not, try finding some toggle switch in the printer and make sure you are set to RAW Mode not Protocol Mode
 

timwil

Active Member
Licensed User
Longtime User
on page two of the manual

DIP Switch Settings
Sw4 - Normal operation mode -Protocol mode
 

kris A

Member
Licensed User
Longtime User
@metzeller , @timwill thanks for your help. I managed to correct the dip switch sw4 and now it works well. Thanks again so much for your time and help

Kris
 

erasmusackon

Member
Licensed User
Longtime User
Hello Timwil, I have downloaded your sample but it wasn't complete as I expected. My problem now is how to design a simple receipt and then send it to the printer. Please help me it's urgent. Thanks so much
 

jahswant

Well-Known Member
Licensed User
Longtime User
your printer should have a utility that would allow the download of the logo

then you would send the command sequence to print the logo

Chr(28) & "p" & Chr(1) & "0"

On a ESC/POS printer the above string prints the logo set as NV graphic 0
Hi @timwil i download the logo to my printer but can't print if from my B4A app i used your ESC commands but no luck.Please considering the barcode side do you have a tutorial or snippet ???
 

timwil

Active Member
Licensed User
Longtime User
sending this this worked for me

Chr(28) & "p" & Chr(1) & "0"

that will print the stored NV - logo - 0
 

timwil

Active Member
Licensed User
Longtime User
B4X:
Private Sub PrintBarCode(ByVal PrintData As String, ByVal ShowNumbers As Boolean)
   PrintBuffer = PrintBuffer & Chr(29) & "h" & Chr(50) & vbCrLf
   PrintBuffer = PrintBuffer & Chr(29) & "w" & Chr(2) & vbCrLf

   If ShowNumbers Then
      PrintBuffer = PrintBuffer & Chr(29) & "H" & "2" & vbCrLf
      PrintBuffer = PrintBuffer & Chr(29) & "f" & "0" & vbCrLf
   Else
      PrintBuffer = PrintBuffer & Chr(29) & "H" & "0" & vbCrLf
   End If

   PrintBuffer = PrintBuffer & Chr(29) & "k" & Chr(4) & PrintData & Chr(0) & vbCrLf
End Sub

This is a bit of code from a Visual Basic 6 application that I have. It prints bar codes on ESC/POS printers
 

padvou

Active Member
Licensed User
Longtime User
I have a problem printing Greek characters using this.
Is it possible to use the solution described here:
B4X:
Question

    I have a Zebra ?MZ - 320 thermal printer.

    I? print with?my ?C# .net?CF? application and a WM5 device using bluetooth and serial port.

    I use the following code:

    ?
    Code Snippet

    ?

    using

    ?

    System.IO.Ports;

    ?

    SerialPort comPort1 = new SerialPort("COM8", 57600, Parity.None, 8, StopBits.One);

    comPort1.Open();

    ?

    StringBuilder DataString = new StringBuilder();

    DataString.Append(

    "! 0 200 200 240 1\r\n");

    DataString.Append(

    "LABEL\r\n");

    DataString.Append(

    "T ARI10PT.CPF 0 130 90 Καλημ?ρα\r\n");? // Printing ????? instead of Καλημ?ρα (Greek characters)

    DataString.Append("T 0 0 250 100 Goodmorning\r\n");???? // WORKS FINE

    DataString.Append(

    "FORM\r\n");

    DataString.Append(

    "PRINT");

    comPort1.WriteLine(DataString.ToString());

    comPort1.Close();

    ?

    ?

    ?

    ?

    I have created with Zebra Label Vista a font (Arial,Regular,size 10,script Greek,character range 32-255)

    and save it as ARI10PT.CPF.

    I then sent it to the printer.

    When I print from my desktop computer and Label Vista everything is fine.

    When I run the code from my device it prints ???? as many as the length of the string? and in size 10.

    Does anybody knows why the printer understands the length and size of created font,but not the greek character set.

    I repeat from my desktop computer everything works fine.

    ?

    ?

    ?

    ?

    ?

    Thanks in advance

    Sorry for my english.

    ?

? Hi,

? I had the same problem with -hebrew- fonts.
?
? and i solve it by convert the string to array of bytes.

?
? try this :

SerialPort comPort1 = new SerialPort("COM2", 57600, Parity.None, 8, StopBits.One);

comPort1.Open();

//here replace the hebrew text with greek/XXXX text
string sToPrint=Reverse("????? ") ;??

?
sToPrint=sToPrint+ "\r\n";

//here replace the Encoding "windows-1255" to greek/xxxx encoding
byte []arrByte1255= Encoding.GetEncoding("windows-1255").GetBytes(sToPrint);

comPort1.Write(arrByte1255,0,arrByte1255.Length );

comPort1.Close();
Or any other solution would be greatly appreciated
 

padvou

Active Member
Licensed User
Longtime User
Can you post the code that converts the string to bytes?
here you are:
B4X:
? Hi,

? I had the same problem with -hebrew- fonts.
?
? and i solve it by convert the string to array of bytes.

?
? try this :

SerialPort comPort1 = new SerialPort("COM2", 57600, Parity.None, 8, StopBits.One);

comPort1.Open();

//here replace the hebrew text with greek/XXXX text
string sToPrint=Reverse("????? ") ;??

?
sToPrint=sToPrint+ "\r\n";

//here replace the Encoding "windows-1255" to greek/xxxx encoding
byte []arrByte1255= Encoding.GetEncoding("windows-1255").GetBytes(sToPrint);

comPort1.Write(arrByte1255,0,arrByte1255.Length );

comPort1.Close();
 

padvou

Active Member
Licensed User
Longtime User
Where is the problem? In the device or Windows?

You can use B4J to write the windows program. It will be easier and you will be able to use prefix mode which is more reliable.
I'm trying to print from this sample application, but I cannot print greek characters.
The printer is a Zebra MZ220. With Latin characters, there is no problem.
The solution I pasted is from somebody using some other language and converts string to bytes and sends it to the com port.
I was wondering if this solution or some other solution can be implemented in B4A
I mean there must be somebody printing in other languages that use extended characters
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…