Unity C# and Phidget22 Action

Supporting Visual Studio on Windows
Post Reply
Gron
Phidgetsian
Posts: 8
Joined: Fri Jul 24, 2020 5:57 pm
Contact:

Unity C# and Phidget22 Action

Post 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?
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Unity C# and Phidget22 Action

Post 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.
Gron
Phidgetsian
Posts: 8
Joined: Fri Jul 24, 2020 5:57 pm
Contact:

Re: Unity C# and Phidget22 Action

Post 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.
Attachments
Capture.PNG
Gron
Phidgetsian
Posts: 8
Joined: Fri Jul 24, 2020 5:57 pm
Contact:

Re: Unity C# and Phidget22 Action

Post 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.
Gron
Phidgetsian
Posts: 8
Joined: Fri Jul 24, 2020 5:57 pm
Contact:

Re: Unity C# and Phidget22 Action

Post 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.
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Unity C# and Phidget22 Action

Post 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).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests