### Configure baudRate for WebSerialReceiptPrinter
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
Example of setting the baudRate to 9600 when creating a WebSerialReceiptPrinter instance. Other serial port settings have defaults: bufferSize 255, dataBits 8, flowControl 'none', parity 'none', stopBits 1.
```javascript
const receiptPrinter = new WebSerialReceiptPrinter({
baudRate: 9600
});
```
--------------------------------
### Encode and print a receipt with ReceiptPrinterEncoder
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
Use this snippet to encode receipt data with the ReceiptPrinterEncoder and print it via receiptPrinter.print(). The data must be properly encoded for the printer. The example encodes text and a QR code using the 'esc-pos' language and 'epson' codepage mapping.
```javascript
/* Encode the receipt */
let encoder = new ReceiptPrinterEncoder({
language: 'esc-pos',
codepageMapping: 'epson'
});
let data = encoder
.initialize()
.text('The quick brown fox jumps over the lazy dog')
.newline()
.qrcode('https://nielsleenheer.com')
.encode();
/* Print the receipt */
receiptPrinter.print(data);
```
--------------------------------
### Import WebSerialReceiptPrinter as ES module
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
Import the ES module build and instantiate the WebSerialReceiptPrinter object. Use this when working with a module-based JavaScript environment.
```javascript
import WebSerialReceiptPrinter from 'webserial-receipt-printer.esm.js';
const receiptPrinter = new WebSerialReceiptPrinter();
```
--------------------------------
### Load WebSerialReceiptPrinter with UMD script tag
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
Include the UMD build in an HTML page and instantiate the WebSerialReceiptPrinter object. This is the simplest way to use the library in a browser without a module bundler.
```html
```
--------------------------------
### Listen for connected event to store device info
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
Add an event listener for the 'connected' event to receive device information including vendorId and productId. Store the device object for later reconnection. The callback receives an object with type, vendorId, and productId properties.
```javascript
receiptPrinter.addEventListener('connected', device => {
console.log(`Connected to a device with vendorId: ${device.vendorId} and productId: ${device.productId}`);
/* Store device for reconnecting */
lastUsedDevice = device;
});
```
--------------------------------
### Connect to receipt printer on button click
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
The connect() function must be called as a result of a user action, such as clicking a button. It cannot be called on page load.
```javascript
function handleConnectButtonClick() {
receiptPrinter.connect();
}
```
--------------------------------
### Reconnect to previously used receipt printer
Source: https://github.com/at-point-of-sale/webserialreceiptprinter/blob/main/README.md
The reconnect() function requires an object with vendorId and productId of the previously connected printer. It will not reconnect if multiple devices share the same vendorId and productId, or if no previously connected device is found.
```javascript
receiptPrinter.reconnect(lastUsedDevice);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.