building a barcode scanning feature with Xamarin (we are encountering specific problem)

BradMSimmonsBradMSimmons USMember
edited October 2013 in Cross Platform with Xamarin

Background: We are trying to incorporate a barcode scanning feature into our mobile app. Specifically, this is a VIN scanner to make it more efficient for auto mechanics to do vehicle inspections. Here is a problem we are encountering.

Details:
I wanted to integrate one third-part library for VIN scanning (it works very good on old Android devices, which is important). But unfortunately, it doesn't build for Xamarin.

I've taken Java example and rewrote it in C#, but that doesn't work, and I don't know why. I am hoping the Xamarin team or community can help.

This is Java code from example:

public class B4HScanner
{
     public float acuracy;

      // load native library when initializing
      static
      {
            System.loadLibrary("b4hvinscanner");
      };

      // constructor
      public B4HScanner()
      {
            super();
            acuracy = 1.0f;
      }

      // parse VIN code from "data" or NULL if VIN code not found
      public native String parse( byte []data, int size, int width, int height, int q, Context context);

      // check status of Bees4Honey scanner license
      public native int status(Context context);
}

I need to use "parse" method from this class, so I rewritten this class to C#:

public class B4HScanner
{
      public const float Acuracy = 0.1f;

      static B4HScanner()
      {
            //JavaSystem.LoadLibrary("b4hvinscanner");
      }

      [DllImport("libb4hvinscanner.so")]
      public extern static string parse(byte[] data, int size, int width, int height, int q, Context context);
}

But every time I'm calling B4HScanner.parce method, I'm getting "System.EntryPointNotFoundException: parse"

Not sure what I am doing wrong. Any help would be greatly appreciated.

Best Answer

Answers

  • BillHolmesBillHolmes USXamarin Team Xamurai
  • BradMSimmonsBradMSimmons USMember
    edited October 2013

    Yes, I've added to my project file this:

    [For some reason, I could not copy and paste this correctly. Here is screenshot of what I added: http://screencast.com/t/nfjn04W3zE ]

    And... as I understand, if library can't be found, I'll get System.DllNotFoundException exception, instead of EntryPointNotFoundException

  • BradMSimmonsBradMSimmons USMember

    This works great! Thank you!

    I just did as you said and it work.

    I've modified code a little:

    public class B4HScanner
    {
    public const float Acuracy = 0.1f;

      [DllImport("b4hvinscanner", EntryPoint = "Java_com_bees4honey_vinscanner_B4HScanner_parse")]
            static extern IntPtr _Parse(
            IntPtr jnienv, // JNIEnv.Handle
            IntPtr self, // For instance method, `this` reference
            IntPtr data, // JNI handle to Java-side byte[]
            int size, // yay blittable types
            int width, // yay blittable types
            int height, // yay blittable types
            int q, // yay blittable types
            IntPtr context); // JNI handle to Java-side Context
    
    
      public static string Parse(byte[] data, int size, int width, int height, int q, Context context)
      {
            IntPtr lrefData = IntPtr.Zero;
            try
            {
                  lrefData = JNIEnv.NewArray(data);
                  var contextPtr = context == null ? IntPtr.Zero : context.Handle;
                  IntPtr resultRef = _Parse(JNIEnv.Handle, IntPtr.Zero, lrefData, size, width, height, q, contextPtr);
                  var result = JNIEnv.GetString(resultRef, JniHandleOwnership.TransferLocalRef);
                  return result;
            }
            finally
            {
                  if (lrefData != IntPtr.Zero)
                  {
                        JNIEnv.DeleteLocalRef(lrefData);
                  }
            }
      }
    

    }

  • makaveiljojomakaveiljojo USMember

    Looking farward to have the Xamarin with barcode reading function. I believe it'll be awesome.

  • DanielPlaisted.6736DanielPlaisted.6736 USMember
    edited January 2014

    Have you tried ZXing.Net? I've heard good things about it. It's available in the Xamarin component store. See also https://zxingnet.codeplex.com/ and https://github.com/Redth/ZXing.Net.Mobile (which provides UI for it).

    Here's the Getting Started Guide from the component store.

  • arronleearronlee USMember
    edited June 2014

    Hi, makaveil jojo.
    Thanks for your sharing.It is appreciated very much. And I wonder whether there are some differences between the c# barcode generation add-in I am testing these days and the one you mentioned above? Do you have any ideas about it? Or any good suggestion? Thanks in advance.

    Best regards,
    Arron

  • arronleearronlee USMember

    Hi, makaveil jojo.
    Thanks for your sharing.It is appreciated very much. And I wonder whether there are some differences between the c# barcode generation add-in I am testing these days and the one you mentioned above? Do you have any ideas about it? Or any good suggestion? Thanks in advance.

    Best regards,
    Arron

  • arronleearronlee USMember

    Hi, makaveil jojo.
    Thanks for your sharing.It is appreciated very much. And I wonder whether there are some differences between the c# barcode generation add-in I am testing these days and the one you mentioned above? Do you have any ideas about it? Or any good suggestion? Thanks in advance.

    Best regards,
    Arron

Sign In or Register to comment.