コード例 #1
0
        bool WaitForLongtimeOperation(int AxisIndex, byte CommandOrderExpected, out AxisStateReport AxisState)
        {
            bool     timeout      = false;
            int      lastPosition = 0;
            DateTime reqStart     = DateTime.Now;

            do
            {
                if (RequestAxisState(AxisIndex, out AxisState))
                {
                    var axisStateInReport = HidReport.AxisStateCollection[AxisIndex];
                    axisStateInReport.IsRunning   = AxisState.IsRunning;
                    axisStateInReport.IsHomed     = AxisState.IsHomed;
                    axisStateInReport.AbsPosition = AxisState.AbsPosition;
                    axisStateInReport.Error       = AxisState.Error;

                    OnReportUpdated?.Invoke(this, HidReport);

                    // Check whether the home process is alive
                    if (lastPosition != AxisState.AbsPosition)
                    {
                        reqStart     = DateTime.Now;
                        lastPosition = AxisState.AbsPosition;
                    }

                    //Trace.WriteLine(string.Format("{0:mm:ss.ffffff}\tCommandOrder in Report {1}, Desired {2} ...", DateTime.Now, AxisState.CommandOrder, CommandOrderExpected));

                    if (AxisState.CommandOrder == CommandOrderExpected)
                    {
                        // the operation is done
                        break;
                    }
                }

                // check if it's timeout
                if ((DateTime.Now - reqStart).TotalSeconds > 5)
                {
                    timeout = true;
                    break;
                }

                Thread.Sleep(20);
            } while (true);

            if (timeout)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        bool RequestAxisState(int AxisIndex, out AxisStateReport AxisState)
        {
            bool ret = false;

            AxisState = new AxisStateReport();
            lockUSBPort.Wait();


            //Trace.WriteLine(string.Format("Thread {0}, Enter request axis {1} ...", Thread.CurrentThread.ManagedThreadId, AxisIndex));
            try
            {
                CommandStruct cmd = new CommandStruct()
                {
                    Command   = EnumCommand.REQ_AXIS_STATE,
                    AxisIndex = AxisIndex
                };

                if (hidPort.WriteData(cmd.ToBytes()))
                {
                    var buff = hidPort.ReadData();
                    if (buff != null)
                    {
                        if (buff[0] == REPORT_ID_AXISSTATE)
                        {
                            var buffAvailable = new byte[buff.Length - 1];
                            Buffer.BlockCopy(buff, 1, buffAvailable, 0, buffAvailable.Length);
                            AxisState.Parse(buffAvailable);

                            ret = true;
                        }
                    }
                }
            }
            catch
            {
                ret = false;
            }
            finally
            {
                lockUSBPort.Release();
            }
            //Trace.WriteLine(string.Format("Thread {0}, Exit request ...", Thread.CurrentThread.ManagedThreadId));
            return(ret);
        }
コード例 #3
0
        public object Clone()
        {
            AxisStateReport state = new AxisStateReport
            {
                AbsPosition = this.AbsPosition,
                AxisIndex   = this.AxisIndex,
                IsHomed     = this.IsHomed,
                IsRunning   = this.IsRunning,
                Error       = this.Error,
                CWLS        = this.CWLS,
                CCWLS       = this.CCWLS,
                ORG         = this.ORG,
                ZeroOut     = this.ZeroOut,
                IN_A        = this.IN_A,
                IN_B        = this.IN_B,
                OUT_A       = this.OUT_A,
                OUT_B       = this.OUT_B
            };

            return(state);
        }