This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.
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 http://www.teuniz.net/RS-232/. 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.
Note: The following programming example will enable you to create your own graphical user interface. It demonstrates all the basics, such as how to read data from the PC’s USB port, write data, and display data on the screen.
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 combo box 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 115,200 baud into the program but can be modified easily. Of course, this is not necessarily 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 a more professional network monitoring and diagnostics tool, you will need more and different screen elements, and the baud rate settings should be part of that project. So feel free adding more functionality as you see fit.
All screen elements in this project stick with their default settings, however with a few exceptions as shown in the following:
Download the code:
While the actual C# code is fairly simple and thus short, I have chose not to list it here on this web page. You can download the code at ARD1939 - SAE J1939 Protocol Stack for Aduino.
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 a screen shot taken through a session of sending J1939 data:
SAE J1939 has become the accepted industry standard and the vehicle network technology of choice for off-highway machines in applications such as construction, material handling, and forestry machines. J1939 is a higher-layer protocol based on Controller Area Network (CAN). It provides serial data communications between microprocessor systems (also called Electronic Control Units - ECU) in any kind of heavy duty vehicles. The messages exchanged between these units can be data such as vehicle road speed, torque control message from the transmission to the engine, oil temperature, and many more.
A Comprehensible Guide to J1939 is the first work on J1939 besides the SAE J1939 standards collection. It provides profound information on the J1939 message format and network management combined with a high level of readability.