I'm using the Zebra SDK on a iOS App made with Xamarin framework on .NET using Visual Studio 2019.
I've added ExternalAccessory information and support for bluetooth in info.plist.
I've paried my ZQ320 printer on iOS settings.
<code>
var conn = new Zebra.Sdk.Comm.BluetoothConnection(mac);
conn.Open();
var printer = Zebra.Sdk.Printer.ZebraPrinterFactory.GetLinkOsPrinter(conn, Zebra.Sdk.Printer.PrinterLanguage.ZPL);
var status = printer.GetCurrentStatus();
</code>
The GetCurrentStatus (and any other functionality) will throw an exception "Error writing to connection"
at Zebra.Sdk.Comm.Internal.ZebraBluetoothSocket+OutputStream.Write (System.Byte[] source) [0x00065] in <81e75b784ceb453f94368622a751b567>:0
at Zebra.Sdk.Comm.Internal.ZebraBluetoothSocket+OutputStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0003f] in <81e75b784ceb453f94368622a751b567>:0
at System.IO.MemoryStream.WriteAsync (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Threading.CancellationToken cancellationToken) [0x00060] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/IO/MemoryStream.cs:764
Anyone can help?
5 Replies
The problem is with the BluetoothConnection(mac) statement. On iOS, we have to use the friendly_name of the printer's Bluetooth. By default, the friendly_name is the serial number of the printer.
Hello, thanks for the reply. I've changed the friendly_name, so its not the serialnumber anymore, but if i use the friendly name i get:
<code>Could not connect to device: Object reference not set to an instance of an object</code>
I've also tried then to use the GetConnection from the discovered printers gained from Zebra.Sdk.Printer.Discovery.BluetoothDiscoverer.FindPrinters. But i still get the "Error writing to connection" error.
I saw the same error msg on an old build of the XamarinDevDemo already installed on my iOS device. Then I updated the Visual Studio and created a new build for my iOS 14.8 device. The error msg went away and the Bluetooth connection started working. Please try to update the Visual Studio for the latest Xamarin package. Hope this makes the "Could not connect to device: Object reference not set to an instance of an object" error msg go away for you.
I've already VS19 with latest version, and latest version of Xamarin Package, and latest version of Zebra SDK, i've also tried to create a new empty project and still not working.
I finally find the solution by myself. In order to work, the printing process should be executed on a different thread of the GUI.
Glad that you've figured it out. The Zebra printers are considered as slow accessories in general. Any interaction to the printer cannot be done in a UI thread. It is recommended to spawn a separate thread when calling the Link-OS SDK API.