Skip to main content

A python package to interface with serial laser distance sensors fron Chengdu JRT Meter Technology Co., Ltd.

Project description

JRT Laser Distance Sensor Python Library

This library is a Python library for the JRT laser distance sensor for laser devices from Chengdu JRT Meter Technology Company, Ltd.

This library has been tested with the following sensors:

The author of this library has no affiliation with Chengdu JRT and this library is not endorsed by Chengdu JRT.

Installation

Use the package manager pip to install jrt-laser-distance-sensor.

pip install jrt_laser_distance_sensor

After installation, you should be able to test the library with the following command:

jrt-laser-distance-sensor <serial-port-name>

Serial port naming conventions vary by platform (e.g. /dev/ttyUSB0 on Linux, COM1 on Windows, /dev/tty.usb-12345 on OS X).

All measurements from the library are reported in millimeters.

Usage

A simple example of using the library is as follows, with the sensor connected to /dev/ttyUSB0:

from jrt_laser_distance_sensor import JrtSerial

sensor = JrtSerial('/dev/ttyUSB0')
print(sensor.one_shot_measurement())

You can also do continuous measurements:

from jrt_laser_distance_sensor import JrtSerial

sensor = JrtSerial('/dev/ttyUSB0')

sensor.start_continuous_measurement()

while True:
    print(sensor.read_measurement())

This is block of code demonstrates most of the useful features of the library:

import sys
import time
from binascii import hexlify
from jrt_laser_distance_sensor import JrtSerial

def main():
    if len(sys.argv) > 1:
        port = sys.argv[1]
    else:
        print(f'usage: {sys.argv[0]} <port>')
        sys.exit(1)
    jrt = JrtSerial(port)
    hw_version = hexlify(jrt.read_hw_version().to_bytes(2, 'big', signed=True))
    print(f'hw version: {hw_version}')
    sw_version = hexlify(jrt.read_sw_version().to_bytes(2, 'big', signed=True))
    print(f'sw version: {sw_version}')
    input_voltage= hexlify(jrt.read_input_voltage().to_bytes(2, 'big', signed=True))
    print(f'input voltage: {input_voltage}')
    print(f"reading status: {jrt.status_to_text(jrt.read_status())}")
    print("testing laser on / off")
    print('laser', jrt.set_laser(True))
    print('laser should be on (sleeping 2 seconds)')
    time.sleep(2)
    print('laser', jrt.set_laser(False))
    print('laser should be off (sleeping 2 seconds)')
    time.sleep(2)

    print('testing continuous measurement in auto mode (10 readings)')
    jrt.start_continuous_measurement('auto')
    x = 0
    while x < 10:
        print(f"{x + 1}: {jrt.read_measurement()} (signal quality: {jrt.last_signal_quality})")
        time.sleep(0.1)
        x += 1

    jrt.stop_continuous_measurement()

    print('continuous measurement test finished')
    time.sleep(0.5)
    print('test one shot measurement')

    print('auto', jrt.one_shot_measurement('auto'))
    print('slow', jrt.one_shot_measurement('slow'))
    print('fast', jrt.one_shot_measurement('fast'))

    print('turning laser off')
    print('laser', jrt.set_laser(False))

It should produce output similar to the following:

hw version: b'8301'
sw version: b'1b08'
input voltage: b'3303'
reading status: No error
testing laser on / off
laser 1
laser should be on (sleeping 2 seconds)
laser 0
laser should be off (sleeping 2 seconds)
testing continuous measurement in auto mode (10 readings)
1: 271 (signal quality: 98)
2: 271 (signal quality: 97)
3: 270 (signal quality: 108)
4: 270 (signal quality: 110)
5: 270 (signal quality: 83)
6: 270 (signal quality: 81)
7: 270 (signal quality: 87)
8: 271 (signal quality: 83)
9: 270 (signal quality: 87)
10: 270 (signal quality: 103)
continuous measurement test finished
test one shot measurement
auto 271
slow 271
fast 270
turning laser off
laser 0

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

jrt-laser-distance-sensor-0.0.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

jrt_laser_distance_sensor-0.0.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file jrt-laser-distance-sensor-0.0.5.tar.gz.

File metadata

File hashes

Hashes for jrt-laser-distance-sensor-0.0.5.tar.gz
Algorithm Hash digest
SHA256 cba50a26af4607770ec1f73e07902770e53a2dc93ae5c0240ef95bfee7cf338d
MD5 8c65caeae0ed03d0386bdc47b9d49903
BLAKE2b-256 d600ef15edae1fd190263757fefeccba07a45f96fb6a4bbbeb16e841200007de

See more details on using hashes here.

File details

Details for the file jrt_laser_distance_sensor-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for jrt_laser_distance_sensor-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 39fde8cde0bb95efa1b95d0a10ae3cbbae6e9808ae4c1d1510ef7000b23926d2
MD5 5ee5c69cb2b90a88e5b03f16a311b49e
BLAKE2b-256 f45bb308d387ded0893e5aefcb6303f00c1d2568e905648eaf6ebbe41b1e4a3b

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