3 Replies Latest reply on May 26, 2016 3:09 PM by Robin West

    LinkOS with Xamarin and VS2015

    Chris Dafnis

      Hi,

       

      I'm writing a C# app to connect to a bluetooth printer and print labels off.

      As part of this, I want to save the connected printer to an XML file, so that we can connect to it on subsequent runs without having to rediscover.

       

      I've happily extracted the IDiscoveredPrinter details and saved them, and can read them back out again, but I am having problems recreating the printer.

      I can create a DiscoveredPrinter, or DiscoveredPrinterBluetooth, but I cannot create or cast the relevant instances.

       

      Any help please.

       

      Thanks, Chris

        • Re: LinkOS with Xamarin and VS2015
          Robin West

          Hi Chris,

          Using the SDK, I would recommend saving the IDiscoveredPrinter.Address to your file.  Then you can use:

          IConnection connection = ConnectionBuilder.Current.Build("BT:" + address);

          To create a new Bluetooth connection.

          Robin

          1 of 1 people found this helpful
            • Re: LinkOS with Xamarin and VS2015
              Chris Dafnis

              Hi Robin,

               

              Thank you, I had resorted to this, I was just wondering why you can't cast between interface and object like you can elsewhere in C#.

               

              With regards to using IConnection, I am seeing a lot of Exceptions, such as:

              ex = {Zebra.Sdk.Comm.ConnectionException: Could not open connection string "BT:AC:3F:A4:53:FC:FB"

                at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscor...

               

              Which I don't see using BluetoothConnectionInsecure, can you explain why please?

                • Re: LinkOS with Xamarin and VS2015
                  Robin West

                  Hi Chris,

                  This is still an early phase of the SDK and we will be adding in additional functionality in the future. 

                   

                  Some of the reasons why casting between the object and interface don't work as you expect are because of the way we implemented the SDK to be cross platform.  The DiscoveredPrinter class does not really inherit from IDiscoveredPrinter.  The classes inheriting from the IDiscoveredPrinter interfaces are actually private (hidden) Android and iOS specific implementation classes.  We do intend to add the api's to recreate an IDiscoveredPrinter object

                   

                  I'm not sure why you are seeing these exceptions.  Have you checked the Bluetooth security mode of the printer and Android device? One of the features we intend to implement next is the ability to create specific types of connections like the BluetoothConnectionInsecure connection. 

                  Robin