Git Product home page Git Product logo

python-plin's Introduction

Python PLIN library

This library provides a Python interface for interacting with PEAK devices such as the PCAN-USB Pro and PLIN-USB on Linux using the chardev API provided by the PEAK LIN Linux Beta. The PEAK Linux beta driver is required to use this library and is available here.

Installation

The plin-linux package is available on PyPI and can be directly installed with pip install plin-linux.

Examples

Runnable examples are located in the examples/ directory.

Master Example

from plin.device import PLIN
from plin.enums import (PLINFrameChecksumType, PLINFrameDirection,
                        PLINFrameFlag, PLINMode)

# Initializes /dev/plin0 as a LIN master
master = PLIN(interface="/dev/plin0")

master.start(mode=PLINMode.MASTER, baudrate=19200)

# Get firmware version of the PEAK device
print(master.get_firmware_version())

# Get current status of the PEAK device
print(master.get_status())

# Add a publisher frame entry
master.set_frame_entry(id=0x22,
                       direction=PLINFrameDirection.PUBLISHER,
                       checksum_type=PLINFrameChecksumType.CLASSIC,
                       data=bytearray([0x01, 0x02, 0x03, 0x04]))

# Add a subscriber frame entry
master.set_frame_entry(id=0x23,
                       direction=PLINFrameDirection.SUBSCRIBER_AUTO_LEN,
                       checksum_type=PLINFrameChecksumType.CLASSIC)

# Get frame entry
print(master.get_frame_entry(id=0x22))

# Add unconditional slot to schedule 0
master.add_unconditional_schedule_slot(schedule=0, delay_ms=10, id=0x22)
master.add_unconditional_schedule_slot(schedule=0, delay_ms=10, id=0x23)

# Get schedule 0 slots
print(master.get_schedule_slots(0))

# Start schedule 0
master.start_schedule(0)

# Set ID filter
master.set_id_filter(bytearray([0xff] * 8))

# Read frames
while True:
    result = master.read()
    print(result)

Slave Example

from plin.device import PLIN
from plin.enums import PLINMode

# Initializes /dev/plin0 as a LIN slave
slave = PLIN(interface="/dev/plin0")

slave.start(mode=PLINMode.SLAVE, baudrate=19200)

# Set ID filter
slave.set_id_filter(bytearray([0xff] * 8))

# Read frames
while True:
    result = slave.read()
    print(result)

Unit Tests

  • Unit tests are located in the unit_tests/ directory.
  • Tests in unit_tests/integration/ require a PEAK LIN device connected to run.
  • Can be run with pytest.

License

Copyright 2024 Rivian Automotive, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

python-plin's People

Contributors

lumagi avatar rivian-kstrishock avatar willzhang05 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sittkuma lumagi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.