using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace z8094_1 { public partial class Form1 : Form { int step = 0;//show status text public Form1() { InitializeComponent(); MessageBox.Show("Please start your ISaGRAF application before press start button.", "Button Clicked", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); timer1.Interval = 250; timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { ScanProperties();//scan properties. ScanStatus();//for all X axis boolean status carible. switch_step(); } //status scan private void ScanStatus() { //Scan X axis D/I satus byte do_value; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(1), out do_value); if (do_value == 1) start.BackColor = Color.Red; else start.BackColor = Color.Black; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(2), out do_value); if (do_value == 1) limit_p.BackColor = Color.Red; else limit_p.BackColor = Color.Black; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(3), out do_value); if (do_value == 1) limit_n.BackColor = Color.Red; else limit_n.BackColor = Color.Black; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(4), out do_value); if (do_value == 1) home.BackColor = Color.Red; else home.BackColor = Color.Black; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(5), out do_value); if (do_value == 1) N_home.BackColor = Color.Red; else N_home.BackColor = Color.Black; Quicker.UserShare.UserGetCoil(Convert.ToUInt16(6), out do_value); if (do_value == 1) { Drill.BackColor = Color.Red; } else { Drill.BackColor = Color.Black; } Quicker.UserShare.UserGetCoil(Convert.ToUInt16(20), out do_value); if (do_value == 1) { emg.BackColor = Color.Red; step = -1; } else { emg.BackColor = Color.Black; } } private void ScanProperties() { int Value = 0; //scan properties /*get current position */ Quicker.UserShare.UserGetReg_Long(Convert.ToUInt16(7), out Value); logic_p.Text = Value.ToString(); //get start speed Quicker.UserShare.UserGetReg_Long(Convert.ToUInt16(9), out Value); st_sp.Text = Value.ToString(); /*get drive speed*/ Quicker.UserShare.UserGetReg_Long(Convert.ToUInt16(11), out Value); drive_sp.Text = Value.ToString(); //get search Home switch speed Quicker.UserShare.UserGetReg_Long(Convert.ToUInt16(13), out Value); search_sp.Text = Value.ToString(); //get how much pulse to move Quicker.UserShare.UserGetReg_Long(Convert.ToUInt16(15), out Value); pulse_mv.Text = Value.ToString(); //switch step show on StepStatus Quicker.UserShare.UserGetReg_Short(Convert.ToUInt16(17), out step); } private void button1_Click(object sender, EventArgs e) { //click then start motion Quicker.UserShare.UserSetCoil(Convert.ToUInt16(1), 1); } private void switch_step(){ int wait=0; switch (step) { case 0: StepStatus.Text = "Idleing."; break; case 1: StepStatus.Text = "Detecing Near-Home-Switch and Home-Switch."; break; case 2: Quicker.UserShare.UserGetReg_Short(Convert.ToUInt16(19), out wait); wait = wait / 1000; StepStatus.Text = "Reset pulse. wait "+wait.ToString() +" seconds"; break; case 3: StepStatus.Text = "now move to position 1."; position.Text = "100000"; break; case 4: Quicker.UserShare.UserGetReg_Short(Convert.ToUInt16(19), out wait); wait = wait / 1000; StepStatus.Text = "Drill work " + wait.ToString() + " seconds"; break; case 5: StepStatus.Text = "now move to position 2."; position.Text = "250000"; break; case 6: Quicker.UserShare.UserGetReg_Short(Convert.ToUInt16(19), out wait); wait = wait / 1000; StepStatus.Text = "Drill work " + wait.ToString() + " seconds"; break; case 7: StepStatus.Text = "now move to position 3."; position.Text = "120000"; break; case 8: Quicker.UserShare.UserGetReg_Short(Convert.ToUInt16(19), out wait); wait = wait / 1000; StepStatus.Text = "Drill for " + wait.ToString() + " seconds"; break; case 9: StepStatus.Text = "now back home!!"; break; default: StepStatus.Text = "error!!! Please check your ISaGRAF I/O connection or Manual."; break; } } private void Form1_Load(object sender, EventArgs e) { } } }