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
// Create the serial port and parser
const port = new SerialPort({ path: portName, baudRate:baudRate });
const parser = port.pipe(new ReadlineParser(parserOptions));
// Attach data handler before opening port
parser.on('data', (data) => {
console.log('Modem response:', data);
});
// Open the port and send AT command
port.on('open', ()=>{
port.write('AT\r\n', (err) => {
if (err) {
console.error('Error sending AT command:', err);
}
});
port.drain();
// Ensure data flow
port.resume();
})
// Start Express server
app.listen(process.env.PORT || 4000, () => {
console.log(Server started on port ${process.env.PORT || 4000});
});
`
here in my Code When i Change
parser.on('data', (data) => {
console.log('Modem response:', data);
});
with
port.on('data', (data) => {
console.log('Modem response:', data);
});
i can see my Data Coming From modem gsm ,
Modem response: <Buffer 7c fe fe>
Modem response:
But i need them to be converted As text because , this Buffer must Represent OK i guess,
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
-
, Hello , So i think my problem is simple but i'm finding it hard to find the solution ,
`const express = require('express');
const app = express();
const { SerialPort } = require('serialport');
const { ReadlineParser } = require('@serialport/parser-readline');
// Configure port settings
const portName = 'COM6';
const baudRate = 115200;
const parserOptions = { delimiter: '\r\n' }; // Adjust delimiter if needed
// Create the serial port and parser
const port = new SerialPort({ path: portName, baudRate:baudRate });
const parser = port.pipe(new ReadlineParser(parserOptions));
// Attach data handler before opening port
parser.on('data', (data) => {
console.log('Modem response:', data);
});
// Error handling
port.on('error', (err) => {
console.error('Serial port error:', err);
});
// Open the port and send AT command
port.on('open', ()=>{
port.write('AT\r\n', (err) => {
if (err) {
console.error('Error sending AT command:', err);
}
});
})
// Start Express server
app.listen(process.env.PORT || 4000, () => {
console.log(
Server started on port ${process.env.PORT || 4000}
);});
`
here in my Code When i Change
parser.on('data', (data) => {
console.log('Modem response:', data);
});
with
port.on('data', (data) => {
console.log('Modem response:', data);
});
i can see my Data Coming From modem gsm ,
Modem response: <Buffer 7c fe fe>
Modem response:
But i need them to be converted As text because , this Buffer must Represent OK i guess,
Beta Was this translation helpful? Give feedback.
All reactions