Cannot Use pin with multiple instances Exeption
Hi,
i have a problem: System.Exeption: Cannot use pin with multiple instances. Unexport the previous instance with Dispose() first (pin 24)
I have only one instance of pin 24 in my Code and I get this Exeption where ever I delcare.
in_gpio24 = new GPIOMem(GPIOPins.V2_GPIO_24, GPIODirection.In);
Raspberry Pi 2
I'm quite new to programming so please help me to fix this problem
That exception is only thrown when you've used that pin already. Can you post all your code?
I use only two pins in my Code (17 and 24) It was just a Test pogramm. I checked more then 3 Times of i Used Pin 24 Twice.
I will Post my Code tommorow
Am Mittwoch, 5. August 2015 schrieb cypherkey :
That exception is only thrown when you've used that pin already. Can you post all your code?
— Reply to this email directly or view it on GitHub https://github.com/cypherkey/RaspberryPi.Net/issues/32#issuecomment-127819982 .
class c_GPIO
{
public enum IN : byte
{
GPIO24 = 24
};
public enum OUT : byte
{
GPIO17 = 17
};
//GPIO IN
GPIOMem in_gpio24;
//GPIO OUT
GPIOMem out_gpio17;
public c_GPIO()
{
InitializeGPIO();
}
~c_GPIO()
{
//GPIO freigeben
//in_gpio24.Dispose();
//out_gpio17.Dispose();
}
public void InitializeGPIO()
{
//IN
in_gpio24 = new GPIOMem(GPIOPins.V2_GPIO_24, GPIODirection.In);
//Out#
out_gpio17 = new GPIOMem(GPIOPins.V2_GPIO_17);
}
//Testen ob Schalter geschlossen ist
public bool CheckInput(IN GPIO_Pin)
{
GPIOMem Input;
switch (GPIO_Pin)
{
case IN.GPIO24: Input = in_gpio24;
break;
default:
return false;
}
if (Input.Read() == PinState.High)
{
return true;
}
else
{
return false;
}
}
//Outputs schalten
public bool SwitchOut(OUT GPIO_Pin, bool Closed)
{
GPIOMem Output;
switch (GPIO_Pin)
{
case OUT.GPIO17: Output = out_gpio17;
break;
default:
return false;
}
Output.Write(Closed);
return true;
}
}
I suspect it has to do with when you assign the Input variable. It may be making a copy of the object and therefore re-calling it's constructor. Can you change your code to pass the GPIOMem object as an argument and not the enum?
Unfortunately I don't have my PI anymore, so I can't test it.