Skip to main content

pysartoriusb

Project description

SartoriUSB

Build Status

USB serial connection to Sartorius Scales

Example:

    import sartoriusb as sub

    with sub.SartoriusUsb('COM4') as conn:
        result = conn.measure()

    assert result.mode == "G"
    assert result.value == "+3.4"
    assert result.unit == "mg"
    assert result.stable == True
    assert result.message == None

Required settings on the scale

The USB protocol on the scale must be set to SBI.

Connection to the scale

The prefered way to establish an connection is the use of a context manager: with sartoriusb.SartoriusUsb('COM4') as conn:

For manually handling the connection, the methods connect() and close() can be used. For convenience there is also and open() method that just behaves like connect()

Sending commands and receiving output

Sending commands to the scale can be done with the send(cmd), the available commands according to the manual are listed below, but you could but propably shouldn't send any arbitrary commands to the scale.

For reading the results from the scale, there are two methods available:

  • read(bytes): reads a number of bytes from the scale
  • readlines(): returns a list of text lines, already decoded from bytes

Since sending a command and recieving an output are often used side by side, there is a convenience method: get(cmd) will first send the command and returns the output from the scale as a list of strings.

Measuring

To measure a weight (or whatever the scale is set to), you could use get(CMD_PRINT) and parse the output yourselve or use the measure() method and get an already parsed output:

The function returns a sartoriusb.Measurement named tuple:

  • Measurement.mode: The measurement mode, might be unknown if reporting on the scale is set to 16 byte output
  • Measurement.value: The value as string as reported by the scale; whitespace an nonnumeric characters are removed, so int() or float() could be used directly
  • Measurement.unit: The unit of the Measurement reported by the scale. Might be None if it was an unstable read
  • Measurement.stable: Boolean value indicating if the measured value was stable or unstable
  • Measurement.message: If a non-measurement message was sent from the scale, it is reported here and all other fields are set to None. For a regular measurement result this field is None.

Available Commands

  • CMD_PRINT: "Print" the current measurement result

  • CMD_TARA: performa a tara or set the display to zero

  • CMD_EXPCLICIT_TARA: explicit tara only

  • CMD_EXPCLICIT_NULL: explicit set display to zero

  • CMD_INFO_TYPE: show scale type

  • CMD_INFO_SNR: show serial number of scale

  • CMD_INFO_VERSION_SCALE: show software version of the scale

  • CMD_INFO_VERSION_CONTROL_UNIT: show the software version of the command and display module

  • CMD_INFO_USER: display user and device id

  • CMD_FILTER_ENVIRONMENT_VERY_STABLE: set the filter to "very stable enviroment"

  • CMD_FILTER_ENVIRONMENT_STABLE: set the filter to "stable enviroment"

  • CMD_FILTER_ENVIRONMENT_UNSTABLE: set the filter to "unstable enviroment"

  • CMD_FILTER_ENVIRONMENT_VERAY_UNSTABLE: set the filter to "very unstable enviroment"

  • CMD_KEYBOARD_LOCK: lock the keyboard on the command and display module

  • CMD_KEYBOARD_UNKLOCK: unlock the keyboard on the command and display module

  • CMD_KEYPRESS_PRINT: simulate a keypress on the command modules 'print' key

  • CMD_KEYPRESS_CANCEL: simulate a keypress on the command modules 'cancel' key

  • CMD_BEEP: make the scale beep

  • CMD_ADJUST_INTERNAL: start internal adjustment

  • CMD_ADJUST_EXTERNAL: start external adjustment with standard weights

  • CMD_RESTART: restart the scale

Development

To install the development version of SartoriUSB:

git clone https://github.com/holgi/sartoriusb.git
cd sartoriusb

# create a virtual environment and activate it
python3 -m venv --prompt sartorius .venv
.venv/bin/activate

# upgrade pip, install flit and sartoriusb
python3 -m pip install --upgrade pip
python3 -m pip install flit
python3 -m flit install --pth-file

To run the tests, run make tests or make coverage for a complete report.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SartoriUSB-0.2.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

SartoriUSB-0.2.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file SartoriUSB-0.2.1.tar.gz.

File metadata

  • Download URL: SartoriUSB-0.2.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for SartoriUSB-0.2.1.tar.gz
Algorithm Hash digest
SHA256 043f5a6bcd4795371f0d39ff57b139b542b7ee6be7d5ccd5ef92df494a4ab34b
MD5 9147307b4b90a69918d71d7fabf42629
BLAKE2b-256 293a87c5f777adb9133ebadd9a4f498911bf2755ee93a08ac820f93d96803b8a

See more details on using hashes here.

File details

Details for the file SartoriUSB-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: SartoriUSB-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for SartoriUSB-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59c653826ac984089161b7f850bb498982356bd25857c34a5a9826cae57c2226
MD5 b9904942b59201f23772899261369ffa
BLAKE2b-256 ac075cfbbaf1c843da064b2503e5f1e031b350c3f6488675564f6f40c7f50307

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page