You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I use a raspberry pi 4 UART port for communication but we should 2s delay in r/w data on it for correctly working. this speed is very slow for my scenario. how can I solve it?
library version: serialPort ^9.2.8
raspberry pi version: 4 B
bouadrate: 115200
OS: ubuntu 20.04
nodejs version:14.18.2
my code:(uart.js)
const serialport=require('serialport');
let port=new serialport("/dev/ttyS0",{baudRate:115200,autoOpen: true},(err)=>{
if(err)
return console.log('serial port connection failed => '+err);
});
async function delay(n) {
return new Promise(done => {
setTimeout(() => {
done();
}, n);
});
}
async function writeToSerial(){
while(1){
port.write("hi serialport", function(err) {
if (err) {
return console.log('Error on write: ', err.message)
}
})
await delay(2000);
}
}
writeToSerial();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi. I use a raspberry pi 4 UART port for communication but we should 2s delay in r/w data on it for correctly working. this speed is very slow for my scenario. how can I solve it?
library version: serialPort ^9.2.8
raspberry pi version: 4 B
bouadrate: 115200
OS: ubuntu 20.04
nodejs version:14.18.2
my code:(uart.js)
const serialport=require('serialport');
let port=new serialport("/dev/ttyS0",{baudRate:115200,autoOpen: true},(err)=>{
if(err)
return console.log('serial port connection failed => '+err);
});
async function delay(n) {
return new Promise(done => {
setTimeout(() => {
done();
}, n);
});
}
async function writeToSerial(){
while(1){
port.write("hi serialport", function(err) {
if (err) {
return console.log('Error on write: ', err.message)
}
})
await delay(2000);
}
}
writeToSerial();
const Readline=serialport.parsers.Readline;
const parser=new Readline();
port.pipe(parser);
//read data from serial port
parser.on('data',(message)=>{
console.log(message.toString());
});
Beta Was this translation helpful? Give feedback.
All reactions