Exemple #1
0
        public async Task StartJob(string JobName)
        {
            if (m_commsError)
            {
                return;
            }

            if (!JobName.ToLower().Contains(".jbi"))
            {
                SetError("Error *.jbi jobname extension is missing !");
                return;
            }

            await TaskEx.WaitUntil(isIdle);

            SetEvent("StartJob");
            short ret;

            ret = CMotocom.BscSelectJob(m_Handle, JobName);
            if (ret == 0)
            {
                if (await IsReadyToOperate())
                {
                    ret = CMotocom.BscStartJob(m_Handle);
                    if (ret != 0)
                    {
                        SetError("Error starting job !");
                    }
                }

                //ret = CMotocom.BscServoOn(m_Handle);
                //if (ret != 0) SetError("Error executing BscServoON err:" + ret.ToString());
                //else
                //{
                //    ret = CMotocom.BscStartJob(m_Handle);
                //    if (ret != 0) SetError("Error starting job !");
                //}
            }
            else
            {
                SetError("Error selecting job !");
            }

            SetEvent(EnumEvent.Idle);
        }
Exemple #2
0
        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);
        }