The Traffic Light Hack

 

The Software

The program that runs the traffic light is written in C# and is based around the inpout32.dll that can be found here. Unfortunately I cannot host my entire project, since I have no webspace with which to do so, so here are the important pieces of code from the project (or you can look at the project on The Code Project page).

[DllImport("inpout32.dll", EntryPoint="Out32")]
public static extern void Output(int adress, int value);

private const int LPT_PORT = 0x378; // 888
private const int RED = 0;
private const int YELLOW = 1;
private const int GREEN = 2;

bool[] light = new bool[3];

private void UpdateLights() {
int data = 0;

for (int i = 0; i <= 2; i++)
if (light[i])
data += (int)Math.Pow(2, i);

Output(LPT_PORT, data);
}

The first statement is a declaration for importing the external Output() function. inpout32.dll should in the same directory as the application.

The value for LPT_PORT is unlikely to be anything different than 0x378; however, the value for your computer can be found in the properties page of the LPT port in Device Manager. Under the Resources tab, the first value in "I/O Range" should be the your LPT_PORT constant. In my case, I/O range reads "0378-037F", so I just use 378.

The next three constants are just arbitrary value I chose for the lights. To enable or disable certain lights, I just change the values in the boolean array light[] and then call UpdateLights().

For example, if I wanted to light only the green light, I'd do the following:

light[GREEN] = true;
light[YELLOW] = false;
light[RED] = false;
UpdateLights();

Simple as that.

Comments:
I can give you some webspace if you need to host the app. Just email me at light AT Witold_minus_this_.biz (remove all but 'Witold')
 
Can I please get some detailed knowledge about the project.
bhanawatkunal@gmail.com
 
i need to bee a hack any one can u tell me how to do a hack i am so interested to learn it pls any one can u teach me pls pls this is my mail id z.naveenkumar44@gmail.com this my face book naveen699@ymail.com pls i whant to learn
 
Post a Comment

<< Home

Archives

May 2005  

This page is powered by Blogger. Isn't yours?