Skip to content

Instantly share code, notes, and snippets.

@EstebanFuentealba
Created February 7, 2024 15:21
Show Gist options
  • Save EstebanFuentealba/95a911e724236fb52bf95edb9b3ada67 to your computer and use it in GitHub Desktop.
Save EstebanFuentealba/95a911e724236fb52bf95edb9b3ada67 to your computer and use it in GitHub Desktop.
// Label Printer
// vendorId 0x416
// productId 0x5011
// manufacturerName STMicroelectronics
// productName POS Label Printer
async function testPrint(device) {
const cmds = [
'SIZE 99.84 mm,149.93 mm',
'CLS',
'TEXT 30,10,"4",0,1,1,"Hola mundo"',
'TEXT 30,50,"2",0,1,1,"WebUSB API"',
'BARCODE 30,80,"128",70,1,0,2,2,"json.cl"',
'PRINT 1',
'END',
];
await device.open();
await device.selectConfiguration(1);
await device.claimInterface(0);
await device.transferOut(
device.configuration.interfaces[0].alternate.endpoints.find(obj => obj.direction === 'out').endpointNumber,
new Uint8Array(
new TextEncoder().encode(cmds.join('\r\n'))
),
);
await device.close();
}
navigator.usb.requestDevice({ filters: [{ vendorId: 0x416 }] }).then((device)=> {
console.log(`Name: ${device.productName}, Serial: ${device.serialNumber}`);
testPrint(device)
console.log("printed")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment