You are on page 1of 5

using puerto_paralelo.

Properties;

namespace puerto_paralelo { public partial class Form1 : Form { public int i = 0, j = 0, adress = 888; public int D7,D6,D5,D4,D3,D2,D1,D0; public Form1() { InitializeComponent(); Reset_LEDS(); } private void Reset_LEDS() { try { puerto_paralelo.PortInterop.Output(adress, 0); puerto_paralelo.PortInterop.Input(adress); } catch (DllNotFoundException) { Alarma1(); } pictureBox1.Image=Properties.Resources.off; pictureBox2.Image=Properties.Resources.off; pictureBox3.Image=Properties.Resources.off; pictureBox4.Image=Properties.Resources.off; pictureBox5.Image=Properties.Resources.off; pictureBox6.Image=Properties.Resources.off; pictureBox7.Image=Properties.Resources.off; pictureBox8.Image=Properties.Resources.off; } static void Alarma1() { MessageBox.Show("No se encuentra la dll especificada, Asegurese que la dll 'Input32.dll' este al lado del ejecutable"); } public void opciones() { int value = 0; if (D0 == 1) { value += (int)Math.Pow(2, 0); } else { value += 0; } if (D1 == 1) { value += (int)Math.Pow(2, 1); } else

{ value += 0; } try { puerto_paralelo.PortInterop.Output(adress, value); } catch (DllNotFoundException) { Alarma1(); }

private void button_D7_ON_Click(object sender, EventArgs e) { pictureBox1.Image = Properties.Resources.on; button_D7_ON.Enabled = false; button_D7_OFF.Enabled = true; D1=8; opciones(); } private void button_D7_OFF_Click(object sender, EventArgs e) { pictureBox1.Image = Properties.Resources.off; button_D7_ON.Enabled = true; button_D7_OFF.Enabled = false; } private void button_D6_ON_Click(object sender, EventArgs e) { pictureBox2.Image = Properties.Resources.on; button_D6_ON.Enabled = false; button_D6_OFF.Enabled = true; D1=7; opciones(); } private void button_D6_OFF_Click(object sender, EventArgs e) { pictureBox2.Image = Properties.Resources.off; button_D6_ON.Enabled = true; button_D6_OFF.Enabled = false; } private void button_D5_ON_Click(object sender, EventArgs e) { pictureBox3.Image = Properties.Resources.on; button_D5_ON.Enabled = false; button_D5_OFF.Enabled = true; D1=6; opciones(); } private void button_D5_OFF_Click(object sender, EventArgs e)

{ pictureBox3.Image = Properties.Resources.off; button_D5_ON.Enabled = true; button_D5_OFF.Enabled = false; } private void button_D4_ON_Click(object sender, EventArgs e) { pictureBox4.Image = Properties.Resources.on; button_D4_ON.Enabled = false; button_D4_OFF.Enabled = true; D1=5; opciones(); } private void button_D4_OFF_Click(object sender, EventArgs e) { pictureBox4.Image = Properties.Resources.off; button_D4_ON.Enabled = true; button_D4_OFF.Enabled = false; } private void button_D3_ON_Click(object sender, EventArgs e) { pictureBox5.Image = Properties.Resources.on; button_D3_ON.Enabled = false; button_D3_OFF.Enabled = true; D1=4; opciones(); } private void button_D3_OFF_Click(object sender, EventArgs e) { pictureBox5.Image = Properties.Resources.off; button_D3_ON.Enabled = true; button_D3_OFF.Enabled = false; } private void button_D2_ON_Click(object sender, EventArgs e) { pictureBox6.Image = Properties.Resources.on; button_D2_ON.Enabled = false; button_D2_OFF.Enabled = true; D1=3; opciones(); } private void button_D2_OFF_Click(object sender, EventArgs e) { pictureBox6.Image = Properties.Resources.off; button_D2_ON.Enabled = true; button_D2_OFF.Enabled = false; } private void button_D1_ON_Click(object sender, EventArgs e) {

pictureBox7.Image = Properties.Resources.on; button_D1_ON.Enabled = false; button_D1_OFF.Enabled = true; D1=2; opciones(); } private void button_D1_OFF_Click(object sender, EventArgs e) { pictureBox7.Image = Properties.Resources.off; button_D1_ON.Enabled = true; button_D1_OFF.Enabled = false; } private void button_D0_ON_Click(object sender, EventArgs e) { pictureBox8.Image = Properties.Resources.on; button_D0_ON.Enabled = false; button_D0_OFF.Enabled = true; D0=1; opciones(); } private void button_D0_OFF_Click(object sender, EventArgs e) { pictureBox8.Image = Properties.Resources.off; button_D0_ON.Enabled = true; button_D0_OFF.Enabled = false; } private void button_START_Click(object sender, EventArgs e) { puerto_paralelo.PortInterop.Output(adress, 1); puerto_paralelo.PortInterop.Output(adress, 255); } } }

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

private void timer1_Tick(object sender, EventArgs e) { timer1.Interval = 250; x++; //incrementar el conteo en uno if (x == 1) { pictureBox1.Visible = false; TVicPort.SetPin(2, 1); //abrir el pin 2 del puerto 1 // TVicPort.SetPin(2, 0); imagen_rojo.Visible = true; } //.................................................................................. .... if (x == 2) { TVicPort.SetPin(3, 1); //abrir el pin 3 del puerto 1 TVicPort.SetPin(4, 0); TVicPort.SetPin(2, 0); imagen_amarillo.Visible = true; imagen_rojo.Visible = false; //x = 0; } //.................................................................................. if (x == 3) { TVicPort.SetPin(4, 1); //abrir el pin 4 del puerto 1 TVicPort.SetPin(2, 0); TVicPort.SetPin(3, 0); imagen_verde.Visible = true; imagen_amarillo.Visible = false; x = 0; } //.................................................................................. ..... } private void button2_Click(object sender, EventArgs e) { label1.Text = "Semaforo apagado"; timer1.Stop(); //apagar el timer TVicPort.SetPin(2, 0); //apagar el pin 2 TVicPort.SetPin(3, 0); //apagar el pin 3 TVicPort.SetPin(4, 0); //apagar el pin 4 TVicPort.CloseTVicPort(); //cierre del puerto }

You might also like