https://github.com/mattfors/ng-scales
Angular library for reading USB scales
https://github.com/mattfors/ng-scales
angular dymo hid scales usb
Last synced: about 2 months ago
JSON representation
Angular library for reading USB scales
- Host: GitHub
- URL: https://github.com/mattfors/ng-scales
- Owner: mattfors
- License: mit
- Created: 2024-05-25T21:02:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-11T23:15:11.000Z (7 months ago)
- Last Synced: 2025-04-11T21:11:52.574Z (about 2 months ago)
- Topics: angular, dymo, hid, scales, usb
- Language: TypeScript
- Homepage: https://mattfors.github.io/ng-scales/
- Size: 1.61 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ng-scales
[](https://badge.fury.io/js/ng-scales)




[](https://github.com/prettier/prettier)Angular library for connecting to USB scales
## Demo
Check out the [live demo](https://mattfors.github.io/ng-scales/)## Get started
### Installing
Add the `npm` package to your app
```shell
npm i ng-scales
```### Using in angular application
Add the providers in the `app.config.ts`
```typescript
providers: [
...
provideNgScales()
...
]
```The easiest way to integrate is the provided button directive which handles connecting and disconnecting from the scale. Add this into your template
```html
```
Import the component
```typescript
@Component({
...
imports: [NgScalesConnectionButtonDirective]
...
})
```## Hardware Support
### Built in support
| Vendor | Vendor ID | Product | Product Id | Name | Verified |
|:------:|:----------|:-------:|:-----------|:-------------------------------------:|:--------:|
| DYMO | 2338 | M25 | 32771 | DYMO M25 25 Lb Digital Postal Scale | ✅ |### Adding support for additional scales
You can add a new scale by providing additional mappers. The mapper function coverts the array buffer into a usable data object```typescript
provideNgScales({mappers: [
{
vendorId: 2338,
productId: 32771,
mapper: (arrayBuffer: ArrayBuffer): HardwareScaleReportEvent => {
const d = new Uint8Array(arrayBuffer);
let weight = (d[3] + 256 * d[4])/10;
if (d[0] === 5) {
weight *= -1;
}
return {
units: d[1] === 2 ? 'grams' : 'ounces',
weight
};
}
}
]})
```