简体   繁体   English

v4l2(相机驱动程序)无法进行狂暴的pi pi4j

[英]raspbbery pi pi4j could not work by v4l2(camera driver)

in the a project, a NOIR pi camera and work it by java and eclipse true. 在一个项目中,使用NOIR pi相机并通过java和eclipse true对其进行处理。 and need to turn on IR-LED when camera is start to preview. 并且在开始预览相机时需要打开IR-LED。 so use pi4j in a new class for turn on and turn off LED. 所以在新的类中使用pi4j来打开和关闭LED。 but when call it the pi4j class in source of camera panel, then camera not started. 但是在相机面板的源代码中调用pi4j类时,则相机无法启动。 what is the problem 问题是什么

pi4j Class: pi4j类别:

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");
                        }
                }
        }

error: 错误:

wiringPiSetup: Must be root. (Did you forget sudo?)

The problem was solved with python source: 该问题已通过python源解决:

changed java class to: 将Java类更改为:

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();
        }
}

and noirLedControl.py : 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()

so now problem is about java class return reader.readline() null. 所以现在的问题是关于Java类返回reader.readline() null。 and led power on and off not worked, but python /home/pi/noirLedControl.py currently run in terminal. 并无法打开和关闭python /home/pi/noirLedControl.py电源,但是python /home/pi/noirLedControl.py当前在终端中运行。 my java lib version is "1.8.0_122-ea", so i run my project by two java SE 1.8 and 1.7 and problem not solved. 我的Java库版本是“ 1.8.0_122-ea”,所以我用两个Java SE 1.8和1.7运行我的项目,但问题没有解决。 and os is debian 8 every one know what is problem? 而os是debian 8,每个人都知道是什么问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM