Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
Java RXTX和Arduino之间串行通信的流量控制设置_Arduino_Rxtx_Flow Control - Fatal编程技术网

Java RXTX和Arduino之间串行通信的流量控制设置

Java RXTX和Arduino之间串行通信的流量控制设置,arduino,rxtx,flow-control,Arduino,Rxtx,Flow Control,我在Seeeduino Mega 1.22上有一个简单的草图,它只在LCD显示屏上显示串行输入。使用lynx术语和arduino串行监视器工作正常:显示发送的输入。当我想在我的Java程序(在Win7 x64机器上的Eclipse中运行)和Seeeduino之间启动串行通信时,问题就开始了。我使用的是RXTX64版本。该程序旨在通过开放端口发送和接收一些string.getBytes。Java端的接收工作正常,但Arduino端的接收失败 问题似乎在于正确的流量控制设置。我看到有些人也有类似的问

我在Seeeduino Mega 1.22上有一个简单的草图,它只在LCD显示屏上显示串行输入。使用lynx术语和arduino串行监视器工作正常:显示发送的输入。当我想在我的Java程序(在Win7 x64机器上的Eclipse中运行)和Seeeduino之间启动串行通信时,问题就开始了。我使用的是RXTX64版本。该程序旨在通过开放端口发送和接收一些string.getBytes。Java端的接收工作正常,但Arduino端的接收失败

问题似乎在于正确的流量控制设置。我看到有些人也有类似的问题

但这个解决方案对我不起作用。如果我将FlowControl设置为None,那么我只会在显示屏上看到一个块图标,指示串行连接已经建立,而其他什么都没有。如果我将FlowControl设置为RCTS_IN | RCTS_OUT,那么我仅在关闭已建立的连接时在显示屏上获取字符串字节

为什么只有在我关闭连接时才发送数据,冲洗出流也没有帮助?流量控制设置有什么问题

这是我正在使用的修改后的连接方法

void connect(String portName) throws Exception {
        CommPortIdentifier portIdentifier = CommPortIdentifier
                .getPortIdentifier(portName);
        if (portIdentifier.isCurrentlyOwned()) {
            System.out.println("Error: Port is currently in use");
        } else {
            CommPort commPort = portIdentifier.open(this.getClass().getName(),
                    2000);

            if (commPort instanceof SerialPort) {
                SerialPort serialPort = (SerialPort) commPort;
                serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

                try {
                  serialPort.setFlowControlMode(
                  //      SerialPort.FLOWCONTROL_NONE);
                  // OR
                  // If CTS/RTS is needed
                  //serialPort.setFlowControlMode(
                        SerialPort.FLOWCONTROL_RTSCTS_IN |
                        SerialPort.FLOWCONTROL_RTSCTS_OUT);
                } catch (UnsupportedCommOperationException ex) {
                  System.err.println(ex.getMessage());
                }

                serialPort.setRTS(true);

                in = serialPort.getInputStream();
                out = serialPort.getOutputStream();

                (new Thread(new SerialWriter(out))).start();

                serialPort.addEventListener(new SerialReader(in, this));
                serialPort.notifyOnDataAvailable(true);

            } else {
                System.out.println("Error: Only serial ports are to use!");
            }
        }
    }

提前感谢您抽出时间

解决了这个问题。正如许多人所说,这不是缓冲区。问题是,电路板上的SEEEDUNOS RST开关设置为自动。将其设置为手动,解决了问题。 无需流量控制