dymoscale

package module
v0.0.0-...-265f3c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2015 License: MIT Imports: 5 Imported by: 0

README

dymoscale

GoDoc Build Status

Go library for reading Dymo USB postal scales.

You can buy them relatively cheap from Ebay.

Tested with a Dymo M5, but will probably work with other models too.

Developing

darwin/amd64

To test and build on Darwin.

brew install libusb
make darwin

You may get an access denied error though when using the binary/library because of [this problem][libusb_osx] with OS X attaching its HID driver.

[libusb_osx]: https://github.com/libusb/libusb/wiki/FAQ#How_can_I_run_libusb_applications_under_Mac_OS_X_if_there_is_already_a_kernel_extension_installed_for_the_device)

linux/amd64

To test, build, and run on Linux in Docker:

make docker
make
./dymodump/dymodump
linux/arm

To test and cross-compile to ARM, which can run on a Raspberry Pi:

make docker
make test arm

Credit

Goes to this article for doing all the hard work of reverse engineering the binary protocol:

Documentation

Index

Constants

View Source
const GramsInOunce = 28.3495231
View Source
const VendorID usb.ID = 0x0922 // Dymo, all devices

Variables

View Source
var (
	ErrInvalidRead = fmt.Errorf("scale gave invalid reading")
	ErrNeedsTare   = fmt.Errorf("scale reads negative, please tare")
)

Functions

This section is empty.

Types

type Measurement

type Measurement struct {
	AlwaysThree int8      // Don't know what this is but it's always 3
	Stability   Stability // How accurate the measurement was
	Mode        Mode      // Grams or Ounces
	ScaleFactor int8      // Total weight * 10^n
	WeightMinor uint8     //
	WeightMajor uint8     // Overflow for WeightMinor, n*256
}

Measurement represents a parsed reading from the scale.

func (*Measurement) Grams

func (m *Measurement) Grams() (int, error)

Grams returns the measurement in grams.

type Measurementer

type Measurementer interface {
	Grams() (int, error)
}

func ReadMeasurement

func ReadMeasurement(reader io.Reader) (Measurementer, error)

ReadMeasurement obtains a Measurement from an io.Reader.

type Mode

type Mode int8
const (
	Grams  Mode = 2
	Ounces Mode = 11
)

type Scale

type Scale struct {
	// contains filtered or unexported fields
}

func (*Scale) Close

func (s *Scale) Close() error

Close closes the USB device and context. If there are any errors then the inner-most is returned, but both will still attempt to be closed.

func (*Scale) ReadGrams

func (s *Scale) ReadGrams() (int, error)

ReadGrams returns a reading from the scale in grams.

func (*Scale) ReadMeasurement

func (s *Scale) ReadMeasurement() (Measurementer, error)

ReadMeasurement returns a parsed Measurement from the scale.

func (*Scale) ReadRaw

func (s *Scale) ReadRaw() ([]byte, error)

ReadRaw gets a raw reading from the scale.

type Scaler

type Scaler interface {
	ReadRaw() ([]byte, error)
	ReadMeasurement() (Measurementer, error)
	ReadGrams() (int, error)
	Close() error
}

func NewScale

func NewScale() (Scaler, error)

NewScale opens a connection to a Dymo USB scale. You MUST call Close() when you're finished.

type Stability

type Stability int8
const (
	NoWeight  Stability = 2
	NeedsTare Stability = 5
	Stable    Stability = 4
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL