Пример #1
0
        private void ProcessGcode()
        {
            bool takeabreak = false;

            while (GcodeIsRunning)
            {
                GcodeIsRunning = Gcode.Where(x => !x.IsProcessed).FirstOrDefault() != null;

                takeabreak = !InIdleState & !InCheckState & !InRunState;

                lock (Gcode) QueuedSize = Gcode.Where(x => !x.IsProcessed & x.InSerialBuffer).Sum(x => x.CommandLength);
                GcodeLine gcodeline = Gcode.Where(x => !x.IsProcessed & !x.InSerialBuffer).FirstOrDefault();

                while (gcodeline != null & !takeabreak && (GcodeIsRunning & ((rx_buffer_size - QueuedSize) >= gcodeline.CommandLength)))
                {
                    serialport.Write(Command.AddReturn(gcodeline.GrblCommand).ToString());
                    gcodeline.InSerialBuffer = true;
                    lock (Gcode) QueuedSize = Gcode.Where(x => !x.IsProcessed & x.InSerialBuffer).Sum(x => x.CommandLength);
                    gcodeline = Gcode.Where(x => !x.IsProcessed & !x.InSerialBuffer).FirstOrDefault();
                }
            }
        }
Пример #2
0
        private void ProcessResponse(string _data, bool _iserror = false)
        {
            if (GcodeIsRunning)
            {
                GcodeLine gcodeline = Gcode.Where(x => x.Index == lastprocessedindex).First();
                gcodeline.InSerialBuffer = false;
                gcodeline.IsProcessed    = true;
                gcodeline.Response       = _iserror ? Error.Codes[_data.Split(':')[1]] : _data;
                GcodeLineChanged?.Invoke(gcodeline, new EventArgs());

                ++lastprocessedindex;
            }
            else
            {
                if (_iserror)
                {
                    ErrorReceived?.Invoke(this, new ErrorReceivedEventArgs(Error.Codes[_data.Split(':')[1]]));
                }
            }

            GetStatus();
        }