Android Question CPCL Bluetooth Print

Pantelis Loizou

Member
Licensed User
Longtime User
hi to everyone

i need to convert the below VB6 Code to B4A language. any ideas will be appreciate a lot. the bluetooth printer now is working with cpcl emulation

printdata = "! 0 200 200 584 1" & vbCrLf
printdata = printdata + "LABEL" & vbCrLf
printdata = printdata + "TONE " & CStr(modGlobal.PrinterTone) & vbCrLf
printdata = printdata + "SPEED 5" & vbCrLf
printdata = printdata + "PAGE-WIDTH 384" & vbCrLf
printdata = printdata + "BAR(-SENSE)" & vbCrLf
printdata = printdata + "PREFEED(0)" & vbCrLf
printdata = printdata + "POSTFEED(0)" & vbCrLf
printdata = printdata + "PRESENT-AT 0 2" & vbCrLf
printdata = printdata + "COUNTRY(UK)" & vbCrLf
printdata = printdata + "CHAR-SET7 " & "CP-737" & vbCrLf
printdata = printdata + "BT 7 1 0" & vbCrLf
printdata = printdata + "VB 128 1 0 85 130 534 " & txtLabelItemNo.Text & vbCrLf
printdata = printdata + "BT(OFF)" & vbCrLf
printdata = printdata + "SETMAG 2 3" & vbCrLf

printdata = printdata + "T90 7 3 145 160 " & itemprice & vbCrLf '180
printdata = printdata + "SETMAG 0 0" & vbCrLf

printdata = printdata + "T90 7 1 165 185 " & "=" & vbCrLf '205
printdata = printdata + "SETMAG 0 0" & vbCrLf

printdata = printdata + "T90 7 1 165 180 " & "C" & vbCrLf '200
printdata = printdata + "SETMAG 0 0" & vbCrLf

If Len(ppwstring) <> 0 Then
printdata = printdata + "T90 0 3 230 200 " & ppwstring & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf
Else
If chkSpecialoffer.Checked Then
printdata = printdata + "T90 0 3 230 200 Special Offer" & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf
End If
End If

If Len(DLine2) > 0 Then
printdata = printdata + "T90 7 1 0 534 " & DLine1 & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf

printdata = printdata + "T90 7 1 40 534 " & DLine2 & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf

If Len(Trim(Me.lblLabelItemLevel.Text)) > 1 Then
printdata = printdata + "T90 0 2 80 534 " & Me.lblLabelItemLevel.Text & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf
End If
Else
printdata = printdata + "T90 7 1 20 534 " & DLine1 & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf
If Len(Trim(Me.lblLabelItemLevel.Text)) > 1 Then
printdata = printdata + "T90 0 2 80 534 " & Me.lblLabelItemLevel.Text & vbCrLf
printdata = printdata + "SETMAG 0 0" & vbCrLf
End If
End If
printdata = printdata + "SETMAG 0 0" & vbCrLf
printdata = printdata + "FORM" & vbCrLf
printdata = printdata + "PRINT" & vbCrLf

''//here replace the Encoding "windows-1255" to greek/xxxx encoding
arrByte1253 = Encoding.GetEncoding("ibm737").GetBytes(printdata)
wSerialPort.Write(arrByte1253, 0, arrByte1253.Length)

wSerialPort.Close()
 

TILogistic

Expert
Licensed User
Longtime User
see:
spanish
other
search:

I personally modified the class to be able to print on different commands (ESC/POS, ZPL, CPCL, etc)
 
Upvote 0

Pantelis Loizou

Member
Licensed User
Longtime User
Hi Omar. I appreciate your reply but i am very beginner with B4A so i am facing a problem. i follow your examples but nothing happen. below you may find my code. could you please tell me what is wrong
Dim Serial1 As Serial
Dim Printer2 As OutputStream
Dim BConv As ByteConverter
Dim CPCLcomand() As Byte

CPCLcomand = BConv.StringToBytes("! 0 200 200 210 1", "ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("LABEL","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("TONE 5","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SPEED 5","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("PAGE-WIDTH 384","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("BAR(-SENSE)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("PREFEED(0)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("POSTFEED(0)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("PRESENT-AT 0 2","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("COUNTRY(UK)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("COUNTRY(UK)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("CHAR-SET7 " & "CP-737","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("BT 7 1 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("VB 128 1 0 85 130 534 " & txtPrintItem.Text,"ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("BT(OFF)","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 2 3","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("T90 7 3 145 160 " & txtPrice.Text,"ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 0 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("T90 7 1 165 185 " & "=","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 0 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("T90 7 1 165 180 " & "C","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 0 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("T90 7 1 20 534 " & txtDescription.Text,"ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 0 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("SETMAG 0 0","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("FORM","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)
CPCLcomand = BConv.StringToBytes("PRINT","ibm737")
Printer2.WriteBytes(CPCLcomand, 0, CPCLcomand.Length)

Printer2.Flush
 
Upvote 0

Pantelis Loizou

Member
Licensed User
Longtime User
1655911660923.png
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Dear looking at the printer configuration picture, you can use ESC/POS emulation and use "ESC/POS Bluetooth Printer Class".

1655947129352.png


Now why do you want to use CPCL emulation?
 
Upvote 0
Top