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.
If printer_AStream.IsInitialized = False Then
printer_AStream.InitializePrefix(printer_serial1.InputStream, True, printer_serial1.OutputStream, "PrinterAStream")
EndIf
Dim buffer() As Byte
buffer="Hello World".GetBytes("UTF8")
printer_AStream.Write(buffer)
Log("Send data to printer")
I converted the TextWriter Code to asychronous stream as recommended in other posts. The code did not crash.