Skip to content

Connection

Here you will be able to connect to the JSD device for the very first time.

First of all, create a new file in the src/webserial folder, and name it jsd.js.

Terminal window
touch src/webserial/jsd.js
Terminal window
echo "" > src/webserial/jsd.js

If you are using the script tag, you can skip this step.

src/webserial/jsd.js
import {JSD} from '@danidoble/webserial';

Create a new instance of the JSD class (by default, is not needed pass any parameter to the constructor.)

src/webserial/jsd.js
const jsd = new JSD();

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.

src/webserial/jsd.js
async function tryConnect() {
await jsd.connect().catch(console.error);
}