Compare CAN database with Python

Hi All. I have a very boring task, and that is to compare two automotive CAN (Controller Area Network) database (DBC) files. This is a very boring task, but what makes this task a nightmare is that database files are automatically generated. This means that the message definition inside the file can just change the order in the file. This is no logical or functional change, but there is a problem. I’m getting a lot of false findings in both files in every place that some message changed place. And this is very annoying, especially if your database DBC file is more than 1000 lines of code, like mine. So I decided to create my own Python program with GUI that will do exactly that. Compare CAN Database files logically, message by message, signal by signal. I named this program CAN DBC Compare Tool.

Try CAN DBC Compare tool with Gumroad

So, let me present to you the CAN DBC Compare tool written by me in Python.

And if you are searching for a good place to start selling your digital product, maybe check out Gumroad. Simply

Gumroad is a powerful, but simple, e-commerce platform. We make it easy to earn your first dollar online by selling digital products, memberships and more.

from Gumroad site

First look at GUI

CAN DBC Compare tool has a very basic, simple GUI, and it is shown in the image below.

Let us break it down. There is a split in the middle of the screen to accommodate two CAN DBC files, one on the left and one on the right.

And for each CAN DBC file, there are 3 windows for

  • Text CAN DBC view – Simple raw text view of the selected CAN DBC file
  • Message (Frame) CAN View – Parsed view of all messages (Frames) from the selected CAN DBC file above.
  • Signal selected Message View – List of all signals that are defined in the selected message in Message (Frame) CAN View

Short demo

As we saw in the section above, GUI is pretty simple. Functionality is also basic, so let us go over it. For this demo, I will compare CAN Database files using the DBC Volvo example file for https://github.com/commaai/opendbc. I created a copy of the DBC file and added some changes to both files, so the files that are used in this dome are:

If you like to follow and do the same steps as me for this demo please download and change the extension from .txt to .dbc for the volvo_ver1 and volvo_ver2 files.

Next download the CAN DBC Compare Tool from the next link https://blnlabs.gumroad.com/l/CAN_DBC_Compare_tool. This is the link to my Gumroad store. Download the .exe file and just double-click on it to start the Program.

The next order of business is to select the file that will be shown on the left side. That can be done by selecting File->Load file to the Left, and then choosing the desired file. For this example, I will choose volvo_ver1.dbc file (shown in the image above). Do the same thing for the Right side as well, but now chose volvo_ver2.dbc file.

The current GUI is shown in the image below.

We are now able to select one message from the list on the left/right side and check out defined signals inside. But this is just a simple CAN message overview. Then select File->Compare.

The program will go over each message and try to find it in another file. Compare will not stop at the message level, but the CAN DBC Compare tool can detect the change in Signal level too. Then it can highlight the Message and signal with yellow if there is some change. Messagess hightlight in red doesn’t exist in other CAN database version.

And that is pretty much all, for now.

Final words

And I think that is a good basis to state. A simple but useful program that will compare CAN DBC files. Compare is not simply done on the text basic level, but on the logical level, messages and signals. This can speed up your work especially if you are working with automatically generated CAN DBC files. There, messages can change the place and order where are they defined inside the DBC files. The program will know that this is no logical difference between the two versions of the dbc file, but regular text diff would have shown this as a difference. And it was a great opportunity to play around with Python GUI. And, of course, to figure out how to host some digital products at Gumroad. That is all, for now, please comment below and check out my other post at: https://blnlabs.com/how-to-add-usb-type-c-to-esp32-development-board/.

Leave a Comment