/// <summary> Homes the given device. </summary> /// <param name="device"> The device. </param> public static bool Home_1(IGenericAdvancedMotor device) { Console.WriteLine("Homing device"); // create wait handler ManualResetEvent waitEvent = new ManualResetEvent(false); waitEvent.Reset(); // clear errors device.ClearDeviceExceptions(); // call home function, passing in event handler // could alternatively use method with in-built wait handler by passing a timeout instead of callback device.Home(p => waitEvent.Set()); if (!waitEvent.WaitOne(60000)) { // timed out return(false); } // check for exceptions thrown by background thread during process device.ThrowLastDeviceException(); // check status bool homed = device.Status.IsHomed; Console.WriteLine("Device Homed"); return(true); }
/// <summary> Move to. </summary> /// <param name="device"> The device. </param> /// <param name="position"> The position. </param> /// <param name="deviceUnitConverter"> The device unit converter. </param> public static bool MoveTo_1(IGenericAdvancedMotor device, decimal position, DeviceUnitConverter deviceUnitConverter) { // create wait handler ManualResetEvent waitEvent = new ManualResetEvent(false); int iPos = deviceUnitConverter.RealToDeviceUnit(position, DeviceUnitConverter.UnitType.Length); Console.WriteLine("Moving Device to {0} ({1})", position, iPos); // call moveto function, passing in event handler // could alternatively use method with in-built wait handler by passing a timeout instead of callback waitEvent.Reset(); // clear errors device.ClearDeviceExceptions(); device.MoveTo_DeviceUnit(iPos, p => { Console.WriteLine("Message Id {0}", p); waitEvent.Set(); }); if (!waitEvent.WaitOne(60000)) { return(false); } // check for exceptions thrown by background thread during process device.ThrowLastDeviceException(); StatusBase status = device.Status; Decimal newPos = status.Position; Console.WriteLine("Device Moved to {0}({1})", newPos, position); return(true); }