Lỗi phân đoạn khi kết nối serialport nodejs

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!

Go to https://serialport.io/ to learn more, find guides and api documentation.
  • Guides
  • The serialport package api docs (most people start here)

Developing

Developing node serialport projects

  1. Clone this repo git clone [email protected]:serialport/node-serialport.git
  2. Run npm install to setup local package dependencies (run this any time you depend on a package local to this repo)
  3. Run npm test to ensure everything is working properly
  4. Add dev dependencies to the root package.json and package dependencies to the package's one.

Developing Docs

See https://github.com/serialport/website

License

SerialPort packages are all MIT licensed and all it's dependencies are MIT licensed.

Code of Conduct

SerialPort follows the Nodebots Code of Conduct. While the code is MIT licensed participation in the community has some rules to make this a good place to work and learn.

TLDR

  • Be respectful.
  • Abusive behavior is never tolerated.
  • Data published to NodeBots is hosted at the discretion of the service administrators, and may be removed.
  • Don't build evil robots.
  • Violations of this code may result in swift and permanent expulsion from the NodeBots community.

Governance and Community

SerialPort is currently employees a governance with a group of maintainers, committers and contributors, all fixing bugs and adding features and improving documentation. You need not apply to work on SerialPort, all are welcome to join, build, and maintain this project.

  • A Contributor is any individual creating or commenting on an issue or pull request. By participating, this is you.
  • Committers are contributors who have been given write access to the repository. They can review and merge pull requests.
  • Maintainers are committers representing the required technical expertise to resolve rare disputes.

If you have a PR that improves the project people in any or all of the above people will help you land it.

Maintainers

  • Francis Gulotta | reconbot
  • Nick Hehr | hipsterbrown

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 []

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. []

I need help, I want to exchange information via serialport between Arduino Pro mini with a distance sensor and a local website (e.g. provide information about the end of the session and its beginning) I use Windows 11, node.js with the 'serialport' library (installed locally and globally) , I installed everything a few days ago, because I'm just starting my adventure with it) and of course Arduino with its C++... I've reached the point of connecting via the serial port (now Arduino is on the COM3 port, which I can see in the Arduino IDE and Device Manager), but still I get the error message: "TypeError: SerialPort is not a constructor"...

The code of my app.js file (node.js version: v18.17.1, globally [C:\Users\ja\AppData\Roaming\npm] serialport version is: ` [email protected], and locally also: [email protected]):

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const port = 8080;
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html');
});
app.post('/start-session', (req, res) => {
    const SerialPort = require('serialport');
    const arduinoPort = new SerialPort('COM3', { baudRate: 9600 }); 
    arduinoPort.write('START_SESSION\n', (err) => {
        if (err) {
            console.error('Err Arduino:', err);
        } else {
            console.log('Success Arduino.');
        }
    });
    res.send('Session started.');
});
app.listen(port, () => {
    console.log(`Port ${port}`);
});

My website (lokal) index.html:




...







    

Hello. Start. :)

Here are the local directories of my project: (images)enter image description here

and in the node_modules directory: enter image description here

Please help me remove the error and connect.