英特尔爱迪生和NodeJS串行端口通信:我收到奇怪的字符 [英] Intel Edison and NodeJS serial port communication: I am receiving strange characters

查看:128
本文介绍了英特尔爱迪生和NodeJS串行端口通信:我收到奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FTDI连接到我的PC,并且FTDI连接到了英特尔Edison Arduino突破板0RX和1TX引脚.

I have a FTDI connected to my PC and the FTDI is connected to an Intel Edison Arduino breakout board 0RX and 1TX pins.

串行引脚连接:
爱迪生TX ------> FTDI RX
爱迪生RX ------> FTDI TX

Serial pin hookup:
Edison TX ------> FTDI RX
Edison RX ------> FTDI TX

要编辑英特尔Edisons GPIO,我在第一篇文章中遵循了正确的答案:
https://communities.intel.com/message/265411#265411

To edit the Intel Edisons GPIO I followed the correct answer in the first post:
https://communities.intel.com/message/265411#265411

要查看我的GPIO配置,我执行了以下操作:
猫/sys/kernel/debug/gpio

To view my GPIO configurations I executed:
cat /sys/kernel/debug/gpio

然后回声:

Which then echoed out:

Nodejs代码:

var SerialPort = require("serialport").SerialPort;  
var port = "/dev/ttyMFD1";  
var serialPort = new SerialPort(port, {  
  baudrate: 9600  
}, false);  

console.log("Open port: "+ port);  
serialPort.open(function (error) {  
  if (error) {  
    console.log('Failed to open: '+error);  
  } else {  
    console.log('open');  
    serialPort.on('data', function(data) {  
      console.log('data received: ' + data);  
    });  
    //write data to serial port every second  
    var counter = 90;  
    setInterval(function () {  
      serialPort.write(String(counter)+ "\r\n", function(err) {  
        if(err) {  
          console.log('err ' + err);  
        }else{  
          console.log('Writing data ');  
        }  
      });  
      counter++;  
      if(counter>100)  
        counter =90;  
    }, 1000);  
  }  
});

然后我执行了:
节点uart.js

I then executed:
node uart.js

即使我没有向英特尔爱迪生发送字符,我也会得到奇怪的字符
奇怪的字符:

I get strange characters even when I am not sending characters to the Intel Edison
Strange characters:

我不确定我的nodejs脚本是否引起了任何问题,所以我执行了: 猫/dev/ttyMFD1
即使我没有向英特尔爱迪生发送数据,它也回荡了相同的奇怪字符.

I wasn't sure if my nodejs script was causing any issues so I executed: cat /dev/ttyMFD1
which echoed out the same strange characters even when I wasn't sending data to the Intel Edison.

我不知道为什么不向英特尔爱迪生发送数据时为什么会收到奇怪的字符,或者如何阻止这种情况的发生.我不确定我是否正确配置了GPIO,或者是噪声还是什么……?我该怎么做才能解决此问题/解决问题?

I have no idea why I am receiving the strange characters when I am not sending data to the Intel Edison or how to stop that from happening. I am not sure if I configured my GPIOs correct or if it is noise or what...? What do I need to do to fix/troubleshoot this issue?

为进一步解决此问题,我在函数的serialPort内添加了以下代码片段:

To troubleshoot this further I added the following code snippet inside of the serialPort on function:

var s = JSON.stringify(data);
console.log ("data: " + s);

该代码产生:
[255,255,255,255]

That code produces:
[255,255,255,255]

更新
问题似乎与setInterval函数有关.我删除了设置的时间间隔,并且为了进行测试,我实现了一个for循环.循环进行了10轮,成功发送了字符,但没有收到垃圾字符.

UPDATE
The issues seems to be with the setInterval function. I remove the set interval and for a test I implemented a for-loop. The loop made 10 rounds successfully sending characters without receiving the garbage characters.

推荐答案

奇怪的字符是由于我的一个真正愚蠢的错误所致.我忘了将FTDI板上的GND连接到Intel Edison的GND.一旦我将GND连接在一起,奇怪的字符就会停止.

The strange characters were due to a really stupid mistake on my part. I forgot to hook the GND from the FTDI board to the GND of the Intel Edison. Once I connected the GNDs together the strange characters stopped.

这篇关于英特尔爱迪生和NodeJS串行端口通信:我收到奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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