Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Using LabJack U3 with Unity

  • Please log in to reply
2 replies to this topic

#1 tarelom

  • Members
  • 2 posts

Posted 28 June 2012 - 10:47 AM

I'm attempting to write a program using Unity that gives a signal to a LabJack U3-hv when certain triggers are hit. I'm scripting the interface in Unity 3D with C#. In order to access the U3 I am trying to call functions directly from the dll. I created a Namespace called labjack and made a class called Native Methods inside of it. This is where I Import the dlls. I am currently only trying to open the device to ensure that I have communication. [codebox]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using UnityEngine; namespace LabJack { public class NativeMethods { [DllImportAttribute(@"C:\Windows\SysWOW64\labjackud.dll", CharSet = CharSet.Ansi, SetLastError = true, EntryPoint = "OpenLabJack")] public static extern long OpenLabJack(long DeviceType, long ConnectionType, System.String pAddress, long FirstFound, ref long pHandle); } }[/codebox] I then call OpenLabJack in another class method. [codebox]long lngHandle; long lngError; bool InitializeLabJack() { lngError = NativeMethods.OpenLabJack(3, 1, "1", 1, ref lngHandle); if (lngError != 0) { return false; } else { return true; } } [/codebox] When I run this I keep getting a LJE_UNKNOWN_ERROR (1001). Is there a different way I should be trying to give inputs to the OpenLabJack function. It is originally OpenLabJack(long DeviceType, long ConnectionType, const char *pAddress, long FirstFound, long *pHandle). I'm wondering if I'm not doing the correct equivalency in C#, or is there something else anyone can see. Thanks for the Help!

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 28 June 2012 - 12:27 PM

You'll want to use an int (32-bit) data type instead of a long. C# longs are 64-bit while the C driver's longs are 32-bit. We do provide a .NET driver with our installed software. Are you unable to use that?

#3 tarelom

  • Members
  • 2 posts

Posted 28 June 2012 - 12:54 PM

Thank you very much! When using Unity I've been told that it is best to access the dll files directly within your own wrapper. Using ints instead of longs has fixed my problem and now my entire solution is working. I can't thank you enough.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users