Hi all,
I'm currently writing a program to control a device over the parallel
port using a slider control. (it's a small motor that runs over the 5v
+ve line), however although it is fine powering on and increasing the
speed, it won't decrease.
I've included the relevant source code below and look forward to hearing
how to get this. I'm sure it's easy, but I'm just not sure how to do it!
Cheers,
Matt
------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Control_e_appliances
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
int val=0;
private AxHWINTERFACELib.AxHwinterface axHwinterface1;
private System.Windows.Forms.TrackBar speed;
private System.Windows.Forms.TextBox txtSpeed;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
axHwinterface1.OutPort(888,0);
//
// 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()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.axHwinterface1 = new AxHWINTERFACELib.AxHwinterface();
this.speed = new System.Windows.Forms.TrackBar();
this.txtSpeed = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.axHwinterface1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.speed)).BeginInit();
this.SuspendLayout();
//
// axHwinterface1
//
this.axHwinterface1.Enabled = true;
this.axHwinterface1.Location = new System.Drawing.Point(584,
32);
this.axHwinterface1.Name = "axHwinterface1";
this.axHwinterface1.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axHwinterface1.OcxState")));
this.axHwinterface1.Size = new System.Drawing.Size(16, 24);
this.axHwinterface1.TabIndex = 0;
//
// speed
//
this.speed.Location = new System.Drawing.Point(16, 16);
this.speed.Name = "speed";
this.speed.Orientation =
System.Windows.Forms.Orientation.Vertical;
this.speed.Size = new System.Drawing.Size(42, 248);
this.speed.TabIndex = 10;
this.speed.Scroll += new System.EventHandler(this.speed_Scroll);
//
// txtSpeed
//
this.txtSpeed.Location = new System.Drawing.Point(112, 16);
this.txtSpeed.Name = "txtSpeed";
this.txtSpeed.TabIndex = 11;
this.txtSpeed.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(72, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 12;
this.label2.Text = "speed:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(80, 48);
this.label1.Name = "label1";
this.label1.TabIndex = 13;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(618, 287);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtSpeed);
this.Controls.Add(this.speed);
this.Controls.Add(this.axHwinterface1);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Control electical appliances";
((System.ComponentModel.ISupportInitialize)(this.axHwinterface1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.speed)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void IO(int bit)
{
val=axHwinterface1.InPort(888);
axHwinterface1.OutPort(888,(short)(val|bit));
label1.Text=axHwinterface1.InPort(888).ToString();
}
private void speed_Scroll(object sender, System.EventArgs e)
{
this.txtSpeed.Text = this.speed.Value.ToString();
IO(int.Parse(this.speed.Value.ToString())* 25);
}
}
}
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/