LinkOS Binding Project for Xamarin.iOS

C Chris Misztur 3 years 7 months ago
3 6 0

Attached is a Xamarin Binding project for LinkOS SDK.
 
Sample code:
InvokeInBackground (delegate {                  Console.WriteLine ("DEBUG::searching external accessories for zebra s/n");                    List serialNumbers = new List ();                  var connectedAccessories = EAAccessoryManager.SharedAccessoryManager.ConnectedAccessories;                  foreach (var accessory in connectedAccessories) {                      if (accessory.ProtocolStrings.Contains ("com.zebra.rawport")) {                          serialNumbers.Add (accessory.SerialNumber);                          Console.WriteLine ("DEBUG::found external zebra device with s/n:" + accessory.SerialNumber);                      }                  }                    if (serialNumbers.Count == 0) {                      Console.WriteLine ("DEBUG::no external zebra devices found!");                      return;                  }                    Console.WriteLine ("DEBUG::executing SDK API against s/n:" + serialNumbers [0]);                    MfiBtPrinterConnection thePrinterConn = new MfiBtPrinterConnection (serialNumbers [0]);                  //thePrinterConn.TimeToWaitAfterReadInMilliseconds = 1000;                  //thePrinterConn.TimeToWaitAfterWriteInMilliseconds = 1000;                    Console.WriteLine ("DEBUG::printer connected? : " + thePrinterConn.IsConnected.ToString ());                  bool success = thePrinterConn.Open ();                  Console.WriteLine ("DEBUG::printer connected? : " + thePrinterConn.IsConnected.ToString ());                    Console.WriteLine ("DEBUG::printer opened:" + success.ToString ());                    NSData data = NSData.FromString (@"^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ", NSStringEncoding.UTF8);                  NSError error = new NSError ();                    int bytesWritten = thePrinterConn.Write (data, out error);                    Console.WriteLine ("DEBUG::written bytes:" + bytesWritten.ToString () + ", error-code:" + (error==null ? "(null)" : error.Code.ToString ()));                    //TODO: does this have to be called before closing printer conn?                  ZebraPrinter zebraPrinter = ZebraPrinterFactory.GetInstance(thePrinterConn, out error);                  ToolsUtil toolsUtil = zebraPrinter.GetToolsUtil();                  //toolsUtil.PrintConfigurationLabel(out error);                    FileUtil fileUtil = zebraPrinter.GetFileUtil();                  var f = fileUtil.RetrieveFileNames(out error);                    PrinterStatus printerStatus = zebraPrinter.GetCurrentStatus(out error);                    string sgdValue = SGD.GET("bluetooth", thePrinterConn, out error);                    thePrinterConn.Close ();                  //thePrinterConn.DangerousRelease ();                    Console.WriteLine ("DEBUG::finished");              }); 

Please Register or Login to post a reply

6 Replies

Y Yanis Dalabiras

Hi Everyone,
Our newest Link-OS SDK now has a Xamarin Component for Android, iOS, and Forms development.  Check it out.

Will keep everyone informed as we add new cross platform API's.
Robin

C Chris Misztur

I added UnifiedAndTasks2.zip.
Focus on the WriteToPrinter method and strip out the class to just do that, including getting the connection and such.

A Adam Hill

Ignore all the Hexers and Restsharp nameaspaces and such. I have ripped out all the extraneous stuff and built it in Mac Xam Studio, moved the resulting DLL to the PC, added it to my VS project and used it just fine.

Remember - Before Xamarin 3.11, you can only build Binding projects on Mac. I have upgraded to 3.11 and just added the binding project to my VS solution and it has been working.

Adam

W William Shepherd

Hi, Chris.

I am attempting to integrate the UnifiedAndTask project (compiled in Xamarin Studio and copied the DLL into my VS2014 Project) and having a lot of trouble. Could you expand on what it takes to use the ZebraService.CS in a project. Also, I when attempting to resolve all the build errors I was getting, I noticed that there is a package named RestSharp and Hexers. I was able to fined RestSharp on Nuget, but I was unable to locate Hexers. Is Hexers some proprietary library I would need access to as well?

C Chris Misztur

Hexers is an internal project that has nothing to do with the Zebra stuff. 
Would that work if you compile in Xamarin and run in VS?  Is your VS setup to work with Mono or .NET?

A Adam Hill

Have you (or anyone) made Universal bindings yet?

I tried adding LinkTarget.Arm64 to the LinksWith and changing to the non-Monotouch namespace in the posted solution.

Bluetooth discovery and getting a MfiBtPrinterConnection() works, but Write() writes -1 bytes and returns an error code 1. Trying to call ZebraPrinterFactory.GetInstance() returns null.

I am about to give ObjectiveSharpie a try. Just wanted to ask before going down that road.

Thanks

CONTACT
Can’t find what you’re looking for?