easy-scale-serial
v1.0.1
Published
Easy Scale Plugin for Capacitorjs
Readme
easy-scale-serial
Easy Scale Plugin for CapacitorJS
Install
npm install easy-scale-serial
npx cap syncQuick intro
This plugin was developed for Android App with CapacitorJS. The plugin's main feature is connecting Android devices with digital scales, such as TORREY; this plugin allows request weight from a digital scale.
📋️ Requirements
- capacitor/android 7.x.x
- capacitor/core 7.x.x
- Open android/build.gradle file and add repositories before building the app.
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // required for usb-serial-for-android
}
}
- Open android/app/build.gradle file and add the dependency before building the app.
dependencies {
implementation 'com.github.mik3y:usb-serial-for-android:3.9.0'
}
- Open android/app/src/main/AndroidManifest.xml file and add feature before building the app.
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
💻️ Quick example
The best way to add the plugin to CapacitorJS app (ex: Angular) is creating a service, the following example is a suggestion of application and logic.
import { Injectable, NgZone } from '@angular/core';
import { ScaleSerial } from 'easy-scale-serial';
@Injectable({
providedIn: 'root'
})
export class ScaleService {
constructor(private zone: NgZone){}
// Just call the func.
scanWeight(){
this.zone.run(async () => {
try {
// In this example Torrey Scale request command is: P
const res = await ScaleSerial.requestWeight({ command: 'P'});
console.log('Weight: ', res.weight);
} catch (err) {
console.error('Error', err);
}
});
}
}API
requestWeight(...)
requestWeight(options: { command: string; }) => Promise<{ weight: string; }>| Param | Type |
| ------------- | --------------------------------- |
| options | { command: string; } |
Returns: Promise<{ weight: string; }>
Contact, Reports or Bugs
Thanks for checking out the project. You can take a peek about my work by visiting my website.
🌍 Website: Visit
