Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C#

Controlling Floppy Drive Stepper Motor via Parallel Port

Rate me:
Please Sign up or sign in to vote.
4.92/5 (80 votes)
15 Mar 200710 min read 438.2K   10.2K   140  
Controlling a floppy drive stepper motor using computer's parallel port
/* --------------------------------------------------------------------
 * Floppy Drive Stepper Motor Control Code
 * Written by: Ashish Derhgawen
 * E-mail: ashish.derhgawen@gmail.com
 * Web: http://ashishrd.blogspot.com
 * 
 * This code is provided without implied warranty so the author
 * is not responsible for any damages caused  by the use of the code.
 --------------------------------------------------------------------*/

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

namespace FloppyStepper
{
    public partial class MainForm : Form
    {
        private int adress = 888;
        
        public MainForm()
        {
            InitializeComponent();
        }

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

        #region Events
        private void stepperMoveButton1_Click(object sender, EventArgs e)
        {
            MoveStepper(int.Parse(stepTextBox.Text), int.Parse(delayTextBox.Text), 1, 0);
        }

        
        private void stepperMoveButton2_Click(object sender, EventArgs e)
        {
            MoveStepper(int.Parse(stepTextBox.Text), int.Parse(delayTextBox.Text), 3, 2);
        }

        
        private void applyButton_Click(object sender, EventArgs e)
        {
            if (this.adressTextBox.Text == "378")
                adress = 888;
            else
                adress = 632;
        }


        private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("IExplore", "http://ashishrd.blogspot.com");
        }
        #endregion

        private void MoveStepper(int steps, int delay, Int32 onValue, Int32 offValue)
        {
            for (int i = 0; i < steps; i++)
            {
                Application.DoEvents();
                PortAccess.Output(adress, onValue);
                Thread.Sleep(delay);
                PortAccess.Output(adress, offValue);
                Thread.Sleep(delay);
            }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
India India

Comments and Discussions