Additional Information

Site Information

 Loading... Please wait...

CAN Bus Prototyping With Arduino Uno - CAN Bus Network Monitoring under Windows

Posted by Wilfried Voss on

This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.

While programming the Arduino can be exciting (especially since everything works so smoothly), the real fun comes when you can extend the Arduino’s reach to a PC running Windows.

Note: My apologies to all Mac and LINUX users for bringing a Windows programming example, but there is no better programming than using C# under Microsoft’s Visual Studio. I have enjoyed programming under OS-X and LINUX, but when it comes to producing quick and effective programming examples, I prefer to stay with Visual Studio. However, the experienced programmer should be able to replicate the functionality of the serial monitor.

To learn more about serial port programming (RS-232 and USB) under LINUX see I consider this by far the most professional application for serial ports under LINUX. It also suits Windows applications but is primarily meant for compilers inferior to Visual Studio and/or for programming embedded systems.

In the following we assume that you have the Arduino USB driver installed under your Windows machine. The driver is automatically installed with the Arduino development environment.

As I have mentioned in my note, I am using Microsoft’s Visual Studio 2012, and I have designed the following GUI that may look very familiar to the Arduino developer. Basically, this very simple program is a replica of the Arduino serial monitor.

The screen elements are a textbox for data entry, a command button to send the entry to the Arduino, and another larger text box to display the data coming from the Arduino. Last, but not least, there is a combobox displaying all available USB COM ports (It is your task to determine the proper USB port; there is no auto detection).

What the program does not provide is the baud rate settings, which has been hard-coded as 9600 baud into the program but can be modified easily. Of course, this is not the professional way of doing it, but, after all, this programming sample serves as an example on reading/sending messages from/to the Arduino. In regards to the envisioned extended CAN network monitoring and diagnostics tool, you will need more and different screen elements, and the baud rate settings should be part of that project.

All screen elements in this project stick with their default settings, however with a few exceptions as shown in the following:

Note: Instead of showing the full listing here, please feel free to download the C# source code (zip file).

Reference: The handling of the USB port is based on an article by Ryan Alford (with added content by Arjun Walmiki, Gregory Krzywoszyja and Mahesh Chand) at:

At program start, the user first needs to select the applicable USB COM port, which initializes the port (SelectedIndexChanged event).

Beyond that, the program functions as a simple USB terminal: Messages are typed in the top text box and sent by clicking on the Send command button. The larger text box displays the received data.

The following shows screen shots taken through a session with our Arduino CAN Network Monitoring and Diagnostics program:

In this case, we sent two CAN Messages with the same ID (0100) but different data. Next, we received to messages through my standard test configuration (i.e. USB-to-CAN gateway with Windows monitoring tool as the second CAN node).

The previous two screen shots serve as evidence that the messages sent to/from the serial monitor via the Arduino CAN Shield were received/transmitted as expected.

At this point, after having accomplished all the necessary steps, it is easily possible to develop a professional, full-fledged CAN Network Monitoring, Diagnostics, and Simulation Software.

The groundwork has been laid for all necessary hardware and software components:

  1. A USB-to-CAN Gateway to provide CAN connectivity to the host system
  2. A communication protocol between the USB-to-CAN and the host system
  3. A graphical user interface (GUI) for the presentation of the CAN network