简体   繁体   English

无法通过串口node.js与四个Arduino进行通信

[英]Can't communicate with four Arduino's over serial port node.js

I can't communicate to four Arduino's at the same time. 我无法同时与四个Arduino通信。 I tried the code below with three serial ports and it worked fine. 我用三个串口尝试了下面的代码,它工作正常。 If I add a fourth Arduino, there is no communication with any Arduino. 如果我添加第四个Arduino,则无法与任何Arduino进行通信。
Can somebody help me? 有人能帮助我吗?

var SerialPort = require('serialport');
sport1 = new SerialPort('COM10', { autoOpen: true ,
  parser: SerialPort.parsers.readline('\n'), baudRate: 9600});
sport2 = new SerialPort('COM11', { autoOpen: true ,
  parser: SerialPort.parsers.readline('\n'), baudRate: 9600});
sport3 = new SerialPort('COM12', { autoOpen: true ,
  parser: SerialPort.parsers.readline('\n'), baudRate: 9600});
sport4 = new SerialPort('COM13', { autoOpen: true ,
  parser: SerialPort.parsers.readline('\n'), baudRate: 9600});

var u = 0;
  setInterval(function() {
    if(u==0) {
        sport1.write("a");
        sport2.write("b");
        sport3.write("a");
        sport4.write("b");
    }else {
        sport1.write("b");
        sport2.write("a");
        sport3.write("a");
        sport4.write("b");
    }
    u = !u;
  },500);

Seems like an hardware issue - USB hub tend to cause issues. 看起来像硬件问题 - USB集线器往往会导致问题。 I suggest the following: 我建议如下:

  • Don't use USB hub (extend USB from PCI) 不要使用USB集线器(从PCI扩展USB)
  • Use reliable USB hub 使用可靠的USB集线器
  • Anyway, connect to your USB hub the 5V input it needs. 无论如何,连接到USB集线器需要5V输入。
  • Extend the serial ports on your computer instead of using many USB to RS232 扩展计算机上的串行端口,而不是使用许多USB转RS232
  • Maybe connect all your Arduinos to one RS485 bus instead 也许将所有Arduinos连接到一个RS485总线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM