First Connection
Here you will be able to connect to the Jofemar device for the very first time.
Note
The jofemar machines by default listen on address 1 so, this guide will use the address 1.*
Create a new file to add the code
First of all, create a new file in the src/webserial
folder, and name it jofemar.js
.
Linux/Mac
touch src/webserial/jofemar.js
Windows
echo "" > src/webserial/jofemar.js
Import the module in your code
If you are using the script tag, you can skip this step.
Module
src/webserial/jofemar.js
import {Jofemar} from '@danidoble/webserial';
New instance of the Jofemar
class
Create a new instance of the Jofemar
class (by default, is not needed pass any parameter to the constructor.)
src/webserial/jofemar.js
const machine = new Jofemar();
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.
src/webserial/jofemar.js
async function tryConnect() {
await machine.connect().catch(console.error);
}