Package: loadstar-sensors-interface
AboutExample UsageInstallationDevelopmentAbout-Python Package Name: loadstar_sensors_interface-Description: Python async interface to Loadstar Sensors USB devices.-Version: 2.1.1-Python Version: 3.9-Release Date: 2023-02-09-Creation Date: 2022-08-16-License: BSD-3-Clause-URL: https://github.com/janelia-pypi/loadstar_sensors_interface_python-Author: Peter Polidoro-Email: peter@polidoro.io-Copyright: 2023 Howard Hughes Medical Institute-References:-https://pyserial-asyncio.readthedocs.io/en/latest/-https://python.readthedocs.io/en/latest/library/asyncio.html-https://pint.readthedocs.io/en/stable/getting/overview.html-https://tinkering.xyz/async-serial/-https://www.loadstarsensors.com/-https://www.loadstarsensors.com/di-100u-di-1000u-command-set.html-Dependencies:-pyserial-asyncio-pint-clickExample UsagePythonfromloadstar_sensors_interfaceimportLoadstarSensorsInterfaceimportasyncioasyncdefmy_sensor_value_callback(sensor_value):print(f'sensor value magnitude:{sensor_value.magnitude}, units:{sensor_value.units}')awaitasyncio.sleep(0)asyncdefexample():dev=LoadstarSensorsInterface()awaitdev.open_high_speed_serial_connection(port='/dev/ttyUSB0')dev.set_sensor_value_units('gram')dev.set_units_format('.1f')awaitdev.tare()dev.start_getting_sensor_values(my_sensor_value_callback)awaitasyncio.sleep(5)awaitdev.stop_getting_sensor_values()count=dev.get_sensor_value_count()duration=dev.get_sensor_value_duration()rate=dev.get_sensor_value_rate()print(f'{count}sensor values in{duration}at a rate of{rate}')awaitdev.print_device_info()asyncio.run(example())Command Linehelploadstar--help# Usage: loadstar [OPTIONS]#   Command line interface for loadstar sensors.# Options:#   -p, --port TEXT          Device name (e.g. /dev/ttyUSB0 on GNU/Linux or COM3#                            on Windows)#   -H, --high-speed         Open serial port with high speed baudrate.#   --debug                  Print debugging information.#   -i, --info               Print the device info and exit#   -T, --tare               Tare before getting sensor values.#   -d, --duration INTEGER   Duration of sensor value measurements in seconds.#                            [default: 10]#   -u, --units TEXT         Sensor value units.  [default: gram]#   -f, --units-format TEXT  Units format.  [default: .1f]#   -h, --help               Show this message and exit.device info# DI-100, DI-1000loadstar--port/dev/ttyUSB0--info# DI-1000UHSloadstar--port/dev/ttyUSB0--high-speed--info# device info:# port                     /dev/ttyUSB0# baudrate                 230400# model                    FCM DI-1000# id                       F230235995# sensor_value_units       gram# units_format             .1f# load_capacity            2041.2 gramexample usage# DI-100, DI-1000loadstar--port/dev/ttyUSB0--tare--duration10--unitskilogram--units-format=.3f# DI-1000UHSloadstar--port/dev/ttyUSB0--high-speed--tare--duration10--unitskilogram--units-format=.3f# 2023-02-03 18:35:11.086982 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.087548 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.088130 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.088705 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.089174 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.089540 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.089905 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.090268 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.090634 - sensor_value -> 0.500 kilogram# 2023-02-03 18:35:11.091001 - sensor_value -> 0.500 kilogram# 5166 sensor values in 10.051 second at a rate of 513.980 hertz# device info:# port                     /dev/ttyUSB0# baudrate                 230400# model                    FCM DI-1000# id                       F230235995# sensor_value_units       kilogram# units_format             .3f# load_capacity            2.041 kilogramInstallationhttps://github.com/janelia-pypi/python_setupGNU/LinuxDriversGNU/Linux computers usually have all of the necessary drivers already installed, but users need the appropriate permissions to open the device and communicate with it.Udev is the GNU/Linux subsystem that detects when things are plugged into your computer.Udev may be used to detect when a loadstar sensor is plugged into the computer and automatically give permission to open that device.If you plug a sensor into your computer and attempt to open it and get an error such as: "FATAL: cannot open /dev/ttyUSB0: Permission denied", then you need to install udev rules to give permission to open that device.Udev rules may be downloaded as a file and placed in the appropriate directory using these instructions:99-platformio-udev.rulesDownload rules into the correct directorycurl-fsSLhttps://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules|sudotee/etc/udev/rules.d/99-platformio-udev.rulesRestart udev management toolsudoserviceudevrestartUbuntu/Debian users may need to add own “username” to the “dialout” groupsudousermod-a-Gdialout$USERsudousermod-a-Gplugdev$USERAfter setting up rules and groupsYou will need to log out and log back in again (or reboot) for the user group changes to take effect.After this file is installed, physically unplug and reconnect your board.Python CodeThe Python code in this library may be installed in any number of ways, chose one.pippython3-mvenv~/venvs/loadstar_sensors_interfacesource~/venvs/loadstar_sensors_interface/bin/activate
pipinstallloadstar_sensors_interfaceguixSetup guix-janelia channel:https://github.com/guix-janelia/guix-janeliaguixinstallpython-loadstar-sensors-interfaceWindowsDriversDownload and install Windows driver:Loadstar Sensors Windows DriverPython CodeThe Python code in this library may be installed in any number of ways, chose one.pippython3-mvenvC:\venvs\loadstar_sensors_interface
C:\venvs\loadstar_sensors_interface\Scripts\activate
pipinstallloadstar_sensors_interfaceDevelopmentClone Repositorygitclonegit@github.com:janelia-pypi/loadstar_sensors_interface_python.gitcdloadstar_sensors_interface_pythonGuixInstall GuixInstall GuixEdit metadata.orgmake-f.metadata/Makefilemetadata-editsTangle metadata.orgmake-f.metadata/MakefilemetadataDevelop Python packagemake-f.metadata/Makefileguix-dev-containerexitTest Python package using ipython shellmake-f.metadata/Makefileguix-dev-container-ipython
importloadstar_sensors_interfaceexitTest Python package installationmake-f.metadata/Makefileguix-containerexitUpload Python package to pypimake-f.metadata/MakefileuploadTest direct device interaction using serial terminalLow SpeedDI-100, DI-1000make-f.metadata/Makefileguix-dev-container-port-serial# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 guix-dev-container-port-serial?# helpsettings[C-a][C-x]# to exitHigh SpeedDI-1000UHSmake-f.metadata/Makefileguix-dev-container-port-serial-hs# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 guix-dev-container-port-serial-hs?# helpsettings[C-a][C-x]# to exitTest Python package using ipython shell with serial port accessmake-f.metadata/Makefileguix-dev-container-port-ipython# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 guix-dev-container-port-ipythonimportloadstar_sensors_interfaceexitTest Python package installation with serial port accessmake-f.metadata/Makefileguix-container-port# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 guix-container-portexitDockerInstall Docker Enginehttps://docs.docker.com/engine/Develop Python packagemake-f.metadata/Makefiledocker-dev-containerexitTest Python package using ipython shellmake-f.metadata/Makefiledocker-dev-container-ipython
importloadstar_sensors_interfaceexitTest Python package installationmake-f.metadata/Makefiledocker-containerexitTest Python package using ipython shell with serial port accessmake-f.metadata/Makefiledocker-dev-container-port-ipython# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 docker-dev-container-port-ipythonimportloadstar_sensors_interfaceexitTest Python package installation with serial port accessmake-f.metadata/Makefiledocker-container-port# PORT=/dev/ttyUSB0# make -f .metadata/Makefile PORT=/dev/ttyUSB1 docker-container-portexit