YOUR FEEDBACK
sahil wrote: How to use onmouseover on marker with c# code, by default when u click on marker...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Making the .NET Micro Framework Work for You
The ultimate flashlight - building a device

In this excerpt, we'll create the ultimate flashlight. With find-in-the-dark flashing behavior and a power-audit mode, this single-button-controlled device will become the ultimate in personal illumination for the twenty-first century.

Figure 1 shows how the flashlight will be constructed. The .NET Micro Framework device will have an input from a push-button switch and will provide an output to a lamp. It will also have a connection to an external device so that it can transfer usage information to the external device in response to a trigger message.

To make the flashlight work, the program inside it must be able to perform a number of tasks:

  • It will need to provide a signal to turn on the lamp.
  • It will need to read the state of the input button.
  • For some of the later applications, it will need some form of a timer.
  • It will need a way of communicating with an external device.
For the purpose of the exercise, we can use the device emulation features of the .NET Micro Framework, so there will be no need to create a physical device, although there is, of course, nothing stopping us from building one if we wish

Driving the Output
The output from the flashlight will be a lamp of some kind that will be controlled by a pin configured as an output on the target hardware. The connection to be used on a genuine device would be chosen when the circuit that controls the lamp is designed.

CREATING AN OUTPUT-PORT OBJECT
Most pins on a device are general purpose in that whether they are input or output is controlled by software. To control a simple device like the lamp on our flashlight, we can use an instance of the OutputPort class, which is provided as part of the .NET Micro Framework. It is an object whose job is to manage an output connection to an external device. The code to create the object is as follows:

OutputPort lampOutput = new OutputPort(lampPin, false);

The new keyword causes the creation of an object. An object is an instance of a class. The constructor (the code in a class that sets up the object) needs to know the physical pin the output is to be connected to. This is analogous to telling a file stream which file to use. In this case, it is a constant identifying the output pin. (We will see how this is done in detail later.) The constructor for the OutputPort also needs the initial state for the output port when it is created. The second parameter provides this information. In the preceding code, the pin will initially be set to low, which is specified by the Boolean value false. In other words, when the flashlight starts up, the lamp is not lit.

INSTANCES AND REFERENCES
It is important to understand that in C#, objects are managed by reference. Figure 2 shows what happens when the OutputPort instance is created. Note that we do not create an object with the identifier lampOutput; instead we create a reference with that identifier, which is made to refer to a particular object.

CONTROLLING OBJECTS
We can call methods on our reference to give the instance commands. For example, to set the port output to high, we could use the following code:

lampOutput.Write(true);

The Write method accepts a single Boolean parameter that can either be true or false. Note: Remember that, because of the way the lamp is physically connected to the circuit, setting the output to high (true) might not cause the lamp to illuminate. A hardware designer may use buffers that will have the effect of inverting the sense of the signal, meaning that to light the lamp you might have to set the output to low.

The OutputPort class also contains a method called Read that returns a Boolean value indicating the state of the port.

if (lampOutput.Read())
Debug.Print("output high");

This code also shows the use of the reference Debug. This refers to an instance of an object that implements the debug output stream. This object contains a Print method that can be passed a string to be displayed on the debug channel, which is normally the output window in Microsoft Visual Studio 2005. Precisely how this works, and where the output appears, is not the concern of the user of the Debug object. The output could be sent to a file, transmitted down a serial port, or displayed on a screen.

OutputPort Lamp
lampOutput

This shows a very useful feature of object-based design: our program can use an object that supports a particular set of methods without knowing the details of precisely what it does.


About Donald Thompson
Donald Thompson is responsible for overseeing the end-to-end design and day-to-day management of the developers, software, protocols, and technology strategy fueling the SPOT initiative. During the Internet boom, he built the centralized ad serving system used by all MSN Web properties, including Hotmail, MSNBC, and MSN.com. Prior to joining Microsoft, he developed an automated loan kiosk and decisioning system for Citibank, a cellular billing and management system for Bell South, and wrote AI and 3D graphics algorithms for commercial game companies. Before committing to a life of software, he was a professional child actor working in movies and television.

About Rob Miles
Rob Miles is a Microsoft Most Valuable Professional. He is a lecturer and Teaching Fellow in the Department of Computer Science at the University of Hull and is presently responsible for delivering the first year programming course and he also lectures on software development and virtual machine architectures. Visit his blog at www.robmiles.com

MICROSOFT .NET LATEST STORIES
Miguel de Icaza, the head of the open source Moonlight project, reassuringly says that “the Silverlight Control Pack under the Microsoft Permissive License really addresses the needs of developers by enabling them to learn how advanced controls are authored directly from the high-qua...
Kevin Lynch, who will be keynoting on October 21, 2008, helped originally coin the term "Rich Internet Application" in 2002. He has been at the center of innovation in Flash and Adobe AIR since their inception, and currently drives Adobe’s technology platform for designers and develo...
The one thing that unifies the distributed computing style known as SOA, in most of its manifestations, is self-describing data via the Extensible Markup Language (XML). The benefits of XML over opaque message formats in data interchange are well established. No matter if your focus is...
Although the .NET Framework simplifies the challenge of developing distributed Web applications, it increases the complexity of deploying, and then managing, those applications. The adoption of Web 2.0 techniques and SOA Web Services only amplify this complexity, making performance ass...
SYS-CON Events announced today that the leading global SOA technology provider Web Age Solutions named "Silver Sponsor" of SYS-CON's upcoming SOA World Conference & Expo 2008 West, which will take place November 19-21, 2008, at the Fairmont Hotel in the heart of Silicon Valley, in San ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Microsoft Corp. today announced the availability of Silverlight 2, one of the industry's most compre...