Android Question Bluetooth Printer problem

kilat kosasih

Member
Licensed User
Longtime User
Hi,
I got this source from the forum here, but when I tried it with a Bluetooth printer that was paired to the device, the program immediately exited without leaving an error message. After I investigated, the problem arose when running the command "PairedDevices = BTConnection.GetPairedDevices" What's missing from the source below, for the record, I've included a serial library

regards
kilat kosasih





#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: Bluetooth POS Printing
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

Sub Process_Globals
Dim PrintBuffer As String

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

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
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)
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

Sub Activity_Resume

End Sub

Sub Activity_Pause

End Sub

Sub Printer_Connected (Success As Boolean)
If Success 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(PrintBuffer)
Printer.Flush

Msgbox("Printed!","")
Printer.Close
BTConnection.Disconnect 'disable this if you like
Else
Msgbox("No printer found...","Print error")
End If
End Sub
 
Sorry, I have a problem with this code:
when running, at line 28, my program suddenly exit without any message
please assist me
thank you
regards
kilat kosasih

Code: Copy
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: Bluetooth POS Printing
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

Sub Process_Globals
Dim PrintBuffer As String

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

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
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)
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

Sub Activity_Resume

End Sub

Sub Activity_Pause

End Sub

Sub Printer_Connected (Success As Boolean)
If Success 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(PrintBuffer)
Printer.Flush

Msgbox("Printed!","")
Printer.Close
BTConnection.Disconnect 'disable this if you like
Else
Msgbox("No printer found...","Print error")
End If
End Sub
 
Upvote 0
my program suddenly exit without any message
no such thing

When a app crashes there must be something in the LOG.
Connection your device over USB and run it again.

Maybe uncheck the filtered checkbox to see all log.
 
Upvote 0
Back
Top