/// <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); }
/// <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_3(IGenericAdvancedMotor device, decimal position, DeviceUnitConverter deviceUnitConverter) { int iPos = deviceUnitConverter.RealToDeviceUnit(position, DeviceUnitConverter.UnitType.Length); Console.WriteLine("Moving Device to {0} ({1})", position, iPos); device.MoveTo_DeviceUnit(iPos, 60000); StatusBase status = device.Status; Decimal newPos = status.Position; Console.WriteLine("Device Moved to {0}({1})", newPos, position); 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_2(IGenericAdvancedMotor device, decimal position, DeviceUnitConverter deviceUnitConverter) { int iPos = deviceUnitConverter.RealToDeviceUnit(position, DeviceUnitConverter.UnitType.Length); Console.WriteLine("Moving Device to {0} ({1})", position, iPos); // call moveto function, passing in message complete handler provided by device Action <UInt64> workDone = device.InitializeWaitHandler(); device.MoveTo_DeviceUnit(iPos, workDone); device.Wait(60000); StatusBase status = device.Status; Decimal newPos = status.Position; Console.WriteLine("Device Moved to {0}({1})", newPos, position); return(true); }