2
Reply

parallel port addressing

Gunnar

Gunnar

Aug 25 2008 11:46 PM
7.2k

Hello everyone,

I found a program on the net that lets me set parallel port pins hi/low. I modified it to my needs and it works fine. The problem came when I bought another parallel port , it was a pci card and the addressing is different. Instead of 378, I have E000. I tried to change parts of the code to match my new addresses but I can't find the ports now. Does anyone know why?

Below is the original working code, you will need inpout32.dll to play with it. Any takers?

 

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


namespace Led
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.TextBox textBox_port_adress;
        private System.Windows.Forms.Button button_Address;
        public int i = 0, j = 0, b = 1, 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.textBox_port_adress = new System.Windows.Forms.TextBox();
            this.button_Address = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.button7 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // textBox_port_adress
            //
            this.textBox_port_adress.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.textBox_port_adress.Location = new System.Drawing.Point(8, 83);
            this.textBox_port_adress.Name = "textBox_port_adress";
            this.textBox_port_adress.Size = new System.Drawing.Size(33, 20);
            this.textBox_port_adress.TabIndex = 22;
            this.textBox_port_adress.Text = "378";
            //
            // button_Address
            //
            this.button_Address.FlatAppearance.BorderSize = 0;
            this.button_Address.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.button_Address.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button_Address.Location = new System.Drawing.Point(44, 73);
            this.button_Address.Margin = new System.Windows.Forms.Padding(0);
            this.button_Address.Name = "button_Address";
            this.button_Address.Size = new System.Drawing.Size(41, 41);
            this.button_Address.TabIndex = 23;
            this.button_Address.Text = "Apply Address";
            this.button_Address.Click += new System.EventHandler(this.button_Address_Click);
            //
            // button6
            //
            this.button6.Location = new System.Drawing.Point(136, 55);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(32, 23);
            this.button6.TabIndex = 38;
            this.button6.Text = "UP";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.UP_start);
            this.button6.MouseUp += new System.Windows.Forms.MouseEventHandler(this.UP_stop);
            //
            // button7
            //
            this.button7.Location = new System.Drawing.Point(136, 103);
            this.button7.Name = "button7";
            this.button7.Size = new System.Drawing.Size(33, 23);
            this.button7.TabIndex = 39;
            this.button7.Text = "DN";
            this.button7.UseVisualStyleBackColor = true;
            this.button7.MouseDown += new System.Windows.Forms.MouseEventHandler(this.DN_start);
            this.button7.MouseUp += new System.Windows.Forms.MouseEventHandler(this.DN_stop);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(211, 199);
            this.Controls.Add(this.button7);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.button_Address);
            this.Controls.Add(this.textBox_port_adress);
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.Text = "Controlling LEDs with Parallel Port";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }


        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;
        }
        public class PortAccess
        {
            [DllImport("inpout32.dll", EntryPoint = "Out32")]
            public static extern void Output(int adress, int value);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
            
        private Button button6;
        private Button button7;

      
        private void UP_start(object sender, MouseEventArgs e)
        {
            PortAccess.Output(adress, 223);
        }

        private void UP_stop(object sender, MouseEventArgs e)
        {
            PortAccess.Output(adress, 255);
        }

        private void DN_start(object sender, MouseEventArgs e)
        {
            PortAccess.Output(adress, 191);
        }

        private void DN_stop(object sender, MouseEventArgs e)
        {
            PortAccess.Output(adress, 255);
        }
      
    }

 }


Answers (2)