Windows Forms Application and CSV files

In this guide I will show you how to import and visualize a CSV Excel table using "Microsoft Windows Studio Express 2013 for Windows Desktop". The application is very simple and it has been created using Windows Forms Application. Source code can be downloaded here: datalogger_20160623.

datalogger_windows_forms01

I created this application since I had CSV file, which contains the data logged on my motorcycle, and I wanted to import the data and visualize it. If I used Excel, I would have to create a new graph for each signal, and then select the time range. This requires a lot of time, and in case I change the file, I need to start from the beginning. On opposite, this program is very easy to use. You just need to select the file path, click on "Import", select the time range that you want to visualize. All 3 graphs will have the same time range. Then, you can select which data you want to visualize into each graph.

datalogger_windows_forms02

The CSV file contains the following columns (starting from "zero" index):

  1. Engine speed (rpm)
  2. Injection time (us)
  3. Throttle position (%)
  4. Vehicle speed (km/h)
  5. Yaw angle (degrees)
  6. Pitch angle (degrees)
  7. Roll angle (degrees)
  8. iTOW (s), GPS time of week
  9. Latitude (degrees)
  10. Longitude (degrees)
  11. Height (degrees)
  12. Type of data, reserved

datalogger_windows_forms03

When the program runs, the window above is shown. At first, you need to select the file path (example: c:\test.csv) and click on "Import". After that, the screen will look as following.

datalogger_windows_forms04

As visible in the above screen, the CSV file raw data is shown on the left side. When the data is read from the CSV file, it is stored in a "DataTable" variable. After that, it is shown on the left side using a "DataGridView" block. As default settings, the 3 graphs show: Speed, Yaw, Pitch angle. It is possible to change the graph time in real time by clicking on the numeric up/down icons. Also, the graph time range can be modified, in real time, by changing the "iTOW Start" and "iTOW End" time values. The application automatically searches which is the CSV file row corresponding to "iTOW Start" and "iTOW End", and plot the graph using the data in this row range.

For example, suppose that I want to visualize the following Google Fusion Tables info. The iTOW time range is between "iTOW[s]: 434060" and "iTOW[s]: 434306".

datalogger_windows_forms05

By setting the iTOW range in the application, and changing graph type, the following screen is shown. The graphs visualized are: Motorcycle Speed [km/h], Pitch [deg], Engine Speed [rpm]. By having a look at the following graphs, we can conclude that:

  • The speed reduces and I dat to stop, since the traffic light was red. However, I was behind some cars, so I moved through them until being in the front. Then, I moved again for some time and stop at the next traffic light.
  • The pitch signal behaviour follows acceleration and deceleration of the vehicle. When the motorcycle accelerates, pitch angle becomes negative (motorcycle is leaning back). On opposite, when the motorcycle decelerates, the pitch angle becomes positive (motorcycle leaning front).
  • Engine speed and vehicle speed are related by gear ratio. Since engine speed is calculated based on the time difference between two consecutive injections, the signal drops to zero when I close the throttle or I press the brake, due to the fact that the fuel injection stops, therefore rpm cannot be calculated during this period. As you can see below, this behaviour happens at each gear change, or when I press the brake.

datalogger_windows_forms06

Author: Davide Cavaliere

I am an Italian Electrical Engineer graduated at Politecnico di Milano. My interests are motorcycles and cars, electronics, programming, Internet of Things, and Japanese culture.

2 thoughts on “Windows Forms Application and CSV files”

    1. Yes, of course. The contents of this site is open source and available to everyone. You can reblog the contents, but please keep a link to my Blog Monocilindro. Thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *