Possible Bug: Unity 2021 + Phidget22 + 1047_1B High Speed Encoder

Supporting Visual Studio on Windows
Post Reply
bm3n
Fresh meat
Posts: 2
Joined: Mon Jun 13, 2022 8:10 am
Contact:

Possible Bug: Unity 2021 + Phidget22 + 1047_1B High Speed Encoder

Post by bm3n »

I built a proto-type game controller for Unity3D using PhidgetEncoder High Speed 4-Input model 1047_2B. After successfully prototyping I needed to build another controller, however, at the time I placed the follow-up order, 1047_2B was out of stock and only the older 1047_1B devices were available. Within my Unity application, attempts to open the 1047_1B device timeout with a message saying: open failed because device is in use. Deeper investigation shows that the process holding the device is the Unity Editor itself, it seems to grab the device immediately upon start up. When I plug in my original prototype built with the newer 1047_2B device, my Unity project works fine.

I am using Phidget22 1.12 with Unity versions 2021.3.[4f1, 7f1, and 11f1] all versions of Unity are affected. I have tried several older Phidget22 versions with the same results. I have tried the following with no success:
  • Rebooting machine
  • Powering down, unplugging device, booting up, plugging device back in.
  • Plugging in device after Unity starts
I was able to force it work by doing the following:
  • Close Unity
  • Open Phidget Control Panel
  • Open Encoder Input 0
  • Open Digital Input 0
  • Open Unity project
  • Close Phidget Control Panel (releasing phidget)
  • Start Unity project in Editor
This works one or two times, then the Editor crashes, after which, the Editor will crash upon future attempts to re-open the project.

Also for further clarification, my project is based on the Unity example code (phidgets dot com/?view=articles&article=UsingPhidgetsWithUnity) which includes the recommended clean-up code:

Code: Select all

void OnApplicationQuit()
{
        encoder.PositionChange -= OnPositionChange;
        encoder.Close();
        encoder = null;

        if (Application.isEditor)
            Phidget.ResetLibrary();
        else
            Phidget.FinalizeLibrary(0);	
}
bm3n
Fresh meat
Posts: 2
Joined: Mon Jun 13, 2022 8:10 am
Contact:

Re: Possible Bug: Unity 2021 + Phidget22 + 1047_1B High Speed Encoder

Post by bm3n »

Just to follow up. I replaced the older 1047_1B with the newer 1047_2B and my device works fine with Unity now. I am able to start and stop the game within the editor frequently and with no problem opening the device channels or with the Unity editor crashing. The problem seems isolated to the older encoder board.

There is another interesting behavior that I want to document here that is not a bug but might be useful information for people working with Phidgets in Unity. When the game is running within the Editor in "Play Focused" mode (i.e. a window within the editor) I receive events from the encoder in a timely fashion and objects controlled by the encoder are playable. When the editor is switched to "Play Maximized" (i.e. full-screen) events come in very sporadically and objects controlled by the encoder are unplayable.

I did a test build to make sure this wasn't an issue playing full-screen, and it's not, the events come in much faster in the compiled build.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests