public GCodeCompressed(GCode c)
        {
            int    p   = c.orig.IndexOf(';');
            string tmp = (p >= 0 ? c.orig.Substring(0, p) : c.orig).Trim();

            data = enc.GetBytes(tmp);
        }
Beispiel #2
0
        void OnPosChange(GCode act, float x, float y, float z)
        {
            bool isLastPos = Math.Abs(x - lastx) + Math.Abs(y - lasty) + Math.Abs(z - lastz) < 0.00001;

            if (!act.hasG || (act.G > 1 && act.G != 28))
            {
                return;
            }
            if (segments.Count == 0 || laste >= ana.e) // start new segment
            {
                if (!isLastPos)                        // no move, no action
                {
                    GCodePath p = new GCodePath();
                    p.Add(new Vector3(x, y, z));
                    if (segments.Count > 0 && segments.Last.Value.points.Count == 1)
                    {
                        segments.RemoveLast();
                    }
                    segments.AddLast(p);
                    changed = true;
                }
            }
            else
            {
                if (!isLastPos)
                {
                    segments.Last.Value.Add(new Vector3(x, y, z));
                    changed = true;
                }
            }
            lastx = x;
            lasty = y;
            lastz = z;
            laste = ana.emax;
        }
        public void receiveLine(GCode code)
        {
            bytesin += code.orig.Length;
            ana.Analyze(code);
            lock (output)
            {
                if (code.hasM)
                {
                    switch (code.M)
                    {
                    case 115:     // Firmware
                        output.AddLast("FIRMWARE_NAME:RepetierVirtualPrinter FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
                        //output.AddLast("FIRMWARE_NAME:Marlin FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
                        break;

                    case 105:     // Print Temperatures
                        output.AddLast("T:" + extruderTemp.ToString("0") + " B:" + bedTemp.ToString("0") + " @:" + extruderOut.ToString("0"));
                        break;

                    case 205:     // EEPROM Settings
                        output.AddLast("EPR:2 75 76800 Baudrate");
                        output.AddLast("EPR:2 79 0 Max. inactive time [ms,0=off]");
                        output.AddLast("EPR:2 83 60000 Stop stepper afer inactivity [ms,0=off]");
                        output.AddLast("EPR:3 3 40.00 X-axis steps per mm");
                        output.AddLast("EPR:3 7 40.00 Y-axis steps per mm");
                        output.AddLast("EPR:3 11 3333.59 Z-axis steps per mm");
                        output.AddLast("EPR:3 15 20000.00 X-axis max. feedrate [mm/min]");
                        output.AddLast("EPR:3 19 20000.00 Y-axis max. feedrate [mm/min]");
                        output.AddLast("EPR:3 23 2.00 Z-axis max. feedrate [mm/min]");
                        output.AddLast("EPR:3 27 1500.00 X-axis homing feedrate [mm/min]");
                        output.AddLast("EPR:3 31 1500.00 Y-axis homing feedrate [mm/min]");
                        output.AddLast("EPR:3 35 100.00 Z-axis homing feedrate [mm/min]");
                        output.AddLast("EPR:3 39 20.00 X-axis start speed [mm/s]");
                        output.AddLast("EPR:3 43 20.00 Y-axis start speed [mm/s]");
                        output.AddLast("EPR:3 47 1.00 Z-axis start speed [mm/s]");
                        output.AddLast("EPR:3 51 750.00 X-axis acceleration [mm/s^2]");
                        output.AddLast("EPR:3 55 750.00 Y-axis acceleration [mm/s^2]");
                        output.AddLast("EPR:3 59 50.00 Z-axis acceleration [mm/s^2]");
                        output.AddLast("EPR:3 63 750.00 X-axis travel acceleration [mm/s^2]");
                        output.AddLast("EPR:3 67 750.00 Y-axis travel acceleration [mm/s^2]");
                        output.AddLast("EPR:3 71 50.00 Z-axis travel acceleration [mm/s^2]");
                        output.AddLast("EPR:3 150 373.00 Extr. steps per mm");
                        output.AddLast("EPR:3 154 1200.00 Extr. max. feedrate [mm/min]");
                        output.AddLast("EPR:3 158 10.00 Extr. start feedrate [mm/s]");
                        output.AddLast("EPR:3 162 10000.00 Extr. acceleration [mm/s^2]");
                        output.AddLast("EPR:0 166 1 Heat manager [0-1]");
                        output.AddLast("EPR:0 167 130 PID drive max");
                        output.AddLast("EPR:2 168 300 PID P-gain [*0.01]");
                        output.AddLast("EPR:2 172 2 PID I-gain [*0.01]");
                        output.AddLast("EPR:2 176 2000 PID D-gain [*0.01]");
                        output.AddLast("EPR:0 180 200 PID max value [0-255]");
                        output.AddLast("EPR:2 181 0 X-offset [steps]");
                        output.AddLast("EPR:2 185 0 Y-offset [steps]");
                        output.AddLast("EPR:2 189 40 Temp. stabilize time [s]");
                        break;
                    }
                }
                output.AddLast("ok");
            }
        }
Beispiel #4
0
        public GCode PopData()
        {
            if (jobList.Count == 0)
            {
                return(null);
            }
            GCode gc = null;

            try
            {
                gc = jobList.First.Value;
                jobList.RemoveFirst();
                linesSend++;
                PrintTime pt = new PrintTime();
                pt.line = linesSend;
                pt.time = DateTime.Now.Ticks;
                lock (times)
                {
                    times.AddLast(pt);
                    if (times.Count > 1500)
                    {
                        times.RemoveFirst();
                    }
                }
            }
            catch { };
            if (jobList.Count == 0)
            {
                dataComplete = false;
                mode         = 2;
                jobFinished  = DateTime.Now;
                long ticks = (jobFinished.Ticks - jobStarted.Ticks) / 10000;
                long hours = ticks / 3600000;
                ticks -= 3600000 * hours;
                long min = ticks / 60000;
                ticks -= 60000 * min;
                long sec = ticks / 1000;
                Main.conn.log("Printjob finished at " + jobFinished.ToShortDateString() + " " + jobFinished.ToShortTimeString(), false, 3);
                StringBuilder s = new StringBuilder();
                if (hours > 0)
                {
                    s.Append(hours);
                    s.Append("h:");
                }
                if (min > 0)
                {
                    s.Append(min);
                    s.Append("m:");
                }
                s.Append(sec);
                s.Append("s");
                Main.conn.log("printing time:" + s.ToString(), false, 3);
                Main.conn.log("lines send:" + linesSend.ToString(), false, 3);
                Main.conn.firePrinterAction("Finished in " + s.ToString());
                DoEndKillActions();
                Main.main.Invoke(Main.main.UpdateJobButtons);
            }
            return(gc);
        }
 private void StoreHistory(GCode gcode)
 {
     history.AddLast(gcode);
     log(gcode.getAscii(true, true), false, 0);
     if (history.Count > 40)
     {
         history.RemoveFirst();
     }
 }
 public void receiveLine(GCode code)
 {
     bytesin += code.orig.Length;
     ana.Analyze(code);
     lock (output)
     {
         if (code.hasM) switch (code.M)
             {
                 case 115: // Firmware
                     output.AddLast("FIRMWARE_NAME:RepetierVirtualPrinter FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
                     //output.AddLast("FIRMWARE_NAME:Marlin FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
                     break;
                 case 105: // Print Temperatures
                     output.AddLast("T:" + extruderTemp.ToString("0") + " B:" + bedTemp.ToString("0"));
                     break;
                 case 205: // EEPROM Settings
                     output.AddLast("EPR:2 75 76800 Baudrate");
                     output.AddLast("EPR:2 79 0 Max. inactive time [ms,0=off]");
                     output.AddLast("EPR:2 83 60000 Stop stepper afer inactivity [ms,0=off]");
                     output.AddLast("EPR:3 3 40.00 X-axis steps per mm");
                     output.AddLast("EPR:3 7 40.00 Y-axis steps per mm");
                     output.AddLast("EPR:3 11 3333.59 Z-axis steps per mm");
                     output.AddLast("EPR:3 15 20000.00 X-axis max. feedrate [mm/min]");
                     output.AddLast("EPR:3 19 20000.00 Y-axis max. feedrate [mm/min]");
                     output.AddLast("EPR:3 23 2.00 Z-axis max. feedrate [mm/min]");
                     output.AddLast("EPR:3 27 1500.00 X-axis homing feedrate [mm/min]");
                     output.AddLast("EPR:3 31 1500.00 Y-axis homing feedrate [mm/min]");
                     output.AddLast("EPR:3 35 100.00 Z-axis homing feedrate [mm/min]");
                     output.AddLast("EPR:3 39 20.00 X-axis start speed [mm/s]");
                     output.AddLast("EPR:3 43 20.00 Y-axis start speed [mm/s]");
                     output.AddLast("EPR:3 47 1.00 Z-axis start speed [mm/s]");
                     output.AddLast("EPR:3 51 750.00 X-axis acceleration [mm/s^2]");
                     output.AddLast("EPR:3 55 750.00 Y-axis acceleration [mm/s^2]");
                     output.AddLast("EPR:3 59 50.00 Z-axis acceleration [mm/s^2]");
                     output.AddLast("EPR:3 63 750.00 X-axis travel acceleration [mm/s^2]");
                     output.AddLast("EPR:3 67 750.00 Y-axis travel acceleration [mm/s^2]");
                     output.AddLast("EPR:3 71 50.00 Z-axis travel acceleration [mm/s^2]");
                     output.AddLast("EPR:3 150 373.00 Extr. steps per mm");
                     output.AddLast("EPR:3 154 1200.00 Extr. max. feedrate [mm/min]");
                     output.AddLast("EPR:3 158 10.00 Extr. start feedrate [mm/s]");
                     output.AddLast("EPR:3 162 10000.00 Extr. acceleration [mm/s^2]");
                     output.AddLast("EPR:0 166 1 Heat manager [0-1]");
                     output.AddLast("EPR:0 167 130 PID drive max");
                     output.AddLast("EPR:2 168 300 PID P-gain [*0.01]");
                     output.AddLast("EPR:2 172 2 PID I-gain [*0.01]");
                     output.AddLast("EPR:2 176 2000 PID D-gain [*0.01]");
                     output.AddLast("EPR:0 180 200 PID max value [0-255]");
                     output.AddLast("EPR:2 181 0 X-offset [steps]");
                     output.AddLast("EPR:2 185 0 Y-offset [steps]");
                     output.AddLast("EPR:2 189 40 Temp. stabilize time [s]");
                     break;
             }
         output.AddLast("ok");
     }
 }
        public void ResendLine(int line)
        {
            resendError++;
            errorsReceived++;
            if (pingpong)
            {
                readyForNextSend = true;
            }
            else
            {
                nackLines.Clear(); // printer flushed all coming commands
            }
            LinkedListNode <GCode> node = history.Last;

            if (resendError > 5 || node == null)
            {
                log("Receiving only error messages. Stopped communication.", false, 2);
                close();
                return; // give up, something is terribly wrong
            }
            line &= 65535;
            do
            {
                GCode gc = node.Value;
                if (gc.hasN && (gc.N & 65535) == line)
                {
                    resendNode = node;
                    if (binaryVersion != 0)
                    {
                        int send = receivedCount();
                        serial.DiscardOutBuffer();
                        System.Threading.Thread.Sleep(send * 10000 / baud); // Wait for buffer to empty
                        byte[] buf = new byte[32];
                        for (int i = 0; i < 32; i++)
                        {
                            buf[i] = 0;
                        }
                        serial.Write(buf, 0, 32);
                        System.Threading.Thread.Sleep(320000 / baud); // Wait for buffer to empty
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(receiveCacheSize * 10000 / baud); // Wait for buffer to empty
                    }
                    TrySendNextLine();
                    return;
                }
                if (node.Previous == null)
                {
                    return;
                }
                node = node.Previous;
            } while (true);
        }
Beispiel #8
0
        public void ParseText(string text, bool clear)
        {
            GCode gc = new GCode();

            if (clear)
            {
                Clear();
            }
            foreach (string s in text.Split('\n'))
            {
                gc.Parse(s);
                AddGCode(gc);
            }
        }
Beispiel #9
0
 public void PushData(string code)
 {
     code = code.Replace('\r', '\n');
     string[] lines = code.Split('\n');
     foreach (string line in lines)
     {
         if (line.Length == 0)
         {
             continue;
         }
         GCode gcode = new GCode();
         gcode.Parse(line);
         jobList.AddLast(gcode);
         totalLines++;
     }
 }
        /// <summary>
        /// Send a print command, that does not belong to a print job.
        /// </summary>
        /// <param name="command">GCode command</param>
        public void injectManualCommand(string command)
        {
            GCode gc = new GCode();

            gc.Parse(command);
            lock (history)
                injectCommands.AddLast(gc);
            if (job.dataComplete == false)
            {
                if (injectCommands.Count == 0)
                {
                    firePrinterAction("Idle");
                }
                else
                {
                    firePrinterAction(injectCommands.Count.ToString() + " commands waiting");
                }
            }
        }
Beispiel #11
0
 public void PushGCodeShortArray(List <GCodeShort> codes)
 {
     foreach (GCodeShort line in codes)
     {
         if (line.Length == 0)
         {
             continue;
         }
         ana.analyzeShort(line);
         GCode gcode = new GCode();
         gcode.Parse(line.text);
         if (!gcode.comment)
         {
             jobList.AddLast(gcode);
             totalLines++;
         }
         if (line.hasLayer)
         {
             maxLayer = line.layer;
         }
     }
     computedPrintingTime = ana.printingTime;
 }
Beispiel #12
0
        void OnPosChange(GCode act, float x, float y, float z)
        {
            float locDist   = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
            bool  isLastPos = locDist < 0.00001;

            if (!act.hasG || (act.G > 1 && act.G != 28))
            {
                return;
            }
            if (segments.Count == 0 || laste >= ana.e) // start new segment
            {
                if (!isLastPos)                        // no move, no action
                {
                    GCodePath p = new GCodePath();
                    p.Add(new Vector3(x, y, z), ana.emax, totalDist);
                    if (segments.Count > 0 && segments.Last.Value.pointsLists.Last.Value.Count == 1)
                    {
                        segments.RemoveLast();
                    }
                    segments.AddLast(p);
                    changed = true;
                }
            }
            else
            {
                if (!isLastPos)
                {
                    totalDist += locDist;
                    segments.Last.Value.Add(new Vector3(x, y, z), ana.emax, totalDist);
                    changed = true;
                }
            }
            lastx = x;
            lasty = y;
            lastz = z;
            laste = ana.emax;
        }
Beispiel #13
0
 private void writeArray(BinaryWriter file, List<GCodeShort> list, bool binary)
 {
     foreach (GCodeShort code in list)
     {
         GCode gc = new GCode();
         gc.Parse(code.text);
         if (gc.hostCommand) continue;
         if (binary)
         {
             if (gc.hasCode)
             {
                 byte[] data = gc.getBinary(1);
                 file.Write(data);
             }
         }
         else
         {
             System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
             string cmd = gc.getAscii(false, false);
             if (cmd.Length > 0)
                 file.Write(enc.GetBytes(cmd + "\n"));
         }
     }
 }
Beispiel #14
0
 void OnPosChange(GCode act, float x, float y, float z)
 {
     if (!ana.drawing)
     {
         lastx = x;
         lasty = y;
         lastz = z;
         laste = ana.emax;
         return;
     }
     float locDist = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
     bool isLastPos = locDist < 0.00001;
     if (!act.hasG || (act.G > 1 && act.G != 28)) return;
     int segpos = ana.activeExtruder;
     if (segpos < 0 || segpos >= MaxExtruder) segpos = 0;
     LinkedList<GCodePath> seg = segments[segpos];
     if (seg.Count == 0 || laste >= ana.e) // start new segment
     {
         if (!isLastPos) // no move, no action
         {
             GCodePath p = new GCodePath();
             p.Add(new Vector3(x, y, z), ana.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
             if (seg.Count > 0 && seg.Last.Value.pointsLists.Last.Value.Count == 1)
             {
                 seg.RemoveLast();
             }
             seg.AddLast(p);
             changed = true;
         }
     }
     else
     {
         if (!isLastPos)
         {
             totalDist += locDist;
             seg.Last.Value.Add(new Vector3(x, y, z), ana.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
             changed = true;
         }
     }
     lastx = x;
     lasty = y;
     lastz = z;
     laste = ana.emax;
 }
Beispiel #15
0
 void OnPosChange(GCode act,float x, float y, float z)
 {
     bool isLastPos = Math.Abs(x-lastx)+Math.Abs(y-lasty)+Math.Abs(z-lastz)<0.00001;
     if (!act.hasG || (act.G > 1 && act.G!=28)) return;
     if (segments.Count == 0 || laste >= ana.e) // start new segment
     {
         if (!isLastPos) // no move, no action
         {
             GCodePath p = new GCodePath();
             p.Add(new Vector3(x, y, z));
             if (segments.Count > 0 && segments.Last.Value.points.Count == 1)
             {
                 segments.RemoveLast();
             }
             segments.AddLast(p);
             changed = true;
         }
     }
     else
     {
         if (!isLastPos)
         {
             segments.Last.Value.Add(new Vector3(x, y, z));
             changed = true;
         }
     }
     lastx = x;
     lasty = y;
     lastz = z;
     laste = ana.emax;
 }
Beispiel #16
0
 private void writeString(BinaryWriter file, string code, bool binary)
 {
     GCode gc = new GCode();
     gc.Parse(code);
     if (gc.hostCommand) return;
     if (binary)
     {
         if (gc.hasCode)
         {
             byte[] data = gc.getBinary(1);
             file.Write(data);
         }
     }
     else
     {
         System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
         string cmd = gc.getAscii(false, false);
         if (cmd.Length > 0)
             file.Write(enc.GetBytes(cmd + "\n"));
     }
 }
 public void Analyze(GCode code)
 {
     if (code.hostCommand)
     {
         string cmd = code.getHostCommand();
         if (cmd.Equals("@hide"))
             drawing = false;
         else if (cmd.Equals("@show"))
             drawing = true;
         else if (cmd.Equals("@isathome"))
         {
             hasXHome = hasYHome = hasZHome = true;
             x = xOffset = 0;
             y = yOffset = 0;
             z = zOffset = 0;
         }
         return;
     }
     if (code.forceAscii) return; // Don't analyse host commands and unknown commands
     if (code.hasN)
         lastline = code.N;
     if (uploading && !code.hasM && code.M != 29) return; // ignore upload commands
     if (code.hasG)
     {
         switch (code.G)
         {
             case 0:
             case 1:
                 if (code.hasF) f = code.F;
                 if (relative)
                 {
                     if (code.hasX) x += code.X;
                     if (code.hasY) y += code.Y;
                     if (code.hasZ) z += code.Z;
                     if (code.hasE) e += code.E;
                 }
                 else
                 {
                     if (code.hasX) x = xOffset + code.X;
                     if (code.hasY) y = yOffset + code.Y;
                     if (code.hasZ)
                     {
                          z = zOffset + code.Z;
                     }
                     if (code.hasE)
                     {
                         if (eRelative)
                             e += code.E;
                         else
                             e = eOffset + code.E;
                     }
                 }
                 if (x < 0) { x = 0; hasXHome = false; }
                 if (y < 0) { y = 0; hasYHome = false; }
                 if (z < 0) { z = 0; hasZHome = false; }
                 if (x > printerWidth) { hasXHome = false; }
                 if (y > printerDepth) { hasYHome = false; }
                 if (z > printerHeight) { hasZHome = false; }
                 if (e > emax)
                 {
                     emax = e;
                     if (z > lastZPrint)
                     {
                         layer++;
                         lastZPrint = z;
                         if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                         {
                             PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                         }
                     }
                 }
                 if (eventPosChanged != null)
                     if (privateAnalyzer)
                         eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged, code, x, y, z);
                 float dx = Math.Abs(x - lastX);
                 float dy = Math.Abs(y - lastY);
                 float dz = Math.Abs(z - lastZ);
                 float de = Math.Abs(e - lastE);
                 if (dx + dy + dz > 0.001)
                 {
                     printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f;
                 }
                 else printingTime += de * 60.0f / f;
                 lastX = x;
                 lastY = y;
                 lastZ = z;
                 lastE = e;
                 break;
             case 28:
             case 161:
                 {
                     bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                     if (code.hasX || homeAll) { xOffset = 0; x = 0; hasXHome = true; }
                     if (code.hasY || homeAll) { yOffset = 0; y = 0; hasYHome = true; }
                     if (code.hasZ || homeAll) { zOffset = 0; z = 0; hasZHome = true; }
                     if (code.hasE) { eOffset = 0; e = 0; emax = 0; }
                     if (eventPosChanged != null)
                         if (privateAnalyzer)
                             eventPosChanged(code, x, y, z);
                         else
                             Main.main.Invoke(eventPosChanged, code, x, y, z);
                 }
                 break;
             case 162:
                 {
                     bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                     if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true; }
                     if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true; }
                     if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; }
                     if (eventPosChanged != null)
                         if (privateAnalyzer)
                             eventPosChanged(code, x, y, z);
                         else
                             Main.main.Invoke(eventPosChanged, code, x, y, z);
                 }
                 break;
             case 90:
                 relative = false;
                 break;
             case 91:
                 relative = true;
                 break;
             case 92:
                 if (code.hasX) { xOffset = x - code.X; x = xOffset; }
                 if (code.hasY) { yOffset = y - code.Y; y = yOffset; }
                 if (code.hasZ) { zOffset = z - code.Z; z = zOffset; }
                 if (code.hasE) { eOffset = e - code.E; lastE = e = eOffset; }
                 if (eventPosChanged != null)
                     if (privateAnalyzer)
                         eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged, code, x, y, z);
                 break;
         }
     }
     else if (code.hasM)
     {
         switch (code.M)
         {
             case 28:
                 uploading = true;
                 break;
             case 29:
                 uploading = false;
                 break;
             case 80:
                 powerOn = true;
                 fireChanged();
                 break;
             case 81:
                 powerOn = false;
                 fireChanged();
                 break;
             case 82:
                 eRelative = false;
                 break;
             case 83:
                 eRelative = true;
                 break;
             case 104:
             case 109:
                 if (code.hasS) extruderTemp = code.S;
                 fireChanged();
                 break;
             case 106:
                 fanOn = true;
                 if (code.hasS) fanVoltage = code.S;
                 fireChanged();
                 break;
             case 107:
                 fanOn = false;
                 fireChanged();
                 break;
             case 110:
                 lastline = code.N;
                 break;
             case 111:
                 if (code.hasS)
                 {
                     debugLevel = code.S;
                 }
                 break;
             case 140:
             case 190:
                 if (code.hasS) bedTemp = code.S;
                 fireChanged();
                 break;
             case 203: // Temp monitor
                 if(code.hasS)
                     tempMonitor = code.S;
                 break;
             case 220:
                 if(code.hasS)
                     speedMultiply = code.S;
                 break;
         }
     }
     else if (code.hasT)
     {
         activeExtruder = code.T;
     }
 }
Beispiel #18
0
 public void PushGCodeShortArray(List<GCodeShort> codes)
 {
     foreach (GCodeShort line in codes)
     {
         if (line.Length == 0) continue;
         ana.analyzeShort(line);
         GCode gcode = new GCode();
         gcode.Parse(line.text);
         if (!gcode.comment)
         {
             jobList.AddLast(new GCodeCompressed(gcode));
             totalLines++;
         }
         if (line.hasLayer)
             maxLayer = line.layer;
     }
     computedPrintingTime = ana.printingTime;
 }
Beispiel #19
0
 public GCode PopData()
 {
     GCode gc = null;
     bool finished = false;
     lock (jobList)
     {
         if (jobList.Count == 0) return null;
         try
         {
             gc = new GCode(jobList.First.Value);
             jobList.RemoveFirst();
             linesSend++;
             /*PrintTime pt = new PrintTime();
             pt.line = linesSend;
             pt.time = DateTime.Now.Ticks;
             lock (times)
             {
                 times.AddLast(pt);
                 if (times.Count > 1500)
                     times.RemoveFirst();
             }*/
         }
         catch { };
         finished = jobList.Count == 0 && mode != 3;
     }
     if (finished)
     {
         dataComplete = false;
         mode = 2;
         jobFinished = DateTime.Now;
         long ticks = (jobFinished.Ticks - jobStarted.Ticks) / 10000;
         long hours = ticks / 3600000;
         ticks -= 3600000 * hours;
         long min = ticks / 60000;
         ticks -= 60000 * min;
         long sec = ticks / 1000;
         //Main.conn.log("Printjob finished at " + jobFinished.ToShortDateString()+" "+jobFinished.ToShortTimeString(),false,3);
         Main.conn.log(Trans.T1("L_PRINTJOB_FINISHED_AT",jobFinished.ToShortDateString() + " " + jobFinished.ToShortTimeString()), false, 3);
         StringBuilder s = new StringBuilder();
         if (hours > 0)
             s.Append(Trans.T1("L_TIME_H:",hours.ToString())); //"h:");
         if (min > 0)
             s.Append(Trans.T1("L_TIME_M:",min.ToString()));
         s.Append(Trans.T1("L_TIME_S",sec.ToString()));
         //Main.conn.log("Printing time:"+s.ToString(),false,3);
         //Main.conn.log("Lines send:" + linesSend.ToString(), false, 3);
         //Main.conn.firePrinterAction("Finished in "+s.ToString());
         Main.conn.log(Trans.T1("L_PRINTING_TIME:",s.ToString()), false, 3);
         Main.conn.log(Trans.T1("L_LINES_SEND:X",linesSend.ToString()), false, 3);
         Main.conn.firePrinterAction(Trans.T1("L_FINISHED_IN",s.ToString()));
         DoEndKillActions();
         Main.main.Invoke(Main.main.UpdateJobButtons);
         Main.main.printPanel.Invoke(Main.main.printPanel.SetStatusJobFinished);
         RepetierHost.view.SoundConfig.PlayPrintFinished(false);
     }
     return gc;
 }
Beispiel #20
0
 /// <summary>
 /// Add a GCode line to be visualized.
 /// </summary>
 /// <param name="g"></param>
 public void AddGCode(GCode g)
 {
     act = g;
     ana.Analyze(g);
     laste = ana.emax;
 }
Beispiel #21
0
 public void OnPosChangeCreateCheckpoint(GCode code, float x, float y, float z)
 {
     movementsCount++;
     bool EnableCreateCheckpointOnNumberOfMovements = RegMemory.GetBool("enableCreateCheckpointOnNumberOfMovements", true);
     long NumberOfMovementsToCreateCheckpoint = RegMemory.GetLong("numberOfMovementsToCreateCheckpoint", 10);
     if (Main.conn.connector.IsJobRunning() && !Main.conn.connector.IsPaused && EnableCreateCheckpointOnNumberOfMovements && (NumberOfMovementsToCreateCheckpoint > 0 && movementsCount % NumberOfMovementsToCreateCheckpoint == 0))
     {
         checkpoints.CreateCheckpoint(MovementCountCheckpointType.Instance);
     }
 }
 public override void ResendLine(int line)
 {
     if (line == openResend) return; // line was not send yet, do not do it twice
     if (binaryVersion != 0)
     {
         int send = receivedCount();
         //serial.DiscardOutBuffer();
         System.Threading.Thread.Sleep(send * 10000 / int.Parse(baudRate)); // Wait for buffer to empty
         byte[] buf = new byte[32];
         for (int i = 0; i < 32; i++) buf[i] = 0;
         serial.Write(buf, 0, 32);
         System.Threading.Thread.Sleep(320000 / int.Parse(baudRate)); // Wait for buffer to empty
     }
     else
     {
         //serial.DiscardOutBuffer();
         serial.WriteLine("");
         System.Threading.Thread.Sleep(receiveCacheSize * 10000 / int.Parse(baudRate)); // Wait for buffer to empty
     }
     if (line > lastline) return; // resend request during connect can request unpossible resends
     if (line == ignoreResendLine && con.isRepetier == true) // Ignore repeated resend requests
     {
         if (ignoreResendLineForXCalls > 0) ignoreResendLineForXCalls--;
         if (ignoreResendLineForXCalls > 0) return;
     }
     ignoreResendLine = line;
     ignoreResendLineForXCalls = 7;
       /*  if (!prequelFinished && line > lastline)
     {
         RLog.message("ignoring resend in prequel");
         if (pingPong)
             readyForNextSend = true;
         return;
     }*/
     if (!connected) return;
     errorsReceived++;
     resendError++;
     lock (nextlineLock)
     {
         if (serial == null) return;
         /*if (ignoreXEqualResendsResend>0 && (line & 65535) == (lastResendLine & 65535))
         {
             ignoreXEqualResendsResend--;
             return;
         }
         lastResendLine = line;
         ignoreXEqualResendsResend = 15;*/
         if (pingPong)
             readyForNextSend = true;
         lock (nackLines)
         {
             nackLinesBuffered.Clear();
             nackLines.Clear(); // printer flushed all coming commands
         }
         lock (history)
         {
             LinkedListNode<GCode> node = history.Last;
             GCode gc = null;
             if (node == null)
             {
                 gc = new GCode("N" + line + " M105");
                 openResend = line;
                 history.AddLast(gc);
                 resendNode = history.Last;
                 history.AddFirst(new GCode("N1 M110"));
                 return;
             }
             if (resendError > 5 || node == null)
             {
                 con.log(Trans.T("L_RECEIVING_ONLY_ERRORS"), false, 2); // Receiving only error messages. Stopped communication.
                 con.close(true);
                 RepetierHost.view.SoundConfig.PlayError(false);
                 return; // give up, something is terribly wrong
             }
             line &= 65535;
             do
             {
                 gc = node.Value;
                 if (gc.hasN && (gc.N & 65535) == line)
                 {
                     openResend = line;
                     resendNode = node;
                     TrySendNextLine();
                     return;
                 }
                 if (node.Previous == null)
                 {
                     history.Clear();
                     openResend = line;
                     history.AddFirst(new GCode("N" + line + " M105"));
                     resendNode = history.First;
                     history.AddFirst(new GCode("N1 M110"));
                     return;
                 }
                 node = node.Previous;
                 //history.RemoveLast();
                 //node = history.Last;
             } while (true);
         }
     }
 }
Beispiel #23
0
 /// <summary>
 /// Add a GCode line to be visualized.
 /// </summary>
 /// <param name="g"></param>
 public void AddGCode(GCode g)
 {
     act = g;
     ana.Analyze(g);
     laste = ana.activeExtruder.emax;
 }
Beispiel #24
0
 void OnPosChange(GCode act, float x, float y, float z)
 {
     if (!ana.drawing)
     {
         lastx = x;
         lasty = y;
         lastz = z;
         laste = ana.activeExtruder.emax;
         return;
     }
     float locDist = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
     bool isLastPos = locDist < 0.00001;
     if (!act.hasG || (act.G > 3 && act.G != 28)) return;
     bool isTravel = (FormPrinterSettings.ps.printerType == 3 ? Math.Max(z, lastz) - ana.zOffset >= FormPrinterSettings.ps.cncZTop : !ana.eChanged);
     int segpos = ana.activeExtruderId;
     if (segpos < 0 || segpos >= MaxExtruder) segpos = 0;
     LinkedList<GCodePath> seg = segments[segpos];
     if (isTravel)
     {
         GCodeTravel travel = new GCodeTravel();
         travel.fline = GCodePoint.toFileLine(fileid, actLine);
         travel.p1.X = lastx;
         travel.p1.Y = lasty;
         travel.p1.Z = lastz;
         travel.p2.X = x;
         travel.p2.Y = y;
         travel.p2.Z = z;
         travelMoves.Add(travel);
         if (FormPrinterSettings.ps.printerType == 3 && z - ana.zOffset < FormPrinterSettings.ps.cncZTop) // End od travel moves
         { // Start new milling move sequence
             GCodePath p = new GCodePath();
             p.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
             if (seg.Count > 0 && seg.Last.Value.pointsLists.Last.Value.Count == 1)
             {
                 seg.RemoveLast();
             }
             seg.AddLast(p);
         }
     }
     if (seg.Count == 0 || (laste >= ana.activeExtruder.e && FormPrinterSettings.ps.printerType != 3)) // start new segment
     {
         if (!isLastPos) // no move, no action
         {
             GCodePath p = new GCodePath();
             p.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
             if (seg.Count > 0 && seg.Last.Value.pointsLists.Last.Value.Count == 1)
             {
                 seg.RemoveLast();
             }
             seg.AddLast(p);
             changed = true;
         }
     }
     else
     {
         if (!isLastPos && (FormPrinterSettings.ps.printerType != 3 || !isTravel))
         {
             totalDist += locDist;
             seg.Last.Value.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
             changed = true;
         }
     }
     lastx = x;
     lasty = y;
     lastz = z;
     laste = ana.activeExtruder.emax;
 }
 public override bool Connect()
 {
     con.isMarlin = con.isRepetier = con.isSprinter = false;
     connected = true;
     virtualPrinter.open(int.Parse(baudRate));
     GCode gc = new GCode();
     gc.Parse("M105");
     virtualPrinter.receiveLine(gc);
     connected = true;
     if (transferProtocol < 2)
         binaryVersion = 0;
     else binaryVersion = transferProtocol - 1;
     con.binaryVersion = binaryVersion;
     readyForNextSend = true;
     lock (nackLines)
     {
         nackLines.Clear();
     }
     linesSend = errorsReceived = bytesSend = 0;
     gc.Parse("N0 M110");
     virtualPrinter.receiveLine(gc);
     gc.Parse("M115");
     virtualPrinter.receiveLine(gc);
     gc.Parse("M105");
     virtualPrinter.receiveLine(gc);
     con.FireConnectionChange(Trans.T("L_CONNECTED") + ":" + con.printerName);
     Main.main.Invoke(Main.main.UpdateJobButtons);
     return true;
 }
Beispiel #26
0
 /// <summary>
 /// Add a GCode line to be visualized.
 /// </summary>
 /// <param name="g"></param>
 public void AddGCode(GCode g)
 {
     act = g;
     ana.Analyze(g);
     laste = ana.emax;
 }
 public GCodeCompressed(GCode c)
 {
     int p = c.orig.IndexOf(';');
     string tmp = (p >= 0 ? c.orig.Substring(0, p) : c.orig).Trim();
     data = enc.GetBytes(tmp);
 }
Beispiel #28
0
        public void Analyze(GCode code)
        {
            if (code.hasN)
            {
                lastline = code.N;
            }
            if (code.hasG)
            {
                switch (code.G)
                {
                case 0:
                case 1:
                    if (relative)
                    {
                        if (code.hasX)
                        {
                            x += code.X;
                        }
                        if (code.hasY)
                        {
                            y += code.Y;
                        }
                        if (code.hasZ)
                        {
                            z += code.Z;
                        }
                        if (code.hasE)
                        {
                            e += code.E;
                        }
                    }
                    else
                    {
                        if (code.hasX)
                        {
                            x = xOffset + code.X;
                        }
                        if (code.hasY)
                        {
                            y = yOffset + code.Y;
                        }
                        if (code.hasZ)
                        {
                            z = zOffset + code.Z;
                        }
                        if (code.hasE)
                        {
                            if (eRelative)
                            {
                                e += code.E;
                            }
                            else
                            {
                                e = eOffset + code.E;
                            }
                        }
                    }
                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (y < 0)
                    {
                        y = 0;
                    }
                    if (z < 0)
                    {
                        z = 0;
                    }
                    if (e > emax)
                    {
                        emax = e;
                    }
                    if (eventPosChanged != null)
                    {
                        Main.main.Invoke(eventPosChanged, code, x, y, z);
                    }
                    break;

                case 28:
                case 161:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = 0; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = 0; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = 0; hasZHome = true;
                    }
                    if (code.hasE)
                    {
                        eOffset = 0; e = 0; emax = 0;
                    }
                    if (eventPosChanged != null)
                    {
                        Main.main.Invoke(eventPosChanged, code, x, y, z);
                    }
                }
                break;

                case 162:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true;
                    }
                    if (eventPosChanged != null)
                    {
                        Main.main.Invoke(eventPosChanged, code, x, y, z);
                    }
                }
                break;

                case 90:
                    relative = false;
                    break;

                case 91:
                    relative = true;
                    break;

                case 92:
                    if (code.hasX)
                    {
                        xOffset = Math.Max(0, x - code.X); x = code.X;
                    }
                    if (code.hasY)
                    {
                        yOffset = Math.Max(0, y - code.Y); y = code.Y;
                    }
                    if (code.hasZ)
                    {
                        zOffset = Math.Max(0, z - code.Z); z = code.Z;
                    }
                    if (code.hasE)
                    {
                        eOffset = Math.Max(0, e - code.E); e = code.E;
                    }
                    if (eventPosChanged != null)
                    {
                        Main.main.Invoke(eventPosChanged, code, x, y, z);
                    }
                    break;
                }
            }
            else if (code.hasM)
            {
                switch (code.M)
                {
                case 80:
                    powerOn = true;
                    fireChanged();
                    break;

                case 81:
                    powerOn = false;
                    fireChanged();
                    break;

                case 82:
                    eRelative = false;
                    break;

                case 83:
                    eRelative = true;
                    break;

                case 104:
                case 109:
                    if (code.hasS)
                    {
                        extruderTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 106:
                    fanOn = true;
                    if (code.hasS)
                    {
                        fanVoltage = code.S;
                    }
                    fireChanged();
                    break;

                case 107:
                    fanOn = false;
                    fireChanged();
                    break;

                case 110:
                    lastline = code.N;
                    break;

                case 111:
                    if (code.hasS)
                    {
                        debugLevel = code.S;
                    }
                    break;

                case 140:
                case 141:
                    if (code.hasS)
                    {
                        bedTemp = code.S;
                    }
                    fireChanged();
                    break;
                }
            }
            else if (code.hasT)
            {
                activeExtruder = code.T;
            }
        }
 public void Analyze(GCode code)
 {
     if (code.hostCommand)
     {
         if (code.getHostCommand().Equals("@hide"))
             drawing = false;
         else if (code.getHostCommand().Equals("@show"))
             drawing = true;
         return;
     }
     if (code.forceAscii) return; // Don't analyse host commands and unknown commands
     if (code.hasN)
         lastline = code.N;
     if (uploading && !code.hasM && code.M != 29) return; // ignore upload commands
     if (code.hasG)
     {
         switch (code.G)
         {
             case 0:
             case 1:
                 if (relative)
                 {
                     if(code.hasX) x += code.X;
                     if(code.hasY) y += code.Y;
                     if(code.hasZ) z += code.Z;
                     if(code.hasE) e += code.E;
                 }
                 else
                 {
                     if (code.hasX) x = xOffset+code.X;
                     if (code.hasY) y = yOffset+code.Y;
                     if (code.hasZ) z = zOffset+code.Z;
                     if (code.hasE)
                     {
                         if (eRelative)
                             e += code.E;
                         else
                             e = eOffset + code.E;
                     }
                 }
                 if (x < 0) { x = 0; hasXHome = false; }
                 if (y < 0) { y = 0; hasYHome = false; }
                 if (z < 0) { z = 0; hasZHome = false; }
                 if (x > printerWidth) { hasXHome = false; }
                 if (y > printerDepth) { hasYHome = false; }
                 if (z > printerHeight) { hasZHome = false; }
                 if (e > emax) emax = e;
                 if (eventPosChanged != null)
                     if (privateAnalyzer)
                         eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged,code, x, y, z);
                 break;
             case 28:
             case 161:
                 {
                     bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                     if (code.hasX || homeAll) { xOffset = 0; x = 0; hasXHome = true; }
                     if (code.hasY || homeAll) { yOffset = 0; y = 0; hasYHome = true; }
                     if (code.hasZ || homeAll) { zOffset = 0; z = 0; hasZHome = true; }
                     if (code.hasE) { eOffset = 0; e = 0; emax = 0; }
                     if (eventPosChanged != null)
                         if (privateAnalyzer)
                             eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged, code, x, y, z);
                 }
                 break;
             case 162:
                 {
                     bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                     if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true; }
                     if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true; }
                     if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; }
                     if (eventPosChanged != null)
                         if (privateAnalyzer)
                             eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged, code, x, y, z);
                 }
                 break;
             case 90:
                 relative = false;
                 break;
             case 91:
                 relative = true;
                 break;
             case 92:
                 if (code.hasX) { xOffset = x-code.X; x = xOffset; }
                 if (code.hasY) { yOffset = y-code.Y; y = zOffset; }
                 if (code.hasZ) { zOffset = z-code.Z; z = zOffset; }
                 if (code.hasE) { eOffset = e-code.E; e = eOffset; }
                 if (eventPosChanged != null)
                     if (privateAnalyzer)
                         eventPosChanged(code, x, y, z);
                     else
                         Main.main.Invoke(eventPosChanged, code, x, y, z);
                 break;
         }
     }
     else if (code.hasM)
     {
         switch (code.M)
         {
             case 28:
                 uploading = true;
                 break;
             case 29:
                 uploading = false;
                 break;
             case 80:
                 powerOn = true;
                 fireChanged();
                 break;
             case 81:
                 powerOn = false;
                 fireChanged();
                 break;
             case 82:
                 eRelative = false;
                 break;
             case 83:
                 eRelative = true;
                 break;
             case 104:
             case 109:
                 if (code.hasS) extruderTemp = code.S;
                 fireChanged();
                 break;
             case 106:
                 fanOn = true;
                 if (code.hasS) fanVoltage = code.S;
                 fireChanged();
                 break;
             case 107:
                 fanOn = false;
                 fireChanged();
                 break;
             case 110:
                 lastline = code.N;
                 break;
             case 111:
                 if (code.hasS)
                 {
                     debugLevel = code.S;
                 }
                 break;
             case 140:
             case 141:
                 if (code.hasS) bedTemp = code.S;
                 fireChanged();
                 break;
         }
     }
     else if (code.hasT)
     {
         activeExtruder = code.T;
     }
 }
Beispiel #30
0
 public void executeHostCommand(GCode code)
 {
     string com = code.getHostCommand();
     string param = code.getHostParameter();
     if (com.Equals("@info"))
     {
         conn.log(param, false, 3);
     }
     else if (com.Equals("@pause"))
     {
         conn.pause(param);
     }
 }
Beispiel #31
0
 public void PushData(string code)
 {
     code = code.Replace('\r', '\n');
     string[] lines = code.Split('\n');
     foreach (string line in lines)
     {
         if (line.Length == 0) continue;
         GCode gcode = new GCode();
         gcode.Parse(line);
         if (!gcode.comment)
         {
             jobList.AddLast(new GCodeCompressed(gcode));
             totalLines++;
         }
     }
 }
Beispiel #32
0
        public void Analyze(GCode code)
        {
            if (code.hostCommand)
            {
                string cmd = code.getHostCommand();
                if (cmd.Equals("@hide"))
                    drawing = false;
                else if (cmd.Equals("@show"))
                    drawing = true;
                else if (cmd.Equals("@isathome"))
                {
                    hasXHome = hasYHome = hasZHome = true;
                    x = Main.printerSettings.XHomePos;
                    y = Main.printerSettings.YHomePos;
                    z = Main.printerSettings.ZHomePos;
                    xOffset = yOffset = zOffset = 0;
                }
                return;
            }
            //if (code.forceAscii) return; // Don't analyse host commands and unknown commands
            if (code.hasN)
                lastline = code.N;
            if (uploading && !code.hasM && code.M != 29) return; // ignore upload commands
            if (code.hasG)
            {
                switch (code.G)
                {
                    case 0:
                    case 1:
                        eChanged = false;
                        if (code.hasF) f = code.F;
                        if (relative)
                        {
                            if (code.hasX) x += code.X;
                            if (code.hasY) y += code.Y;
                            if (code.hasZ) z += code.Z;
                            if (code.hasE)
                            {
                                if (eChanged = code.E != 0)
                                {
                                    if (code.E < 0) activeExtruder.retracted = true;
                                    else if (activeExtruder.retracted)
                                    {
                                        activeExtruder.retracted = false;
                                        activeExtruder.e = activeExtruder.emax;
                                    }
                                    else
                                        activeExtruder.e += code.E;
                                }
                            }
                        }
                        else
                        {
                            if (code.hasX) x = xOffset + code.X;
                            if (code.hasY) y = yOffset + code.Y;
                            if (code.hasZ)
                            {
                                z = zOffset + code.Z;
                            }
                            if (code.hasE)
                            {
                                if (eRelative)
                                {
                                    if (eChanged = code.E != 0)
                                    {
                                        if (code.E < 0) activeExtruder.retracted = true;
                                        else if (activeExtruder.retracted)
                                        {
                                            activeExtruder.retracted = false;
                                            activeExtruder.e = activeExtruder.emax;
                                        }
                                        else
                                            activeExtruder.e += code.E;
                                    }
                                }
                                else
                                {
                                    if (eChanged = activeExtruder.e != (activeExtruder.eOffset + code.E))
                                    {
                                        activeExtruder.e = activeExtruder.eOffset + code.E;
                                        if (activeExtruder.e < activeExtruder.lastE)
                                            activeExtruder.retracted = true;
                                        else if (activeExtruder.retracted)
                                        {
                                            activeExtruder.retracted = false;
                                            activeExtruder.e = activeExtruder.emax;
                                            activeExtruder.eOffset = activeExtruder.e - code.E;
                                        }
                                    }
                                }
                            }
                        }
                        if (x < Main.printerSettings.XMin) { x = Main.printerSettings.XMin; hasXHome = false; }
                        if (y < Main.printerSettings.YMin) { y = Main.printerSettings.YMin; hasYHome = false; }
                        if (z < 0 && FormPrinterSettings.ps.printerType!=3) { z = 0; hasZHome = false; }
                        if (x > Main.printerSettings.XMax) { hasXHome = false; }
                        if (y > Main.printerSettings.YMax) { hasYHome = false; }
                        if (z > printerHeight) { hasZHome = false; }
                        if (activeExtruder.e > activeExtruder.emax)
                        {
                            activeExtruder.emax = activeExtruder.e;
                            if (z != lastZPrint)
                            {
                                layer++;
                                lastZPrint = z;
                                if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                                {
                                    //PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                                    PrinterConnection.logInfo(Trans.T2("L_PRINTING_LAYER_X_OF_Y", layer.ToString(), Main.conn.job.maxLayer.ToString()));
                                }
                            }
                        }
                        if (eventPosChanged != null)
                            if (privateAnalyzer)
                                eventPosChanged(code, x, y, z);
                            else
                                Main.main.Invoke(eventPosChanged, code, x, y, z);
                        float dx = Math.Abs(x - lastX);
                        float dy = Math.Abs(y - lastY);
                        float dz = Math.Abs(z - lastZ);
                        float de = Math.Abs(activeExtruder.e - activeExtruder.lastE);
                        if (dx + dy + dz > 0.001)
                        {
                            printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f;
                        }
                        else printingTime += de * 60.0f / f;
                        if (z != lastZ) unchangedLayer.Clear();
                        lastX = x;
                        lastY = y;
                        lastZ = z;
                        activeExtruder.lastE = activeExtruder.e;
                        break;
                    case 2:
                    case 3:
                        {
                            isG1Move = true;
                            eChanged = false;
                            if (code.hasF) f = code.F;
                            if (relative)
                            {
                                if (code.hasX)
                                {
                                    x += code.X;
                                }
                                if (code.hasY)
                                {
                                    y += code.Y;
                                }
                                if (code.hasZ)
                                {
                                    z += code.Z;
                                }
                                if (code.hasE)
                                {
                                    if (eChanged = code.E != 0)
                                    {
                                        if (code.E < 0) activeExtruder.retracted = true;
                                        else if (activeExtruder.retracted)
                                        {
                                            activeExtruder.retracted = false;
                                            activeExtruder.e = activeExtruder.emax;
                                        }
                                        else
                                            activeExtruder.e += code.E;
                                    }
                                }
                            }
                            else
                            {
                                if (code.hasX)
                                {
                                    x = xOffset + code.X;
                                }
                                if (code.hasY)
                                {
                                    y = yOffset + code.Y;
                                }
                                if (code.hasZ)
                                {
                                    z = zOffset + code.Z;
                                    //if (z < 0) { z = 0; hasZHome = NO; }
                                    //if (z > printerHeight) { hasZHome = NO; }
                                }
                                if (code.hasE )
                                {
                                    if (eRelative)
                                    {
                                        if (eChanged = code.E != 0)
                                        {
                                            if (code.E < 0) activeExtruder.retracted = true;
                                            else if (activeExtruder.retracted)
                                            {
                                                activeExtruder.retracted = false;
                                                activeExtruder.e = activeExtruder.emax;
                                            }
                                            else
                                                activeExtruder.e += code.E;
                                        }
                                    }
                                    else
                                    {
                                        if (eChanged = activeExtruder.e != (activeExtruder.eOffset + code.E))
                                        {
                                            activeExtruder.e = activeExtruder.eOffset + code.E;
                                            if (activeExtruder.e < activeExtruder.lastE)
                                                activeExtruder.retracted = true;
                                            else if (activeExtruder.retracted)
                                            {
                                                activeExtruder.retracted = false;
                                                activeExtruder.e = activeExtruder.emax;
                                                activeExtruder.eOffset = activeExtruder.e - code.E;
                                            }
                                        }
                                    }
                                }
                            }

                            float[] offset = new float[] { code.I, code.J};
                            /* if(unit_inches) {
                               offset[0]*=25.4;
                               offset[1]*=25.4;
                             }*/
                            float[] position = new float[] { lastX, lastY };
                            float[] target = new float[] { x, y };
                            float r = code.R;
                            if (r > 0)
                            {
                                /*
                                  We need to calculate the center of the circle that has the designated radius and passes
                                  through both the current position and the target position. This method calculates the following
                                  set of equations where [x,y] is the vector from current to target position, d == magnitude of
                                  that vector, h == hypotenuse of the triangle formed by the radius of the circle, the distance to
                                  the center of the travel vector. A vector perpendicular to the travel vector [-y,x] is scaled to the
                                  length of h [-y/d*h, x/d*h] and added to the center of the travel vector [x/2,y/2] to form the new point
                                  [i,j] at [x/2-y/d*h, y/2+x/d*h] which will be the center of our arc.

                                  d^2 == x^2 + y^2
                                  h^2 == r^2 - (d/2)^2
                                  i == x/2 - y/d*h
                                  j == y/2 + x/d*h

                                                                                       O <- [i,j]
                                                                                    -  |
                                                                          r      -     |
                                                                              -        |
                                                                           -           | h
                                                                        -              |
                                                          [0,0] ->  C -----------------+--------------- T  <- [x,y]
                                                                    | <------ d/2 ---->|

                                  C - Current position
                                  T - Target position
                                  O - center of circle that pass through both C and T
                                  d - distance from C to T
                                  r - designated radius
                                  h - distance from center of CT to O

                                  Expanding the equations:

                                  d -> sqrt(x^2 + y^2)
                                  h -> sqrt(4 * r^2 - x^2 - y^2)/2
                                  i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2
                                  j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2

                                  Which can be written:

                                  i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2
                                  j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2

                                  Which we for size and speed reasons optimize to:

                                  h_x2_div_d = sqrt(4 * r^2 - x^2 - y^2)/sqrt(x^2 + y^2)
                                  i = (x - (y * h_x2_div_d))/2
                                  j = (y + (x * h_x2_div_d))/2

                                */
                                //if(unit_inches) r*=25.4;
                                // Calculate the change in position along each selected axis
                                float cx = target[0] - position[0];
                                float cy = target[1] - position[1];

                                float h_x2_div_d = -(float)Math.Sqrt(4 * r * r - cx * cx - cy * cy) / (float)Math.Sqrt(cx * cx + cy * cy); // == -(h * 2 / d)
                                // If r is smaller than d, the arc is now traversing the complex plane beyond the reach of any
                                // real CNC, and thus - for practical reasons - we will terminate promptly:
                                // if(isnan(h_x2_div_d)) { OUT_P_LN("error: Invalid arc"); break; }
                                // Invert the sign of h_x2_div_d if the circle is counter clockwise (see sketch below)
                                if (code.G == 3) { h_x2_div_d = -h_x2_div_d; }

                                /* The counter clockwise circle lies to the left of the target direction. When offset is positive,
                                   the left hand circle will be generated - when it is negative the right hand circle is generated.

                                                                                 T  <-- Target position

                                                                                 ^
                                      Clockwise circles with this center         |          Clockwise circles with this center will have
                                      will have > 180 deg of angular travel      |          < 180 deg of angular travel, which is a good thing!
                                                                       \         |          /
                          center of arc when h_x2_div_d is positive ->  x <----- | -----> x <- center of arc when h_x2_div_d is negative
                                                                                 |
                                                                                 |

                                                                                 C  <-- Current position                                 */

                                // Negative R is g-code-alese for "I want a circle with more than 180 degrees of travel" (go figure!),
                                // even though it is advised against ever generating such circles in a single line of g-code. By
                                // inverting the sign of h_x2_div_d the center of the circles is placed on the opposite side of the line of
                                // travel and thus we get the unadvisably long arcs as prescribed.
                                if (r < 0)
                                {
                                    h_x2_div_d = -h_x2_div_d;
                                    r = -r; // Finished with r. Set to positive for mc_arc
                                }
                                // Complete the operation by calculating the actual center of the arc
                                offset[0] = 0.5f * (cx - (cy * h_x2_div_d));
                                offset[1] = 0.5f * (cy + (cx * h_x2_div_d));

                            }
                            else
                            { // Offset mode specific computations
                                r = (float)Math.Sqrt(offset[0] * offset[0] + offset[1] * offset[1]); // Compute arc radius for mc_arc
                            }

                            // Set clockwise/counter-clockwise sign for mc_arc computations
                            bool isclockwise = code.G == 2;

                            // Trace the arc
                            arc(position, target, offset, r, isclockwise,code);
                            lastX = x;
                            lastY = y;
                            lastZ = z;
                            activeExtruder.lastE = activeExtruder.e;
                            if (x < Main.printerSettings.XMin) { x = Main.printerSettings.XMin; hasXHome = false; }
                            if (y < Main.printerSettings.YMin) { y = Main.printerSettings.YMin; hasYHome = false; }
                            if (z < 0) { z = 0; hasZHome = false; }
                            if (x > Main.printerSettings.XMax) { hasXHome = false; }
                            if (y > Main.printerSettings.YMax) { hasYHome = false; }
                            if (z > printerHeight) { hasZHome = false; }
                            if (activeExtruder.e > activeExtruder.emax)
                            {
                                activeExtruder.emax = activeExtruder.e;
                                if (z > lastZPrint)
                                {
                                    lastZPrint = z;
                                    layer++;
                                }
                            }

                        }
                        break;
                    case 28:
                    case 161:
                        {
                            bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                            if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XHomePos; hasXHome = true; }
                            if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YHomePos; hasYHome = true; }
                            if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.ZHomePos; hasZHome = true; }
                            if (code.hasE) { activeExtruder.eOffset = 0; activeExtruder.e = 0; activeExtruder.emax = 0; }
                            if (eventPosChanged != null)
                                if (privateAnalyzer)
                                    eventPosChanged(code, x, y, z);
                                else
                                    Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                        break;
                    case 162:
                        {
                            bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                            if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XMax; hasXHome = true; }
                            if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YMax; hasYHome = true; }
                            if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; }
                            if (eventPosChanged != null)
                                if (privateAnalyzer)
                                    eventPosChanged(code, x, y, z);
                                else
                                    Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                        break;
                    case 90:
                        relative = false;
                        break;
                    case 91:
                        relative = true;
                        break;
                    case 92:
                        if (code.hasX) { xOffset = x - code.X; x = xOffset; }
                        if (code.hasY) { yOffset = y - code.Y; y = yOffset; }
                        if (code.hasZ) { zOffset = z - code.Z; z = zOffset; }
                        if (code.hasE) { activeExtruder.eOffset = activeExtruder.e - code.E; activeExtruder.lastE = activeExtruder.e = activeExtruder.eOffset; }
                        if (eventPosChanged != null)
                            if (privateAnalyzer)
                                eventPosChanged(code, x, y, z);
                            else
                                Main.main.Invoke(eventPosChanged, code, x, y, z);
                        break;
                }
            }
            else if (code.hasM)
            {
                switch (code.M)
                {
                    case 28:
                        uploading = true;
                        break;
                    case 29:
                        uploading = false;
                        break;
                    case 80:
                        powerOn = true;
                        fireChanged();
                        break;
                    case 81:
                        powerOn = false;
                        fireChanged();
                        break;
                    case 82:
                        eRelative = false;
                        break;
                    case 83:
                        eRelative = true;
                        break;
                    case 104:
                    case 109:
                        {
                            int idx = activeExtruderId;
                            if (code.hasT) idx = code.T;
                            if (code.hasS) setTemperature(idx, code.S);
                        }
                        fireChanged();
                        break;
                    case 106:
                        fanOn = true;
                        if (code.hasS) fanVoltage = code.S;
                        fireChanged();
                        break;
                    case 107:
                        fanOn = false;
                        fireChanged();
                        break;
                    case 110:
                        lastline = code.N;
                        break;
                    case 111:
                        if (code.hasS)
                        {
                            debugLevel = code.S;
                        }
                        break;
                    case 140:
                    case 190:
                        if (code.hasS) bedTemp = code.S;
                        fireChanged();
                        break;
                    case 203: // Temp monitor
                        if (code.hasS)
                            tempMonitor = code.S;
                        break;
                    case 220:
                        if (code.hasS)
                            speedMultiply = code.S;
                        break;
                }
            }
            else if (code.hasT)
            {
                activeExtruderId = code.T;
                if (!extruder.ContainsKey(activeExtruderId))
                    extruder.Add(activeExtruderId, new ExtruderData(activeExtruderId));
                activeExtruder = extruder[activeExtruderId];
                fireChanged();
            }
        }
Beispiel #33
0
 private void coordUpdate(GCode code,float x,float y,float z)
 {
     if (x != -lastx)
     {
         labelX.Text = "X=" + x.ToString("0.00");
         if (ann.hasXHome)
             labelX.ForeColor = SystemColors.ControlText;
         else
             labelX.ForeColor = Color.Red;
         lastx = x;
     }
     if (y != lasty)
     {
         labelY.Text = "Y=" + y.ToString("0.00");
         if (ann.hasYHome)
             labelY.ForeColor = SystemColors.ControlText;
         else
             labelY.ForeColor = Color.Red;
         lasty = y;
     }
     if (z != lastz)
     {
         labelZ.Text = "Z=" + z.ToString("0.00");
         if (ann.hasZHome)
             labelZ.ForeColor = SystemColors.ControlText;
         else
             labelZ.ForeColor = Color.Red;
         lastz = z;
     }
 }
Beispiel #34
0
        public GCode PopData()
        {
            GCode gc       = null;
            bool  finished = false;

            lock (jobList)
            {
                if (jobList.Count == 0)
                {
                    return(null);
                }
                try
                {
                    gc = jobList.First.Value;
                    jobList.RemoveFirst();
                    linesSend++;

                    /*PrintTime pt = new PrintTime();
                     * pt.line = linesSend;
                     * pt.time = DateTime.Now.Ticks;
                     * lock (times)
                     * {
                     *  times.AddLast(pt);
                     *  if (times.Count > 1500)
                     *      times.RemoveFirst();
                     * }*/
                }
                catch { };
                finished = jobList.Count == 0 && mode != 3;
            }
            if (finished)
            {
                dataComplete = false;
                mode         = 2;
                jobFinished  = DateTime.Now;
                long ticks = (jobFinished.Ticks - jobStarted.Ticks) / 10000;
                long hours = ticks / 3600000;
                ticks -= 3600000 * hours;
                long min = ticks / 60000;
                ticks -= 60000 * min;
                long sec = ticks / 1000;
                //Main.conn.log("Printjob finished at " + jobFinished.ToShortDateString()+" "+jobFinished.ToShortTimeString(),false,3);
                Main.conn.log(Trans.T1("L_PRINTJOB_FINISHED_AT", jobFinished.ToShortDateString() + " " + jobFinished.ToShortTimeString()), false, 3);
                StringBuilder s = new StringBuilder();
                if (hours > 0)
                {
                    s.Append(Trans.T1("L_TIME_H:", hours.ToString())); //"h:");
                }
                if (min > 0)
                {
                    s.Append(Trans.T1("L_TIME_M:", min.ToString()));
                }
                s.Append(Trans.T1("L_TIME_S", sec.ToString()));
                //Main.conn.log("Printing time:"+s.ToString(),false,3);
                //Main.conn.log("Lines send:" + linesSend.ToString(), false, 3);
                //Main.conn.firePrinterAction("Finished in "+s.ToString());
                Main.conn.log(Trans.T1("L_PRINTING_TIME:", s.ToString()), false, 3);
                Main.conn.log(Trans.T1("L_LINES_SEND:X", linesSend.ToString()), false, 3);
                Main.conn.firePrinterAction(Trans.T1("L_FINISHED_IN", s.ToString()));
                DoEndKillActions();
                Main.main.Invoke(Main.main.UpdateJobButtons);
                Main.main.printPanel.Invoke(Main.main.printPanel.SetStatusJobFinished);
                RepetierHost.view.SoundConfig.PlayPrintFinished(false);
            }
            return(gc);
        }
 /// <summary>
 /// Send a print command, that does not belong to a print job.
 /// </summary>
 /// <param name="command">GCode command</param>
 public void injectManualCommand(string command)
 {
     GCode gc = new GCode();
     gc.Parse(command);
     lock(history)
         injectCommands.AddLast(gc);
     if (job.dataComplete == false)
     {
         if (injectCommands.Count == 0)
         {
             firePrinterAction("Idle");
         }
         else
         {
             firePrinterAction(injectCommands.Count.ToString() + " commands waiting");
         }
     }
 }
Beispiel #36
0
 public void Reduce()
 {
     if (segments.Count < 2)
     {
         return;
     }
     if (!liveView)
     {
         GCodePath first = segments.First.Value;
         while (segments.Count > 1)
         {
             first.Join(segments.First.Next.Value);
             segments.First.Next.Value.Free();
             segments.Remove(segments.First.Next.Value);
         }
     }
     else
     {
         LinkedListNode <GCodePath> act = segments.First, next;
         while (act.Next != null)
         {
             next = act.Next;
             if (next.Next == null)
             {
                 return;                    // Don't touch last segment we are writing to
             }
             GCodePath nextval = next.Value;
             if (nextval.pointsCount < 2)
             {
                 act = next;
                 if (act.Next != null)
                 {
                     act = act.Next;
                 }
             }
             else if (nextval.lastDist > minHotDist)
             {
                 if (act.Value.pointsCount < 500)
                 {
                     act.Value.Join(nextval);
                     segments.Remove(nextval);
                     nextval.Free();
                 }
                 else
                 {
                     act = next;
                 }
             }
             else
             if (act.Value.pointsCount < 5000 || (nextval.pointsCount >= 5000 && act.Value.pointsCount < 27000))
             {
                 act.Value.Join(nextval);
                 segments.Remove(nextval);
                 nextval.Free();
             }
             else
             {
                 act = next;
             }
         }
     }
 }
Beispiel #37
0
 public void executeHostCommand(GCode code)
 {
     string com = code.getHostCommand();
     string param = code.getHostParameter();
     if (com.Equals("@info"))
     {
         conn.log(param, false, 3);
     }
     else if (com.Equals("@pause"))
     {
         SoundConfig.PlayPrintPaused(false);
         conn.pause(param);
     }
     else if (com.Equals("@sound"))
     {
         SoundConfig.PlaySoundCommand(false);
     }
 }
        public void TrySendNextLine()
        {
            string logtext       = null;
            int    loglevel      = 0;
            float  logprogress   = -1;
            string printeraction = null;
            GCode  historygc     = null;

            try
            {
                lock (nextlineLock)
                {
                    if (pingpong && !readyForNextSend)
                    {
                        return;
                    }
                    if (serial == null)
                    {
                        return;         // Not ready yet
                    }
                    if (!serial.IsOpen) // someone unplugged the cord?
                    {
                        close();
                        return;
                    }
                    GCode gc = null;
                    try
                    {
                        // first resolve old communication problems
                        if (resendNode != null)
                        {
                            gc = resendNode.Value;
                            if (binaryVersion == 0)
                            {
                                string cmd = gc.getAscii(true, true);
                                if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize)
                                {
                                    return;                                                                   // printer cache full
                                }
                                if (pingpong)
                                {
                                    readyForNextSend = false;
                                }
                                else
                                {
                                    lock (nackLines) { nackLines.AddLast(cmd.Length + 2); }
                                }
                                serial.WriteLine(cmd);
                                bytesSend += cmd.Length + 2;
                            }
                            else
                            {
                                byte[] cmd = gc.getBinary(binaryVersion);
                                if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize)
                                {
                                    return;                                                               // printer cache full
                                }
                                if (pingpong)
                                {
                                    readyForNextSend = false;
                                }
                                else
                                {
                                    lock (nackLines) { nackLines.AddLast(cmd.Length); }
                                }
                                serial.Write(cmd, 0, cmd.Length);
                                bytesSend += cmd.Length;
                            }
                            linesSend++;
                            lastCommandSend = DateTime.Now.Ticks;
                            resendNode      = resendNode.Next;
                            logtext         = "Resend: " + gc.getAscii(true, true);
                            //  if (resendNode == null) readyForNextSend = true;
                            //readyForNextSend = false;
                            return;
                        }
                        if (resendError > 0)
                        {
                            resendError--;                  // Drop error counter
                        }
                        // then check for manual commands
                        if (injectCommands.Count > 0)
                        {
                            lock (history)
                            {
                                gc   = injectCommands.First.Value;
                                gc.N = ++lastline;
                                if (binaryVersion == 0)
                                {
                                    string cmd = gc.getAscii(true, true);
                                    if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize)
                                    {
                                        --lastline; return;
                                    }                                                                                             // printer cache full
                                    if (pingpong)
                                    {
                                        readyForNextSend = false;
                                    }
                                    else
                                    {
                                        lock (nackLines) { nackLines.AddLast(cmd.Length); }
                                    }
                                    serial.WriteLine(cmd);
                                    bytesSend += cmd.Length + 2;
                                }
                                else
                                {
                                    byte[] cmd = gc.getBinary(binaryVersion);
                                    if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize)
                                    {
                                        --lastline; return;
                                    }                                                                                         // printer cache full
                                    if (pingpong)
                                    {
                                        readyForNextSend = false;
                                    }
                                    else
                                    {
                                        lock (nackLines) { nackLines.AddLast(cmd.Length); }
                                    }
                                    serial.Write(cmd, 0, cmd.Length);
                                    bytesSend += cmd.Length;
                                }
                                injectCommands.RemoveFirst();
                            }
                            linesSend++;
                            lastCommandSend = DateTime.Now.Ticks;
                            historygc       = gc;
                            analyzer.Analyze(gc);
                            if (job.dataComplete == false)
                            {
                                if (injectCommands.Count == 0)
                                {
                                    printeraction = "Idle";
                                }
                                else
                                {
                                    printeraction = injectCommands.Count.ToString() + " commands waiting";
                                }
                            }
                            return;
                        }
                        // do we have a printing job?
                        if (job.dataComplete)
                        {
                            lock (history)
                            {
                                gc   = job.PeekData();
                                gc.N = ++lastline;
                                if (binaryVersion == 0)
                                {
                                    string cmd = gc.getAscii(true, true);
                                    if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize)
                                    {
                                        --lastline; return;
                                    }                                                                                             // printer cache full
                                    if (pingpong)
                                    {
                                        readyForNextSend = false;
                                    }
                                    else
                                    {
                                        lock (nackLines) { nackLines.AddLast(cmd.Length + 2); }
                                    }
                                    serial.WriteLine(cmd);
                                    bytesSend += cmd.Length + 2;
                                }
                                else
                                {
                                    byte[] cmd = gc.getBinary(binaryVersion);
                                    if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize)
                                    {
                                        --lastline; return;
                                    }                                                                                         // printer cache full
                                    if (pingpong)
                                    {
                                        readyForNextSend = false;
                                    }
                                    else
                                    {
                                        lock (nackLines) { nackLines.AddLast(cmd.Length); }
                                    }
                                    serial.Write(cmd, 0, cmd.Length);
                                    bytesSend += cmd.Length;
                                }
                                historygc = gc;
                                job.PopData();
                            }
                            linesSend++;
                            lastCommandSend = DateTime.Now.Ticks;
                            analyzer.Analyze(gc);
                            printeraction = "Printing...ETA " + job.ETA;
                            logprogress   = job.PercentDone;
                        }
                    }
                    catch (InvalidOperationException ex)
                    {
                        logtext  = "Error sending data:" + ex;
                        loglevel = 2;
                    }
                }
            }
            finally
            {
                // need to extract log/event calls because they cause deadlocks inside
                // the lock statement.
                if (historygc != null)
                {
                    StoreHistory(historygc);
                }
                if (logtext != null)
                {
                    log(logtext, false, loglevel);
                }
                if (printeraction != null)
                {
                    firePrinterAction(printeraction);
                }
                if (logprogress >= 0 && eventJobProgress != null)
                {
                    Main.main.Invoke(eventJobProgress, job.PercentDone);
                }
            }
        }
Beispiel #39
0
        private void arc(float[] position, float[] target, float[] offset, float radius, bool isclockwise,GCode code)
        {
            //   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
            //   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
            float center_axis0 = position[0] + offset[0];
            float center_axis1 = position[1] + offset[1];
            //float linear_travel = 0; //target[axis_linear] - position[axis_linear];
            float r_axis0 = -offset[0];  // Radius vector from center to current location
            float r_axis1 = -offset[1];
            float rt_axis0 = target[0] - center_axis0;
            float rt_axis1 = target[1] - center_axis1;

            // CCW angle between position and target from circle center. Only one atan2() trig computation required.
            float angular_travel = (float)Math.Atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
            if (angular_travel < 0) { angular_travel += 2 * (float)Math.PI; }
            if (isclockwise) { angular_travel -= 2 * (float)Math.PI; }

            float millimeters_of_travel = Math.Abs(angular_travel) * radius; //hypot(angular_travel*radius, fabs(linear_travel));
            if (millimeters_of_travel < 0.001) { return; }
            printingTime += millimeters_of_travel * 60.0f / f;
            if (eventPosChangedFast == null) return;
            //uint16_t segments = (radius>=BIG_ARC_RADIUS ? floor(millimeters_of_travel/MM_PER_ARC_SEGMENT_BIG) : floor(millimeters_of_travel/MM_PER_ARC_SEGMENT));
            // Increase segment size if printing faster then computation speed allows
            int segments = (int)Math.Min(millimeters_of_travel,millimeters_of_travel*10/radius);
            if (segments > 32) segments = 32;
            if (segments == 0) segments = 1;
            /*
              // Multiply inverse feed_rate to compensate for the fact that this movement is approximated
              // by a number of discrete segments. The inverse feed_rate should be correct for the sum of
              // all segments.
              if (invert_feed_rate) { feed_rate *= segments; }
            */
            float theta_per_segment = angular_travel / segments;
            //float linear_per_segment = linear_travel / segments;
            float extruder_per_segment = (activeExtruder.e - activeExtruder.lastE) / segments;
            float arc_target_e = activeExtruder.lastE;
            float sin_Ti;
            float cos_Ti;
            int i;

            for (i = 1; i < segments; i++)
            { // Increment (segments-1)
                // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
                // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
                cos_Ti = (float)Math.Cos(i * theta_per_segment);
                sin_Ti = (float)Math.Sin(i * theta_per_segment);
                r_axis0 = -offset[0] * cos_Ti + offset[1] * sin_Ti;
                r_axis1 = -offset[0] * sin_Ti - offset[1] * cos_Ti;

                // Update arc_target location
                //arc_target[axis_linear] += linear_per_segment;
                arc_target_e += extruder_per_segment;
                if (arc_target_e > activeExtruder.emax)
                {
                    activeExtruder.emax = arc_target_e;
                    if (z > lastZPrint)
                    {
                        lastZPrint = z;
                        layer++;
                        if (code!=null)
                        {
                            if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                            {
                                //PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                                PrinterConnection.logInfo(Trans.T2("L_PRINTING_LAYER_X_OF_Y", layer.ToString(), Main.conn.job.maxLayer.ToString()));
                            }
                        }
                    }
                }
                if (code!=null)
                {
                    if (privateAnalyzer)
                        eventPosChanged(code, center_axis0 + r_axis0, center_axis1 + r_axis1, z);
                    else
                        Main.main.Invoke(eventPosChanged, code, center_axis0 + r_axis0, center_axis1 + r_axis1, z);
                } else
                eventPosChangedFast(center_axis0 + r_axis0, center_axis1 + r_axis1, z, arc_target_e);
            }
            // Ensure last segment arrives at target location.
            if (activeExtruder.e > activeExtruder.emax)
            {
                activeExtruder.emax = activeExtruder.e;
                if (z > lastZPrint)
                {
                    lastZPrint = z;
                    layer++;
                    if (code!=null)
                    {
                        if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                        {
                            //PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                            PrinterConnection.logInfo(Trans.T2("L_PRINTING_LAYER_X_OF_Y", layer.ToString(), Main.conn.job.maxLayer.ToString()));
                        }
                    }
                }
            }
            if (code!=null)
            {
                if (privateAnalyzer)
                    eventPosChanged(code, x, y, z);
                else
                    Main.main.Invoke(eventPosChanged, code, x, y, z);
            }
            else
                eventPosChangedFast(x, y, z, activeExtruder.e);
        }
 void OnPosChange(GCode act, float x, float y, float z)
 {
     if (!ana.drawing)
     {
         lastx = x;
         lasty = y;
         lastz = z;
         laste = ana.emax;
         return;
     }
     float locDist = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
     bool isLastPos = locDist < 0.00001;
     if (!act.hasG || (act.G > 1 && act.G != 28)) return;
     if (segments.Count == 0 || laste >= ana.e) // start new segment
     {
         if (!isLastPos) // no move, no action
         {
             GCodePath p = new GCodePath();
             p.Add(new Vector3(x, y, z), ana.emax, totalDist);
             if (segments.Count > 0 && segments.Last.Value.pointsLists.Last.Value.Count == 1)
             {
                 segments.RemoveLast();
             }
             segments.AddLast(p);
             changed = true;
         }
     }
     else
     {
         if (!isLastPos)
         {
             totalDist += locDist;
             segments.Last.Value.Add(new Vector3(x, y, z), ana.emax, totalDist);
             changed = true;
         }
     }
     lastx = x;
     lasty = y;
     lastz = z;
     laste = ana.emax;
 }
 private void StoreHistory(GCode gcode)
 {
     history.AddLast(gcode);
     log(gcode.getAscii(true, true), false, 0);
     if (history.Count > 40)
         history.RemoveFirst();
 }
 public void open()
 {
     if (writeThread == null)
     {
         writeThread = new Thread(new ThreadStart(this.WriteLoop));
         writeThread.Start();
     }
     isMarlin = isRepetier = false;
     try
     {
         if (port.ToLower().Equals("virtual printer"))
         {
             isVirtualActive = true;
             virtualPrinter.open();
             GCode gc = new GCode();
             gc.Parse("M105");
             virtualPrinter.receiveLine(gc);
             connected = true;
             if (transferProtocol < 2)
                 binaryVersion = 0;
             else binaryVersion = transferProtocol - 1;
             readyForNextSend = true;
             nackLines.Clear();
             ignoreNextOk = false;
             linesSend = errorsReceived = bytesSend = 0;
             gc.Parse("N0 M110");
             virtualPrinter.receiveLine(gc);
             gc.Parse("M115");
             virtualPrinter.receiveLine(gc);
             gc.Parse("M105");
             virtualPrinter.receiveLine(gc);
             if (eventConnectionChange != null)
                 eventConnectionChange(Trans.T("L_CONNECTED"));
             Main.main.Invoke(Main.main.UpdateJobButtons);
             return;
         }
         isVirtualActive = false;
         if (Main.IsMono)
             serial = new SerialPort();
         else
             serial = new ProtectedSerialPort();
         garbageCleared = false;
         serial.PortName = port;
         serial.BaudRate = baud;
         serial.Parity = parity;
         serial.DataBits = databits;
         serial.StopBits = stopbits;
         if (!Main.IsMono)
             serial.DataReceived += received;
         serial.ErrorReceived += error;
         serial.RtsEnable = false;
         serial.DtrEnable = false;
         serial.Open();
       //  serial.DtrEnable = true;
      //   Thread.Sleep(400);
      //   serial.DtrEnable = false;
         // If we didn't restart the connection we need to eat
         // all unread data on this port.
         serial.DiscardInBuffer();
         /*while(serial.BytesToRead > 0)
         {
             string indata = serial.ReadExisting();
         }*/
         serial.WriteLine("M105");
         connected = true;
         if (transferProtocol < 2)
             binaryVersion = 0;
         else binaryVersion = transferProtocol - 1;
         readyForNextSend = true;
         nackLines.Clear();
         ignoreNextOk = false;
         linesSend = errorsReceived = bytesSend = 0;
         if (readThread == null && Main.IsMono)
         {
             readThread = new Thread(new ThreadStart(this.ReadThread));
             readThread.Start();
         }
         GetInjectLock();
         injectManualCommand("N0 M110"); // Make sure we tal about the same linenumbers
         injectManualCommand("M115"); // Check firmware
         injectManualCommand("M105"); // Read temperature
         ReturnInjectLock();
         if (eventConnectionChange != null)
             eventConnectionChange(Trans.T("L_CONNECTED"));
         Main.main.Invoke(Main.main.UpdateJobButtons);
     }
     catch (IOException ex)
     {
         serial = null;
         log(ex.Message, true, 2);
         if (eventConnectionChange != null)
             eventConnectionChange(Trans.T("L_CONNECTION_ERROR")); // "Conn. error");
         RepetierHost.view.SoundConfig.PlayError(false);
     }
 }
 public void Reduce()
 {
     if (segments.Count < 2) return;
     if (!liveView)
     {
         GCodePath first = segments.First.Value;
         while (segments.Count > 1)
         {
             first.Join(segments.First.Next.Value);
             segments.First.Next.Value.Free();
             segments.Remove(segments.First.Next.Value);
         }
     }
     else
     {
         LinkedListNode<GCodePath> act = segments.First, next;
         while (act.Next != null)
         {
             next = act.Next;
             if (next.Next == null) return; // Don't touch last segment we are writing to
             GCodePath nextval = next.Value;
             if (nextval.pointsCount < 2)
             {
                 act = next;
                 if (act.Next != null)
                     act = act.Next;
             }
             else if (nextval.lastDist > minHotDist)
             {
                 if (act.Value.pointsCount < 500)
                 {
                     act.Value.Join(nextval);
                     segments.Remove(nextval);
                     nextval.Free();
                 }
                 else
                 {
                     act = next;
                 }
             }
             else
                 if (act.Value.pointsCount < 5000 || (nextval.pointsCount >= 5000 && act.Value.pointsCount < 27000))
                 {
                     act.Value.Join(nextval);
                     segments.Remove(nextval);
                     nextval.Free();
                 }
                 else
                 {
                     act = next;
                 }
         }
     }
 }
Beispiel #44
0
        public void Analyze(GCode code)
        {
            if (code.hostCommand || code.forceAscii)
            {
                return;                                      // Don't analyse host commands and unknown commands
            }
            if (code.hasN)
            {
                lastline = code.N;
            }
            if (uploading && !code.hasM && code.M != 29)
            {
                return;                                          // ignore upload commands
            }
            if (code.hasG)
            {
                switch (code.G)
                {
                case 0:
                case 1:
                    if (relative)
                    {
                        if (code.hasX)
                        {
                            x += code.X;
                        }
                        if (code.hasY)
                        {
                            y += code.Y;
                        }
                        if (code.hasZ)
                        {
                            z += code.Z;
                        }
                        if (code.hasE)
                        {
                            e += code.E;
                        }
                    }
                    else
                    {
                        if (code.hasX)
                        {
                            x = xOffset + code.X;
                        }
                        if (code.hasY)
                        {
                            y = yOffset + code.Y;
                        }
                        if (code.hasZ)
                        {
                            z = zOffset + code.Z;
                        }
                        if (code.hasE)
                        {
                            if (eRelative)
                            {
                                e += code.E;
                            }
                            else
                            {
                                e = eOffset + code.E;
                            }
                        }
                    }
                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (y < 0)
                    {
                        y = 0;
                    }
                    if (z < 0)
                    {
                        z = 0;
                    }
                    if (e > emax)
                    {
                        emax = e;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    break;

                case 28:
                case 161:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = 0; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = 0; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = 0; hasZHome = true;
                    }
                    if (code.hasE)
                    {
                        eOffset = 0; e = 0; emax = 0;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 162:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 90:
                    relative = false;
                    break;

                case 91:
                    relative = true;
                    break;

                case 92:
                    if (code.hasX)
                    {
                        xOffset = x - code.X; x = xOffset;
                    }
                    if (code.hasY)
                    {
                        yOffset = y - code.Y; y = zOffset;
                    }
                    if (code.hasZ)
                    {
                        zOffset = z - code.Z; z = zOffset;
                    }
                    if (code.hasE)
                    {
                        eOffset = e - code.E; e = eOffset;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    break;
                }
            }
            else if (code.hasM)
            {
                switch (code.M)
                {
                case 28:
                    uploading = true;
                    break;

                case 29:
                    uploading = false;
                    break;

                case 80:
                    powerOn = true;
                    fireChanged();
                    break;

                case 81:
                    powerOn = false;
                    fireChanged();
                    break;

                case 82:
                    eRelative = false;
                    break;

                case 83:
                    eRelative = true;
                    break;

                case 104:
                case 109:
                    if (code.hasS)
                    {
                        extruderTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 106:
                    fanOn = true;
                    if (code.hasS)
                    {
                        fanVoltage = code.S;
                    }
                    fireChanged();
                    break;

                case 107:
                    fanOn = false;
                    fireChanged();
                    break;

                case 110:
                    lastline = code.N;
                    break;

                case 111:
                    if (code.hasS)
                    {
                        debugLevel = code.S;
                    }
                    break;

                case 140:
                case 141:
                    if (code.hasS)
                    {
                        bedTemp = code.S;
                    }
                    fireChanged();
                    break;
                }
            }
            else if (code.hasT)
            {
                activeExtruder = code.T;
            }
        }
 public void injectManualCommandFirst(string command)
 {
     GCode gc = new GCode();
     gc.Parse(command);
     if (gc.comment) return;
     lock (history)
         injectCommands.AddFirst(gc);
     if (job.dataComplete == false)
     {
         if (injectCommands.Count == 0)
         {
             firePrinterAction(Trans.T("L_IDLE"));
         }
         else
         {
             firePrinterAction(Trans.T1("L_X_COMMANDS_WAITING", injectCommands.Count.ToString()));
         }
     }
 }
Beispiel #46
0
 public void ParseText(string text, bool clear)
 {
     GCode gc = new GCode();
     if (clear)
         Clear();
     foreach (string s in text.Split('\n'))
     {
         gc.Parse(s);
         AddGCode(gc);
     }
 }
Beispiel #47
0
        public void Analyze(GCode code)
        {
            if (code.hostCommand)
            {
                string cmd = code.getHostCommand();
                if (cmd.Equals("@hide"))
                {
                    drawing = false;
                }
                else if (cmd.Equals("@show"))
                {
                    drawing = true;
                }
                else if (cmd.Equals("@isathome"))
                {
                    hasXHome = hasYHome = hasZHome = true;
                    x        = Main.printerSettings.XHomePos;
                    y        = Main.printerSettings.YHomePos;
                    z        = Main.printerSettings.ZHomePos;
                    xOffset  = yOffset = zOffset = 0;
                }
                return;
            }
            //if (code.forceAscii) return; // Don't analyse host commands and unknown commands
            if (code.hasN)
            {
                lastline = code.N;
            }
            if (uploading && !code.hasM && code.M != 29)
            {
                return;                                          // ignore upload commands
            }
            if (code.hasG)
            {
                switch (code.G)
                {
                case 0:
                case 1:
                    if (code.hasF)
                    {
                        f = code.F;
                    }
                    if (relative)
                    {
                        if (code.hasX)
                        {
                            x += code.X;
                        }
                        if (code.hasY)
                        {
                            y += code.Y;
                        }
                        if (code.hasZ)
                        {
                            z += code.Z;
                        }
                        if (code.hasE)
                        {
                            e += code.E;
                        }
                    }
                    else
                    {
                        if (code.hasX)
                        {
                            x = xOffset + code.X;
                        }
                        if (code.hasY)
                        {
                            y = yOffset + code.Y;
                        }
                        if (code.hasZ)
                        {
                            z = zOffset + code.Z;
                        }
                        if (code.hasE)
                        {
                            if (eRelative)
                            {
                                e += code.E;
                            }
                            else
                            {
                                e = eOffset + code.E;
                            }
                        }
                    }
                    if (x < Main.printerSettings.XMin)
                    {
                        x = Main.printerSettings.XMin; hasXHome = false;
                    }
                    if (y < Main.printerSettings.YMin)
                    {
                        y = Main.printerSettings.YMin; hasYHome = false;
                    }
                    if (z < 0)
                    {
                        z = 0; hasZHome = false;
                    }
                    if (x > Main.printerSettings.XMax)
                    {
                        hasXHome = false;
                    }
                    if (y > Main.printerSettings.YMax)
                    {
                        hasYHome = false;
                    }
                    if (z > printerHeight)
                    {
                        hasZHome = false;
                    }
                    if (e > emax)
                    {
                        emax = e;
                        if (z != lastZPrint)
                        {
                            layer++;
                            lastZPrint = z;
                            if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                            {
                                //PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                                PrinterConnection.logInfo(Trans.T2("L_PRINTING_LAYER_X_OF_Y", layer.ToString(), Main.conn.job.maxLayer.ToString()));
                            }
                        }
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    float dx = Math.Abs(x - lastX);
                    float dy = Math.Abs(y - lastY);
                    float dz = Math.Abs(z - lastZ);
                    float de = Math.Abs(e - lastE);
                    if (dx + dy + dz > 0.001)
                    {
                        printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f;
                    }
                    else
                    {
                        printingTime += de * 60.0f / f;
                    }
                    lastX = x;
                    lastY = y;
                    lastZ = z;
                    lastE = e;
                    break;

                case 28:
                case 161:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = Main.printerSettings.XHomePos; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = Main.printerSettings.YHomePos; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = Main.printerSettings.ZHomePos; hasZHome = true;
                    }
                    if (code.hasE)
                    {
                        eOffset = 0; e = 0; emax = 0;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 162:
                {
                    bool homeAll = !(code.hasX || code.hasY || code.hasZ);
                    if (code.hasX || homeAll)
                    {
                        xOffset = 0; x = Main.printerSettings.XMax; hasXHome = true;
                    }
                    if (code.hasY || homeAll)
                    {
                        yOffset = 0; y = Main.printerSettings.YMax; hasYHome = true;
                    }
                    if (code.hasZ || homeAll)
                    {
                        zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 90:
                    relative = false;
                    break;

                case 91:
                    relative = true;
                    break;

                case 92:
                    if (code.hasX)
                    {
                        xOffset = x - code.X; x = xOffset;
                    }
                    if (code.hasY)
                    {
                        yOffset = y - code.Y; y = yOffset;
                    }
                    if (code.hasZ)
                    {
                        zOffset = z - code.Z; z = zOffset;
                    }
                    if (code.hasE)
                    {
                        eOffset = e - code.E; lastE = e = eOffset;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    break;
                }
            }
            else if (code.hasM)
            {
                switch (code.M)
                {
                case 28:
                    uploading = true;
                    break;

                case 29:
                    uploading = false;
                    break;

                case 80:
                    powerOn = true;
                    fireChanged();
                    break;

                case 81:
                    powerOn = false;
                    fireChanged();
                    break;

                case 82:
                    eRelative = false;
                    break;

                case 83:
                    eRelative = true;
                    break;

                case 104:
                case 109:
                    if (code.hasS)
                    {
                        extruderTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 106:
                    fanOn = true;
                    if (code.hasS)
                    {
                        fanVoltage = code.S;
                    }
                    fireChanged();
                    break;

                case 107:
                    fanOn = false;
                    fireChanged();
                    break;

                case 110:
                    lastline = code.N;
                    break;

                case 111:
                    if (code.hasS)
                    {
                        debugLevel = code.S;
                    }
                    break;

                case 140:
                case 190:
                    if (code.hasS)
                    {
                        bedTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 203:     // Temp monitor
                    if (code.hasS)
                    {
                        tempMonitor = code.S;
                    }
                    break;

                case 220:
                    if (code.hasS)
                    {
                        speedMultiply = code.S;
                    }
                    break;
                }
            }
            else if (code.hasT)
            {
                activeExtruder = code.T;
            }
        }
Beispiel #48
0
 public void Reduce()
 {
     for (int i = 0; i < MaxExtruder; i++)
     {
         LinkedList<GCodePath> seg = segments[i];
         if (seg.Count < 2) continue;
         if (!liveView)
         {
             GCodePath first = seg.First.Value;
             while (seg.Count > 1)
             {
                 first.Join(seg.First.Next.Value);
                 seg.First.Next.Value.Free();
                 seg.Remove(seg.First.Next.Value);
             }
         }
         else
         {
             LinkedListNode<GCodePath> act = seg.First, next;
             while (act.Next != null)
             {
                 next = act.Next;
                 if (next.Next == null)
                 {
                     break; // Don't touch last segment we are writing to
                 }
                 GCodePath nextval = next.Value;
                 if (nextval.pointsCount < 2)
                 {
                     act = next;
                     if (act.Next != null)
                         act = act.Next;
                 }
                 else if (nextval.lastDist > minHotDist)
                 {
                     if (act.Value.pointsCount < 500)
                     {
                         act.Value.Join(nextval);
                         seg.Remove(nextval);
                         nextval.Free();
                     }
                     else
                     {
                         act = next;
                     }
                 }
                 else
                     if (act.Value.pointsCount < 5000 || (nextval.pointsCount >= 5000 && act.Value.pointsCount < 27000))
                     {
                         act.Value.Join(nextval);
                         seg.Remove(nextval);
                         nextval.Free();
                     }
                     else
                     {
                         act = next;
                     }
             }
         }
     }
 }