Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialport.on data is returned multiple times. #1514

Closed
zhibo59 opened this issue Mar 7, 2018 · 1 comment
Closed

serialport.on data is returned multiple times. #1514

zhibo59 opened this issue Mar 7, 2018 · 1 comment
Labels

Comments

@zhibo59
Copy link

zhibo59 commented Mar 7, 2018

  • SerialPort Version:6.1.1

  • NodeJS Version:7.4.0

  • Operating System and Hardware Platform:window

  • Have you checked the right version of the api docs?: yes

  • Are you having trouble installing and you checked the Installation Special Cases docs?

  • Are you using Electron and have you checked the Electron Docs?:

Summary of Problem

After I execute a write method, the returned data of the listener divides the data into two returns, but sometimes it can be returned all at once.

Steps and Code to Reproduce the Issue

this.serialport = new Serialport(_this.portVal,_this.config)

    this.serialport.open((err) => {
      if(!err){
          this.status = false
          this.serialport.on('data',(res) => {
              console.log(res)
          })
      }else{
      }
    })

this.serialport.write([0xfa,0xaf,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88],'hex')
image

@reconbot
Copy link
Member

This is normal behavior. You'll want to look into parsers for how to handle it. https://node-serialport.github.io/node-serialport/global.html#Parsers

You can find more info about the data event here. https://node-serialport.github.io/node-serialport/global.html#event:data

@lock lock bot locked as resolved and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants