public Motor GenerateMotor(Guid channelId, string channelName, string positionName, PositionLocation positionLocation) { int drivePin = (new Random()).Next(0, 40); int groundPin = (new Random()).Next(0, 40); MotorPosition motorPosition = new MotorPosition(positionName, positionLocation); Motor motor = new Motor(channelId, channelName, drivePin, groundPin, motorPosition); return(motor); }
/// <summary> /// Poll for axis motor status and update appropriate motor position and /// status controls. Must be called periodically to keep controls up to date. /// </summary> public void UpdateAxis() { int regVal; if (MyController.Connected) { try { int status = MyController.Read(Controller.regStatus_1 + RegOffset); if (MyController.ProductID == PRODUCT_GEN_2_CONTROLLER) { groupBoxAxis.Text = Axis == 0 ? ZOOM_STR : FOCUS_STR; if (((uint)status & STATUS_BITS_INSUFFICIENT_VOLTAGE) != 0) { groupBoxAxis.Text += " ("; groupBoxAxis.Text += INSUFFICIENT_VOLTAGE_STR; groupBoxAxis.Text += " )"; } // If this is a Gen 2 two-phase controller, then the motor type should be identifible. else if ((MyController.ProductSubclass == 2) || (MyController.ProductSubclass == 3) || (MyController.ProductSubclass == 1) || (MyController.ProductSubclass == (unchecked ((int)0xffffffd9)))) { uint motorId = ((uint)status & STATUS_MOTOR_TYPE_BITS) >> STATUS_MOTOR_TYPE_SHIFT; groupBoxAxis.Text += " ("; switch (motorId) { case TWO_PHASE_AM0820_MOTOR: groupBoxAxis.Text += AM0820_MOTOR_STR; break; case TWO_PHASE_AM1524_MOTOR: groupBoxAxis.Text += AM1524_MOTOR_STR; break; case TWO_PHASE_UNKNOWN_MOTOR: // Intentional fall through case TWO_PHASE_UNKNOWN_OPEN_SHORT: // Intentional fall through default: groupBoxAxis.Text += UNKNOWN_MOTOR_STR; break; } groupBoxAxis.Text += ")"; } } Idle = (((uint)status & 0x000000ff) == 0) ? true : false; buttonAtHome.BackColor = (((uint)status & 0x00000100) != 0) ? Color.Red : Color.LightGray; buttonAtLimit.BackColor = (((uint)status & 0x00000200) != 0) ? Color.Red : Color.LightGray; // Fetch motor limit position value. regVal = MyController.Read(Controller.regSetupLimit_1 + RegOffset); if (regVal == 0) { this.Enabled = false; return; } else { this.Enabled = true; } if (MotorLimit != regVal) { MotorLimit = regVal; this.textBoxLimit.Text = MotorLimit.ToString(); this.numericUpDownStepMin.Minimum = 1; this.numericUpDownStepMin.Maximum = MotorLimit / 10; this.numericUpDownStepMin.Value = MotorLimit / 100; this.numericUpDownStepMax.Minimum = 1; this.numericUpDownStepMax.Maximum = MotorLimit / 4; this.numericUpDownStepMax.Value = MotorLimit / 10; this.numericUpDownTarget1.Minimum = 0; this.numericUpDownTarget1.Maximum = MotorLimit; this.numericUpDownTarget2.Minimum = 0; this.numericUpDownTarget2.Maximum = MotorLimit; this.numericUpDownTarget3.Minimum = 0; this.numericUpDownTarget3.Maximum = MotorLimit; this.numericUpDownTarget4.Minimum = 0; this.numericUpDownTarget4.Maximum = MotorLimit; this.vProgressPosition.Maximum = MotorLimit; this.vProgressPosition.Minimum = 0; //regVal = MyController.Read(Controller.regTarget_1 + RegOffset); //SetTargetPostion(regVal); } MotorPosition = MyController.Read(Controller.regCurrent_1 + RegOffset); vProgressPosition.Value = Math.Min(Math.Max(0, MotorPosition), vProgressPosition.Maximum); textBoxPosition.Text = MotorPosition.ToString(); if (AutoStepping) { if (MotorTarget == MotorPosition || Idle) { if (numericUpDownDwellTime.Value == 0) { AutoStep(); } else if (!timerDwell.Enabled) { timerDwell.Interval = (int)numericUpDownDwellTime.Value * 1000; timerDwell.Start(); } } } if (Idle) { if (HomeRequested) { HomeRequested = false; MyController.Write(Controller.regLimit_1 + RegOffset, 0); } else if (LimitRequested) { LimitRequested = false; MyController.Write(Controller.regLimit_1 + RegOffset, 1); } else if (MoveRequested) { MoveRequested = false; MyController.Write(Controller.regTarget_1 + RegOffset, MotorTarget); } else if (!AutoStepping) { MotorTarget = MotorPosition; } } } catch (Exception) { } } else { Stop(); this.Enabled = false; } }