WebScale 1.0.0

dotnet add package WebScale --version 1.0.0                
NuGet\Install-Package WebScale -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebScale" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WebScale --version 1.0.0                
#r "nuget: WebScale, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WebScale as a Cake Addin
#addin nuget:?package=WebScale&version=1.0.0

// Install WebScale as a Cake Tool
#tool nuget:?package=WebScale&version=1.0.0                

WebScale

Nuget GitHub Workflow Status Testspace Coveralls

Measure weight using a Stamps.com digital USB postage scale

Stamps.com 5-pound digital postage scale

  1. Quick Start
  2. Prerequisites
  3. Installation
  4. Usage
  5. Sample
  6. See also

Quick Start

dotnet new console
dotnet add package WebScale
// Program.cs
using Aldaviva.WebScale;

using IWebScale webScale = new WebScale();

webScale.WeightChanged += (sender, weight) => Console.WriteLine($"{weight.OunceForce,4:N1} oz.");

// Keep console program running while waiting for WeightChanged events
CancellationTokenSource cancellationTokenSource = new();
Console.CancelKeyPress += (sender, eventArgs) => {
    eventArgs.Cancel = true;
    cancellationTokenSource.Cancel();
};
Console.WriteLine("Press Ctrl+C to exit");
cancellationTokenSource.Token.WaitHandle.WaitOne();
dotnet run

Prerequisites

Installation

This package is available as WebScale on NuGet Gallery.

dotnet add package WebScale
NuGet\Install-Package WebScale

Usage

Connect to device

Construct a new WebScale instance.

using IWebScale webScale = new WebScale();

This connects to the first Stamps.com Stainless Steel 5 lb. Digital Scale found connected to the computer.

If there is no suitable device connected, this will wait and connect when one appears. If the device disconnects, this will wait for it to reconnect and then automatically reestablish a connection.

The IsConnected property shows whether or not the instance is currently connected to a scale. Updates to this property are indicated by the IsConnectedChanged event.

Read weight

Get how much weight is currently on the scale. The precision is 0.1 ounces. Can be negative if the scale was tared with weight on it which was subsequently reduced.

Force weight = webScale.Weight;

The Force type is from the UnitsNet library. You can get specific units of force using properties on it like OunceForce or KilogramsForce.

This property automatically updates every 400 ± 15 milliseconds whenever the scale is connected.

Listen for weight change events

Receive a notification when the weight on the scale changes. Not fired while taring.

webScale.WeightChanged += (sender, weight) => Console.WriteLine($"{weight.OunceForce,4:N1} oz.");

The event argument is the amount of weight currently on the scale.

If you need event callbacks to run on the UI thread so you can update a Windows Forms or WPF UI, you can set the IWebScale.EventSynchronizationContext property.

Tare

The scale automatically resets itself to zero when it powers on. You can also manually tare it by calling Tare().

await webScale.Tare();

After this task completes, the scale's weight will read zero.

Dispose

When you are done with this instance, call Dispose() to disconnect from the device. You can also use a using statement or declaration.

public void ExplicitlyDispose() {
    IWebScale webScale = new WebScale();
    // use webScale here
    device.Dispose();
}
public void ImplicitlyDisposeWithUsingDeclaration() {
    using IWebScale webScale = new WebScale();
    // use webScale here
    // when control exits the ImplicitlyDisposeWithUsingDeclaration method, webScale will be disposed
}
public void ImplicitlyDisposeWithUsingStatement() {
    using (IWebScale webScale = new WebScale()) {
        // use webScale here
        // when control exits the using block, webScale will be disposed
    }
}

Sample

The sample application demonstrates usage of this library.

You may clone this repository and run the sample with dotnet run in the Sample project directory.

You may also download prebuilt executables of the sample app for Windows, Linux, and MacOS, each on x64 and ARM. Remember that the Linux app needs to be run with sudo, and the MacOS and Linux apps need the chmod +x executable bit.

See also

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 239 4/13/2023
0.0.0-SNAPSHOT2 124 4/10/2023
0.0.0-SNAPSHOT1 107 4/9/2023