How To Convert Buffer Data to text #2756
Unanswered
hellcat29A
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
, 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