none
Como hace el puerto LTP tenga entrada de datos RRS feed

  • Pregunta

  • Buenas tarde es que tengo un problemita estoy haciendo un programa en el cual por medio de un boton se encienda un led´s salida son (2,3,4,5,6,7,8,9)pero tengo un problema cuando el  led´s me envie una señal al puerto  entrada son(10,11,12,13,15) no se  como hacer el programa ahora para que resiva la señal que le manda el led´s por favor les agradesco su ayuda programacion en c#

    Gracias

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Threading;
    using System.Timers;

    namespace Led
    {
        /// <summary>
        /// Summary description for Form1.
        /// </summary>
        public class Form1 : System.Windows.Forms.Form
        {
            private System.Windows.Forms.CheckBox checkBox_Pin1;
            private System.Windows.Forms.CheckBox checkBox_Pin2;
            private System.Windows.Forms.CheckBox checkBox_Pin3;
            private System.Windows.Forms.Button button_Reset_Leds;
            private System.ComponentModel.IContainer components;
            private System.Windows.Forms.PictureBox pictureBox_D2;
            private System.Windows.Forms.PictureBox pictureBox_D1;
            private System.Windows.Forms.PictureBox pictureBox_D0;
            public int i=0, j=0, adress = 888;


            public Form1()
            {
                //
                // Required for Windows Form Designer support
                //

                InitializeComponent();
                Reset_LEDs(); // Resets everything after form initialization
                //
                // TODO: Add any constructor code after InitializeComponent call
                //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                if( disposing )
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.checkBox_Pin1 = new System.Windows.Forms.CheckBox();
                this.checkBox_Pin2 = new System.Windows.Forms.CheckBox();
                this.checkBox_Pin3 = new System.Windows.Forms.CheckBox();
                this.button_Reset_Leds = new System.Windows.Forms.Button();
                this.pictureBox_D2 = new System.Windows.Forms.PictureBox();
                this.pictureBox_D1 = new System.Windows.Forms.PictureBox();
                this.pictureBox_D0 = new System.Windows.Forms.PictureBox();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D2)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D0)).BeginInit();
                this.SuspendLayout();
                //
                // checkBox_Pin1
                //
                this.checkBox_Pin1.Location = new System.Drawing.Point(400, 40);
                this.checkBox_Pin1.Name = "checkBox_Pin1";
                this.checkBox_Pin1.Size = new System.Drawing.Size(56, 24);
                this.checkBox_Pin1.TabIndex = 1;
                this.checkBox_Pin1.Text = "D0";
                this.checkBox_Pin1.CheckedChanged += new System.EventHandler(this.onCheckBoxClick);
                //
                // checkBox_Pin2
                //
                this.checkBox_Pin2.Location = new System.Drawing.Point(344, 40);
                this.checkBox_Pin2.Name = "checkBox_Pin2";
                this.checkBox_Pin2.Size = new System.Drawing.Size(56, 24);
                this.checkBox_Pin2.TabIndex = 2;
                this.checkBox_Pin2.Text = "D1";
                this.checkBox_Pin2.CheckedChanged += new System.EventHandler(this.onCheckBoxClick);
                //
                // checkBox_Pin3
                //
                this.checkBox_Pin3.Location = new System.Drawing.Point(288, 40);
                this.checkBox_Pin3.Name = "checkBox_Pin3";
                this.checkBox_Pin3.Size = new System.Drawing.Size(56, 24);
                this.checkBox_Pin3.TabIndex = 3;
                this.checkBox_Pin3.Text = "D2";
                this.checkBox_Pin3.CheckedChanged += new System.EventHandler(this.onCheckBoxClick);
                //
                // button_Reset_Leds
                //
                this.button_Reset_Leds.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                this.button_Reset_Leds.Location = new System.Drawing.Point(368, 104);
                this.button_Reset_Leds.Name = "button_Reset_Leds";
                this.button_Reset_Leds.Size = new System.Drawing.Size(75, 23);
                this.button_Reset_Leds.TabIndex = 9;
                this.button_Reset_Leds.Text = "Reset Leds";
                this.button_Reset_Leds.Click += new System.EventHandler(this.button_Reset_Leds_Click);
                //
                // pictureBox_D2
                //
                this.pictureBox_D2.Location = new System.Drawing.Point(288, 8);
                this.pictureBox_D2.Name = "pictureBox_D2";
                this.pictureBox_D2.Size = new System.Drawing.Size(24, 24);
                this.pictureBox_D2.TabIndex = 18;
                this.pictureBox_D2.TabStop = false;
                //
                // pictureBox_D1
                //
                this.pictureBox_D1.Location = new System.Drawing.Point(344, 8);
                this.pictureBox_D1.Name = "pictureBox_D1";
                this.pictureBox_D1.Size = new System.Drawing.Size(24, 24);
                this.pictureBox_D1.TabIndex = 19;
                this.pictureBox_D1.TabStop = false;
                //
                // pictureBox_D0
                //
                this.pictureBox_D0.Location = new System.Drawing.Point(400, 8);
                this.pictureBox_D0.Name = "pictureBox_D0";
                this.pictureBox_D0.Size = new System.Drawing.Size(24, 24);
                this.pictureBox_D0.TabIndex = 20;
                this.pictureBox_D0.TabStop = false;
                //
                // Form1
                //
                this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                this.ClientSize = new System.Drawing.Size(448, 158);
                this.Controls.Add(this.pictureBox_D0);
                this.Controls.Add(this.pictureBox_D1);
                this.Controls.Add(this.pictureBox_D2);
                this.Controls.Add(this.button_Reset_Leds);
                this.Controls.Add(this.checkBox_Pin3);
                this.Controls.Add(this.checkBox_Pin2);
                this.Controls.Add(this.checkBox_Pin1);
                this.MaximizeBox = false;
                this.Name = "Form1";
                this.Text = "Controlling LEDs with Parallel Port";
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D2)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D1)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox_D0)).EndInit();
                this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.Run(new Form1());
            }
     
            private void Reset_LEDs() // Makes all the data pins low so the LED's turned off
            {
                PortAccess.Output(adress, 0);
                PortAccess.Input(adress);
            }
           
           
            #region LED Picture Loadings
            private void LoadNewPict_D0()
            {

                string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
                this.pictureBox_D0.Image = Image.FromFile (path);
            }

            private void LoadNewPict_D1()
            {

                string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
                this.pictureBox_D1.Image = Image.FromFile (path);
            }

            private void LoadNewPict_D2()
            {
               
                string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
                this.pictureBox_D2.Image = Image.FromFile (path);
            }

            //private void LoadNewPict_D3()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
            //    this.pictureBox_D3.Image = Image.FromFile (path);
            //}

            //private void LoadNewPict_D4()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
            //    this.pictureBox_D4.Image = Image.FromFile (path);
            //}

            //private void LoadNewPict_D5()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
            //    this.pictureBox_D5.Image = Image.FromFile (path);
            //}

            //private void LoadNewPict_D6()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
            //    this.pictureBox_D6.Image = Image.FromFile (path);
            //}

            //private void LoadNewPict_D7()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\on.gif";
            //    this.pictureBox_D7.Image = Image.FromFile (path);
            //}
           
           
            private void LoadOldPict_D0()
            {
               
                string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
                this.pictureBox_D0.Image = Image.FromFile (path);
            }
           
            private void LoadOldPict_D1()
            {
               
                string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
                this.pictureBox_D1.Image = Image.FromFile (path);
            }
           
            private void LoadOldPict_D2()
            {
               
                string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
                this.pictureBox_D2.Image = Image.FromFile (path);
            }

            //private void LoadOldPict_D3()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
            //    this.pictureBox_D3.Image = Image.FromFile (path);
            //}

            //private void LoadOldPict_D4()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
            //    this.pictureBox_D4.Image = Image.FromFile (path);
            //}

            //private void LoadOldPict_D5()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
            //    this.pictureBox_D5.Image = Image.FromFile (path);
            //}

            //private void LoadOldPict_D6()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
            //    this.pictureBox_D6.Image = Image.FromFile (path);
            //}

            //private void LoadOldPict_D7()
            //{
               
            //    string path = @"C:\Documents and Settings\Camil\Escritorio\222\off.gif";
            //    this.pictureBox_D7.Image = Image.FromFile (path);
            //}
           
            #endregion
           
            void onCheckBoxClick(object sender, EventArgs e) //For checkboxes and the imageboxes you can also use a loop here
            {
                int value = 0;

                if(checkBox_Pin1.Checked)
                {
                    value += (int)Math.Pow(2,0);
                    LoadNewPict_D0();
                }
                else
                    LoadOldPict_D0();
                value += 0;

                if(checkBox_Pin2.Checked)
                {
                    value += (int)Math.Pow(2,1);
                    LoadNewPict_D1();
                }
                else
                    LoadOldPict_D1();
                value += 0;
               
                if(checkBox_Pin3.Checked)
                {
                    value += (int)Math.Pow(2,2);
                    LoadNewPict_D2();
                }
                else
                    LoadOldPict_D2();
                value += 0;
                   
                //if(checkBox_Pin4.Checked)
                //{
                //    value += (int)Math.Pow(2,3);
                //    LoadNewPict_D3();
                //}
                //else
                //    LoadOldPict_D3();
                //value += 0;
                   
                //if(checkBox_Pin5.Checked)
                //{
                //    value += (int)Math.Pow(2,4);
                //    LoadNewPict_D4();
                //}
                //else
                //    LoadOldPict_D4();
                //value += 0;
                   
                //if(checkBox_Pin6.Checked)
                //{
                //    value += (int)Math.Pow(2,5);
                //    LoadNewPict_D5();
                //}
                //else
                //    LoadOldPict_D5();
                //value += 0;
               
                //if(checkBox_Pin7.Checked)
                //{
                //    value += (int)Math.Pow(2,6);
                //    LoadNewPict_D6();
                //}
                //else
                //    LoadOldPict_D6();
                //value += 0;
                   
                //if(checkBox_Pin8.Checked)
                //{
                //    value += (int)Math.Pow(2,7);
                //    LoadNewPict_D7();
                //}
                //else
                //    LoadOldPict_D7();
                //value += 0;


                PortAccess.Output(adress, value);
            }
           

            //private void button_Send_Bits_Click(object sender, System.EventArgs e) // Sends decimal to data pins
            //{
            //    PortAccess.Output(adress, Int32.Parse(this.textBox_byte.Text));
            //}

            private void button_Reset_Leds_Click(object sender, System.EventArgs e) // Unchecks the checkboxes and reset leds
            {
                j=0; i=0;
                Reset_LEDs();
                //checkBox_Pin8.Checked = false;
                //checkBox_Pin7.Checked = false;
                //checkBox_Pin6.Checked = false;
                //checkBox_Pin5.Checked = false;
                //checkBox_Pin4.Checked = false;
                checkBox_Pin3.Checked = false;
                checkBox_Pin2.Checked = false;
                checkBox_Pin1.Checked = false;
            }

            //void dance_LEDs(object o2, EventArgs e2) //Gives a motion to the LEDs
            //{
            //    if(j<9)
            //    {
            //        switch(j)
            //        {
            //            case 0:
            //                PortAccess.Output(888, 24);
            //                break;
            //            case 1:
            //                PortAccess.Output(888, 36);
            //                break;
            //            case 2:
            //                PortAccess.Output(888, 66);
            //                break;
            //            case 3:
            //                PortAccess.Output(888, 129);
            //                break;
            //            case 4:
            //                PortAccess.Output(888, 0);
            //                break;
            //            case 5:
            //                PortAccess.Output(888, 129);
            //                break;
            //            case 6:
            //                PortAccess.Output(888, 195);
            //                break;
            //            case 7:
            //                PortAccess.Output(888, 231);
            //                break;
            //            case 8:
            //                PortAccess.Output(888, 255);
            //                break;
            //        }
            //    }
            //    else
            //    {
            //        ((System.Windows.Forms.Timer)o2).Stop();
            //        ((System.Windows.Forms.Timer)o2).Tick -= new EventHandler(dance_LEDs);
            //    }
            //    j+=1;
            //}
           
           
            //private void button_Dance_Click(object sender, System.EventArgs e) // Executes the timer and dance LEDs function
            //{
            //    System.Windows.Forms.Timer timer02 = new System.Windows.Forms.Timer();
            //    timer02.Interval = 200;
            //    timer02.Tick += new EventHandler(dance_LEDs);
            //    timer02.Enabled = true;

            //}

            //void count_binary(object o1, EventArgs e1) //Makes the leds counting in binary form
            //{
               
            //    if(i<256)
            //    {
            //        PortAccess.Output(adress, i);
            //        i+=1;
            //    }
            //    else
            //    {
            //        ((System.Windows.Forms.Timer)o1).Stop();
            //        ((System.Windows.Forms.Timer)o1).Tick -= new EventHandler(count_binary);
            //    }
            //}

            //private void button_Count_Click(object sender, System.EventArgs e) //Activates the timer for bnary counting delays
            //{
            //    System.Windows.Forms.Timer timer01 = new System.Windows.Forms.Timer();
            //    timer01.Interval = 100;
            //    timer01.Tick += new EventHandler(count_binary);
            //    timer01.Enabled = true;
            //}

            //private void button_Address_Click(object sender, System.EventArgs e) //Sets the parallel port address for the program to run
            //{
            //    if(this.textBox_port_adress.Text == "378")
            //        adress = 888;
            //    else
            //        adress = 632;
            //}

            //private void linkLabel1_LinkClicked_1(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
            //{
            //    // Change the color of the link text by setting LinkVisited
            //    // to True.
            //    linkLabel1.LinkVisited = true;
      
            //    // Call the Process.Start method to open the default browser
            //    // with a URL:
            //    System.Diagnostics.Process.Start("mailto:ls@izdir.com");
            //}
       
        }
    }

    domingo, 19 de septiembre de 2010 19:40