Example #1
0
        private IRobotCommand GetNextCommand(bool canAcceptMoveCommand)
        {
            currentCommand = null;
            if (commandGenerator == null)
            {
                return(null);
            }

            if (sendZeroCommand)
            {
                currentCommand  = commandGenerator.GenerateZeroCommand();
                sendZeroCommand = false;
            }
            if (sendCancelCommand)
            {
                currentCommand    = commandGenerator.GenerateCancelCommand();
                sendCancelCommand = false;
            }
            else if (sendResumeCommand)
            {
                currentCommand    = commandGenerator.GenerateResumeCommand();
                sendResumeCommand = false;
            }
            else if (sendPauseCommand)
            {
                currentCommand   = commandGenerator.GeneratePauseCommand();
                sendPauseCommand = false;
            }
            else if (sendEnableStepperCommand)
            {
                currentCommand           = commandGenerator.GenerateStepperEnableCommand();
                sendEnableStepperCommand = false;
            }
            else if (sendDisableStepperCommand)
            {
                currentCommand            = commandGenerator.GenerateStepperDisableCommand();
                sendDisableStepperCommand = false;
            }
            else if (canAcceptMoveCommand && lastPositionKnown)
            {
                while (currentCommand == null && commands.Count > 0)
                {
                    ICommand command = commands.Dequeue();
                    if (command is MoveTool)
                    {
                        currentCommand = CreateRobotCommand(command as MoveTool, commandGenerator);
                    }
                }
            }
            if (currentCommand == null)
            {
                currentCommand = commandGenerator.GenerateStatusCommand();
            }

            return(currentCommand);
        }
Example #2
0
            internal override bool ProcessResponse(byte data)
            {
                if (data == 0xCA) // Only the binary robot will send this character (it's the packet start character)
                {
                    // Drop anything earlier from the accumulator
                    accumulator.Clear();
                    Console.WriteLine("Found 0xCA start byte, looks like the packetized binary protocol");
                    commandGenerator    = new PacketizedCommandGenerator();
                    binaryStatusCommand = commandGenerator.GenerateStatusCommand();
                }

                accumulator.Add(data);
                if (binaryStatusCommand != null)
                {
                    // The response will be a binary status command, just forward the data and wait until it's good.
                    return(binaryStatusCommand.ProcessResponse(data));
                }
                else
                {
                    // Look for an ASCII communicating robot (like GRBL)
                    var s = System.Text.Encoding.ASCII.GetString(accumulator.ToArray());

                    if (s.EndsWith("\r\n", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("Grbl ") && s.Length >= 9)
                        {
                            var   version       = s.Substring(5, 3);
                            float version_float = 0.0f;
                            if (float.TryParse(version, out version_float) && version_float >= 0.8f)
                            {
                                Console.WriteLine("Compatible Grbl type robot found: " + s.Substring(0, 9));
                                commandGenerator = new GrblCommandGenerator();
                                return(true);
                            }
                        }
                        else
                        {
                            // Seems like a GRBL type robot, but the start of the string wasn't right.  Maybe some garbage
                            // or an extra \r\n, clear it out and wait for more.
                            accumulator.Clear();
                        }
                    }
                }
                return(false);
            }
Example #3
0
            internal override bool ProcessResponse(byte data)
            {
                if (data == 0xCA) // Only the binary robot will send this character (it's the packet start character)
                {
                    // Drop anything earlier from the accumulator
                    accumulator.Clear();
                    Console.WriteLine("Found 0xCA start byte, looks like the packetized binary protocol");
                    commandGenerator = new PacketizedCommandGenerator();
                    binaryStatusCommand = commandGenerator.GenerateStatusCommand();
                }

                accumulator.Add(data);
                if (binaryStatusCommand != null)
                {
                    // The response will be a binary status command, just forward the data and wait until it's good.
                    return binaryStatusCommand.ProcessResponse(data);
                }
                else
                {
                    // Look for an ASCII communicating robot (like GRBL)
                    var s = System.Text.Encoding.ASCII.GetString(accumulator.ToArray());

                    if (s.EndsWith("\r\n", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("Grbl ") && s.Length >= 9)
                        {
                            var version = s.Substring(5, 3);
                            float version_float = 0.0f;
                            if (float.TryParse(version, out version_float) && version_float >= 0.8f)
                            {
                                Console.WriteLine("Compatible Grbl type robot found: " + s.Substring(0, 9));
                                commandGenerator = new GrblCommandGenerator();
                                return true;
                            }
                        }
                        else
                        {
                            // Seems like a GRBL type robot, but the start of the string wasn't right.  Maybe some garbage
                            // or an extra \r\n, clear it out and wait for more.
                            accumulator.Clear();
                        }
                    }
                }
                return false;
            }