我有一个从Windows迁移到Raspbian(raspberry pi 2)的问题。我无法使用RXTX库运行与rs232的通信。在windows上,这段代码工作得很好,但是对于覆盆子,我有一个空响应。应用程序用Java8编写,在Windows 8上编译。
我在用netty和RXTXcomm:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-transport-rxtx</artifactId>
    <version>4.0.0.CR1</version>
</dependency>

<dependency>
    <groupId>net.cloudhopper</groupId>
    <artifactId>RXTXcomm</artifactId>
    <version>2.2-20081207</version>
</dependency>

启动代码:
public void startUp() {
    try {
        this.channelHandler = new MyChannelHandler(this.readTimeout);
        this.group = new OioEventLoopGroup();
        this.bootstrap = new Bootstrap();
        this.bootstrap.group(this.group)
                .channel(RxtxChannel.class)
                .handler(new ChannelInitializer<RxtxChannel>() {
                    @Override
                    protected void initChannel(final RxtxChannel rxtxChannel)               throws Exception {
                        ChannelPipeline pipeline = rxtxChannel.pipeline();
                        pipeline.addLast("frameDecoder", new FrameDecoder());
                        pipeline.addLast("encoder", new MessageEncoder());
                        pipeline.addLast("decoder", new MessageDecoder());
                        pipeline.addLast("handler", channelHandler);
                    }
                });
        this.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
        this.bootstrap.option(RxtxChannelOption.BAUD_RATE, this.baudRate);
        this.bootstrap.option(RxtxChannelOption.PARITY_BIT, Paritybit.NONE);
        this.bootstrap.option(RxtxChannelOption.DATA_BITS, Databits.DATABITS_8);
        this.bootstrap.option(RxtxChannelOption.STOP_BITS, Stopbits.STOPBITS_1);
        LOGGER.info("Started adapter " + this.toString());
    } catch (Throwable t) {
        LOGGER.error("Couldn't to start adapter. Reason: " +                    ExceptionUtils.getStackTrace(t));
    }

并创建连接:
public Channel connect() {
    // Make a new connection
    String port = File.separator+"dev"+File.separator+"ttyUSB0");
ChannelFuture connectFuture = this.bootstrap.connect(new RxtxDeviceAddress(port);
    // Wait until the connection is made successfully
    Channel channel = connectFuture.awaitUninterruptibly().channel();

    return channel;
}

我已从存储库下载库:
sudo apt-get install librxtx-java

以防万一,我更改了对串行文件的权限:
sudo chmod 777 /dev/ttyUSB0

当我插入设备时,dmeseg显示:
[  996.380535] usb 1-1.2: new full-speed USB device number 9 using dwc_otg
[  996.508021] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001
[  996.508048] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  996.508066] usb 1-1.2: Product: FT232R USB UART
[  996.508082] usb 1-1.2: Manufacturer: FTDI
[  996.508098] usb 1-1.2: SerialNumber: AL00B3PT
[  996.517387] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[  996.517765] usb 1-1.2: Detected FT232RL
[  996.518998] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0

在应用程序日志中,我有:
Stable Library
=========================================
Native lib Version = RXTX-2.2pre2
Java lib Version   = RXTX-2.1-7
WARNING:  RXTX Version mismatch
    Jar version = RXTX-2.1-7
    native lib Version = RXTX-2.2pre2

所以库已正确加载。
帮忙?

最佳答案

java库和本机库之间不匹配。尝试对两者使用相同的版本。

关于java - 从RXTX迁移到Raspbian,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33633932/

10-12 02:43