Exemplo n.º 1
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                for (int i = 0; i < 200; i++)
                {
                    Thread.Sleep(1000);

                    //ReducedPointsofInterest = AnalysisFunctionality.GetPointsofInterest(CombinedScannerData);

                    //ScannerInformation info = new ScannerInformation();
                    //info.GetNecessaryInformation(ReducedPointsofInterest);
                    ////PossiblePointsofInterest = AnalysisFunctionality.GetPossiblePointsOfInterest(CombinedScannerData);
                    ////ReducedPointsofInterest = AnalysisFunctionality.FilterPossiblePoints(PossiblePointsofInterest);

                    ////ReducedPointsofInterest = AnalysisFunctionality.GetCornerPoints(CombinedScannerData, out int widthtopobject, out int leftside, out int rightside, out int deviationcenter, out int scannerdistance);

                    ////ReducedPointsofInterest = AnalysisFunctionality.GetCornerPoints(PossiblePointsofInterest, out int widthtopobject);

                    //Invoke(new Action(() =>
                    //{
                    //    labelWidthTopObjectValue.Text = info.TopSlabWidth.ToString();
                    //    labelDeviationCenterValue.Text = info.TopSlabYDeviation.ToString();
                    //    labelDistanceFromLeftValue.Text = info.GrippingDepthTopEast.ToString();
                    //    labelDistancefromRightValue.Text = info.GrippingDepthTopWest.ToString();
                    //}));
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void LogData(object sender, List <Tuple <int, int, int> > Data)
        {
            try
            {
                lock (Locker)
                {
                    if ((DateTime.Now - RecordTime).Days > 0)
                    {
                        if (RecordWriter != null)
                        {
                            Dispose();
                        }

                        RecordWriter = CreateStreamWriter();
                    }

                    if (RecordWriter != null)
                    {
                        string message = GetMessagefromList(Data);

                        string inputMessage = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff;") + message;

                        RecordWriter.BaseStream.Seek(0, SeekOrigin.End);
                        RecordWriter.WriteLine(inputMessage);
                        RecordWriter.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private string GetMessagefromList(List <Tuple <int, int, int> > data)
        {
            string sMessage = string.Empty;

            try
            {
                foreach (var ok in data)
                {
                    sMessage = sMessage + $"{ok.Item1.ToString()};{ok.Item2.ToString()};{ok.Item3.ToString()};";
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }

            return(sMessage);
        }
Exemplo n.º 4
0
        private async Task <byte[]> TReceive()
        {
            UdpReceiveResult result;

            try
            {
                result = await UdpClient.ReceiveAsync();
            }
            catch (ObjectDisposedException ode)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ode.Message);
            }
            catch (SocketException se)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + se.Message);
            }

            return(result.Buffer);
        }
Exemplo n.º 5
0
        private bool OpenConnection()
        {
            try
            {
                Client = new SiemensDevice(IPEndPoint, SiemensDeviceType.S71500);

                Licenser.LicenseKey = "lgAAAA29d9Q/xtEBlgFDb21wYW55TmFtZT1Mb2dvVGVrICBHbWJIIEdlc2VsbHNjaGFmdCBmw7xyIEluZm9ybWF0aW9uc3RlY2hub2xvZ2llO0ZpcnN0TmFtZT1DaHJpc3RvcGhlcjtMYXN0TmFtZT1Lw7ZtcGVsO0VtYWlsPWNocmlzdG9waGVyLmtvZW1wZWxAbG9nb3Rlay1nbWJoLmRlO0NvdW50cnlOYW1lPUQ7Q2l0eU5hbWU9TWFya3RoZWlkZW5mZWxkO1ppcENvZGU9OTc4Mjg7U3RyZWV0TmFtZT1BbiBkZXIgS8O2aGxlcmVpIDc7U3RyZWV0TnVtYmVyPTtSZXRhaWxlck5hbWU9VHJhZWdlciBJbmR1c3RyeSBDb21wb25lbnRzO1ZvbHVtZT0xO1NlcmlhbE51bWJlcj0xMDAxO1N1cHBvcnRFeHBpcnlEYXRlPTA2LzE0LzIwMTcgMDA6MDA6MDA7VXNlTm9CcmFuZGluZz1GYWxzZTtDb250YWN0Rmlyc3ROYW1lPTtDb250YWN0TGFzdE5hbWU9GQwP4pqjgIkqQ3rkHBitUvrSkZA87Wf+QGXIW7F54n+Fnqh7gR8rfZy/oUnKKTGz";
                PlcConnection       = Client.CreateConnection();
                PlcConnection.Open();

                return(true);
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);

                return(false);
            }
        }
Exemplo n.º 6
0
        private void DrawAnalyser()
        {
            try
            {
                if (chartAnalyser.InvokeRequired)
                {
                    FillChartCallback test = new FillChartCallback(DrawAnalyser);
                    chartAnalyser.Invoke(test, new object[] { });
                }
                else
                {
                    chartAnalyser.Series["Analysis Graph"].Points.Clear();
                    chartAnalyser.Series["Points of Interest"].Points.Clear();

                    if (CombinedScannerData.Count != 0)
                    {
                        for (int i = 0; i < CombinedScannerData?.Count; i++)
                        {
                            chartAnalyser.Series["Analysis Graph"].Points.AddXY(CombinedScannerData[i].Item1, CombinedScannerData[i].Item2);
                        }
                    }

                    if (ReducedPointsofInterest != null)
                    {
                        for (int i = 0; i < ReducedPointsofInterest?.Count; i++)
                        {
                            chartAnalyser.Series["Points of Interest"].Points.AddXY(ReducedPointsofInterest[i].Item1, ReducedPointsofInterest[i].Item2);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Exemplo n.º 7
0
        public void ProcessReceive()
        {
            LogFiler.Log(Category.Info, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": started receiving data.");

            try
            {
                while (!IsStopped)
                {
                    var watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    Task <byte[]> receive = TReceive();
                    ScannerDecode Info    = new ScannerDecode().Decode(receive.Result);

                    if (Info.ID == 1)
                    {
                        RefreshScanner(Info);
                        Tuple <float, float> angleinfo = ScannerFunctionality.GetAngleId1(receive.Result);
                        Degree          = angleinfo.Item1;
                        AngleDifference = angleinfo.Item2;
                    }
                    else if (Info.ID == 6)
                    {
                        if (BlockOrderCorrect(Info.Block))
                        {
                            ExpandScanner(Info, receive.Result);

                            // if the id6 telegramblocks are finished - split the distance based on the scannergap information (not visible area)
                            // if its not getting split, the averaging will create datapoints where the scanner couldnt be able to see at all - leads to consequential errors
                            if (Id6Complete())
                            {
                                Distance = ScannerFunc.GetProcessedDistance(Id6Distance.ToList());

                                if (Mainframe.IsNormalizedbyMedian[Tag])
                                {
                                    Distance = ScannerFunc.GetMedianAverageArray(Distance.ToList());
                                }

                                XYCoord = ScannerFunc.GetXYCoordinate(Distance.ToList(), this);

                                XYCoordinate = ScannerFunctionality.MergeXYArray(XYCoord.ToList());
                                OnScannerRaw(this, XYCoordinate.ToList());

                                List <List <Tuple <int, int, int> > > Normalizer = new List <List <Tuple <int, int, int> > >();
                                List <Tuple <int, int, int> >         Normalized = new List <Tuple <int, int, int> >();

                                // try to accomplish the necessary kinds of averaging the distance sent by the scanner
                                // data averaged by time
                                if (Mainframe.IsNormalizedbyTime[Tag])
                                {
                                    List <Tuple <int, int, int> > xycollection = new List <Tuple <int, int, int> >(XYCoordinate);
                                    XYCollection[RingBufferCount] = xycollection;

                                    List <List <Tuple <int, int, int> > > xycolle = new List <List <Tuple <int, int, int> > >(XYCoord);
                                    XYColl[RingBufferCount] = xycolle;

                                    RingBufferCount++;
                                    CountTimeAverage++;

                                    if (RingBufferCount == Mainframe.NormalizebyTimeCountStoredData[Tag])
                                    {
                                        RingBufferCount = 0;
                                    }

                                    if (CountTimeAverage == Mainframe.NormalizebyTimeCountDataAverage[Tag])
                                    {
                                        Normalizer       = ScannerFunc.NormalizationByTime(RingBufferCount, XYColl);
                                        CountTimeAverage = 0;
                                    }
                                }
                                else
                                {
                                    Normalizer = XYCoord;
                                }

                                if (Normalizer.Count != 0)
                                {
                                    if (Mainframe.IsNormalizedbyTriangle[Tag])
                                    {
                                        Normalizer = ScannerFunc.Normalization(Normalizer.ToList());
                                    }

                                    Normalized = ScannerFunctionality.MergeNormalizeArray(Normalizer.ToList());

                                    Normalized = ScannerFunc.ChangePositionOfXY(Normalized.ToList());

                                    NormalizedData = Normalized;
                                    OnScannerNormalized(this, new List <Tuple <int, int, int> >(NormalizedData));

                                    List <Tuple <int, int, int> > Analyser = new List <Tuple <int, int, int> >(Normalized);
                                    AnalyseData = Analyser;
                                }

                                if (watch.IsRunning)
                                {
                                    watch.Stop();
                                    LogFiler.Log(Category.Info, "normalise" + watch.ElapsedMilliseconds.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }