WebScale 0.0.0-SNAPSHOT2
See the version list below for details.
dotnet add package WebScale --version 0.0.0-SNAPSHOT2
NuGet\Install-Package WebScale -Version 0.0.0-SNAPSHOT2
<PackageReference Include="WebScale" Version="0.0.0-SNAPSHOT2" />
paket add WebScale --version 0.0.0-SNAPSHOT2
#r "nuget: WebScale, 0.0.0-SNAPSHOT2"
// Install WebScale as a Cake Addin #addin nuget:?package=WebScale&version=0.0.0-SNAPSHOT2&prerelease // Install WebScale as a Cake Tool #tool nuget:?package=WebScale&version=0.0.0-SNAPSHOT2&prerelease
WebScale
Measure weight using a Stamps.com digital USB postage scale
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
Stamps.com Stainless Steel 5 lb. Digital Scale
- Sign up for free trial at Stamps.com.
- During signup, request a complimentary 5-pound digital postage scale. Pay $9.99 USD shipping and handling.
- Before the four-week trial is up, cancel your account and avoid the monthly fee.
I successfully performed these steps in September 2014. Today, it may work differently, or not at all.
Any .NET runtime that supports .NET Standard 2.0 or later:
Operating systems:
- Windows
- MacOS
- Linux (may need superuser permissions to access
/dev/hidraw0
)
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
- Aldaviva/webscale - Node.js version of this library
Product | Versions 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. |
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 |