Skip to content

Connection

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

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

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

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

src/webserial/pinPad.js
import {PinPad} from '@danidoble/webserial';

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

src/webserial/pinPad.js
const pinPad = new PinPad({
username: 'TEST',
password: 'TEST',
});

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/pinPad.js
async function tryConnect() {
await machine.connect().catch(console.error);
}