Skip to main content

Asyncio implementation of ISO-TP (ISO 15765-2)

Project description

This package implements ISO-TP over CAN as an asyncio transport layer, enabling simultaneous receiving and transmitting messages with any number of connections.

Raw CAN communication uses python-can which offers compatibility for many different CAN interfaces and operating systems. If SocketCAN is used on Python 3.7+, the transport is delegated to the kernel if possible for better timing performance.

Why asynchronous?

Asynchronous programming simplifies some possible use-cases:

  • Full duplex receiving and transmitting on a single connection.

  • Communicate on multiple connections simultaneously.

  • Functional addressing where one request is sent out and all nodes respond, then processing the responses as they arrive.

  • Implementing or simulating multiple servers.

No threads need to be handled with all the locking mechanisms required by it.

Installation

Install from PyPI:

$ pip install aioisotp==0.1.0.dev0

Documentation

A basic documentation can be built using Sphinx:

$ python setup.py build_sphinx

Quick start

import asyncio
import aioisotp


class EchoServer(asyncio.Protocol):

    def connection_made(self, transport):
        self._transport = transport

    def data_received(self, data):
        # Echo back the same data
        self._transport.write(data)


async def main():
    network = aioisotp.ISOTPNetwork(
        channel='vcan0', bustype='virtual', receive_own_messages=True)
    with network.open():
        # A server that uses a protocol
        transport, protocol = await network.create_connection(
            EchoServer, 0x1CDADCF9, 0x1CDAF9DC)

        # A client that uses streams
        reader, writer = await network.open_connection(
            0x1CDAF9DC, 0x1CDADCF9)

        writer.write(b'Hello world!')
        response = await reader.read(4095)
        assert response == b'Hello world!'


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

UDS

This package is meant to enable the use of other protocols that require ISO-TP. One of the most common is UDS. A third party library like udsoncan or pyvit can be used to encode and decode payloads.

import aioisotp
import udsoncan

...

reader, writer = await network.open_connection(0x1CDAF9DC, 0x1CDADCF9)

# Construct and send request
request = udsoncan.Request(
    udsoncan.services.ReadDataByIdentifier, data=b'\xF1\x90')
writer.write(request.get_payload())

# Wait for response and decode the payload
payload = await reader.read(4095)
response = udsoncan.Response.from_payload(payload)

print(response)
print(response.data)

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

aioisotp-0.1.0.dev0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

aioisotp-0.1.0.dev0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file aioisotp-0.1.0.dev0.tar.gz.

File metadata

  • Download URL: aioisotp-0.1.0.dev0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.0

File hashes

Hashes for aioisotp-0.1.0.dev0.tar.gz
Algorithm Hash digest
SHA256 f144ae64e9806571da5b98c19bf2459214c3d4f942c4f257ea6033b9d2fd0f95
MD5 2bf1a6319f8edcd7c5e3d61b9c421c1d
BLAKE2b-256 cc69c2e90357f75c0eedc4b3c99147a761e1decdf9de0e74b9e9151a41bf29d6

See more details on using hashes here.

Provenance

File details

Details for the file aioisotp-0.1.0.dev0-py3-none-any.whl.

File metadata

  • Download URL: aioisotp-0.1.0.dev0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.0

File hashes

Hashes for aioisotp-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 a58e9fb8adbd03b102b46f0429706704ccccf0e711f8fa2c919e781012766933
MD5 c4baeb23c4c127c791d08c2becd12fc6
BLAKE2b-256 79683a0b0b123b67542f8ee418dede83c59a63c98c80f9e2756365f5d3d90727

See more details on using hashes here.

Provenance

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