Skip to content
tidepool-orgPublic

About

Silicon Labs CP2102 user-space USB driver for Node.js

Topics

Resources

Contributing

Security policy

Stars

20 stars

Watchers

10 watching

Forks

Latest commit

 

History

63 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CP2102

Silicon Labs CP2102 user-space USB to serial adapter driver for Node.js and WebUSB in the browser

Usage

const CP2102 = require('cp2102');
const { webusb } = require('usb');

const opts = {
    baudRate : 38400
};

(async () => {
  const device = await webusb.requestDevice({
    filters: [
      {
        vendorId: 0x10c4,
        productId: 0x85a7,
      },
    ],
  });

  const connection = new CP2102(device, opts);

  connection.addEventListener('data', (res) => {
    console.log('Data:', res);
    connection.close(() => {});
  });

  connection.addEventListener('ready', () => {
    connection.write([0x01, 0x02, 0x02], (err) => {
      if (err) {
        console.log('Error sending command:', err);
      }
    });
  });
})().catch((error) => {
  console.log('Error: ', error);
});

Thanks

Thanks to Seiya Nuta who posted a WebUSB version as a GitHub gist.

About

Silicon Labs CP2102 user-space USB driver for Node.js

Topics

Resources

Contributing

Security policy

Stars

20 stars

Watchers

10 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages