[CanTp] Vehicle Diagnostic Communication Part 20 [Simulation 8]

[CanTp] Vehicle Diagnostic Communication Part 20 [Simulation 8] 車両診断通信
[CanTp] Vehicle Diagnostic Communication Part 20 [Simulation 8]

Click here for back issues.
https://www.simulationroom999.com/blog/diagnostic-communication-en-back-issue/

Introduction.

Let’s simulate ISO-TP. series.
This time, we will talk about the Python package can-isotp.

Can we do ISO15765-2 if we work hard with python-can?

Is it correct that we could control CAN with Python, which means that we can realize ISO15765-2, which corresponds to the transport and network layers, by making full use of it?
I am sure we can do it if we try hard enough.

But actually, there is an easier way.

Python can-isotp

There is a Python package equivalent to ISO15765-2 (ISO-TP).
It is called can-isotp.
You can use it!

If so, why did we need to talk about python-can in the previous article?
If there is a package equivalent to ISO-TP, why not just use it?
You would think.

There is a dependency of can-isotp on python-can.
So the installation of python-can itself was necessary anyway.

Then, we could have omitted how to use it, right?

Well, I guess that’s possible, but I’m also proceeding by hand as it stands.
Besides, I’m planning to use python-can after all at the stage of experimenting with can-isotp, so I still don’t think I should omit it.

Installing can-isotp

You may not need an explanation, it is possible to install can-isotp just by using pip.

> pip install can-isotp

*For via proxy.

> pip install --proxy=[proxy name]:[port number] can-isotp

Can-isotp transmission test

Let’s test the transmission once for now.
The script code is as follows.
The file name is isotpsndtest.py.

import isotp
import time

from can.interfaces.vector import VectorBus

bus = VectorBus(channel=0, bitrate=500000)
addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits, source_address=0xF1, target_address=0x10)
stack = isotp.CanStack(bus, address=addr)

stack.send(b'\x01\x02\x03\x04\x05\x06\x07') 

while stack.transmitting():
   stack.process()
   time.sleep(0.0001)

bus.shutdown()

Execute the above script after starting can.logger as well.

Start can.logger

> python -m can.logger -c 0 -i vector -f isotpsnd.asc

Transmission Script Execution

> python isotpsndtest.py

Then check the can line information measured by can.logger.

Begin Triggerblock
 0.000000 Start of measurement
 0.000000 1  18DA10F1x       Rx   d 8 07 01 02 03 04 05 06 07
End TriggerBlock

The message was 7 bytes, so it is a single frame transmission.
It can be said that the message was sent without any problem.
Then, try extending the message length by changing the argument of the send method in the previous script code.

stack.send(b'\x01\x02\x03\x04\x05\x06\x07')

stack.send(b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10') 

Since the message is more than 8 bytes, it should be multiframed.
However, the following error occurs when executing in this state.

> python isotpsndtest.py
Reception of FlowControl timed out. Stopping transmission

Let’s look at the log.

Begin Triggerblock Sat
 0.000000 Start of measurement
 0.000000 1  18DA10F1x       Rx   d 8 10 1E 01 02 03 04 05 06
End TriggerBlock

This is a situation where only FF (FirstFrame) is sent.

Normally, after sending FF, the destination should send FC (Flow Control) once, but there is no corresponding process, resulting in an error.

Next time, I will try to handle this FC better.

Conclusion

  • The Python package can-isotp can communicate ISO15765-2, or ISO-TP.
    • However, python-can must also be installed due to dependencies.
  • For now, SF (SingleFrame) transmission is possible.
  • The multi-frame transmission stopped at FF (FirstFrame) and ended in an error.
    • The protocol specification is that the next sequence cannot proceed unless FC is received after FF.

Click here for back issues.

コメント

タイトルとURLをコピーしました