LinkOS Binding Project for Xamarin.iOS

Attached is a Xamarin Binding project for LinkOS SDK.

 

Sample code:

 InvokeInBackground (delegate {                  Console.WriteLine ("DEBUG::searching external accessories for zebra s/n");                    List<string> serialNumbers = new List<string> ();                  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");              });  

Adam Hill
Have you (or anyone) made

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Adam,Let me look into a

Hi Adam,

Let me look into a couple of things and get back to you on this. Would you be able to share a sample of your code?

Thank you,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adam Hill
Thanks for getting back to me

Thanks for getting back to me so quickly. I had little hope that someone might be watching these forums.

I figured it out. When sending data to the printer over Bluetooth in iOS you must run it on a background thread.

The error you get when you don't do that - "282 failed to write because stream does not have space available" is very misleading  So I finally compiled the demo app, started studying the source and noticed the "detachNewThreadSelector:@selector(....)" for all of your button presses and it clicked.

I would still like to make the suggestion that you make some official Link-OS bindings that will track SDK releases and put them in the Xamarin Store or contribute them back to the monotouch-bindings  project for 3rd party libraries on GitHub . It would give you a leg up on the competition. (Prexisting and up to date bindings are the reason we are going to use a specific iOS laser barcode scanner instead of their competitors)

I'll make you a deal, if you do the bindings and send me the some printers to test on, I will port your demo app to Xamarin.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
Adam,  I added

Adam,  I added UnifiedAndTasks.zip to my original posting.

You are correct it has to be started on a separate thread.  InvokeInBackground should work but I prefer the LongRunning Task. 

RE DemoApp... do it!

Adam, where are you at?  I'm near Chicago.

/c

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adam Hill
Dude you rock! Wish I would

Dude you rock! Wish I would have posted earlier, could have saved me a lot of grief yesterday. After being trained not to update the UI on a background thread in WPF, I wasnt even thinking this way till I saw the demo project :-)

I am in Dallas

Hey the source says it is still bound against  the 1.2 SDK is this correct? Is there anything significantly changed or fixed in 1.3? I am wondering if I can just link against the new .a.

Beverly: Has the API changed between 1.2 and 1.3?

Once again, thanks!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Adam,The are a few changes

Hi Adam,


The are a few changes (shown below from the change log in latest SDK ver 1.3):


Change Log:

11/13/2014 1.3.924 iOS 7 and 8 are now supported.
XCode 6.0.1 supported.
The Infinite Peripherals libraries have been removed.
The default delay for the MFiBTConnection has been reduced to 10ms.

A few developers have reported being unable to print images and/or text and receiving an “Unable to determine printer language” message due to the delay change above, this article, describes how to resolve that.

Does that answer the question that you had?

Thank you,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adam Hill
Chris,Does the Universal

Chris,

Does the Universal project need Linea still? I get a "Native linking failed...." complaining about Linea.a symbols missing.

Do I need a Unifed version of Linea.a?

Ada\

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
Good question.  Since we are

Good question. 

Since we are using Linea hardware then I have it included. 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adam Hill
So how is it getting

So how is it getting referenced in the new project you posted? Searching for 'Linea' in the ApiDefinition, Enums, .csproj and .sln dont show anything? Are you building the ZSDK_API.a from scratch?

How did I manage to get a DLL that was working? Arrrrg!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
It is referenced by Zebra's

It is referenced by Zebra's DLL.

Maybe strip out the ApiDefinition file to what you need.  It might be referencing a native method that ends up calling Linea?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Adam,The Linea lines are

Hi Adam,

The Linea lines are used when Infinite Peripherals Linea Pro devices are used. If you aren't planning on using those devices with your application, you shouldn't need those lines of code/references.

Thanks,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Adam,This is a good idea. 

Hi Adam,

This is a good idea.  It doesn't look like creating bindings and submitting SDKs to the Xamarin Component store is difficult or costly.  I'm sending the info on to our SDK product manager.  He'll have to review the legal stuff.  I should be able to get some response in if we will be able to add it to the store within the next few weeks.

Robin

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


William Shepherd
Hi, Chris. I am attempting to

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?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
Hexers is an internal project

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?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


William Shepherd
Ok that explains why it was

Ok that explains why it was complaining about Hexers. I attempted to compile the ZebraService.CS file as an initial test. VS2013 is setup to work with .NET. And I think that it is possible to compile a DLL in Xamarin Studio then use that DLL in other projects.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
I added UnifiedAndTasks2.zip

I added UnifiedAndTasks2.zip.

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


William Shepherd
Thanks, for the new

Thanks, for the new attachment. I will try to get this up and working today.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


William Shepherd
I cleaned out the

I cleaned out the ZebraService class as advised, but I am still getting reference errors in ZebraPrintModel.CS. I assume this class is necessary, but I do not know if the method FromApplicationConfiguration is necessary. I could not find any usages of it in the files you sent, but it does seem to be returning a ZebraPrinterModel. Screen Shot 2015-05-13 at 8.38.53 AM.png

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adam Hill
Ignore all the Hexers and

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Everyone, Our newest Link

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments