树莓派 pi4j 无法通过 v4l2(相机驱动程序)工作
raspbbery pi pi4j could not work by v4l2(camera driver)
在一个项目中,一个 NOIR pi 相机并通过 java 和 eclipse true 进行处理。并且需要在相机开始预览时打开 IR-LED。所以在新的 class 中使用 pi4j 来打开和关闭 LED。但是当在相机面板的源中调用它 pi4j class 时,相机没有启动。有什么问题
pi4j Class:
import com.pi4j.io.gpio.*;
public class gpio_prg {
private static GpioPinDigitalOutput pin;
private GpioController gpio;
public void out(int bcmn, boolean state){
System.out.println("gpio controler");
gpio = GpioFactory.getInstance();
if(bcmn == 29){
if(state){
System.out.println("gpio pin");
pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_29, "MyLED", PinState.HIGH);
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO NOIR LED state should be: ON");
}else{
pin.low();
System.out.println("--> GPIO NOIR LED state should be: OFF");
}
}
}
错误:
wiringPiSetup: Must be root. (Did you forget sudo?)
问题已通过 python 来源解决:
已将 java class 更改为:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class gpio_prg {
public void out() throws IOException, InterruptedException{
String command = "python /home/pi/noirLedControl.py";
Process proc = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
System.out.print("led status = ");
System.out.println(reader.readLine());
proc.waitFor();
}
}
和noirLedControl.py
:
import RPi.GPIO as GPIO
f = open('ledstatus', 'r')
s = 3
s = f.read()
f.close()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
if(s == '0'):
GPIO.output(21, GPIO.LOW)
print "off"
s = 1
else:
GPIO.output(21, GPIO.HIGH)
print "on"
s = 0
f = open('ledstatus', 'w')
f.write(str(s))
f.close()
所以现在问题是关于 java class return reader.readline()
null。并且 LED 电源开关不起作用,但终端中目前 python /home/pi/noirLedControl.py
运行。
我的 java 库版本是“1.8.0_122-ea”,所以我 运行 我的项目由两个 java SE 1.8 和 1.7 组成,问题没有解决。 os 是 debian 8
大家知道是什么问题吗?
在一个项目中,一个 NOIR pi 相机并通过 java 和 eclipse true 进行处理。并且需要在相机开始预览时打开 IR-LED。所以在新的 class 中使用 pi4j 来打开和关闭 LED。但是当在相机面板的源中调用它 pi4j class 时,相机没有启动。有什么问题
pi4j Class:
import com.pi4j.io.gpio.*;
public class gpio_prg {
private static GpioPinDigitalOutput pin;
private GpioController gpio;
public void out(int bcmn, boolean state){
System.out.println("gpio controler");
gpio = GpioFactory.getInstance();
if(bcmn == 29){
if(state){
System.out.println("gpio pin");
pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_29, "MyLED", PinState.HIGH);
pin.setShutdownOptions(true, PinState.LOW);
System.out.println("--> GPIO NOIR LED state should be: ON");
}else{
pin.low();
System.out.println("--> GPIO NOIR LED state should be: OFF");
}
}
}
错误:
wiringPiSetup: Must be root. (Did you forget sudo?)
问题已通过 python 来源解决:
已将 java class 更改为:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class gpio_prg {
public void out() throws IOException, InterruptedException{
String command = "python /home/pi/noirLedControl.py";
Process proc = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
System.out.print("led status = ");
System.out.println(reader.readLine());
proc.waitFor();
}
}
和noirLedControl.py
:
import RPi.GPIO as GPIO
f = open('ledstatus', 'r')
s = 3
s = f.read()
f.close()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
if(s == '0'):
GPIO.output(21, GPIO.LOW)
print "off"
s = 1
else:
GPIO.output(21, GPIO.HIGH)
print "on"
s = 0
f = open('ledstatus', 'w')
f.write(str(s))
f.close()
所以现在问题是关于 java class return reader.readline()
null。并且 LED 电源开关不起作用,但终端中目前 python /home/pi/noirLedControl.py
运行。
我的 java 库版本是“1.8.0_122-ea”,所以我 运行 我的项目由两个 java SE 1.8 和 1.7 组成,问题没有解决。 os 是 debian 8
大家知道是什么问题吗?