private async Task WritePositionVariable(short Index, CRobPosVar PosVar) { if (m_commsError) { return; } await TaskEx.WaitUntil(isIdle); SetEvent("WritePositionVariable"); Console.WriteLine("X is " + PosVar.X.ToString()); StringBuilder StringVal = new StringBuilder(256); double[] PosVarArray = PosVar.HostGetVarDataArray; short ret = CMotocom.BscHostPutVarData(m_Handle, 4, Index, ref PosVarArray[0], StringVal); if (ret != 0) { SetError("Error executing WritePositionVariable"); } await SetEvent(EnumEvent.Idle); }
public async Task MoveByJob(bool isHome, CRobPosVar position = null) { if (isHome) { await MoveToHome1(); return; } if (position == null) { return; } await TaskEx.WaitUntil(isIdle); SetEvent("MoveByJob"); short ret = 0; string moveHomeJob = "TO_POS_0.jbi"; double[] speed = new double[10]; speed[0] = 2000; // is VJ=20.00 short varNo = 0; //// stop any current jobs //ret = CMotocom.BscHoldOn(m_Handle); //if (ret != 0) SetError("Error MoveToPosition:BscHoldOn"); //else //{ // write position at varNo StringBuilder StringVal = new StringBuilder(256); double[] PosVarArray = position.HostGetVarDataArray; ret = CMotocom.BscHostPutVarData(m_Handle, 4, varNo, ref PosVarArray[0], StringVal); if (ret != 0) { SetError("Error executing MoveToPosition:WritePositionVariable"); } else { // read position at varNo StringVal = new StringBuilder(256); double[] readPosition = new double[10]; ret = CMotocom.BscHostGetVarData(m_Handle, 4, varNo, ref readPosition[0], StringVal); if (ret != 0) { SetError("Error executing MoveToPosition:ReadPositionVariable"); } else { // compare the set home position with read from robot if (!readPosition.SequenceEqual(position.HostGetVarDataArray)) { SetError("MoveToPosition: arrays are not equal."); } else { ret = CMotocom.BscPutVarData(m_Handle, 1, varNo, ref speed[0]); if (ret != 0) { SetError("Error executing MoveToPosition:ReadByteVariable"); } else { // select job ret = CMotocom.BscSelectJob(m_Handle, moveHomeJob); if (ret != 0) { SetError("Error selecting job at MoveToPosition"); } else { // run the job ret = CMotocom.BscStartJob(m_Handle); if (ret != 0) { SetError("Error starting job at MoveToPosition!"); } } } } } } //} await SetEvent(EnumEvent.Idle); }