Page 1 of 1

Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Tue Jul 09, 2019 2:38 pm
by frazer
Hi!

I've updated my Phidget drivers and library using the new NuGet package from 1.0 to the latest (1.4.20190605).

Now I can't call the setter of the DigitalOutput.DutyCycle without getting an EntryPointNotFoundException like this:
"Unable to find an entry point named 'Phidget_getLastError' in DLL 'phidget22'."
I've noted this in the changelog which I guess has to do with this error:
- Add getLastError API for exposing extra error information.
If I revert back to version 1.0, I keep getting an PhidgetException with the errorcode NotAttached (which is probably since I'm using the new Windows drivers).

This means I'm currently stuck here and can't run my application for now.

Any ideas?

Regards,
Daniel

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Wed Jul 10, 2019 9:06 am
by fraser
I tried to replicate this, but cannot.

Code: Select all

static void Main(string[] args)
        {
            DigitalOutput dout = new DigitalOutput();

            
          
            try
            {
                dout.Open(5000);

                Console.WriteLine("Setting duty");
                dout.DutyCycle = 0.5;
                Console.WriteLine("And Again");
                dout.DutyCycle = 0.0;

                dout.Close();

                while (true)
                { }
                
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
                while (true)
                { }

            }
        }
Running the older library wouldn't cause an issue so the NotAttached is probably accurate and you need to make sure the device is correctly attaching, which might be why calling the set DutyCycle invoked a "getLastError" call. I'll try some other uses to see if I can replicate the issue you saw, can you share some code?

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 15, 2019 8:14 am
by HuntJason
I believe the problem is occurring because you are closing the channel in your .Close() call. Do you get the same error when you omit that line?

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 15, 2019 8:35 am
by frazer
Sorry for my late reply.

Here's a code example of how I'm doing it (using multiple DigitalOutputs):

Code: Select all

DigitalOutput[] phidgetsLeds = new DigitalOutput[64];

		static void Main()
		{
			InitializePhidgetsLed64();
			UpdateLeds();
			ClosePhidgetsLed64();
		}

		private void UpdateLeds()
		{
			SetLed(1, WarningPanel.IndicatorState.On);
			SetLed(2, WarningPanel.IndicatorState.Off);
			SetLed(3, WarningPanel.IndicatorState.On);
		}

		private void SetLed(byte channel, WarningPanel.IndicatorState state)
		{
			double multiplier = 1.0;

			if (indicatorsDim)
				multiplier = 0.6;

            double brightnessValue = 0.0;
			if (state == WarningPanel.IndicatorState.On || (state == WarningPanel.IndicatorState.Blinking && blinkLed))
				brightnessValue = 1.0;
			else if(state == WarningPanel.IndicatorState.Blinking && !blinkLed)
				brightnessValue = 0.2;

            if (phidgetsLeds[channel] != null)
            {
                phidgetsLeds[channel].DutyCycle = brightnessValue * multiplier;
            }
		}
		
		private bool InitializePhidgetsLed64()
        {
            try
            {
                for (int i = 0; i < 64; i++)
                {
                    phidgetsLeds[i] = new DigitalOutput
                    {
                        Channel = i,
                        IsLocal = true
                    };
                    phidgetsLeds[i].Open();
                }
                return true;
            }
            catch(PhidgetException pEx)
            {
                logger.Error(pEx, "Exception initializing Phidgets LED-64 Advanced");
                return false;
            }
            catch(DllNotFoundException dnfEx)
            {
                logger.Error(dnfEx, "Could not initialize Phidgets due to missing drivers");
                return false;
            }
        }

        private bool ClosePhidgetsLed64()
        {
            try
            {
                for (int i = 0; i < 64; i++)
                {
                    if(phidgetsLeds[i] != null)
                        phidgetsLeds[i].Close();
                }
                return true;
            }
            catch (PhidgetException pEx)
            {
                logger.Error(pEx, "Exception initializing Phidgets LED-64 Advanced");
                return false;
            }
        }

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 15, 2019 8:37 am
by frazer
Anyhow, if the problem is that the device is not connected, I don't think it should throw an internal EntryPointNotFoundException. I would consider that a bug in the Phidgets library.

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 15, 2019 9:15 am
by fraser
Well an EntryPointNotFound exception points toward a mismatch in dll's. I myself am not super familiar with the relationship between what you load in NuGET packages, and what you have installed on your machine from the website. I'm trying a variety of combinations of versions from both the website and installed nuget version, but can't cause the exception you're seeing.
Sounds like you couldn't find this link for old libraries, this might be useful for you.
https://www.phidgets.com/downloads/

Our library dev is away, but there could be a library bug here I'm not seeing. We will see what we can do. For now, try installing older drivers and see if that helps

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Wed Jul 17, 2019 1:25 am
by frazer
I've now fixed the immediate problem I had. The code was originally from a quite old version of the API, and I had made most migrations tasks when going to version 22. But I had missed that one call was synchronous before, and is asynchronous now. After fixing this, the attach issue is no longer present.

BUT: I think that there still is a bug if trying to set DutyCycle without having the device/channel attached. You should get a PhidgetException with the error code NotAttached (like in previous versions) and not an EntryPointNotFoundException. I have tried all NuGet package versions and they all have the same behavior.

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 22, 2019 7:14 am
by fraser
Glad to hear you resolved it. Yes we've run into the same Exception on other devices as well and are looking into getting it fixed asap

Re: Problems with LED64 Advanced and phidget .net library > 1.1

Posted: Mon Jul 22, 2019 4:06 pm
by Patrick
Hi,

Are you running this in Visual Studio?

Try deleting the packages folder and the bin folder and then reinstall the latest nuget library. I'm wondering if somehow the C dlls were not updated when the .NET library was updated. The nuget package includes it's own build of the C library, so it should not be possible to have this sort of mismatch.

You could also make sure the date on the bin/Debug/dll/x64/phidget22.dll file matches the bin/Debug/Phidget22.NET.dll

Also, can you enable native code debugging and on error have a look at the modules debug pane and ensure that the phidget22.dll is loaded from the bin/Debug/dll/x64 folder and not from somewhere else on the system.

-Patrick

Unable to find an entry point named 'Phidget_getLastError' in DLL

Posted: Fri Jul 15, 2022 1:59 pm
by ecklerpa
I was missing the corresponding phidget dll... so find the proper dll in the 'dll' folder that gets created with your project. It's either in the 'x86' or 'x64' folder depending on your solutions platform and throw the 'phidget22.dll' in with your 'Phidget22 .NET.dll' dll.