private async Task <bool> IsReadyToOperate() { short ret = 0; if (robotStatus.isServoOn) { if (robotStatus.isOperating) { // stop any current jobs await Task.Delay(commsDelay_mm); ret = CMotocom.BscHoldOn(m_Handle); if (ret != 0) { SetError("Error IsReadyToOperate:BscHoldOn"); return(false); } else { await Task.Delay(commsDelay_mm); ret = CMotocom.BscHoldOff(m_Handle); if (ret != 0) { SetError("Error IsReadyToOperate:BscHoldOff"); return(false); } else { return(true); } } } else { return(true); } } else { SetError("Error MoveToPosition: SERVO is OFF"); return(false); } }
//private async Task MoveToPosition(double[] posVar, decimal speedSP) //{ // await TaskEx.WaitUntil(isIdle); // SetEvent("MoveToPosition"); // short ret = 0; // StringBuilder vType = new StringBuilder("V"); // VR; // double speed = (speedSP > 300) ? 300 : ((speedSP < 0) ? 0 : (double)speedSP); // is VJ=20.00 // StringBuilder framename = new StringBuilder("TOOL"); // ROBOT BASE // short toolNo = 0; // double[] pos = (posVar != null) ? posVar : new double[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // //if (posVar != null) pos = new double[] { posVar.X, posVar.Y, posVar.Z, posVar.Rx, posVar.Ry, posVar.Rz, 0, 0, 0, 0, 0, 0 }; // //short form = (short)Convert.ToInt32("0", 2); ; // Bits: 0 No-flip, 1 elbow under, 2 Back side, 3 R>=180, 4 T>=180, S>=180 // if (IsReadyToOperate()) // { // ret = CMotocom.BscImov(m_Handle, vType, speed, framename, toolNo, ref pos[0]); // if (ret != 0) SetError("Error MoveToPosition:BscMovj"); // } // SetError("NOT ERROR: finished moving."); // SetEvent(EnumEvent.Idle); // //void moveRobot() { // // ret = (isHome) ? // // CMotocom.BscPMovj(m_Handle, 30, toolNo, ref homePosPulse[0]) : // // CMotocom.BscImov(m_Handle, vType, speed, framename, toolNo, ref pos[0]); // // if (ret != 0) SetError("Error MoveToPosition:BscMovj"); // //} //} public async Task CancelOperation() { await TaskEx.WaitUntil(isIdle); SetEvent("CancelOperation"); short ret = 0; ret = CMotocom.BscHoldOn(m_Handle); if (ret != 0) { SetError("Error CancelOperation:BscHoldOn"); } else { ret = CMotocom.BscHoldOff(m_Handle); if (ret != 0) { SetError("Error CancelOperation:BscHoldOff"); } } await SetEvent(EnumEvent.Idle); }