6 Replies Latest reply on Jan 9, 2015 5:36 PM by CMata_Intel

    Not able to read "/dev/ttyMFD1" using serialport module in Intel XDK

    345ishaan

      Hi community,

       

      I am trying to read the data sent by my Ardunio IDE to pin "0" of Galileo . In the edison console , i am able to see the correct data sent using the command "cat /dev/ttyMFD1".

      But if i am using the serialport module in Node.js (XDK) , it opens the port ut not able to read the data. Any hints?

      Here is the code:-

       

      var serialport = require("serialport")

      var SerialPort = serialport.SerialPort;

      serialport.list(function (err, ports) {

        ports.forEach(function(port) {

          console.log(port.comName);

        });

      });

      var serialPort = new SerialPort("/dev/ttyMFD1", {

        baudrate: 9600,

        dataBits: 8, // this is the default for Arduino serial communication

        parity: 'none', // this is the default for Arduino serial communication

        stopBits: 1, // this is the default for Arduino serial communication

        flowControl: false, // this is the default for Arduino serial communication

        parser: serialport.parsers.readline("\r\n")

      });

       

      var readdata = '';

       

      serialPort.on('open', showPortOpen);

      serialPort.on('data', saveLatestData);

      serialPort.on('close', showPortClose);

      //serialPort.on('error', showError);

       

      function showPortOpen() {

         console.log('port open. Data rate: ' + serialPort.options.baudRate);

      }

      function showPortClose() {

         console.log('port closed.');

      }

      function saveLatestData(data) {

          readdata += data.toString();

          console.log(readdata);

      }