我正在使用pi4j在Raspberry pi和Java上进行操作以使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的内部引用,并允许您以后重新配置它。
关于java - “This GPIO pin already exists:” GPIO 1第二次异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28425918/