Arduino的不能发送串行数据回 [英] Arduino not able to send serial data back

查看:285
本文介绍了Arduino的不能发送串行数据回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我发现了如何到Arduino连接到我的Java程序。但是,使用串行连接不给任何有用的数据备份,其无论是在错误的格式,或者只是将其作为一个盒子。我看这里的早期张贴的相关问题,但没有提示似乎帮助。因此,没有人知道如何一个Arduino和使用串行端口的计算机之间发送数据?

So I found out how to connect the Arduino to my java program. But using the serial connections doesn't give any useful data back, its either in the wrong format, or just sends it as a box. I've looked at the related questions posted early in here, but none of the tips seems to help. So does anyone know how to send the data between an Arduino and a computer using the serial port?

这是code我使用的,由这个人提供的:
http://silveiraneto.net/2009/03/01/arduino-and-的Java /

This is the code I'm using, provided by this person: http://silveiraneto.net/2009/03/01/arduino-and-java/

package serialtalk;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;

public class Main {
    static InputStream input;
    static OutputStream output;

    public static void main(String[] args) throws Exception{
        Preferences.init();
        System.out.println("Using port: " + Preferences.get("serial.port"));
        CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
                Preferences.get("serial.port"));

        SerialPort port = (SerialPort)portId.open("serial talk", 4000);
        input = port.getInputStream();
        output = port.getOutputStream();
        port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        while(true){
            while(input.available()>0) {
                System.out.print((char)(input.read()));
            }
        }
    }
}

Arduino的是这样的:
http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove

的code简单地接收号码,并且确定哪个模拟读取应当发送回来,从我的Arduino

The code simply receives a number, and determines which analog reading it should be sending back, from my Arduino.

推荐答案

在使用串行连接处理确保以下要点:

When dealing with serial connections make sure of the following key points:


  • 波特率匹配

  • DATABITS应匹配

  • STOPBITS应匹配

  • 奇偶应匹配

  • 确保您使用正确的电缆(如果需要零调制解调器)

  • 确保电缆的运行不会太长

以上所有能引起奇怪的东西出来的COM端口在Java端。一旦你得到的这个窍门它变得容易多了。

All of the above can cause odd stuff to come out of the com port on the Java side. Once you get the hang of this it gets much easier.

我个人喜爱的图书馆这里

这篇关于Arduino的不能发送串行数据回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆