"This GPIO pin already exists:" 第二次 GPIO 1 异常

"This GPIO pin already exists:" GPIO 1 Exception on Second Time

我正在研究 Raspberry pi 和 java 以使用 pi4j 使 LED 闪烁,一切都已清除并且工作正常,LED 按照代码闪烁但是当我 运行 第二次它导致以下错误,我搜索了很多有很多相同的问题没有明确的答案如何解决它,任何帮助将不胜感激

final GpioController gpio = GpioFactory.getInstance();
            final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(
                    RaspiPin.GPIO_01, "PinLED", PinState.HIGH);
            System.out.println("light is: ON");
            Thread.sleep(2000);


            pin.low();
            System.out.println("light is: OFF");
            Thread.sleep(1000);


            System.out.println("light is: ON for 1 second");
            pin.pulse(1000, true);

            pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
            gpio.shutdown();

这是我遇到的完整错误

com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 1
    com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:507)
    com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:645)
    com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:672)
    com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:684)
    com.restFulService.Controller.LedControl.ledTestFun(LedControl.java:52)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:483)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:202)
    net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:180)
    org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:439)
    org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:178)

您需要取消配置您的个人识别码。

调用 .shutdown() 后,您需要执行以下操作

...
gpio.shutdown();
...
gpio.unProvisionPin(pin);
...

这应该会释放 pi4j 的内部参考并允许您稍后重新配置它