Skip to main content

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 ISO-TP module is loaded and Python 3.7+ is used, the transport is delegated to the kernel if possible for better timing performance. Use the ‘socketcan’ interface. If unsuccessful, raw CAN will be used as fallback.

The isotpserver from can-utils can also be used to bridge a SocketCAN ISO-TP connection over TCP/IP. Use the ‘isotpserver’ interface and ‘host:port’ as channel.

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.1

Documentation

A basic documentation can be built using Sphinx:

$ python setup.py build_sphinx

Quick start

Here is an example of an echo server implemented using a callback based protocol and a client implemented as sequencial reader and writer streams.

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('vcan0',
                                    interface='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)

Metadata

Release files for aioisotp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioisotp 0.1.1
File Size Uploaded
aioisotp-0.1.1.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aioisotp 0.1.1
File Interpreter ABI Platform
aioisotp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / aioisotp-0.1.1.tar.gz

Download URL aioisotp-0.1.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
27bcffe39835e937e7be2f3374e613399d2c95631b324d292caf1f5a18f829bd
BLAKE2b-256 checksum
How to use checksums
bdcd09dda8536f05cd00e350e8ee217594e29fee57e495769fc4aa0fee13afba
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / aioisotp-0.1.1-py3-none-any.whl

Download URL aioisotp-0.1.1-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f998284978a7a41a5b527fdcf1555fe7996fd98e80b48dbe95c005df1ddf1b4a
BLAKE2b-256 checksum
How to use checksums
ea38946a69888f76627b4e311b1ee3d834306245dad3d52c8916822dab8e5296
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page