Quadrature in Unity3D | LabJack
 

Quadrature in Unity3D

2 posts / 0 new
Last post
johnking
johnking's picture
Quadrature in Unity3D

Hi, I am trying to use a U3-HV with Unity3D gaming engine. I can access the AIN and DAC but something's not working when I try to read quadrature from a rotary encoder. It works fine on FIO4 and FIO5 in the test mode of control panel, but I'm getting no data in Unity.

I import the DLL in a C# script as follows:

[DllImportAttribute("LabJackUD", CharSet = CharSet.Ansi, SetLastError = true, EntryPoint = "eTCConfig")]

public static extern int eTCConfig(int ljHandle, ref int[] aEnableTimers, ref int[] aEnableCounters, int TCPinOffset, int TimerClockBaseIndex, int TimerClockDivisor, ref int[] aTimerModes, ref double[] aTimerValues, int Reserved1, int Reserved2);

[DllImportAttribute("LabJackUD", CharSet = CharSet.Ansi, SetLastError = true, EntryPoint = "eTCValues")]

public static extern int eTCValues(int ljHandle, ref int[] aReadTimers, ref int[] aUpdateResetTimers, ref int[] aReadCounters, ref int[] aResetCounters, ref double[] aTimerValues, ref double[] aCounterValues, int Reserved1, int Reserved2);

Then I initialize in quadrature mode like this:

int[] aEnableTimers = {1,1};

int[] aEnableCounters = {0,0};

int[] aTimerModes = {8,8}; //Quadrature mode

double[] aTimerValues={0,0};

ljError = NativeMethods.eTCConfig(ljHandle, ref aEnableTimers, ref aEnableCounters, 4, 22, 1, ref aTimerModes, ref aTimerValues, 0 ,0);

Initialization returns zero - ie no errors. If I try illegal settings, I do get errors returned.

Then I try to read quadrature like this:

int[] aReadTimers = {1,1};

int[] aUpdateResetTimers = {0,0};

int[] aReadCounters = {0,0};

int[] aResetCounters = {0,0};

double[] aTimerValues={0,0};

double[] aCounterValues={0,0};

ljError = NativeMethods.eTCValues(ljHandle, ref aReadTimers, ref aUpdateResetTimers, ref aReadCounters, ref aResetCounters, ref aTimerValues, ref aCounterValues, 0 ,0);

This also returns zero, ie no error, but aTimervalues always reads zero.

Am I doing something stupid?

Sorry for bad formatting of the code - I can't see how to choose a codeblock in this forum software.

johnking
johnking's picture
Never mind - using ePut calls

Never mind - using ePut calls I got it working.