[CAN-FD] Vehicle Diagnostic Communication Part 91 [python-can 5]

[CAN-FD] Vehicle Diagnostic Communication Part 91 [python-can 5] 車両診断通信
[CAN-FD] Vehicle Diagnostic Communication Part 91 [python-can 5]

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

Introduction.

Explanation of CAN-FD simulation in python-can.
This article is about creating a Python code for CAN-FD.

Review transmitting/receiving by python-can

Transmission and Receiving by python-can.
This is the CAN-FD version of what we did before with CAN.
Therefore, it is better to review the previous articles.

Python code for CAN-FD request

The code itself is almost the same as for CAN.

import can

# Bus connection
bus = can.interface.Bus(bustype='vector', channel='0', bitrate=500000, fd=True)

# transmission data(CANID 0x111、DLC:12、Data:01 02 03 04 05 06 07 08 09)
send_msg = can.Message(arbitration_id=0x111, extended_id=1, bitrate_switch=True, is_fd=True, data=[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09])
print('Send msg : %s' % send_msg)
# transmission
bus.send( send_msg )

# receive 
recv_msg = bus.recv(timeout=1)
print('Recv msg : %s' % recv_msg)

fd=True” at initialization.
In the message construction, “bitrate_switch=True, is_fd=True”.
This makes it CAN-FD.

This part is not related to the can.logger and can.player modifications that were done in the previous version.
Rather, can.logger and can.player are calling this Bus initialization and message construction.
It is only can.logger and can.player that did not support CAN-FD.

Python code for CAN-FD response

The code for response is almost the same as for CAN.

import can

# Bus connection
bus = can.interface.Bus(bustype='vector', channel='0', bitrate=500000, fd=True)

# receive
while True:
	recv_msg = bus.recv(timeout=1)
	if recv_msg != None:
		print('Recv msg : %s' % recv_msg )
		break


# transmission data(CANID 0x222、DLC:6、Data:0A 0B 0C 0D 0E 0F)
send_msg = can.Message(arbitration_id=0x222, extended_id=1, bitrate_switch=True, is_fd=True, data=[0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F])
print('Send msg : %s' % send_msg)

# transmission
bus.send( send_msg )

This one is similar, so there will be no problem.

Conclusion

  • Review of python-can request and response code.
  • Create request and response code as CAN-FD.
    • fd=True when initializing Bus.
    • When creating the message, bitrate_switch=True, is_fd=True.

Click here for back issues.

コメント

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