Page 1 of 1

Unity C# and Phidget22 Action

Posted: Thu Aug 06, 2020 6:31 pm
by Gron
Hello everyone!

Im trying to work with a DigitalInput. My issue is the OnStateChange event only fires 2 times. Has anyone else experienced this issue?

Code: Select all

private void StateChange(object sender, DigitalInputStateChangeEventArgs e)
    {
        Debug.Log(e.State);
        OnStateChange?.Invoke(e.State);
    }

Code: Select all

public bool Open()
    {
        bool success = false;
       
        try {
            _Phidget.StateChange += StateChange;
            _Phidget.Open();

            HubPort = _Phidget.HubPort;
            HubLabel = _Phidget.DeviceLabel;

            success = true;
        } catch { Debug.Log("Unable to open Digital Input"); }

        return success;
    }
True will log 1 time and so will False. Any ideas what I'm doing wrong?

Re: Unity C# and Phidget22 Action

Posted: Fri Aug 07, 2020 8:46 am
by mparadis
Is it possible the console is stacking duplicate log messages? I know some debuggers (like the chrome javascript debugger) will do this and display a little number beside the message denoting how many times it has triggered. If this is the case there should be an uncollapse button somewhere.

Re: Unity C# and Phidget22 Action

Posted: Fri Aug 07, 2020 9:57 am
by Gron
Hey! Thank you for your reply, That is not the issue unfortunately it is only firing the first time... I've also checked to see if the DI gets closed prematurely it's not. I'm using unity 2017.4.39 this is the LTS version. I've attached a picture of the console. I feel like I'm missing something.

Re: Unity C# and Phidget22 Action

Posted: Fri Aug 07, 2020 10:14 am
by Gron
This is what confuses me more...

Code: Select all

 jump.HubPort = Port;
        jump.Channel = 0;
        jump.StateChange += onStateChange;
        jump.Open();

Code: Select all

private void onStateChange(object sender, DigitalInputStateChangeEventArgs e)
    {
        if(e.State == true)
        {
            Debug.Log("onStateChange");
        }
    }
This works with a Thumbstick HIN1100_0 I can log state change multiple times. Ill upload a picture if needed.

Re: Unity C# and Phidget22 Action

Posted: Fri Aug 07, 2020 12:17 pm
by Gron
I think the issue is that the DI I'm using is a hub port device that's the only thing I can think that is different. We are dispatching Actions off other phidget event handlers like OnPositionChanged in the same way and getting expected results.

Re: Unity C# and Phidget22 Action

Posted: Fri Aug 07, 2020 2:03 pm
by mparadis
If you're using a VINT port in DigitalInput mode, are you setting the IsHubPortDevice property to 'true' before opening the channel? If not, you might be unintentionally opening some other DigitalInput channel on your system, since "open" will always try to match up with a channel based on which properties you set (and if you don't set any properties, it will match with any available DigitalInput).