R
R
rodionov122016-06-21 09:50:39
Arduino
rodionov12, 2016-06-21 09:50:39

How to sequentially send commands to a COM port in Node.js?

I interact with Node.js with Arduino via COM port. I send the data to the MK, read from the file. There are 3 types of commands: on, off and delay. The first 2 work correctly, but on a delay, the Arduino stops responding to commands. Command processing goes through the readline package.

rl.on('line', (line) => {
            console.log('Line from file:', line);
            if(line.indexOf('P') > -1)
            {
                parseInt(line.slice(0, -1));
                sleep.usleep(parseInt(line.slice(0, -1))*1000);
    	        serialPort.write(data);
            }
            else
    	         serialPort.write(data);
        });

Due to Node.js being asynchronous, latency is common. And I need sequential execution. Prompt solution

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question