Skip to content

Change baud rate during run time? #15

Description

@brandonros

I have a need to go from 250k baud to 2m baud during run time. Any suggestions?

I came up with this but I'm missing the data because it is sent so quickly in between baud changes:

const fillBuffer = (chunk) => {
  for (let i = 0; i < chunk.length; ++i) {
    buffer[pointer] = chunk[i]
    pointer += 1
    if (pointer === 4096) {
      console.log('warning: buffer wrapped')
      pointer = 0
    }
  }
}

const initConnection = async (baudRate) => {
  const connection = new CP2102(0x10c4, 0xea60, { baudRate })
  await new Promise((resolve, reject) => connection.on('ready', resolve))
  connection.on('data', fillBuffer)
  return connection
}

let connection = await initConnection(250000)
...
await new Promise((resolve, reject) => connection.close(resolve))
connection.off('data', fillBuffer)
connection = await initConnection(2000000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions