private void ServoCommand(double position) { if (ARM_MIN < position && position < ARM_MAX) { if (servo.Attached) { try { servo.Engaged = true; AsyncCallback asyncCallBackDelegate = new AsyncCallback(AsyncCallBackForSetTargetPosition); CallBackInfo callBackInfo = new CallBackInfo(servo, position); TargetPosition = position; IsAtSetpoint = false; UpdateArmSetpointUI(TargetPosition); servo.BeginSetTargetPosition(position, asyncCallBackDelegate, callBackInfo); } catch (Exception e) { Debug.WriteLine($"Phidget command failed with msg {e}"); } } else { Debug.WriteLine("Servo not connected"); } } else { Debug.WriteLine($"Postion {position} out of bounds {ARM_MIN}-{ARM_MAX}"); } }
private void AsyncCallBackForSetTargetPosition(IAsyncResult result) { try { CallBackInfo callBackInfo = (CallBackInfo)result.AsyncState; callBackInfo.Owner.EndSetTargetPosition(result); } catch (Exception exp) { Debug.WriteLine($"Servo command callback error {exp}"); } }