【问题标题】:problems with node Serialport write节点串行端口写入问题
【发布时间】:2018-03-29 14:38:19
【问题描述】:

我正在尝试将命令从节点服务器发送到 arduino mega board 并返回。只要我在 1000 毫秒内只调用一次 SERIALPORT.write,它就可以正常工作,但如果我尝试更快,我不会收到任何控制消息。

node.js:

 if (SERIALPORT) {

        SERIALPORT.on("open", function () {
            SERIALPORT.on('data', function(data) {
                for (let c of data) {
                     console.log(c.toString());
                 }
            });

          });


        function repeat_function() {

            command = [1];

            SERIALPORT.write(command, function(err) {
                if (!err) { 
                    console.log('message writtn ' + command); 
                }
            });
            setTimeout(repeat_function, 1000);
        }
        repeat_function();
    }

arduino 代码:

void loop()
{   
   if (Serial.available()) {
      Serial.write(Serial.read());
  }
}

如果我尝试setTimeout(myFunc, 500);,那么我不会取回串行数据。

设置 node.js:

var serialPort = new SerialPort(CONFIG.serial_port, {
                baudrat: 9600,
                dataBits: 8,
                parity: 'none',
                stopBits: 1,
                flowControl: false
            });

设置arduino:

void setup() {
    Serial.begin(9600);
  }

谢谢!

【问题讨论】:

    标签: javascript node.js arduino serial-port


    【解决方案1】:

    您是否尝试过其他更高的波特率(例如:57600)。提高波特率将有助于更快地发送和接收数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-14
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 2018-12-15
      • 1970-01-01
      相关资源
      最近更新 更多