Connecting to Boardroid
First Connection
Section titled “First Connection”Here you will be able to connect to the Boardroid device for the very first time.
Create a new file to add the code
Section titled “Create a new file to add the code”First of all, create a new file in the src/webserial folder, and name it boardroid.js.
Linux/Mac
Section titled “Linux/Mac”touch src/webserial/boardroid.jsWindows
Section titled “Windows”echo "" > src/webserial/boardroid.jsImport the module in your code
Section titled “Import the module in your code”If you are using the script tag, you can skip this step.
Module
Section titled “Module”import {Boardroid} from '@danidoble/webserial';New instance of the Boardroid class
Section titled “New instance of the Boardroid class”Create a new instance of the Boardroid class (by default, is not needed pass any parameter to the constructor.)
const machine = new Boardroid();Make a function to connect
Section titled “Make a function to connect”Now, let’s connect to the device, since the connect method is asynchronous, we need to use
await/async or promise to handle the connection. Or you can use the then method to handle the connection.
async function tryConnect() { await machine.connect().catch(console.error);}