示例#1
0
 /// <summary>
 /// Reports error. This is there to offload the ExpandError function from the "Real-Time" worker thread to the application thread
 /// also used for alarms
 /// </summary>
 private void ReportError(string error)
 {
     if (NonFatalException != null)
     {
         NonFatalException.Invoke(GrblCodeTranslator.ExpandError(error));
     }
 }
示例#2
0
 /// <summary>
 /// Reports error. This is there to offload the ExpandError function from the "Real-Time" worker thread to the application thread
 /// </summary>
 private void ReportError(string error)
 {
     if (NonFatalException != null)
     {
         NonFatalException.Invoke(GrblErrorProvider.ExpandError(error));
     }
 }
示例#3
0
        /// <summary>
        /// Parses a recevied probe report
        /// </summary>
        private void ParseProbe(string line)
        {
            if (ProbeFinished == null)
            {
                return;
            }

            Match probeMatch = ProbeEx.Match(line);

            Group pos     = probeMatch.Groups["Pos"];
            Group success = probeMatch.Groups["Success"];

            if (!probeMatch.Success || !(pos.Success & success.Success))
            {
                NonFatalException.Invoke($"Received Bad Probe: '{line}'");
                return;
            }

            Vector3 ProbePos = Vector3.Parse(pos.Value);

            LastProbePosMachine = ProbePos;

            ProbePos -= WorkOffset;

            LastProbePosWork = ProbePos;

            bool ProbeSuccess = success.Value == "1";

            ProbeFinished.Invoke(ProbePos, ProbeSuccess);
        }
示例#4
0
        /// <summary>
        /// Parses a recevied probe report
        /// </summary>
        private void ParseProbe(string line)
        {
            if (ProbeFinished == null)
            {
                return;
            }

            Match probeMatch = ProbeEx.Match(line);
            Group mx         = probeMatch.Groups["MX"];
            Group my         = probeMatch.Groups["MY"];
            Group mz         = probeMatch.Groups["MZ"];
            Group success    = probeMatch.Groups["Success"];

            if (!probeMatch.Success || !(mx.Success & my.Success & mz.Success & success.Success))
            {
                NonFatalException.Invoke($"Received Bad Probe: '{line}'");
                return;
            }

            Vector3 ProbePos = new Vector3(double.Parse(mx.Value, Constants.DecimalParseFormat), double.Parse(my.Value, Constants.DecimalParseFormat), double.Parse(mz.Value, Constants.DecimalParseFormat));

            ProbePos += WorkPosition - MachinePosition;                 //Mpos, Wpos only get updated by the same dispatcher, so this should be thread safe

            bool ProbeSuccess = success.Value == "1";

            ProbeFinished.Invoke(ProbePos, ProbeSuccess);
        }
示例#5
0
        /// <summary>
        /// Parses a recevied probe report
        /// </summary>
        private void ParseProbe(string line)
        {
            if (ProbeFinished == null)
            {
                return;
            }

            Match probeMatch = ProbeEx.Match(line);

            Group pos     = probeMatch.Groups["Pos"];
            Group success = probeMatch.Groups["Success"];

            if (!probeMatch.Success || !(pos.Success & success.Success))
            {
                NonFatalException.Invoke($"Received Bad Probe: '{line}'");
                return;
            }

            Vector3 ProbePos = Vector3.Parse(pos.Value);

            ProbePos -= WorkOffset;                 //Mpos, Wpos only get updated by the same dispatcher, so this should be thread safe

            bool ProbeSuccess = success.Value == "1";

            ProbeFinished.Invoke(ProbePos, ProbeSuccess);
        }
示例#6
0
        /// <summary>
        /// Parses a recevied status report (answer to '?')
        /// </summary>
        private void ParseStatus(string line)
        {
            Match statusMatch = StatusEx.Match(line);

            if (!statusMatch.Success)
            {
                NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line));
                return;
            }

            Group status = statusMatch.Groups["State"];

            if (status.Success)
            {
                Status = status.Value;
            }

            Vector3 NewMachinePosition, NewWorkPosition;
            bool    update = false;

            Group mx = statusMatch.Groups["MX"], my = statusMatch.Groups["MY"], mz = statusMatch.Groups["MZ"];

            if (mx.Success)
            {
                NewMachinePosition = new Vector3(double.Parse(mx.Value, Constants.DecimalParseFormat), double.Parse(my.Value, Constants.DecimalParseFormat), double.Parse(mz.Value, Constants.DecimalParseFormat));

                if (MachinePosition != NewMachinePosition)
                {
                    update = true;
                }

                MachinePosition = NewMachinePosition;
            }

            Group wx = statusMatch.Groups["WX"], wy = statusMatch.Groups["WY"], wz = statusMatch.Groups["WZ"];

            if (wx.Success)
            {
                NewWorkPosition = new Vector3(double.Parse(wx.Value, Constants.DecimalParseFormat), double.Parse(wy.Value, Constants.DecimalParseFormat), double.Parse(wz.Value, Constants.DecimalParseFormat));

                if (WorkPosition != NewWorkPosition)
                {
                    update = true;
                }

                WorkPosition = NewWorkPosition;
            }

            if (update && Connected && PositionUpdateReceived != null)
            {
                PositionUpdateReceived.Invoke();
            }
        }
示例#7
0
        /// <summary>
        /// Parses a recevied probe report
        /// </summary>
        private void ParseProbe(string line)
        {
            if (ProbeFinished == null)
            {
                return;
            }

            Match probeMatch = ProbeEx.Match(line);

            Group pos     = probeMatch.Groups["Pos"];
            Group success = probeMatch.Groups["Success"];

            if (!probeMatch.Success || !(pos.Success & success.Success))
            {
                NonFatalException.Invoke($"Received Bad Probe: '{line}'");
                return;
            }

            string PositionString = pos.Value;

            if (Properties.Settings.Default.IgnoreAdditionalAxes)
            {
                string[] parts = PositionString.Split(',');
                if (parts.Length > 3)
                {
                    Array.Resize(ref parts, 3);
                    PositionString = string.Join(",", parts);
                }
            }

            Vector3 ProbePos = Vector3.Parse(PositionString);

            LastProbePosMachine = ProbePos;

            ProbePos -= WorkOffset;

            LastProbePosWork = ProbePos;

            bool ProbeSuccess = success.Value == "1";

            ProbeFinished.Invoke(ProbePos, ProbeSuccess);
        }
 /// <summary>
 /// Initializes a new BoxCutter for debugging.
 /// </summary>
 /// <param name="sortType">True if you want the logs written to be sorted by writer, false if you want them to be written
 /// chronologically. If true, the buffer has to be flushed when the game closes; if it closes unexpectedly the file may
 /// be empty. Also, it keeps everything written in memory; this could become massive fast.</param>
 /// <param name="overwriteOldLogs">True if you want the log to save to debug.log, false if you want the date and time appended
 /// to the filename.</param>
 public BoxCutter(bool sortLogs, bool overwriteOldLogs, string savePath)
 {
     #if DEBUG || TRACE
     string path;
     this.sortLogs = sortLogs;
     overwriteLogs = overwriteOldLogs;
     d = new Default();
     n = new NonFatalException();
     f = new FatalException();
     if(overwriteOldLogs)
     {
         path = savePath + "debug.log";
         if(File.Exists(path))
             file = File.Open(path, FileMode.Truncate);
         else
             file = File.Open(path, FileMode.CreateNew);
     }
     else
     {
         IEnumerable<string> filenames = Directory.EnumerateFiles(savePath, "debug*.log");
         int debuglogs = filenames.Count<string>();
         if(debuglogs > 9)
         {
             int logstodelete = debuglogs - 9;
             for(int i = 0; i < logstodelete; i++)
                 try { File.Delete(filenames.ElementAt(i)); }
                 catch { }
         }
         path = savePath + "debug[" + DateTime.Now.ToShortDateString().Replace(@"/", @"-").Replace(@"\", @"-") + "][" + DateTime.Now.ToLongTimeString().Replace(@":", @".") + "].log";
         file = File.Open(path, FileMode.Create);
     }
     writer = new StreamWriter(file);
     if(sortLogs)
     {
         sortedBuffer = new Dictionary<object, List<string>>();
         sortedBuffer.Add(d, new List<string>());
         sortedBuffer.Add(n, new List<string>());
         sortedBuffer.Add(f, new List<string>());
     }
     #endif
 }
示例#9
0
        /// <summary>
        /// Parses a recevied status report (answer to '?')
        /// </summary>
        private void ParseStatus(string line)
        {
            MatchCollection statusMatch = StatusEx.Matches(line);

            if (statusMatch.Count == 0)
            {
                NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line));
                return;
            }

            bool posUpdate      = false;
            bool overrideUpdate = false;
            bool pinStateUpdate = false;
            bool resetPins      = true;

            foreach (Match m in statusMatch)
            {
                if (m.Index == 1)
                {
                    Status = m.Groups[1].Value;
                    continue;
                }

                if (m.Groups[1].Value == "Ov")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedOverride    = int.Parse(parts[0]);
                        RapidOverride   = int.Parse(parts[1]);
                        SpindleOverride = int.Parse(parts[2]);
                        overrideUpdate  = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "WCO")
                {
                    try
                    {
                        string OffsetString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = OffsetString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                OffsetString = string.Join(",", parts);
                            }
                        }

                        WorkOffset = Vector3.Parse(OffsetString);
                        posUpdate  = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (SyncBuffer && m.Groups[1].Value == "Bf")
                {
                    try
                    {
                        int availableBytes = int.Parse(m.Groups[2].Value.Split(',')[1]);
                        int used           = Properties.Settings.Default.ControllerBufferSize - availableBytes;

                        if (used < 0)
                        {
                            used = 0;
                        }

                        BufferState = used;
                        RaiseEvent(Info, $"Buffer State Synced ({availableBytes} bytes free)");
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "Pn")
                {
                    resetPins = false;

                    string states = m.Groups[2].Value;

                    bool stateX = states.Contains("X");
                    if (stateX != PinStateLimitX)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitX = stateX;

                    bool stateY = states.Contains("Y");
                    if (stateY != PinStateLimitY)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitY = stateY;

                    bool stateZ = states.Contains("Z");
                    if (stateZ != PinStateLimitZ)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitZ = stateZ;

                    bool stateP = states.Contains("P");
                    if (stateP != PinStateProbe)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateProbe = stateP;
                }

                else if (m.Groups[1].Value == "F")
                {
                    try
                    {
                        FeedRateRealtime = double.Parse(m.Groups[2].Value, Constants.DecimalParseFormat);
                        posUpdate        = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "FS")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedRateRealtime     = double.Parse(parts[0], Constants.DecimalParseFormat);
                        SpindleSpeedRealtime = double.Parse(parts[1], Constants.DecimalParseFormat);
                        posUpdate            = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            SyncBuffer = false;             //only run this immediately after button press

            //run this later to catch work offset changes before parsing position
            Vector3 NewMachinePosition = MachinePosition;

            foreach (Match m in statusMatch)
            {
                if (m.Groups[1].Value == "MPos" || m.Groups[1].Value == "WPos")
                {
                    try
                    {
                        string PositionString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = PositionString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                PositionString = string.Join(",", parts);
                            }
                        }

                        NewMachinePosition = Vector3.Parse(PositionString);

                        if (m.Groups[1].Value == "WPos")
                        {
                            NewMachinePosition += WorkOffset;
                        }

                        if (NewMachinePosition != MachinePosition)
                        {
                            posUpdate       = true;
                            MachinePosition = NewMachinePosition;
                        }
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            if (posUpdate && Connected && PositionUpdateReceived != null)
            {
                PositionUpdateReceived.Invoke();
            }

            if (overrideUpdate && Connected && OverrideChanged != null)
            {
                OverrideChanged.Invoke();
            }

            if (resetPins)                                                                         //no pin state received in status -> all zero
            {
                pinStateUpdate = PinStateLimitX | PinStateLimitY | PinStateLimitZ | PinStateProbe; //was any pin set before

                PinStateLimitX = false;
                PinStateLimitY = false;
                PinStateLimitZ = false;
                PinStateProbe  = false;
            }

            if (pinStateUpdate && Connected && PinStateChanged != null)
            {
                PinStateChanged.Invoke();
            }

            if (Connected && StatusReceived != null)
            {
                StatusReceived.Invoke(line);
            }
        }
示例#10
0
        /// <summary>
        /// Parses a recevied status report (answer to '?')
        /// </summary>
        private void ParseStatus(string line)
        {
            MatchCollection statusMatch = StatusEx.Matches(line);

            if (statusMatch.Count == 0)
            {
                NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line));
                return;
            }

            bool posUpdate = false;

            foreach (Match m in statusMatch)
            {
                if (m.Index == 1)
                {
                    Status = m.Groups[1].Value;
                    continue;
                }

                if (m.Groups[1].Value == "WCO")
                {
                    try
                    {
                        WorkOffset = Vector3.Parse(m.Groups[2].Value);
                        posUpdate  = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                if (SyncBuffer && m.Groups[1].Value == "Bf")
                {
                    try
                    {
                        int availableBytes = int.Parse(m.Groups[4].Value);
                        int used           = Properties.Settings.Default.ControllerBufferSize - availableBytes;

                        if (used < 0)
                        {
                            used = 0;
                        }

                        BufferState = used;
                        RaiseEvent(Info, $"Buffer State Synced ({availableBytes} bytes free)");
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            SyncBuffer = false;             //only run this immediately after button press

            //run this later to catch work offset changes before parsing position
            Vector3 NewMachinePosition = MachinePosition;

            foreach (Match m in statusMatch)
            {
                if (m.Groups[1].Value == "MPos" || m.Groups[1].Value == "WPos")
                {
                    try
                    {
                        NewMachinePosition = Vector3.Parse(m.Groups[2].Value);

                        if (m.Groups[1].Value == "WPos")
                        {
                            NewMachinePosition += WorkOffset;
                        }

                        if (NewMachinePosition != MachinePosition)
                        {
                            posUpdate       = true;
                            MachinePosition = NewMachinePosition;
                        }
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            if (posUpdate && Connected && PositionUpdateReceived != null)
            {
                PositionUpdateReceived.Invoke();
            }
        }
        public void HandleNonFatal(Exception e)
        {
            var newException = new NonFatalException(D.UNEXPECTED_ERROR_OCCURED, e.Message, e);

            PrepareException(newException, HandlePrepared);
        }
示例#12
0
 public static void RaiseNonFatalException(System.Exception exception)
 {
     NonFatalException?.Invoke(exception);
 }