Thursday, February 28, 2008

.Net Remoting for the Compact Framework

As you may have read in the summary of the last meeting, Peter Cosemans came up with the idea to use .NET remoting instead of a homebrewed communications protocol.
Maurice Beelen and I investigated this and we found out that, unfortunately, .NET remoting is not supported in the .NET Compact Framework.
Luckily, we ran into the following company: As Good As It Gets LLC. They created a remoting and serialization framework for Windows CE that is compatible with .NET remoting and they claim it's even faster.
It's not free (A license for one developer costs $199) but it's great! Our Siibot can be controlled remotely now, virtually in no time! See it driving around:

video

This is how I did it:

First of all I downloaded the .NET CF.Remoting.Client, CF.Remoting.Server, CF.Serialization - Installer and the 35 day trial license keys for both CF.Serialization and CF.Remoting from this page
Note that both license keys must be copied to the \Program Files\SiibotApp directory on the eBox later on.

The server side

I created a solution containing a CE 5.0 C# Device Application and a CE 5.0 C# Class Library. The class library contains an interface named IRoomba and a Roomba class implementing it. To make remoting work, the Roomba class has to inherit from System.MarshalByRefObject.


The Roomba class contains some code to initialize serial port COM1 and a little serial IO code to send the actual commands. This was borrowed from the RoombaSCI library for the time being.

Next it was time to initialize remoting in the form class. First of all I referenced the two AsGoodAsItGets assemblies and the class library containing the IRoomba interface. Next I added the appropriate using clauses.

The class has to be registered so it can be instantiated and invoked via remoting over TCP/IP.

Note that we chose WellKnownObjectMode.Singleton mode instead of WellKnownObjectMode.SingleCall since the latter reinstantiates the object with every method call.
For testing purposes remoting was initialized for TCP port 1500. According to IANA List of well known port numbers this port is reserved for the VLSI License Manager, but in our environment this is currently not a major issue. To be able to proceed with the client side, the server side project must be compiled first.

The client side

The client is a simple C# (.NET Full Framework) Windows application containing a couple of buttons to control the Siibot.
Make a reference to the class library assembly from the server project containing the IRoomba interface and the implementation.
The nice thing is that we can use standard .NET remoting now to instantiate the remote object and to invoke methods on it:



Note that we used a fixed IP here. I was able to do that because I configured my wireless router to assign this ip address to the eBox only.
Now that we have a referenced interface we can call methods on it. Behind each button on the form I call the appropriate method.

My conclusion: "As Good As It Gets Remoting" is great! We should definately purchase a license.

3 comments:

Bhavin Patel said...

Very Nice. But I want Server to be Full .NET framework and Client to be my pocket pc. I tried As Good As it Gets but it does not have "Activator.GetObject()". Let me know if you figured it out.

Erik Vermeulen said...

Hi Bavin Patel,

Sorry for the late reaction. I just saw your comment. I'm sure this is possible but in our example client and server are reversed. Please inform if this is possible at at "As Good As It Gets". I'm sure they are willing to help you.

admin said...

You should have been using provided rpgen tool to generate compact framework client-side proxy instead of using Activator.GetObject(). We do provide handful of examples on how that is to be done. Please explore them or contact us to get better detail.

As Good As It Gets, LLC
Developers of the CF.Serialization & CF.Remoting
http://www.gotcf.net| info@gotcf.net