Saturday, July 4, 2009
Visual Studio 2005 Express Editions Download
Thursday, June 11, 2009
Put Your C# Program in the System Tray With Icons,MSGs and Windows
Your C# program in the system tray:
note:This post isn't by me, main source here
When creating desktop applications it is sometimes necessary for the application to run in the background, for example firewall, anti-virus and media player software. Instead of permanently taking up space in your taskbar these applications are accessible from the system tray.
This tutorial will show you how to do this in a C# application using Microsoft Visual Studio. I will also show you how to add a right click context menu to the tray icon and how to programmatically change the tray icon.
1) The Notify Icon Control
The control used to make an icon appear in the system tray is a NotifyIcon control. So go ahead and make a new project. Open up the Visual Studio Toolbox and drag a NotifyIcon onto your form. The control will named notifyIcon1 by default and placed below the form because it has no visual representation on the form itself.
Next set the Text property on the NotifyIcon to whatever you want appear when you hover over your icon in the system tray. In this case I just put “System Tray Demo” but usually this would be the name of your application.
Next you need to set the Icon property on the NotifyIcon. You should really make a unique icon for your program to set it apart from the many other applications that often run in the system tray. In this example I’m going to use an email icon (you’ll see why later when we change the icons). So go ahead and choose it.
Note: When I say choose an icon file i don’t just mean any image format. I mean a .ico file. Many image editing applications allow you to save in this format. If you don’t have such an application you can use a website such as www.favicon.cc to generate one.
2) Events
Now time for some coding. In this example our program will minimize to the tray but you can do the same thing for other events such as the window closing etc.
In MS Visual Studio click on your form (in design mode). Then in the properties box click on the small lightning icon (Events) near the top of the properties box. Scroll down to the “Layout” sub-heading and double click on the Resize event. This will generate some code which should look a bit like this.
private void Form1_Resize(object sender, EventArgs e)
{
}
Next add the following code so that when the window is minimized it will be hidden and not shown in the taskbar.
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar = false;
}
}
Now before you get too excited and try and run the program remember we need to be able to show the window again. To do this click on notifyIcon1 (in design mode) then go to its events list (same as above) and double click on the DoubleClick event. Then add the following code so the window will be restored when the system tray icon is double clicked.
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
Now you can try out your program. Run it and make sure it is hidden when you click the minimize button and it can be restored when you double click the system tray icon.
3) Right Click Context Menu
To make it easy to access your application from the system tray the next thing we will add is a right click context menu. To do this go to the Visual Studio Toolbox and drag a ContextMenuStrip control onto your form. It will be placed below the form again as it has no visual representation on the form itself.
Right click on the contextMenuStrip1 and click “Edit Items…”. Add two Menu Items and change their Text properties to “Show” and “Exit”. Obviously in your own application you can add whatever you want here.
When you click on contextMenuStrip1 (in design mode) you should see the menu appear on your form. Don’t worry it won’t actually be there when you run your application. As before double click on the items to create an event for them. For the Show item we just need to copy the code from the notifyIcon1_DoubleClick method we made above. You should have something like this.
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
For the Exit item all we need to do is call the Close() method.
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
this.Close();
}
The last step is to set the NotifyIcon control’s ContextMenuStrip property to our new context menu. Do this the same way you set other properties. The name of our context menu should appear in the dropdown box.
Run your application and you should get something like this when you right click on the system tray icon.
4) Changing the Icon
In some applications the system tray icon might change to reflect the status of the application. For example the AVG Antivirus icon changes when your virus database is out of date. In this example imagine we have an email checking application. We have already set the normal icon, but what if we have new mail? We might want a different icon to show that we have new mail.
To do this right click on your Project in the Visual Studio Solution Explorer. Then go to “Add -> Existing Item…”. Add any icons you want to add. In this example I am adding three icons: normalIcon.ico, workingIcon.ico and newmailIcon.ico. You should see your icons in the solution explorer.
Next you must set the Build Action properties of all your icons to Embedded Resource. If you don’t do this it won’t work. Setting properties is just like above.
Now changing your icons is actually quite easy. All you have to do is programmatically set your icons. For example.
public void checkMail()
{
//Set a working icon
this.notifyIcon1.Icon = new Icon(GetType(), "workingIcon.ico");
//... do some checking here...
//if you have new mail
this.notifyIcon1.Icon = new Icon(GetType(), "newmailIcon.ico");
//else reset the icon
this.notifyIcon1.Icon = new Icon(GetType(), "normalIcon.ico");
}
It should look something like this when it’s working.
Conclusion
In this tutorial we have looked at putting your C# program in the system tray, adding a context menu to the tray icon and programmatically changing the tray icon. Any comments and suggestions you have are always appreciated.
Monday, June 1, 2009
Sunday, May 31, 2009
Free Partitioning Tool Disk
Moving towards legal use of software will need some work to get alternatives.So here is a disk partitioning tool alternative.
If you know Partation magic, Acronis disk management tool or even disk Mangement utility in windows Xp and used them befor, Here is an open source alternative.
http://gparted.sourceforge.net/
Monday, May 25, 2009
What's a transducer ?
is an electronic device that converts energy from one form to another.
Common examples include microphones, loudspeakers, thermometers, position and pressure sensors, and antenna.
Although not generally thought of as transducers, photocells, LEDs (light-emitting diodes), and even common light bulbs are transducers.
Definition from WhatIS.com
http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci213215,00.html
A transducer is a device, usually electrical, electronic, electro-mechanical, electromagnetic, photonic, or photovoltaic that converts one type of energy or physical attribute to another for various purposes including measurement or information transfer (for example, pressure sensors).
The term transducer is commonly used in two senses; the sensor, used to detect a parameter in one form and report it in another (usually an electrical or digital signal), and an actuator may be described as opposite to a sensor-it converts electrical signal into generally nonelectrical energy. An example of a transducer is a loudspeaker which converts an electrical signal into a variable magnetic field and, subsequently, into acoustic waves.
WikiPedia.org
Tuesday, April 28, 2009
Transistor Design
The following is a rundown of how to design simple NPN transistor circuits.
Basically, a transistor sets the Collector current (Ic) to be equal to the Base current (Ib) multiplied by the transistor's Gain "Hfe" (typically around 100). [IC = Ib*Hfe]
This lets you turn a large device (such as a motor or a Laser) from a small signal (such as from a microcontroller or a sensor). However, the transistor also requires a voltage Vbe between its Base and Emitter (typically around 0.7V). Here is an example circuit:

1st step is to determine how much current & power your load will take. If the load is a Laser or a Relay, then it should only be about 100mA at 5 or 12V, which is upto 1.2Watts (Power = Volts * Current).
2nd step is to determine the maximum Base current (Ib) you will have. If the Base resistor (Rb) is connected to a microcontroller, then this is generally a maximum of 20mA (enough to power a simple LED but not much more).
From these 2 steps you should find a transistor that has Max Collector Current (Ic) and Max Power Dissipation (Pd) ratings that are atleast twice your requirements (for safety), and has a DC Gain (Hfe) large enough to convert your Ib into your Ic. To amplify small signals or to turn on a small Relay / Motor / Laser under 100mA using a microcontroller, use a small transistor (eg: BC548) in the TO-92 package, but for any larger currents or power you will need a larger transistor (eg: TO-220 package), possibly with a metal heatsink.
3rd step is to determine the Base resistor value (Rb) to give the correct voltage Vbe (typically around 0.7V) for the transistor, based on what you are connecting it to. Use Ohm's Law (V=I*R) to work out the resistor that would give you the desired current (Ib) between the resistor's voltages (Vin and Vbe). Ideally, Ic = Hfe * Ib = Hfe * (Vin - Vbe) / Rb. However, transistors aren't perfectly linear amplifiers, so you wont get quite this much current output.
When you are trying to either switch something to be completely ON or completely OFF (which is a good idea for Relays, Lasers and Motor PWM), then you want to use the transistor at its "Saturation" limits, which means making Ib about twice as much as you originally calculated, so that it is definitely ON or OFF. In these cases, you can think of the transistor as a switch, that is open (not letting any current through, therefore Vce = Vcc) when Ib = 0, and closed (letting all the current through, therefore Vce = 0 or 'short circuit') when Ib = max. Just be aware that even when you have saturated the transistor on (Ib is max), Vce wont actually reach 0volts, but will usually be between 0.2 - 0.7V depending on the transistor.
Transistor Leads:

source:http://www.itee.uq.edu.au/~emami/metr2800/
Saturday, April 4, 2009
Memory Types in Embedded Systems
Embedded Systems Memory Types
By Michael Barr
SRAM or DRAM? EEPROM or flash? What types of memory will you use in your next embedded systems design?
Many types of memory devices are available for use in modern computer systems. As an embedded software engineer, you must be aware of the differences between them and understand how to use each type effectively.
In our discussion, we will approach these devices from the software developer's perspective. Keep in mind that the development of these devices took several decades and that their underlying hardware differs significantly.
The names of the memory types frequently reflect the historical nature of the development process and are often more confusing than insightful. Figure 1 classifies the memory devices we'll discuss as RAM, ROM, or a hybrid of the two.

Figure 1. Common memory types in embedded systems
Types of RAM
Static RAM (SRAM) and dynamic RAM (DRAM).
The primary difference between them is the lifetime of the data they store.
SRAM retains its contents as long as electrical power is applied to the chip. If the power is turned off or lost temporarily, its contents will be lost forever.
DRAM, on the other hand, has an extremely short data lifetime-typically about four milliseconds. This is true even when power is applied constantly.
Simple piece of hardware called a DRAM controller can be used to make DRAM behave more like SRAM. The job of the DRAM controller is to periodically refresh the data stored in the DRAM. By refreshing the data before it expires, the contents of memory can be kept alive for as long as they are needed. So DRAM is as useful as SRAM after all.
When deciding which type of RAM to use, a system designer must consider access time and cost.
SRAM devices offer extremely fast access times (approximately four times faster than DRAM) but are much more expensive to produce. Generally, SRAM is used only where access speed is extremely important.
A lower cost-per-byte makes DRAM attractive whenever large amounts of RAM are required. Many embedded systems include both types: a small block of SRAM (a few kilobytes) along a critical data path and a much larger block of DRAM (perhaps even Megabytes) for everything else.
Types of ROM
Memories in the ROM family are distinguished by the methods used to write new data to them (usually called programming), and the number of times they can be rewritten.
This classification reflects the evolution of ROM devices from hardwired to programmable to erasable-and-programmable. A common feature of all these devices is their ability to retain data and programs forever, even during a power failure.
The very first ROMs were hardwired devices that contained a preprogrammed set of data or instructions. The contents of the ROM had to be specified before chip production, so the actual data could be used to arrange the transistors inside the chip. Hardwired memories are still used, though they are now called "masked ROMs" to distinguish them from other types of ROM. The primary advantage of a masked ROM is its low production cost. Unfortunately, the cost is low only when large quantities of the same ROM are required.
One step up from the masked ROM is the PROM (programmable ROM), which is purchased in an unprogrammed state. If you were to look at the contents of an unprogrammed PROM, you would see that the data is made up entirely of 1's. The process of writing your data to the PROM involves a special piece of equipment called a device programmer. The device programmer writes data to the device one word at a time by applying an electrical charge to the input pins of the chip. Once a PROM has been programmed in this way, its contents can never be changed. If the code or data stored in the PROM must be changed, the current device must be discarded. As a result, PROMs are also known as one-time programmable (OTP) devices.
An EPROM [UV-EPROM] (erasable-and-programmable ROM) is programmed in exactly the same manner as a PROM. However, EPROMs can be erased and reprogrammed repeatedly. To erase an EPROM, you simply expose the device to a strong source of ultraviolet light. (A window in the top of the device allows the light to reach the silicon.) By doing this, you essentially reset the entire chip to its initial--unprogrammed--state. Though more expensive than PROMs, their ability to be reprogrammed makes EPROMs an essential part of the software development and testing process.
Hybrids
Hybrid memories can be read and written as desired, like RAM, but maintain their contents without electrical power, just like ROM. Two of the hybrid devices, EEPROM and flash, are descendants of ROM devices. These are typically used to store code. The third hybrid, NVRAM, is a modified version of SRAM. NVRAM usually holds persistent data.
EEPROMs are electrically-erasable-and-programmable. Internally, they are similar to EPROMs, but the erase operation is accomplished electrically, rather than by exposure to ultraviolet light. Any byte within an EEPROM may be erased and rewritten. Once written, the new data will remain in the device forever--or at least until it is electrically erased. The primary tradeoff for this improved functionality is higher cost, though write cycles are also significantly longer than writes to a RAM. So you wouldn't want to use an EEPROM for your main system memory.
Flash memory combines the best features of the memory devices described thus far. Flash memory devices are high density, low cost, nonvolatile, fast (to read, but not to write), and electrically reprogrammable. These advantages are overwhelming and, as a direct result, the use of flash memory has increased dramatically in embedded systems. From a software viewpoint, flash and EEPROM technologies are very similar. The major difference is that flash devices can only be erased one sector at a time, not byte-by-byte. Typical sector sizes are in the range 256 bytes to 16KB. Despite this disadvantage, flash is much more popular than EEPROM and is rapidly displacing many of the ROM devices as well.
The third member of the hybrid memory class is NVRAM (non-volatile RAM). Nonvolatility is also a characteristic of the ROM and hybrid memories discussed previously. However, an NVRAM is physically very different from those devices. An NVRAM is usually just an SRAM with a battery backup. When the power is turned on, the NVRAM operates just like any other SRAM. When the power is turned off, the NVRAM draws just enough power from the battery to retain its data.
NVRAM is fairly common in embedded systems. However, it is expensive--even more expensive than SRAM, because of the battery--so its applications are typically limited to the storage of a few hundred bytes of system-critical information that can't be stored in any better way.
Table 1 summarizes the features of each type of memory discussed here, but keep in mind that different memory types serve different purposes. Each memory type has its strengths and weaknesses. Side-by-side comparisons are not always effective.
| Type | Volatile? | Writeable? | Erase Size | Max Erase Cycles | Cost (per Byte) | Speed |
| SRAM | Yes | Yes | Byte | Unlimited | Expensive | Fast |
| DRAM | Yes | Yes | Byte | Unlimited | Moderate | Moderate |
| Masked ROM | No | No | n/a | n/a | Inexpensive | Fast |
| PROM | No | Once, with a device programmer | n/a | n/a | Moderate | Fast |
| EPROM | No | Yes, with a device programmer | Entire Chip | Limited (consult datasheet) | Moderate | Fast |
| EEPROM | No | Yes | Byte | Limited (consult datasheet) | Expensive | Fast to read, slow to erase/write |
| Flash | No | Yes | Sector | Limited (consult datasheet) | Moderate | Fast to read, slow to erase/write |
| NVRAM | No | Yes | Byte | Unlimited | Expensive (SRAM + battery) | Fast |
Table 1. Characteristics of the various memory types
This article was published in the May 2001 issue of Embedded Systems Programming.