Skip to content

sergiotucano/digital_scale

Repository files navigation

Project Owner GitHub stars GitHub forks

Digital Scale

This package read a weight from digital scale by serial, usb or bluetooth port

Installation

flutter pub add digital_scale

Import

import 'package:digital_scale/digital_scale.dart';

Example

void main() {

  /// digital scale models to send in digitalScaleModel param:
  /// Toledo Prix 3
  /// Elgin DP1502
  /// Urano
  /// upx

  /// call Digital Scale and pass arguments
  final digitalScale = DigitalScale(
      digitalScalePort: 'COM1',
      digitalScaleModel: 'toledo prix 3',
      digitalScaleRate: 9600,
      digitalScaleTimeout: 3000,
      digitalScaleBt: false,
      continuosRead: false,
      saveLogFile: true
  );

  /// async return of weight
  digitalScale.getWeight().then((resp) => print('weight $resp'));
  
  /// continuous mode
  
  ///Now You can read the weight in continuos mode with a listner
  ///on intState
  @override
  void initState() {
    super.initState();
    ScaleUtils.startContinuousRead(
      onWeight: (wd) async {
        print('weight $wd');
      }
    );
  }

  /// and dispose
  @override
  void dispose() {
    ScaleUtils.stopContinuousRead();
    super.dispose();
  }
  
  ///call listner 
  static void startContinuousRead({
    required Function(double weight) onWeight,
  }) async {
    
    _digitalScale = DigitalScale(
        digitalScalePort: 'COM1',
        digitalScaleModel: 'toledo prix 3',
        digitalScaleRate: 9600,
        digitalScaleTimeout: 3000,
        digitalScaleBt: false,
        continuosRead: true,
        saveLogFile: true
    );

    _digitalScale!.startContinuousRead();

    _subscription?.cancel();

    _subscription = _digitalScale!.weightStream.listen((weight) {
      onWeight(weight);
    });
  }

  static void stopContinuousRead() {
    _subscription?.cancel();
    _digitalScale?.stopContinuousRead();
  }

}

Digital Scale Params

### digitalScalePort : Com port for communication
### digitalScaleModel : Model of Digital Scale (See below)
### digitalScaleRate : bit rat of communication
### digitalScaleTimeout : Timeout of communication
### digitalScaleBt : If digital scale is a bluetooth device
### continuosRead : if use continuous read protocol
### saveLogFile : if package will save data in log file for debug

Digital Scales tested

  • Toledo Prix 3

    • Configuration

      • Protocol Ptr1
      • recommended timeout 3000 ms
  • Elgin DP-1502

    • Configuration

      • Data1 300030
      • Prog RS232 1030
      • recommended timeout 5000 ms
  • URANO

    • URANO POP LIGHT

      • Configuration

        • stopbits 2
        • recommended timeout 3000 ms
    • URANO US20/2 POP-S

      • Configuration

        • Protocol USE-P2
        • recommended timeout 3000 ms
    • URANO US31/2 POP-S

      • Configuration

        • Protocol USE-P2
        • recommended timeout 3000 ms
  • UPX EA-20 / EA-32

    • Configuration

      • tIPo Prot 3
      • Cont 0 (continuos) or 1 (ENQ)
      • EnCod 0
      • nEG 0

Log Error

  • Any error in weight reader, open or write port a log error will be create.
  • digital_scale_error.log in app directory

About

Repository of Digital Scale flutter package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors