Example #1
0
        public static ProcessUnit GetInstnace()
        {
            if (processUnit == null)
            {
                processUnit = new ProcessUnit();
            }


            return(processUnit);
        }
Example #2
0
        public static void WriteDeltaToJpeg(string filePath, Spec spec, int index, int pos = 0)
        {
            try
            {
                var Tr = ThresholdConfigs.GetInstance();
                //   var index = GetIndex();

                Bitmap bitmap = null;
                using (var stream = File.OpenRead(filePath))
                {
                    bitmap = (Bitmap)Bitmap.FromStream(stream);
                }

                double percent  = 0;
                int    position = pos;
                //     string level = spec.result;
                //if (DR != (DetectionResult)0)
                //{
                //    position=300;

                //}

                var msg = string.Empty;
                if (spec.IsSaturated)
                {
                    msg = "saturated";
                }
                else
                if (spec.IsNoisy)
                {
                    msg = "noisy";
                }
                else if (spec.NoPeakDetected)
                {
                    msg = "noPeakDetected";
                }

                else
                {
                    var level = ProcessUnit.GetInstnace().GetDangerLevel(spec.delta1, spec.delta2, out percent, index);


                    if (((int)level) > -1 && level != DangerLevel.saturation)
                    {
                        msg = Tr.Elements[(int)level].ThresholdName[index];
                    }
                }

                //   Tr.Elements[(int)DangerLevel]
                using (bitmap)
                    using (var graphics = Graphics.FromImage(bitmap))
                        using (var font = new Font("Arial", 15, FontStyle.Regular))
                        {
                            String S = "ScanRate:" + spec.scanRate.ToString("####.##");
                            S += " Delta1:" + spec.delta1.ToString("0.##");
                            S += " Delta2:" + spec.delta2.ToString("0.##");
                            S += "\nMaxVoltage:" + spec.MaxVoltage.ToString("0.##");
                            S += " Voltage1:" + spec.voltageDelta1.ToString("0.##");
                            S += " Voltage2:" + spec.voltageDelta2.ToString("0.##");
                            S += "\nDangerLevel:" + msg;
                            S += "\nPercent:" + percent.ToString("0.##");
                            S += "\nSNR:" + spec.SNR.ToString("0.##");

                            graphics.DrawString(S, font, Brushes.Black, 0, position);

                            //graphics.DrawString("ScanRate:" + scanrate.ToString("####.##"), font, Brushes.Red, 0, 0);
                            // graphics.DrawString("Delta1:" + spec.delta1.ToString("####.##"), font, Brushes.Red, 0, 80);
                            //  graphics.DrawString("Delta2:" + spec.delta2.ToString("####.##"), font, Brushes.Red, 0, 160);
                            //   graphics.DrawString("DangerLevel:" + level, font, Brushes.Red, 0, 240);
                            // Important part!
                            bitmap.Save(filePath);
                        }
            }
            catch (Exception ex)
            {
            }
        }