Skip to main content

Weigh scale Modbus Ethernet client

Project description

Table of Contents

[[TOC]]

1. Introduction

Modbus Scale Client provides the client-side capabilities required to communicate with the Mazzer and Rancilio weigh scales of project UC-02-2024 Coffee Cart Modifications.

2. Dependencies

Modbus Scale Client is part of the UC-02-2024 Coffee Cart Modifications software suite. Scale software has been split along hardware component lines, with the software for each hardware component residing in a separate GitLab repository.

  1. modbus_scale_broker. The Arduino sketch that must be downloaded to the Uno.

  2. modbus_scale_server. The Modbus Ethernet server daemon that runs on the Raspberry Pi.

  3. modbus_scale_client. The Modbus Ethernet client that queries the server.

  4. modbus_scale_ui. A Textual UI (User Interface) that displays the output of the Mazzer and Rancilio scales, and which can be used to tare (zero) either scale.

Because these repositories are designed to be deployed together as part of a comprehensive weigh scale solution, both hardware and software dependencies exist between them. These dependencies must be borne in mind when deciding whether or not to employ Modbus Scale Client in isolation.

Python packages are also available for the following software components.

These packages may be installed using pip. Note however that the caveat regarding hardware and software dependencies still applies.

3. Installation

Two installation methods are available, with the most appropriate depending on whether the intent is to use the code base as-is, or to modify it.

3.1. PyPI Package

Those who wish to use the code base as-is should install the Python package via pip.

Whilst it is not strictly necessary to create a venv (virtual environment) in order to deploy the package, doing so provides a Python environment that is completely isolated from the system-wide Python install. The practical upshot of this is that the venv can be torn-down and recreated multiple times without issue.

$ python -m venv ~/venv

Next, activate the venv and install the package. Note that once activated, the name of the venv will be prepended to the terminal prompt.

$ source ~/venv/bin/activate
(venv) $ python -m pip install modbus-scale-client

3.2. GitLab Repository

Those who wish to modify the code base should clone the GitLab repository instead. Again, whilst not strictly necessary to create a venv in order to modify the code base, doing so is still recommended.

$ python -m venv ~/venv
$ source ~/venv/bin/activate
(venv) $ cd ~/venv
(venv) $ git clone https://gitlab.com/uc_mech_wing/robotics_control_lab/uc-02-2024/modbus_scale_client.git

Irrespective of whether or not a venv has been created, the requirements.txt file may be used to ensure that the correct module dependencies are installed.

(venv) $ cd ~/venv/modbus_scale_client
(venv) $ python -m pip install -r ./requirements.txt

4. Verification

In order to verify that Modbus Scale Client has been installed correctly, it is advisable to create a minimal working example.

$ touch ~/venv/example.py

If installed from the Python package, add the following.

import time

from modbus_scale_client import ModbusScaleClient

client = ModbusScaleClient(host = "<host>")

print("[INFO] Starting reading...")

while True:
    try:
        weight = client.read()
        weight = "{:8.1f}".format(weight)
        
        if client.server_exists() == True and \
            client.broker_exists() == True:
            
            print("[REAL] Scale weight = %sg" % weight)
        
        elif client.server_exists() == True and \
            client.broker_exists() == False:
            
            print("[ERROR] No broker detected")
        
        else:
            print("[FAKE] Scale weight = %sg" % weight)
        
        time.sleep(1)
    
    except (KeyboardInterrupt, SystemExit):
        print("[INFO] Stopping reading...")
        sys.exit()

If installed from the GitLab repository, replace the import statement with the following.

from modbus_scale_client.src.modbus_scale_client import ModbusScaleClient

In either case, be sure to replace <host> with the IPv4 (Internet Protocol version 4) address of your physical Raspberry Pi. All going well, running the example code will produce output similar to the following.

(venv) $ python ~/venv/example.py
[INFO] Starting reading... 
[REAL] Scale weight =    123.4g
[REAL] Scale weight =    123.4g
[REAL] Scale weight =    123.4g
...
[REAL] Scale weight =    123.4g
[INFO] Stopping reading...

Note that verification assumes that all of the requisite hardware and software dependencies have been met.

5. Further Information

For further information about Coffee Cart Modifications please refer to the project UC-02-2024 group README.

6. Documentation

Code has been documented using Doxygen.

7. License

Modbus Scale Client is released under the GNU General Public License.

8. Authors

Code by Rodney Elliott, rodney.elliott@canterbury.ac.nz

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

modbus_scale_client-1.1.0.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modbus_scale_client-1.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file modbus_scale_client-1.1.0.tar.gz.

File metadata

  • Download URL: modbus_scale_client-1.1.0.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for modbus_scale_client-1.1.0.tar.gz
Algorithm Hash digest
SHA256 686b54294c6b73cd417937f9e71c1e16bfdcfa38ccf429996100dc3656568311
MD5 c0b6b6e8e2336a5df07e2ce9c823da7b
BLAKE2b-256 6cae5d1b85b42ed9d0b9184aec6c4c806fe92ed01ddb71d91fe27b3e50c1fb4c

See more details on using hashes here.

File details

Details for the file modbus_scale_client-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modbus_scale_client-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f88901beb540e39578d1df770bcc3622a3add6e8558d4d8b1475ca257792e95
MD5 40714583a75eb01bf00e183b4be7df57
BLAKE2b-256 9364d188f66562d1f55d389a34c982414af3282ebaa21cce93be56d5144fb5e0

See more details on using hashes here.

Supported by

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