Wednesday, December 30, 2009

A lady who travelled faster than light....

I recently read and much inspired by this old poem:

Once there lived a lady
She could travel faster than light
She left out of home today
And returned back yesterday!
Sometimes the real things are stranger and mysterious.....

Tuesday, December 29, 2009

Gui front end for parallel port controller in Linux

A graphical front end for the parallel port controller in Linux was my dream and I just satisfied it in my Xmas vacation. I used Qt framework from Nokia. I just put here everything I did. Of course you are allowed to download and use it under GPL (GNU General Public License). You are appreciated to modify source code according to your needs.
Now the program supports only on Linux platforms even though qt frame work is independent of platform. The reason is that, parallel port controlling is directly depend upon the OS you are used. You can easily control your parallel port in MS DOS environment, but things become worse when you try in Windows XP. Since the program calls the ioperm() function, you should have root privileges. Otherwise an abrupt exiting of the program occur. You only need to do the following things:
  • Be root, and start the program by ./parport2. Try to open it from terminal at least for the first time in order to track bugs.
  • Click 'Initialize' to call ioperm(). If you are not root, then the program abruptly exits while you click it.
  • Nothing will be happened at outside while you click in 'Initialize'.
  • You can use 8 switches to turn on or off the output data ports.
  • The current output value in decimal is displayed on lineEdit.
Most probably the executable version will not work in your system unless your system configuration matches with mine. So it is recommended to compile entire program using qt. You need to have qmake installed in your system (qt-dev-tools). The compiling instructions for qt program is beyond the scope of this post.

Download parport.tar.gz (1.4MB)

I tested it in my PC and worked without any problem.
Warning: Take care while you play with parallel port. Very rarely, the after effect may fatal.
Note:- This program is intended for educational purposes only. May not be updated until anyone report a bug or a request to modify.

Saturday, December 26, 2009

PHET science simulations for students

PhET interactive simulations - Fun, interactive, research-based simulations of physical phenomena from the PhET project at the University of Colorado.

I found those simulations were good in today's eduction- thanks for university of Colorado. Most of them are intended for Upper and High school students and pre- graduate students. However, if you just spend your time in experimenting with it, I am sure you get something new. Phet interactive simulations create a virtual lab environment. It's just a feeling that to enter into a physics or chemistry lab in a college. You can do anything in your own lab. Nothing to fear. No more comments from teachers...
One more advantage is that, you only need a java powered web browser. You can browse through different lab environments. If you like PhET virtual lab, you can download it for offline usage. Linux(80MB), Windows(97MB) and Mac OS(85MB) installation supported.

Browse phet simulations
Download phet for offline usage.

Wednesday, December 23, 2009

Parallel port programming using C/C++

Parallel port programming is easy with C or C++. Even other languages integrate C/C++ codes to their codes in order to program parallel ports. If you are a beginner in parallel port programming and know nothing about it, just go through this intro page. Nevertheless the efficiency of code, the code may be different for different platforms and need to be compiled with some change in the code.Here we see how to program parallel port(printer port or LPT) in both GNU/Linux and MS Windows platform.
Parallel port programming in GNU/Linux
I am not intended to make a wide description. I am directly give an example and this is what you want. If you are experienced the taste of C, you can easily catch what the program code mean.(We use LEDs to check whether our program run. You can see a simple circuit in the intro page). Connect the circuit described in intro page. to the parallel port properly. Then make new file parport.c and edit the file as shown:

#include stdio.h
#include stdlib.h
#include asm/io.h
#include unistd.h

#define base 0x378 /* printer port base address */
#define value 255 /* numeric value to send to printer port */

main(int argc, char **argv)
{
if (ioperm(base,1,1))
fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

outb(value, base);
}



The above program is copied from epanorama. You should compile the program as su (super user) since ioperm() function needs root access. But in my system the above program didn't work. Many of my friends got error while compiling. The solution is to change the 4th line
#include asm/io.h
to
#include sys/io.h

You change the line and recompile only if you get a linking error. Sometimes you get an error like "Couldn't get the port at 378". But this is not a problem due to the port address. You probably may not be su.

Parallel port programming in MS windows
Converse the subtitle suggests, this program is not working in the windows environment, but in the MS DOS environment. I think you have basic knowledge of how to compile a C program.

#include stdio.h
#include conio.h
#include dos.h

/********************************************/
/*This program set the parallel port outputs*/
/********************************************/

void main (void)
{
clrscr(); /* clear screen */
outportb(0x378,0xff); /* output the data to parallel port */
getch(); /* wait for keypress before exiting */
}


The above program is also from epanorama. If you try to compare those programs, you can see a very little difference between those codes. Parallel port is a hardware and surely it is depended upon the OS you are using. So you can't write a cross-platform code for the parallel/printer port control. Please note that you can read inputs as well as write as output however, the example only shows the output control. Sometimes your port address may be different, however in most cases it will be 0x378. If it fails try 0x278 and 0x3BC. Read more here.
You can check your program by simply inserting an LED connected in serial with 1K ohm resistor.

Read my post on parallel port control on python

How do we think? A brief introduction

Thinking about how we think is difficult, because thoughts of thoughts are limited by thoughts itself. But learning of how we think is essential in computing as well as AI powered robots. The basic reason of our thinking ability is a special type of cells in brain - neurons. A neuron is not perfectly known to human yet, but many similar models are proposed. The power of neurons is in its networking ability. Neurons are connected to each other and these complex networks may called as neural networks. I am not describing much about neurons because it is beyond our task. It's well enough if you just get an overview from Wikipedia. As I said, many convenient models are there to explain the behaviour of a neuron (Of course, a networked neuron is complex than a single one), but I am just touching simplest one named Perceptron. I will also mention back propagation during the example. I have pasted one figure from Wikipedia because you need it.The area in the shaded square can be considered as a neuron. x1,x2,......x7 are the inputs and w1,w2.......w7 are the corresponding weights (I will tell you what it is). and f is simply a function and outputs y. If the weighted sum of the inputs exceeds a particular threshold (which is previously be set), output y fires out. In actual neurons, y depends on other parameters such as input frequency. Since whole process in actual neurons are chemical, the explanation become rather complicated. But in all models we consider input as well as output signals are electrical in nature.I am explaining once again: first find
x1*w1+x2*w2+.........+x7*w7
If the resultant value is greater than a threshold (Typically 0), y=1; otherwise y=0.
I hope you understand something. But I know most of you are not satisfied because, you don't know what is really going on! Right?
Let me tell an example. This is a story. Here is you, Heroin is you.
Consider you have three friends and you(your brain) thinks that they are:
  • Albert - Your best friend. You have a confidence level of 0.7 on him. You trust him and ask his opinion before every important attempt
  • Deepika - Your classmate. Confidence level 0.3. Good personality.
  • Tom(me) - Confidence level of -0.55. Always say lie. Cheating personality.
These prejudice are taken by your brain from your experience. May be true or may not be.
The problem starts here. You are getting ready to go to your office/college. There are two ways to go. One is short path (easy way). Other is long. But short way has a problem is that sometimes it will be blocked. If you take the long path, you may reach the destination late. But if you choose the short path and in any case if blocked, you can't reach the destination on that day.
Then you come to know that today short way will be blocked. Then you consult your friends. Check their opinion:
  • Albert - Short road is not blocked. Damn sure.
  • Deepika - Someone told me about it. Short way may not be blocked. But I am not sure.
  • Tom - Hey man, road is blocked.
Can I go straight away through the short path?
Let's look how your brain solve the problem. Albert surely says that road is not blocked. Put a value of +0.95 for his opinion. The positive sign indicates that he is opposing. If Albert says sure that road blocked, the value may be -0.95. You don't know much about Deepika. But she may be right. Put a value of +0.1. Tom says it is blocked. So put -0.8.
Here threshold value is 0. If weighted sum is greater than 0. road is blocked. It is good to choose the long way. I not, road is not blocked, choose the short path.

Weighted sum is:
signal strength of Albert * confidence level+ signal strength of Deepika * confidence level+ signal strength of Tom * confidence level
=0.95*0.7 + 0.1*o.3 + (-0.8)*(-0.55)
=0.66+0.03+0.44
=1.13 which is greater than 0.

The brain successfully derived a decision for you. It is almost sure that road blocked with a confidence level of 1.13. Did you notice the analysis of Mr.Tom's opinion. You think tom is cheat. So the opposite of what he tells will be right. If you didn't understand the meaning of previous sentence just read one more time because some interesting things hidden in that sentence.

Ok, let's continue our story. Then you started going straight away through short path. You started journey in your own car but Alas! road is blocked. You couldn't just believe your eyes. but suddenly you realize the fact that you can't reach your destination today - you trapped in a huge road block.
Here, your brain attempts to rewire the entire circuitry inside it. Your thoughts were entirely wrong. Both Albert and Deepika was wrong, but Tom was right. You change the congedence level as,
  • Albert - 0.4 - I can't blive he cheated me.
  • Deepika - 0.1 - no coments.
  • Tom - 0.2 - oh, sorry Tom.
The actual working principle of neural networks is far deviated from the above story, but the fundamental thing in both is same. Actual neurons has a lot of diifernces and complexities than the neuron models

Tuesday, December 8, 2009

Go on with pyS60

I got a very good feedback from my previous post: "How to simulate PyS60 in your PC". As the request of opentechlab readers, I am attempting to write a brief beginner level tutorial on pyS60 emulator.

Once you are successful in installing and setting up the environment (If you didn't set up yet, click here), it is the time to go on.

Start the emulator program from:

Start->All programs -> S60 Developer tools -> 3rd edition FP2 SDK -> v1.1 -> Emulator

You probably need to wait for a couple of seconds to load it if your system is slow. Then a medium sized window with a full fledged mobile phone appears on the screen.

Now you need to open python. Just do as in your mobile phone. it's in Menu -> Installations -> python.

Now it's ready and do what you want.

Hacking python script

Select options -> Run script ->ball.py

You can move the ball anwhere in the screen. It's a physics simulation example in python. You can see the actual python script by opening ball.py file using any editor (notepad is not recommended. programmers notepad is good). The file is stored in :

C:\S60\devices\S60_3rd_FP2_SDK_v1.1\epoc32\winscw\c\python

Search for the word 'blobsize'. Then you can find a line like:

blobsize = 16

Change the value of blobsize into 25 and save it. Then open ball.py in emulator. Did you notice any change? Similarly you can change acceleration, gravity (what about changing gravity into -0.01 ?) etc.

Developing your own programs

I am just starting with a hello world. Here is the program.

1)Simple hello world

print "Hello World!"

2)Say, hello world

from audio import*

say("Hello World!")

3)graphical hello world!

import appuifw
appuifw.note(u"Hello World!", "info")

It is good practice to make a short cut of python on the mobile desktop by changing options in settings.

Monday, December 7, 2009

How to simulate PyS60 in your PC

You can do your experiments in PyS60 without touching your mobile phone. The experimentation is easy while you set up everything in your PC. Here I am explaining how to set up the PyS60 environment in WinXP platform. I didn't try this attempt on my Linux yet. I will surely post about it if I get some good mobile stuff on Linux. This will be a boon for python developers in Nokia S60 mobile phones. But rarely it can be seen that some python scripts works neatly on simulator may cause strange responses on your real world system. I would like to here about it if you get any funny experience on your S60 device.
Download the required things:

1)Download S60_3rd_Edition_SDK_Feature_Pack_2_v1_1_en.zipfrom the following link:
http://www.forum.nokia.com/info/sw.nokia.com/id/807ec36d-0a8e-4bda-8e10-4d5e5bb4764a/S60_3rd_Edition_SDK_Feature_Pack_2_v1_1_en.zip.html


2)You can find ActivePerl 5.6.1 build 635 here:
http://downloads.activestate.com/Act...SWin32-x86.msi

3)Download PythonForS60 _1_4_5_SDK_3rdEdFP1.zip from http://sourceforge.net/projects/pys60/files/

First install ActivePerl because S60 SDK requires it.
Then install S60 SDK. Please note to install it in C:\ drive to avoid confusion.
Extract PythonForS60_1_4_5_SDK_3rdEdFP1.zip. Then you get another archived file sdk_files.zip.
Extract it again and you get a directory named 'epoc32'.
Copy this directory into "C:\S60\devices\S60_3rd_FP2_SDK_v1.1"
Then probably Windows XP asks to replace the already existing folder 'epoc32'. Click yes.
You have done. Cheers!

Sunday, December 6, 2009

Don't believe your eyes!


Don't believe your eyes, because everything you see, touch and feel is just a feeling only. Consider you are traveling in a space ship. No way to look outside. Space ship is traveling with higher velocity. If there is an obstacle present in front of the spaceship, sensors feel the presence of obstacle and it is reported on your computer. Then you turn the spaceship left or right. Then sensors feels that obstacle is removed (not obstacle, you!) and computer indicates that you can go straight way.
The above explained is a successful turning. But here I go in a something different way. The sensors are intelligent enough to send a fake signal that "there is some sort of obstacle" on the monitor. Actually, there is nothing in front of it. But your computer shows some obstacle. So you put a signal to turn right. Then the sensors shows that "now obstacle is removed. Go straight". You feel that you done well, but the sensor and the computer system really cheated you. Sometimes it was not a cheating, because ,there will be a possibility of thinking that there is an obstacle.
Our brain is not much different or error free in similar cases. If you are think that you know the universe, I think it is actually bad. Things you feeling from the surroundings may be different from reality. Your eyes are similar to the spaceship sensors. Not only your eyes, every sensors just see one phase of the reality. That really implies that knowing reality is too difficult.
I am not going too inside. I am not a philosopher. So let's have a fun. just go thruogh this link. A number of good eye illusions are included. Here I give a puzzle from eyetricks.com - Find which is longer?

Why there is so many constants in equations?

I will tell you the secret of constants in mathematical equations. They are not intruded or the error or nothing, but it is essential part of the equation. I will tell you some facts while going on your story. I will exemplify what you want in this story.
Consider you are a young scientist. You close your room's door and start experimenting on something when you get leisure time on Sundays. You are doing something seriously on your table, with an electrical circuit. Your aim is to find the dependence of a node voltage X (ie, a voltage in a part of the circuit). You came to know that X depend upon the supply voltage V. You start experimenting and plot graph of X for different values of V. Then you
got a graph like this:
It is perfectly linear. So you write,
X is directly proportional to V
To be more specific, X increases for an equivalent increase in V. You repeated your experiment and plot another characteristics with time. This time, your supply voltage kept constant. Plot X with time t.

From the plot, it easy to find that dependence is,

X is directly proportional to e^(-t)

Then from the above town experiments, you can write that,

X is directly proportional to V*e^(-t)
ie, X = K*V*e^(-t) where a K is the proportionality constant.

You can find K from single experiment. Once you got the value X when for a particular V and t,

K = X/(V*e^(-t)

But I want to tell you that your experiment as well as your mathematical expression is not perfectly true. A true dependence of X on it's environment will be very complex and tedious to express in mathematical form. Your X may depend on the atmospheric pressure, temperature, material properties,...raining in New Delhi,.....war on Iraq and so so.
After several years, you repeated your experiment and find that X depending on temperature also. Temperature has a direct linear relationship (like V) on X. But last time, you didn't got it. What's the reason? You were not aware of that, you did the experiment in room temperature itself. But this time you get different answers in day and chilled night. Now you modify your equation as,

X is directly proportional to V*T*e^(-t) where T is the temperature
X = L*V*T*e^(-t) where L is the proportionality constant.

Here I want a point to stress. Do you think your previous equation was wrong? Not at all. It is correct in an isothermal environment. But it become wrong in a temperature varying environment. A single measurement depending upon many things in the surroundings. But many of them can be ignored, because, they have less relationship with X. Something can't be ignored, but they may not be measurable (such as number of electron collision per second).In such cases, just put a constant for that, as long as they are constants. To be more clear, if your experiment depends upon the radius of earth, just put it as a constant in your equation. But when you do the experiment in moon, your experiment may troubled, unless you replaced the radius of earth with moon. I meant that variables can be considered as a constant or variable according to the environment.

Saturday, November 28, 2009

Puppy Linux : Give life to your Thumb drive

If you didn't tried Puppy Linux - one of the smallest Linux, core's yet-remember, you have only one life, try Puppy today itself. Puppy Linux - the name is not much inspiring for geeks, but I found it is the most stable and useful OS in the pocket Linux category.
It has the following advantages over other less-sized Linux operating systems.
  • Small sized. Ranges between 80MB to 150MB
  • Install anywhere - HDD, USB Pen drive, biz. card sized CDs. (You can use ordinary CDs, DVDs, Blu-ray discs - but it is too big for puppy.)
  • Easy to use.
  • Official website offers boot time of less than 1 minute. But it is typically less than 15s in my Intel P4 with 2GB RAM.
  • Puppy is beautiful than any other pocket OS.
  • Smart and crash free. I used more than 10 Linux flavors. Everything crashed, but I haven't experienced Puppy's crash.
  • Puppy sessions are saved in *.sfs file. It can be placed everywhere. Puppy search for it at boot time to recover the previous session. There are a number of fundamental advantages for that. I found many of my friend's computers not supporting USB boot. Of course they can boot from a CD-RW but it is not writable. Puppy offers several ways to overcome it. One is that, it can write previous sessions in CD as a multi session write. But it can be used until CD size limits. Another way is to write *.sfs file in HDD (for home usage) or USB pendrive ( for portability) and puppy kernel file in a a CD. So CD can be booted easily and can save sessions.
  • You can resize puppy save session file while running.
  • Comes with almost all drivers.
  • A wide variety of Puppy flavors are officially and unofficially available. These flavors are called 'Pupplets'. Pupplets are intended for a particular task - ie, it supports a task greatly. There are pupplets for painters, gamers, processionals, children, students and so on.
  • Brief and understanding tutorials, quick replying forums, community etc.
Once you downloaded Puppy, you have a lot of questions about installation, usage etc. Most of them answered in the official website and associated forums. Otherwise just google for that.

Wednesday, November 18, 2009

How to prevent virus from USB pendrive

Sometimes attacks of virus through USB pen drives are a real headache. Even though most of them are trivial, anti virus programs may not catch them. Use this following techniques in order to prevent them.
  • Make a raw file in the name same of a virus file. Most probably, these these files will be hidden. To view this, a good way is open the pen drive in Linux OS. you can see some names such as "virus.exe" on the root folder of pen drive. If it exists, open it using a text editor program and delete all the characters and if you want, include some raw characters and save. If you don't have any such files, but want to prevent them, you first of all need to find the name of that virus file and make a raw file in any text editor and save it in the same extension of the virus file. I successfully prevented a most common virus named "autorun.inf". Warning : This method not always work.
  • Use a good anti virus on your PC as well as in your pen drive. Some good links are http://www.usbantivirus.net/ and http://www.zbshareware.com/download.html
  • Format your pen drive well, if your head ache is cumbersome. Some virus programs can override quick format in windows. So use GParted.Prevention is better than cure. Formatting is the last chance.

Saturday, October 17, 2009

Let's do a simple hack!


If you are not aware of the difference between the words 'Hack' and 'Crack', I recommend you to hear what wikipedia says. Anything you want to do in a propitiatory program like MS Windows which is prohibited by license or it is not intended to do so may be called as crack. But the word 'hacking' has a great meaning which is different from 'cracking'. You can do anything on your open source program. If you are trying to crack your Linux OS which is open source, it may be called as 'hacking'. What is I want to say is that, an open source program can't be cracked because, they provide source code and hacking (cracking!) is allowed by license. If you are trying to beat an open source program, surely it will become a part of development. So an open source program can't be beaten. Hacking is intended for fun, especially by applying intellectual skills on something and and allowed by law. If anything you find violating the law, please call it as 'crack' not 'hack'.
If you are a beginner in Linux, like me, this simple hack will really attract you. This hack is done in my pocket slax 6.1.2 which is installed on my USB pen drive. But you can do this in any linux based distro which has a boot splash screen or login screen. The only thing you need to do is,
Navigate to /boot directory. In pocket slax, it is situated in the following path:
system:/media/sda1/boot
Then you can see one or more image files with .png extension. In slax, it is 'slax.png'. Edit this picture with a suitable image editor and change as you like it. For example, type "Hacked by ". It is interesting that you see your name at every boot up. If you are interested, you can put your photograph. But it is recommended that, you should not change the size of the image. Also, you should not change the name of the image. Of course, you should copy the original image.png file to any other directory in order to undo everything you have done.

Saturday, October 10, 2009

Mouse gestures for Mozilla Firefox


Mozilla Firefox one of the leading power of internet browsers, shows its real power and beauty only when the appropriate add on-s are installed. You can download and use them from Firefox add on page. There are a plenty of add-ons available and no need to specify which is good because it greatly depend upon your tastes. Recently I installed an add-on named All-in-one gestures and I feel it very interesting. You can install by clicking 'add to Firefox' button as you usually do while installing add-on. There provision to change the gesture pattern in the 'preferences' mode. Mouse gesture means that, some operations you done in Firefox such as 'back', 'forward', 'refresh' etc can be done simply by moving your mouse. I experienced no problem with both Windows and Linux platforms. There are tons of interesting add-ons like this. It is really fun to experiment with Firefox add-ons.

Friday, October 2, 2009

Booting from CD ROM or USB devices

Booting from resources other than HDD is very simple, but the way in which configure your system for boot from a particular task may differ. First of all, you should know that, the boot configuration appearing on your monitor is independent of the OS, or any other peripherals connected to your system and it is occupied in your BIOS and it may vary for various type of mother boards. Nowadays, many people use liveCDs or liveUSB loaded with their favorite Linux OS for the sake of portability. So I think this tutorial will be useful to you.

After you power on your PC properly, a splash image will appear within few seconds on your monitor probably mentioning about your motherboard vendor or vendor logo. Some keys and their function may be mentioned on the screen.
For example: F9 : Boot menu F2 : Setup
The keys used for boot setup and boot menu will greatly varied. But the major problem is that this splash screen appears for less than a second in some systems so that you can't even recognize what is written on the screen. Here you should do is that press 'Pause/Break' key in your keyboard (It is positioned in between alphabetic keypad and numeric keypad). Then the screen pauses. Then you can configure as you like it. If you now want to boot system normally, press 'Enter'. Each of the operation will be explained while you are attempting to change this. This will not be explained here because this is different for different systems. But in most systems, if you think that you did something and don't know what is the consequence press 'Esc' continuously and probably one dialog box asks you to save changes. Press n/N for No or y/Y for Yes if you want to save changes.

If you want to just boot from CD ROM or like external devices, good option is that select one resource form the boot menu. The way how to navigate to the boot menu will be specified on the splash screen. If not, try F8 because, many systems having F8 as the boot menu key may not be explicitly shown. In boot menu, you can see several sources. 1.FLOPPY 2.HDD 3. CD-ROM 4.USB HDD .Select one which you want to and press 'Enter'. The system try to boot from the source. If fails, system may try a normal boot or a restart. Sometimes some devices for example USB HDD will not be listed until you inserted your memory stick or pen drive to the system before power up. In this case you should insert the USB device and try a restart and do the same procedure. Similarly, you should insert CD ROM to your drive before selecting boot device. One more thing is that if you are attempting to boot from a pend drive (or memory stick or thumb drive), you should select USB HDD. Some other options like USB FDD, USB ZIP may also be listed. One more problem associated with USB boot is that if you didn't enable USB boot in the boot setup (the key for boot setup will be displayed on splash screen), USB boot will be failure. In some systems you have options to enable/disable USB 2.0. All you need to do is that if a USB boot failure occurs, you should navigate through the boot setup menu and do as your need. In this case, the boot selection will not be saved and need to do the same procedure every time you boot time. Otherwise a normal boot will occur.

To permanently setup a boot configuration, you navigate to the boot setup menu and change the 'boot priority'. In normal case, first boot device will be HDD. You can change it to CD- ROM or USB HDD. One thing be noted is that you should give a priority to HDD as second or third device. Hence, if a boot error occur on the first device, system try on the second device (here HDD), so a normal boot will occur. Change the boot priority to CD-ROM as the first device and second device as HDD is a good practice in order to debug your OS, in case of permanent system crash. Here the system ask to save changes. Press y/Y to say Yes, and this configuration is saved on BIOS for future.

If you do the configuration permanently, every time system checks for first priority device and may feel time consuming if you are waiting for a normal boot. If you are doing it in temporary, every time you need to select boot device. It is recommended that you permanently change boot setup in your Home PC while temporarily do in office PCs.

In the worst case, your motherboard will be entirely different thing and you need o read motherboard users manual. If you didn't got any manual on purchase, you can freely download it from the vendor's website. Probably you need to search by the part number. The part number of your mother board can be found on the top side of your motherboard (Hmmm..Best chance to hack your PC).USB boot is not allowed in some old PCs. But all general purpose motherboards not older than 3 or 4 years can have USB boot capabilities.

Monday, September 14, 2009

Battle Game - The computer thinks!

Recently I built a game and named 'Battle' as a consequence of my studies in the field of artificial intelligence. As a first step, I built a mathematical model instead of more flexible neural network model. The work on neural model is on the way and the work is very slow. The mathematical model also not much efficient but I took care to make the program 'act' as intelligent (I know intelligence is needed to act!). Rarely the program may crash. I not interested to make this game for commercial use and I am givin it under GPL. The program is not much pretty both in efficiency and it's intelligence. Since I am not a proffessional programmer, the rules for a good program may not be satisfied. I compiled it in C++, but the entire structure is like C.
The game is like ordinary 'Tic Tac Toe'. but has a little difference that maximum number of players is limited to 3 and If you placed your all three players, you can move them to adjacent places to align the players in a line. For the simplicity of learning the game I have put a video of how to play the game.



I have built a Qt (which is cross platform) GUI for my game for beginners but have put also the CUI mode game for code diggers. Even though this game is not intended for entertainment surely it provide some entertainment if you read the code. I need you comments to speed up the development of neural model of the game. I did all the work in win32 platform and linux users also can compile the code because, Qt is cross platform. But you need to install Qt on your distro.
Here's the download links:
GUI BattleGame (Recommended)
CUI version 1a.0
CUI version 1b.0

Hackthissite.org A hacker's university!

Hackthissite.org seems like a hacker's university. This website provides a good stuffs useful for hackers (crackers also). The hackers community is really powerful and active. Only you have to do is facing different types of hacking problems and find a quick and easy way to solve it. If you are a perl programmer or a javascript hacker, it is a plus. Innovative php users get the points more. A deep knowledge in html is not needed. Above all, the most important thing is your common sense. The problem phase is broadly classified in to:
personally I felt basic and javascript is good for beginners, but advanced problems like programming missions are needed to eat more points. Earning points is not for just earning points, but it will give you some reputation. You are ranked by your points:

Pentitioner-0 Points
Script Kiddie-700 points
Apprentice-1700 points
Wiseman-3200 points
Master-5400 points
Hacker-7000 points
Elite-8400 points
Sage-10000 points

W3schools help you a lot in learning web programming. Navigate to hackthissite.org and show who you are.

Friday, September 11, 2009

Make your own animations using Gimp


Hey Gimpers,
Gimp is not only an 'image manipulation' program. You can build your own animations using Gimp. It is very very easy. Just try it. There are plenty of tutorials available on the Gimp official website.
Click here for a nice and intuitive video tutorial.

Wednesday, September 2, 2009

Bhuvan, still have a lot of void


ISRO(Indian Space Research Organization), launched Bhuvan , a Google earth for India (But more than Google earth) after the successful launching of Chandrayan-1. In the first sight, it is like Google earth, but tons of information is there and covering almost all over India. Bhuvan is a strong rival for Google earth, and seems better view than Google earth and have some good features, and is more informative. Currently, Bhuvan works only on Win32 platform. You need a program (about 15MB) and a need a good broad band internet. Bhuvan works fairly well in my system with 2GB RAM. All you need to play with Bhuvan is included in their website.
Bhuvan has enough tools to find exact area, length and other terrestrial info. Bhuvan works well even though you have low bandwidth network because it is designed such a way that it covers almost Indians. I personally don't know Bhuvan supports current GPS systems.

Monday, August 31, 2009

Bluetooth interactive console using pyS60

Nowadays, text messages via mobile phones are shortening to small, but difficult to understand language. I don't think whether the major reason behind this shortening is economic, but most people feel tedious to type text through a 4*3 panel. Typing a program like, C or python in correct syntax is again a tedious work. You can use bluetooth console, in order to avoid this problem effectively. Here I describe how to setup bluetooth consloe communcation in your MS Windows XP platform. For beginners, this procedure may feel ambigous. So I tried my maximum to describe it with screenshots.

If you are not aware of pyS60 please read this.

You can find some other tutorials here:
s60python
nokia wiki
pys60 Library Referance
Yet another tutorial
Lecture

The above links were extremely useful to me. The procedure is repeated here, but I tried to describe it in rather simple way. If you feel any difficulties, please inform me.

Setting up bluetooth interactive console in winXP

step1: Plug your bluetooth device into your PC (any USB port). Then Run your bluetooth driver program which you installed from the CD/DVD when you buy your bluetooth dongle.
Then automatically a serial port is assigned for it. In my PC, it is COM6. You can do step 5 in case you don't know the COM port your PC supported.

step2: Run command 'hypertrm' in your run window. Run window can be opened by clicking Run option from the start menu.

step3:You will get hyperterminal opened like this:

Enter any valid name for your connection and select a suitable icon and forward.

step4:Then you will get another box like this:

Type any 3 digit area code and phone number.Your country or region may be automatically filled. If not, do it manually. Select COM6 from 'connection using' lineEdit tab. It may be changed. You will get which COM port your computer assigned (If you didn't get it, notice first screenshot)

step5:Take your symbian smart phone with pys60 installed. Turn your bluetooth ON and open pys60 application. From 'options' menu, select 'bluetooth console'. Your application then searches for blutooth device. You can optionally select it as your default connection.

step6 (Error Debugging): You are now probably connected successfully. Not yet? Check your connections. Check whether you run your bluetooth driver.If your bluetooth driver is running, a symbol of bluetooth will appear on the panel (see screenshot 1). I used Enter blutooth dongle (part number:E-UBTV) from entermultimedia. and it's driver(BlueSoleil). The driver is downloadable in case you lost the CD/DVD with your dongle. If you can type anythong on the white blank screen of hyperterminal, you are probably done everything. Else, you should check the whole procedure.
In any case, you should plug out the dongle and replug.
Didn't connected yet? Some mysterious powers are playing around you ;-)
I am happy to help if you can't find any way to connect.


step7: If you are successful in connecting your mobile, you are done.

step8:You can do anythong with python. Try these

step9: While you close application, you get a dialogue box and click yes.

You can save hyperterminal settings for the future use. Then when you run 'hypertrm' command, you will get a window like screenshot 2. simply close the box named 'Connection Description' and then you can open the saved file (here, pybluetooth.ht). Again there is an option to save the connection in your mobile and make it as default connection.

Friday, August 28, 2009

Slax- A brief review

Yesterday, I found some good stuff on the official website of Slax (It is a simple but very beautiful distro. Yes, it's build up of KDE). Website itself is very cute and everything is simple as like SUSE or Mandriva. I know some real geeks may not like the entire structure of slax, but it will be stunning those who were allured with Microsoft Windows OSs. The simplicity makes everything easy.
One more advantage is that they give a free 30MB online memory which can be easily be used like ordinary disk drives. The memory of 30MB is free for slax users for unlimited period even if you didn't use it for a long time (The info is from the official blog, the unlimited period may be varied. But they didn't commented about it yet). You can use the online memory from any machines that supports slax, or any other OS, even Windows. A 200MB iso file or tar file is to be downloaded in order to make a liveCD or USB. I installed latest version of slax (slax6.1.2) to my SanDisk Cruizer 4GB pendrive and it works fine. A live CD can easily be created, but to do USB installation, you need to work for 2 minutes.
The whole procedure can be done in your windows platform itself. Try this link.
Another fantastic feature I've seen in their website is to run an application without actually installing on our system known as 'activat'ion. Almost all general purpose applications are available as .lzm binary format which is ready for the installation without any dependencies. You can select which software you want to use from modules page. There are three options - first to download (normal download for later installation), secondly 'add to build' which helps to customize your distro before download. If you want to check whether the software listed is good, just do the third method -activate. Then you can use the software as you have installed it in your system, but actually not.

The major advantage is that it is pocket linux (handy) and can be used everywhere. But personally I felt that it has less hardware support compared to Puppy Linux. But I stil like slax because of it's greenish beauty!

Happy slaxing!

Wednesday, August 26, 2009

Linux Demo? What's the hell?

One of the reason why I love linux a lot is that it has no barriers at all. Many programs usually comes as a demo version which will not not be as much handy as a proffessional or full version. Demo versions seems sometimes nasty, and is too dry to wet out appetite. So I hate the word 'Demo' itself.
But what's going on there is the arrival of "Demo Linux". I just wondered for a while and navigated to the official website.
But I found there is nothing to afraid and found some good stuff. How many of you felt boring while repeatedly installing and formating to find a suitable distro. Live CD's reduces this problem to a great extend. But now this problem is greatly dealt by Pendrives (Memory stick). Demo Linux is specially built linux distro to be alive!. That means there is no need of a hard disk at all. A 32MB of RAM is enough to work with it. Hope it will be useful for those people who loves to be small.
Also read about Puppy Linux Slax and Kolibri

Thursday, August 13, 2009

Resize images in Gimp



Resizing pictures is quite easy and there are several free programs available for this purpose. Resizing images by mouse is quite easy, but here is how to resize images in a professional way. It is quite easy.

Here is two images, one is the resized form of the other. To know the actual size difference, please download these images.

step1: Open GIMP
Applications->Graphics->GIMP in Linux (you can enter command 'gimp' in your terminal window as geeks do)
start->programs->GIMP in Windows

step2: Open image in Gimp

step3: Rigt click on the image and select image->scale image..
step4: Change width and height. If you change any one of them, the other will automatically be changed.

step5: Click 'scale' button

step6: Save yoiur image

Saturday, August 8, 2009

Try Ruby on your browser!

If you are ready to spent a 15 minutes of free time, it's enough to learn ruby. Ruby is Japanese brain and quite easy also. It is famous in its simplicity. You need not install ruby to try it, you can do it in your browser- Not joke!
Just navigate to the official website of ruby.


On the sidebar, you have a wonderful tutorial "Ruby in twenty minutes" to start with. Put a click on "Try ruby on browser" -circled in the above screenshot. Then you will get a command prompt like screen on your browser. Then now ruby is ready to what you want!
If you are beginner, type 'help' on the prompt and hit enter. Then the 'virtual' ruby navigate you through an interactive tutorial which is very useful for beginners. The tutorial takes only about 15minutes.

World's Smallest "Hello World" program

It's quite formal way to start with a "hello world!" program while introducing a new programming language. It is convinient by starting from "hello world" because the program may run properly and is helpful in gaining the confedence. Also it gives a proper output - Prints "hello world!" on the monitor. The programmer becomes happy while seeing this output. Here is a simple "hello world!" program in C.

#include
main()
{
printf("hello world!");
}
//output is
//hello world!


Quite simple?
But I think it is not at all simple. The special characters present in the program really offer some disturbances for the beginner, however a C program is not redundant and it is extreamly powerful.

In Python, I found a much more convenient way.

print "hello world!"


Simple?
It seems good but there is still void to shrink.

Take a look at Ruby,

"hello world"


That's it. I didn't found any void to shrink here. Just put the string you want to print in quotes (" ") and it is pretty easy. But this is not the standard way of printing a string on the monitor, as far as the offcial website of Ruby is concerned. They recommends,

puts ("hello world!)


Then the output will be,

Hello World
=> nil

nil stands for there is nothing to return.

Saturday, August 1, 2009

Introduction to parallel port (LPT) interfacing


Warning!:Usage of parallel port without care may cause serious impact on your PC.

Nowadays programing parallel ports (also known as printer port LPT (DB25 female on the back of IBM type PC) are prone to disappear from newer PC's. But, as far as computer based control engineering is concerned, parallel port is the easy way. So many people stick on parallel port. There are a plenty of programming languages offers convinent control over parallel port by high leve l of abstraction.In order to control things through your parallel port,you need a simple hardware also. Don't need to buy, just build one in your home. Before you dig into parallel port, just know what is a parallel port. If you are confedent that you have some knowledge of parallel port, just skip the links below.

Assuming you acquired basic operation of parallel port. Now let's begin to dig. Here I tried to describe maximum of how to work with parallel port in different systems and different platforms. You can read all of them in posts tagged in Parallel Port.

Read my post on parallel port control using python
Read my post on parallel port control using C/C++

Thursday, July 30, 2009

A programming language in my name!

While googling in a sleepless night, I found something intersting (interesting for me and all other Toms!). A good looking programming language named "Tom" which is my name. I just went through the official website and found it was cool. I liked some of its specialities available, and also it's license.-Yes, it's under GPL (GNU General Public License). Some of the pecularities are: (I just copied it from the official site)
  • TOM sports extensibility of objects: a class is not just defined by its main definition: classes can be adjusted, even at run time. A prime example of this is to modify in your program a class offered by a shared library, just to make it suit your program better.
  • TOM methods employ default argument values and multi-valued returns;
  • TOM has multiple inheritance - with semantics much simpler than in C++ or Eiffel and obviating the need for interfaces (Java) or protocols (Objective-C);
  • TOM offers reflectivity on objects, their classes, member variables, and methods;
  • TOM discerns classes and a few basic types - like Java and Objective-C;
  • TOM has conditions modeled after CLOS conditions;
  • TOM, as compiled by Tesla, the first TOM compiler written in TOM, adds blocks to the language;
  • The TOM standard libraries offers time-constrained garbage collection, multi-threading, distributed objects.
In their FAQ, I found a question "What does the name "Tom" mean?
The answer given was like this: "The name TOM is a name. Names don't need to have a meaning. :)"
Well, here is simple "Hello Tom" program in TOM which resembles C and Java.

int
main Array arguments
{
[[[stdio out] print "hello, Tom!"] nl];
}


Currently Tom is available for Linux,BSD platforms. An unsupported version of win32 platform also
Visit official TOM website

Monday, July 27, 2009

What's the value of 0/0 ?


Do you know what's the value of 0/0 ?
Most books just don't care about it. Also many teachers are not interested to touch anything like this. Students are fearing to see this, especially while they are doing some calculations on the exam paper!
Anyway, it is good to be aware of 0/0. I continue this article assuming you know basic addition, multiplication etc.
One question: What's the value of 10/2 ?
It's 10/2 = 5. Is it?
We got the answer as 5. Is that mean 5*2 =10 ?. For example, if you have money Rs.10 and distributed to your two friends equally. Then your friends get 10/2 = Rs.5 each.
From the above example, we can generalize that if a fraction exist in the form x/y=z , then z*y =x.
please note the above line. I will tell you more about that line!
Then the question is if you divide your Rs.x to y people equally, each will get  Rs.z. Then what is z?
The answer z is a number which satisfies z*y=x. In the above example, you put different values for z such that, z*2 =10. Then z is the amount in your each friend's hand. Here 5, the only 5 satisfies the equation when it put to z. Thus each of your friend get exactly Rs.5.
Then consider the case of 0/0 . Like the previous example, if 0 is divided to 0 people, how many rupees each of your friend get? If  the answer of this question is z, we can write z*0 = 0. Put some values for z in order to satisfy the equation. All values of z which satisfies the above equation are the solution. We know that multiplication of any value with 0 is 0. So z can take any values to satisfy the equation.
If the solution of z is written in a page, your page may not be sufficient to include all solutions of the equation because solution is 'any value'. More mathematically,
z = -infinity.......................0.......................+infinity
So, 0/0 = any value
It seems very interesting on the first sight. You have nothing, and you are dividing that to nobody. Then the amount in the nobody's hands may be millions, trillions or anything. If you think, this is like a magic to generate millions from nothing, you are absolutely wrong. Think about it.
Let's go for an example to describe what's actually I am trying express. To understand this example, you should aware of a great law named Ohm's law in Electricity (The circuit shown below is stolen from Wikipedia). If you don't know anything about Ohm's low, you must make yourself aware of that before going to continue.
According to Ohms law (refer picture), R is V/I.
R=V/I
If V=10V and I=2A, then R = 10/2 = 5 ohm. In the above picture, if Voltage V=0, Current I will also be zero (without voltage there will no current). Then R = V/I =0/0.
According to our previous result 0/0 can be 'any value'. So R = 0/0 simply means R can take any value. R can be anything.
R*0 =0 can be treated like this: R is the values that exists when V=0 and I=0.
If you put a resistor in your pocket, the applied voltage V = 0 and hence current I = 0. So you can put Resistances of any value in your pocket. Think about the world of 0/0 = a fixed value. For example, take the fixed value 0/0 = 100. Then Resistance R =100ohm is the only value that can put into your pocket and others can't!
Seems funny? but it is fact.

Sunday, July 26, 2009

Parallel port programming using python

Setup parallel port in linux (Debian/Ubuntu)
You should have installed python on your distro. You must have the previlages of 'su' to do the following installation

# apt-get install python-parallel
# rmmod lp
# modprobe ppdev
# python

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


Assuming you have some basic python knowledge. If you didn't install pyhton -parallel, you can't import parallel. Now p.setData(oxFF) sets every outputs of parallel port to ON. Try different values instead of 0xFF. (To do this you require basic knowledge of hexadecimal representation of binary numbers). Try this chaser program.

x=[1,2,4,8,16,32,64,128]
while(1):
for i in x:
p.setData(0xFF)
time.sleep(2) #Good night for 2 seconds


The program will work until you force to quite python or an unexpected UPS failure. That may be funny ;-) But Intentionally did that for the program simplicity.

No Linux? Windows only? :-( Just try it out

There is nothing to do in windows. Download latest python first. Install it. Then download pyparallel for windows fron sourceforge. Install it Now everything OK. Open python either by command or open IDLE (It will be installed with python core in windows). Then type the following:

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


The example chaser program is also applicable for windows platform.

Read my post on parallel port programming in C/C++

Wednesday, July 22, 2009

Teach your computer how to speak!

It is good idea to teach computer to speak!. There a number of programs available for winXP paltform, but here is a unique program "espeak" for your linux. Just enter the command in terminal,

$espeak "Boss, I can speak now"

will work fine. It is useful for some scripts in linux to remind some status of computer to the user like a personal assistant. espeak is not an internal bash command and need to be installed. I simply installed in my Debian from repository.

#apt-get install espeak


The command above will work well with ubuntu systems also. If you are using any other distro, you need to download and install it manually. Click here to know more.

Here is a simple python program which uses espeak as system command. To use it you require python and espeak installed.

#! /usr/bin/python
# File: speak.py

import os
from Tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()
self.button = Button(frame, text="Click", command=self.activate)
self.button.pack(side=LEFT)


def activate(self):
os.system('espeak "Boss, I can speak now"')
print "Boss, I can speak now"

root = Tk()

app = App(root)

root.mainloop()

Just copy the above program into a new file named speak.py and 'cd' into the directory and enter,

python speak.py


You are free to use this program anywhere since espeak is under GPL.

Friday, July 17, 2009

About our knowledge

We dig everything from the centre. Every experimentation of any branch of science starts learning our world neither from the beginning nor from the ending,but from in between. We don't know the beginning and the ending. But we dig to above and below from the middle, but never reaching anywhere.
For example, a man start to learn about the world. He first learn about the present things -trees, birds, humans etc. He digs to the past and also digs to the future. Here time is the base. When size becomes the base, that man start to learn back to molecules, atoms, sub atomic particles, quarks....And when going up, sun, Milkyway...Here again we don't know the ending. It seems that, man's knowledge is isolated in every axis didn't touch the starting or ending yet. Yes, it's really floating!

Thursday, July 9, 2009

Physical Interpretation of DeMorgan's law

I am asking you what is De Morgan's law. This may be the answer.
If A and B are two events,

(A+B)' = A' . B' and (A.B)' = A' + B'

(Here the operator ' represents the compliment of the operand. That is If A is 'yes' then A' is 'no' and if A is 1 then A' is 0 and vice versa). I assume you have basic knowledge of Boolean algebra. Now I am giving a physical interpretation of the law which is very useful in analising the law.

Consider first law,

(A+B)' = A' . B'

Here '+' is OR operator. That is A or B. Let Y be an event of shutting down your computer. You can do it in two ways and B.

A=>shutdown manually by pressing the power button of CPU.
B=>click 'shtdown' using your mouse.

Then,
Y=A + B ie, Y= A OR B

Another iterpretation is that, you can turn off your computer by either clicking 'sht down' or by pressing power button. If any one event occured, the computer turns off. ie, Y become true.

One day, your friend came to your home and want to learn about computer. He did something in your computer in order to turn off.Unfortunately, the computer didn't turn off. He reported you in the other room. Then you think in this way, what may be the reason why the computer didn't shut down. The output occured is Y'. ie, computer didn't turned off.

Then from the previous equation,

Y' = (A+B)'
Applying De Morgan's law,
Y' = A' . B'

Here the interpretation is that, The event A is false and event B is false. ie, he neither clicked 'shutdown' nor pressed power button.

Take De Morgan's second law (A . B)' = A' + B'
Consider two dependent events. For example,
let A and B be two dependent events. If your friend dont know how to call someone using a coinbox telephone. The procedure written on the side of the machine is first put the coin and then dial the number. They are dependent events.
A => Put the coin.
B => Dial the number.

Here the output Y is to call somone successfully. ie Y = A.B
(Here A.B is not equal to B.A which is another boolean theorm. Here just don't think about it.It will be explained later)
Unfortunately, your friend could not call the other. He asked for help. Then you analise the problem why he didn't call.

Y' = (A . B)'
By, De Morgan's law,
Y' = A' + B'

ie, he either didn't put the coin or dial the number properly. The above example is conditional events.

Saturday, June 20, 2009

Google maps works without GPS


A GPS phone with Google maps is really amazing. But unfortunately, my Nokia E65 has not any GPS support, but navigator programs are included in Symbian. A bluetooth GPS device can be used along with many phones without any GPS module in-built. But it costs around Rs.5000 India. But Google maps is useful even if you have any GPS support because it works well using GPRS network to find current position, not much accurate because it will show the nearest mobile radio transmitting tower. But it becomes handy and have only 1.3MB to download and useful in navigation. Recently, Nokia also provided "nokia maps", but I am not commenting about it because, now I decided to stick with Google!
You can download Google maps directly to your mobile phone from m.google.co.in/maps
or vist www.google.co.in/mobile from your PC.

Saturday, June 13, 2009

Open electronics - Philosophy


Electronics is nowadays being a part of modern human life. Computer, Television, PDAs, Mobile phones, ,Vehicle Engines, and every field of communication, Medical science, Military requirements and everywhere….A similar boom was taken place years ago in the software field. The necessity of software with less cost and freedom opened the windows of open source software foundations like GNU. Thanks to GNU/Linux.
But the case is different in the case of electronics. Here the real source is the circuit schematic and logic. Here the source is more valuable than software distributed under GPL License. But as development goes on, the nomenclature of “opensource” is becoming relevant in electronics also. In modern digital control, the logic is not only the part of hardware and is shared by the software also. That means, hardware is likely to be same in all devices, but the complexity of logic completely depend upon the program itself. That is what is I want to emphasize “opensource” is being relevant in the filed of electronics also.
In older age, it was easy to 'hack' the circuit by the method known as 'Screw Driver Engineering'. But as micro electronics development goes on, a single chip can hide most of the important logic to the end user. The arrival of microcontrollers again increase the complexity of hacking. These technology is extremely useful where security is required. The same security issues exists in software field also. But a programmer can hide important parts of program from the user. This is considered to be severe from the perspective of openness. The similarity in the electronic field and the computer software field gives us a way for a new revolution - open source electronics.

Read more about the open electronics philosophy here.
Another good website concerning open circuits.

Portable programs for your pen drive

Nowadays, there is no need of an introduction to portable applications, but I am starting from introduction before going to some useful portable application links.

Most of the computer application programs are to be installed in your system. It is not a problem in Windows platform just click next->next->.......finish. Quite complicated but amazingly interesting way in Linux. There are several Java programs which is intended for direct work instead of initial installation setups. The problem arises in installable applications comes to play if you are working in your office, college in computer. The computer administrator may prohibit to install your favorite Firefox in the office computer. These problems can be avoided by using some portable versions of your favorite applications. Just download an unzip it in into your pen drive and use it every where. Currently, most applications support portability in MS Windows OS. If you are a Linux user, Linux OS itself become portable to follow you!

Some good links for MS windows:

http://portableapps.com/

http://www.pendriveapps.com/

Here follows a junk of pen drive Linux:

http://www.pendrivelinux.com/

Python for Symbian s60


Python is very convinient language compared to any other and constantly increasing it's popularity. It is listed in the top 10 programming languages also. It can be used in MS Windows, Linux and everywhere. It's a best hacker's choice also. Many varieties are emerging from python. Portable python- which need not be installed but paste the file in your Thumb drive or any other portable devices and you can use it everywhere. Really Nice. Now the pyhton coming to conquer the mobile phone world!. Yes, you can do what is you go for in a PC.

  • Just donwlad the pyhton instllalble file. Install it
  • Open python for s60
  • Options->Interactive Console
  • Do what you want
  • You can see some example *.py files in Options->Run Script
simplest example:

print "hello World!"

#Note: Wherever you want to press enter in PC version of linux, in mobile, you use 'scroll key', not 'enter' character in the list of special characters. You can run python scripts also bu require one text editor. One good text editor is JtextLite.

Happy Programming!

Friday, June 12, 2009

Play with "cdrom" in Linux

Linux comand shell "bash" is powerful as we know. Here is a fun with bash. You can control your cdrom using 'eject command'. Here is only a simple description. For nore details, you should look at it's man pages.

This is not a project or something serious. just for fun. You can control your cdrom by using this code. This will only work on Linux platform. I did it in fedora core 9. But it will work other disro's also.

!!!!!!!WARNING!!!!!!!!
1)Some procedure described in this article is not a recommended or the hardware devices are intended to work like it. Do it in your own risk.
2)Don't interrupt the way the hardware working (the movement of CD ROM tray by your hand).

Open your 'cdrom' tray under software control
Try this command

$eject cdrom


It will try to open your cdrom tray. if you have two or more cdrom drives, try

$eject cdrom0


If you havn't any cdrom device, bash will return an error message:

$eject cdrom2
eject: unable to find or open device for: `cdrom2'


You can find your device name ( "cdrom0', 'cdrom1' etc.) from "/media"

Close your 'cdrom' tray under software control
Try this command

$eject -t cdrom


Other useful parameters are there in 'eject'. You can read about it:

$man eject


Writing a bash script
Just entering the command at a time is not convenient. You can write some commands together and execute it when you want.
Open a new file using gedit editor (or any other you want)

$gedit cdromplay


A winow will appear and type what you want. For example, if you want to open and close your cdrom continously three times just print like this:

eject cdrom
eject -t cdrom
eject cdrom
eject -t cdrom
eject cdrom
eject -t cdrom


save it and close.
Then to resolve permission,

$chmode +x cdromplay

Then execute cdromplay

./cdromplay


You can see what I said before.

Do it in your real applications
As you know, we did some rubbish things before. There is no need to do so. But this is useful in some applications like CDburner - It will automatically eject tray after writing a CD ROM or you can control convineiently in a CD ROM player. We can use python to do a GUI application.

# File: cdromplay.py

import os
from Tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()
self.button = Button(frame, text="Quit", command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text="Eject", command=self.say_hi)
self.hi_there.pack(side=LEFT)

def say_hi(self):
os.system("eject cdrom1 -T")
print "boss, cdrom activated"

root = Tk()

app = App(root)

root.mainloop()

As you can see, the above program is the altered version of "Hello World!" program of one famous python tutorial. Don't get upset or confused by the defnition names. The confusion in program code will not affect the real program.Copy and save it or download it from here. You require python to do this. 'cd' to the appropriate directory and run,

$python cdromplay.py


Now you will see a simple widget with a button.


Press button and observe what's happen.



Download cdromplay for python
Download cdromplay bashscript

Watch the video how cdrom is ejected:

Good Luck!