@cxbs Your TsplPrinter class is very helpful! Thank you very much.
I have changed a minor codes to make it async:
Use InputListAsync instead:
' Ask the user to connect to a printer and return whether she tried or not
' If True then a subsequent Connected event will indicate success or failure
Public Sub Connect As ResumableSub
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
InputListAsync(l, "Choose a printer", 0, False) 'show list with paired devices
Wait For InputList_Result (Index As Int)
If Index <> DialogResponse.CANCEL Then
Log("Selected place: " & l.Get(Index))
Serial1.Connect(PairedDevices.Get(l.Get(Index))) 'convert the name to mac address
Return True
End If
Return False
End Sub
Moreover, could you provide the tspl instruction file for me to learn tspl language?
You can find an example of a Bluetooth connection where you can send a TSPL command and wait for the printer to return a message or wait for the printer to respond once the connection is successful!
You can find an example of a Bluetooth connection where you can send a TSPL command and wait for the printer to return a message or wait for the printer to respond once the connection is successful!
After establishing a connection with Bluetooth printing, you can send the following commands for printing. Please note that different printers support different command formats!
B4X:
Private Sub but1_Click
Starter.Printer2.Size(60,40)
Starter.Printer2.GAP(2,0)
Starter.Printer2.DENSITY2(7)
Starter.Printer2.REFERENCE(0,0)
Starter.Printer2.CLS
Dim a As String
a= 1 & ":Test" & DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now)
Starter.Printer2.TEXT(50,7,"TSS24.BF2",0,1,1,0,a)
Starter.Printer2.BOX(100,100,400,280,1,10)
Starter.Printer2.PRINT(1,0)
Starter.Printer2.EOP
End Sub
After establishing a connection with Bluetooth printing, you can send the following commands for printing. Please note that different printers support different command formats!
B4X:
Private Sub but1_Click
Starter.Printer2.Size(60,40)
Starter.Printer2.GAP(2,0)
Starter.Printer2.DENSITY2(7)
Starter.Printer2.REFERENCE(0,0)
Starter.Printer2.CLS
Dim a As String
a= 1 & ":Test" & DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now)
Starter.Printer2.TEXT(50,7,"TSS24.BF2",0,1,1,0,a)
Starter.Printer2.BOX(100,100,400,280,1,10)
Starter.Printer2.PRINT(1,0)
Starter.Printer2.EOP
End Sub
Please download the TSPL.zip document I uploaded earlier (which can be found on the top floor), extract it and run it. It is recommended to install it on your phone for testing. Open the Bluetooth device on your phone, search for and select the Bluetooth printer to connect to, and press the print button after successful connection. If the printer does not respond, it may be because your printer does not support this command. Please try changing the printer!
I have recorded a demonstration for your reference!
Please rename TSPL.rar to TSPL.z01 to decompress!
Please rename TSPL.txt to TSPL.z02 to decompress!
Last UnZip TSPL.ZIP