B4X:
sub Process_Globals
private printer_serial1 as serial
end sub
Sub Globals
Private printer_foundDevices As List
Private printer_admin As BluetoothAdmin
Private printer_Writer As TextWriter
end sub
printer_admin.Initialize("PrinterAdmin")
printer_foundDevices.Clear
If printer_serial1.IsInitialized=False Then
printer_serial1.Initialize("PrinterSerial")
End If
PairedDevices=printer_serial1.GetPairedDevices
If PairedDevices.size=0 Then
If printer_admin.StartDiscovery = False Then
ToastMessageShow("Error starting discovery process.", True)
Else
ProgressDialogShow("Searching for devices...")
End If
Else
Dim oPDList As List
oPDList.Initialize
Dim nm As NameAndMac
If nm.IsInitialized=False Then
nm.Initialize
End If
For i =0 To PairedDevices.Size-1
oPDList.Add(PairedDevices.GetKeyAt(i))
Next
For i =0 To oPDList.size-1
nm=oPDList.Get(i) '//why doesn't this assignment give me the name and mac address
'If nm.Name="GD200P" Then
printer_serial1.Connect(PairedDevices.Get(oPDList.get(0)))
SendTextToPrinter
'End If
Next
End If
Sub SendTextToPrinter
Try
printer_Writer.Initialize(printer_serial1.OutputStream) '//Crashes with a null pointer
printer_Writer.WriteLine("Hello World")
printer_Writer.Flush
printer_Writer.Close
printer_serial1.Disconnect
Catch
oError.ShowLastException("Error : SendTextToPrinter")
EndTry
End Sub
I want to find a Printer by Name and connect its mac address. The NameAndMac assignment is not working correctly.
Last edited: