In your program, you might want to acquire files from the internet for purposes such as update, additional resources, web image gallery… so here’s a modified version of the codes I found on stackoverflow.com that you can just copy and paste into your Java program. Just supply the URL for path and the file name in filename.
In the engineering world, we often gather lots of data that we need to store and display in a spreadsheet format. Microsoft’s Excel is probably the most popular spreadsheet format there are out there. In order to read and write to an excel file from Java, we need the Apache POI library. The POI library actually handle all kinds of Microsoft document format, however, we will only deal with Excel files today.
In this post, I will talk about using Java as a client and Arduino as a server. To keep it simple, we will only use the Arduino’s built-in LED 13. Before proceeding, please read my other post about Arduino to Java Communication through Serial Port if you haven’t already.
In summary, the only differences in the Java’s side is that we will use jSSC’s serial write method instead of serial read as follows:
Arduino is awesome, but it is pretty much useless as a data acquisition (DAQ) device if we can only read the data in the Arduino IDE. I remember back in Freshman year, worked on a wireless board for my Intro to Engineering project. Back then, not knowing anything really from programming, I decided that it would be cool to make a wireless remote game controller like the Wii controller. So I dug right into it, using the manufacturer’s sample program to get the data I need, write it into a text file, import it into a game I wrote with Game Maker… omg, the errors, the lags. The TA tried to help but it was hopeless, lol. Then I did it again with the Space Hopper project, if I only know how to read Joystick data in Java…
Anyway, did a bit of coding today and this is what I got after messing around for couple hours. Most time was spent trying to get Arduino to send the data out correctly. C++ is just… not my thing. Will probably write a Java Class for it to make it even easier to use.
[WARNING: I REALLY HAVE NO IDEA REALLY WHAT I AM DOING AND SOMEHOW THIS WORKS! THIS PAGE IS JUST TO DOCUMENT MY NOTES!]
Normally, if you write an application, to get the console output, you need to either load it in command propmt or write a batch file to have the Jar file launched with the command prompt window. This method might not work at some locations (ie. Comapny Shared Folder).
To solve this problem, we can create out own Output window in Java, and redirect System.out to that window by overriding the methods.
Let’s say I am writing a program to keep track of amount of hours we spent on testing each engine, I need to utimately generate a report. It will be nice if I can sort the Engine based on it’s Serial number. So here’s the easy way to sort an ArrayList.