Friday, June 22, 2007

Running a J2ME application on Windows Mobile 5.0 devices

It is a real pain for Windows Mobile users to get a simple J2ME program to run on their mobile devices. I owned a Dopod 818 pro which is running WM5, and now I have to get my J2ME application to run on it.

Dopod actually bundled an application named MIDLet manager to run J2ME program. But after using it for a while, I experienced some weird behaviors such as automatic closing of the running program. So I think I should find other JVM for my phone.

After some googlings, I found that IBM J9 is one of the good choices. I download the installation package and follow instructions in install.pdf. There is also a good guide, which covers the installation for other platforms, at Markus blog too.



I first faced with the weird Exception from emulator.exe which says it cannot download the jad files.

An exception occurred
[//J9/IBM/examples/golfscoretrackersuite.jad] while downloading from file://J9/IBM/examples/golfscoretrackersuite.jad


Then, I found out that I mistyped the URL. It has to be “file:///{path}” instead of “file://{path}” (Note that there are THREE SLASHES) :P

I can now get the example ran.

Thursday, June 7, 2007

ChemL1ve! quite a hard time …

My team and I had just finished our Imagine Cup 2007 local round project, ChemL1ve!, and had given presentation on yesterday at TK Park, Central World Plaza. We won the third prize. I am really happy since I thought our team would not be in the top three of six teams from various Universities.

We had to give the presentation in very limited time of 15 minutes and we could not finish it in time. It was a really bad feeling. Try to think of yourself spent days coding a program and had only five minutes to show it off. It is hard to admit but this is normal situation. Good developers should learn some presentation skills too.

The winner was a team from CPE, Kasetsart University. Their project is an application that helps people who cannot read to be able to understand a book. By let the web camera point to the contents of the book. The application quickly recognizes the word on the page and displays the image and details of that word on the screen in a stylish way using WPF. User can also browse to the word he/she interested in by pronouncing that word to the microphone. The demo was really great and I can tell that this is the obvious winner of this year, right after I attend their presentation.

Our project is multi-user virtual chemistry lab software. At the stage of proposal submission, without any research, I thought it would not be so hard to develop such kind of system. But after that, when I tried to model it, I realize this was too big for a team with two inexperienced developers! More importantly, to correctly and effectively model this kind of system, you need a solid understanding of Chemistry which I actually got a “C” in my first Intania year T-T

Since this is a tech blog, I may go into the details of implementation. Here is my “ugly” class diagram at one stage of the development. Please note that it is “ugly” in term of OO design (Visual Studio 2005 generates this polish diagram quite well). It is “ugly” because it cannot support many of the system behaviors.

With this diagram, number of kind of lab equipment is fixed because I use a class to represent equipment. I am wondering if I could dynamically create new equipment at runtime. Those reflection stuffs might be able to do this sort of thing.

That is all my part. Another part is a client that my friend develops using the WPF as presentation layer. The client sends the interaction between lab equipment and get result from Web Service which wraps my part. This diagram below may help visualize architecture of our project (I designed this diagram using Expression Design, it is suitable for creating this kind of image than Adobe Photoshop).

Here are some screenshots of the client, ChemL1ve! Action.

For those who want to join next year’s Imagine Cup s/w design competition, I suggest that you should focus more on your ideas than the implementation details and make sure that your application can really solve the problem addressed. And keep in mind that this is “ideas” and “software design” competition. Do not mess with the coding too much. Just make sure that the app will not throw any uncatched exceptions during the demonstration : )

Friday, May 11, 2007

Programming MSMQ (Microsoft Message Queue) - Sample code

Yesterday, I went to "MSDN Connection Training Sneak Peak Preview" seminar at Microsoft Thailand. The topic is "Distributed Application Development with Visual Studio 2005". It is actually a shortened version of Iverson training course : if you want to take a full course, you will have to pay at least ten thousand baht for 3 days training o__O!

I really learned many things from this session. One of them is MSMQ or Microsoft Message Queue.

Message queuing is a communication tool that allows applications to reliably interconnect in a distributed environment where one of the applications may or may not be available at any given time. The queue acts as a holding container for messages as they are sent between applications. The applications send messages to and read messages from queues to communicate back and forth. An application writes a message to a queue, which will then be received and processed by another application at some point determined by the receiving application. This type of communication is designed for asynchronous use where the applications involved are not waiting for an immediate response from the other end. - http://www.codeguru.com/Csharp/.NET/net_general/netframeworkclasses/article.php/c4241/


This really fits into my project's need for a queue which can serve clients over the internet.

To program the MSMQ you need to install Messaging Queuing first. Insert your Windows Setup CD and choose "Install optional Windows components". Then, tick the checkbox in front of "Message Queuing" and go on.



Now, create a new Visual C# Console project. Add reference to System.Messaging and add the following code.




using System;
using System.Collections.Generic;
using System.Text;
using System.Messaging;
using System.Threading;

namespace MSMQSample
{
class Program
{
static void Main(string[] args)
{
// Check if queue alreasy exists.
string queuePath = @".\private$\SampleQueue";
MessageQueue queue;
if (!MessageQueue.Exists(queuePath))
// If not, create one.
queue = MessageQueue.Create(queuePath);
else
queue = new MessageQueue(queuePath);

// Send something to queue.
DateTime dt = DateTime.Now;
Console.WriteLine("Message to send: " + dt.ToString());
Message sendMsg = new Message(dt, new XmlMessageFormatter());
queue.Send(sendMsg, "My DateTime");

// Wait for five seconds.
Thread.Sleep(5000);

// Get sent message from queue.
Message receiveMsg = queue.Receive();
receiveMsg.Formatter = new XmlMessageFormatter(
new Type[] { typeof(DateTime) });
DateTime ret = (DateTime)receiveMsg.Body;

Console.WriteLine("Message Received: " + ret);
Console.Read();


}
}
}


And this is what our message looks like. You can open this window in Computer Managment/Services and Applications/Message Queuing/samplequeue



Here are some great resources on the basics of MSMQ:
And for those who want to attend next MSDN Connection Training Sneak Peak Preview you have to register for an account at http://www.msdnconnection.com/thailand and monitor this page [MSDN Connection Training Sneak Peak Preview]