Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse OSGI未解决的需求:导入包:com.pi4j.io.gpio_Eclipse_Osgi Bundle_Openhab - Fatal编程技术网

Eclipse OSGI未解决的需求:导入包:com.pi4j.io.gpio

Eclipse OSGI未解决的需求:导入包:com.pi4j.io.gpio,eclipse,osgi-bundle,openhab,Eclipse,Osgi Bundle,Openhab,我想为Raspberry Pi的GPIO编写一个OSGI Bundle(Eclipse SmartHome绑定)。 对于GPIO,我需要包括Pi4J库。我将它们添加到项目文件夹中的lib文件夹中,并将pi4j-core.jar添加到构建路径中 这是我的代码: /** * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others. * All rights reserved. This program and the acco

我想为Raspberry Pi的GPIO编写一个OSGI Bundle(Eclipse SmartHome绑定)。
对于GPIO,我需要包括Pi4J库。我将它们添加到项目文件夹中的lib文件夹中,并将pi4j-core.jar添加到构建路径中

这是我的代码:

/**
 * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.statusgpio.handler;

import static org.openhab.binding.statusgpio.StatusGPIOBindingConstants.*;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

/**
 * The {@link StatusGPIOHandler} is responsible for handling commands, which are
 * sent to one of the channels.
 * 
 * @author Arjuna W. - Initial contribution
 */
public class StatusGPIOHandler extends BaseThingHandler {

    ScheduledFuture<?> refreshJob;

    public StatusGPIOHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void initialize() {
        // TODO Auto-generated method stub
        super.initialize();

        startAutomaticRefresh();
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        // TODO Auto-generated method stub

        // do nothing ;)
    }

    private void startAutomaticRefresh() {

        final GpioController gpio = GpioFactory.getInstance();

        // provision gpio pin #02 as an input pin with its internal pull down
        // resistor enabled
        final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(
                RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);

        // create and register gpio pin listener
        myButton.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(
                    GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                updateState(new ChannelUID(getThing().getUID(), CHANNEL_LOADING_STATE), new StringType(event.getState().toString()));

            }

        });

            try {
                for (;;) {
                Thread.sleep(1000);
                }

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }   

}
/**
*版权所有(c)2014 openHAB UG(haftungsbeschraenkt)及其他。
*版权所有。本计划及随附材料
*根据Eclipse公共许可证v1.0的条款提供
*随本发行版发行,可在
* http://www.eclipse.org/legal/epl-v10.html
*/
包org.openhab.binding.statusgpio.handler;
导入静态org.openhab.binding.statusgpio.StatusGPIOBindingConstants.*;
导入java.util.concurrent.ScheduledFuture;
导入java.util.concurrent.TimeUnit;
导入org.eclipse.smarthome.core.library.types.StringType;
导入org.eclipse.smarthome.core.thing.ChannelUID;
导入org.eclipse.smarthome.core.thing.thing;
导入org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
导入org.eclipse.smarthome.core.types.Command;
//导入org.slf4j.Logger;
//导入org.slf4j.LoggerFactory;
导入com.pi4j.io.gpio.GpioController;
导入com.pi4j.io.gpio.gpio工厂;
导入com.pi4j.io.gpio.gpiopinitalinput;
导入com.pi4j.io.gpio.PinPullResistance;
导入com.pi4j.io.gpio.RaspiPin;
导入com.pi4j.io.gpio.event.gpIOPiIndigitalStateChangeEvent;
导入com.pi4j.io.gpio.event.GpioPinListenerDigital;
/**
*{@link StatusGPIOHandler}负责处理以下命令:
*发送到其中一个频道。
* 
*@author Arjuna W.-初始贡献
*/
公共类StatusGPIOHandler扩展了BaseThingHandler{
预定的未来刷新作业;
public StatusGPIOHandler(Thing){
超级(东西);
}
@凌驾
公共无效初始化(){
//TODO自动生成的方法存根
super.initialize();
startautomaticsrefresh();
}
@凌驾
public void handleCommand(ChannelUID ChannelUID,Command){
//TODO自动生成的方法存根
//什么也不做;)
}
私有void startautomaticsrefresh(){
最终GpioController gpio=GpioFactory.getInstance();
//提供gpio引脚#02作为带有内部下拉的输入引脚
//电阻器启用
最终GPIOIndigitalInput myButton=gpio.ProvisioningDigitalInputPin(
RaspiPin.GPIO_02,PinPullResistance.PULL_DOWN);
//创建并注册gpio引脚侦听器
myButton.addListener(新的GpioPinListenerDigital(){
@凌驾
public void HandlePiopIndicatalstateChangeEvent(
GPIOPIIndigitalStateChangeEvent事件){
//在控制台上显示pin状态
updateState(新的ChannelUID(getThing().getUID(),CHANNEL_LOADING_STATE),新的StringType(event.getState().toString());
}
});
试一试{
对于(;;){
睡眠(1000);
}
}捕捉(中断异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}   
}
该类在找到Pi4J导入和导出到jar方面没有问题。只有在Eclipse OpenHab_运行时直接运行它时,我才会发现错误:

!

当我在我的Raspberry Pi(以及我的Win PC)上启动OSGI捆绑包时,我收到以下信息:

开始92

gogo:BundleException:无法解析模块:org.openhab.binding.statusgpio[92]
未解决的需求:导入包:com.pi4j.io.gpio

我想我必须对这个包做更多的事情,让OSGI找到Pi4J库


谢谢你的帮助。

我发现了自己的错误:
我想我应该将“com.pi4j.io.gpio”添加到清单文件中的includes中,但我不想从其他OSGI包中导入它,我想从alteady导入的JAR中导入它。所以我只需删除这一行,一切都正常了。
编辑:
我在这里找到了答案:
这是我的清单。mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OutputGPIO Binding
Bundle-SymbolicName: org.openhab.binding.outputgpio;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: lib/pi4j-core.jar,
 lib/pi4j-device.jar,
 lib/pi4j-gpio-extension.jar,
 lib/pi4j-service.jar,
 .
Import-Package: com.google.common.collect,
 org.eclipse.smarthome.config.core,
 org.eclipse.smarthome.config.discovery,
 org.eclipse.smarthome.core.library.types,
 org.eclipse.smarthome.core.thing,
 org.eclipse.smarthome.core.thing.binding,
 org.eclipse.smarthome.core.types,
 org.slf4j
Service-Component: OSGI-INF/*
Export-Package: org.openhab.binding.outputgpio,
 org.openhab.binding.outputgpio.handler