Exemple #1
0
        void HandleStatusLine(string line)
        {
            if (machineState == MachineState.waitStatus)
            {
                machineState = MachineState.Idle;
            }

            GrblStatus.MachineState oldState = grblStatus.state;
            float[] axis = new float[grblStatus.axisPos.Length];
            for (int i = 0; i < axis.Length; i++)
            {
                axis[i] = grblStatus.axisPos[i];
            }

            grblStatus.Parse(line);
            if (StatusUpdate != null)
            {
                StatusUpdate(this, grblStatus);
            }
            grblStatus.gStateChange = false;
            if (oldState != grblStatus.state)
            {
                HandleStateChange(oldState);
            }

            if (wasRunningWhenToolChanged)
            {
                float absZ = grblStatus.axisPos[Z_AXIS] + grblStatus.workingCoords[Z_AXIS];
                if (absZ > tcpZmax)
                {
                    tcpZmax = absZ;
                }
            }

            // handle stopping, if in action. Fixme: need to find a better way to do it.
            if (machineState == MachineState.Stopping && grblStatus.state != GrblStatus.MachineState.Run)
            {
                bool motionStopped = true;
                for (int i = 0; i < axis.Length; i++)
                {
                    if (axis[i] != grblStatus.axisPos[i])
                    {
                        motionStopped = false;
                        break;
                    }
                }
                if (motionStopped)
                {
                    SendStop();
                }
            }
            if (machineState == MachineState.ToolChange && grblStatus.state != GrblStatus.MachineState.Run)
            {
                ChangeTool();
            }
        }
Exemple #2
0
        void HandleReceivedLine(string line)
        {
            if (line.Length == 0)
            {
                return;
            }
            bool isStatusLine = false;

            if (line.Length > maxlinelen)
            {
                maxlinelen  = line.Length;
                tmpLongLine = line;
            }
            if (line.StartsWith("Grbl"))
            {
                activePort = port.PortName;
                if (machineState == MachineState.Idle)
                {
                    GetAllGrblParameters();
                }
                //machineState = MachineState.Idle;
                if (ConnectionStatus != CommStatus.Connected)
                {
                    ConnectionStatus = CommStatus.Connected;
                    if (StatusChanged != null)
                    {
                        StatusChanged(this, ConnectionStatus);
                    }
                }
            }
            else if (line.StartsWith("<"))
            {
                isStatusLine = true;
                grblStatus.Parse(line);
                if (StatusUpdate != null)
                {
                    StatusUpdate(this, grblStatus);
                }
            }
            else if (line.StartsWith("$"))
            {
                HandleParamLine(line);
            }
            else if (line.StartsWith("ok"))
            {
                HandleOKLine(line);
            }
            else if (line.StartsWith("["))
            {
                HandleMessageLine(line);
            }
            else if (line.StartsWith("error"))
            {
                HandleErrorLine(line, MessageType.Error);
            }
            else if (line.StartsWith("ALARM"))
            {
                HandleErrorLine(line, MessageType.Alarm);
            }
            if (LineReceived != null)
            {
                LineReceived(this, line, isStatusLine && showStatusMsg == 0);
                if (showStatusMsg > 0)
                {
                    showStatusMsg--;
                }
            }
        }