Exemplo n.º 1
0
        public void StartMeasurement(string interv)
        {
            //measTimeInterval = IntervalConverter(interv);
            if (StartEvent != null)
            {
                StartEvent();
            }

            flagMeasOnOff = true;

            if (!flagPauseOnOff)
            {
                Directory.CreateDirectory(folderPath + "\\Data");
                nameFile = "Data\\" + PreName + DateTime.Now.ToString("dd/MM/yyyy HH_mm_ss") + ".txt";
                WDTF.ChooseFile(nameFile);
                if (WDTF.OpenFile() != 1)
                {
                    PStop(); return;
                }
            }
            flagPauseOnOff     = false;
            MeasTimer.Interval = IntervalConverter(interv);
            MeasTimer.Start();
            сountInterval = MeasTimer.Interval / 1000;

            MeasCountTimer.Start();
        }
Exemplo n.º 2
0
        public void SaveToFile(DataGridViewRowCollection DataRows)
        {
            //WKL.SaveToFile();
            WriteDataToFile WDTF1 = new WriteDataToFile();
            SaveFileDialog  SFD   = new SaveFileDialog();

            SFD.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
            if (SFD.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string filename = SFD.FileName;

            WDTF1.ChooseFile(filename);
            WDTF1.OpenFile();

            foreach (DataGridViewRow Zl in DataRows)
            {
                if (Zl.Cells[iTimeColumn].Value != null)
                {
                    WDTF1.WriteToFile(Zl.Cells[iTimeColumn].Value + "_" + Zl.Cells[idataColumn].Value);
                }
                else
                {
                    WDTF1.WriteToFile("");
                }
            }
            WDTF1.CloseFile();
        }
Exemplo n.º 3
0
        public string MeasFreq() //функция запроса значения частоты прибора
        {
            wdtf.ChooseFile("1.txt");
            wdtf.OpenFile();
            wdtf2.OpenFile("2.txt");
            wdtf3.ChooseFile("3.txt");
            wdtf3.OpenFile();

            //stopWatch.Start();
            string ttt = tt;

            WriteCommand("01683030");
            //WriteCommand("01683030");
            //WriteCommand("01683030");
            //WriteCommand("01683030");

            //ComPort.
            // while (tt.Length - ttt.Length < 95) { if (stopWatch.Elapsed.Seconds >= 1) { errorMessage = "VCH_Error_NotEnoughPhaseData"; return "VCH_Error_NotEnoughPhaseData"; } }
            //int i = 0;
            //while (tt.Length - ttt.Length < 95)
            //{
            //    i++;
            //    if (i > 1000000000)
            //        break;
            //    //if (stopWatch.Elapsed.Seconds >= 50) { errorMessage = "VCH_Error_NotEnoughPhaseData"; return "VCH_Error_NotEnoughPhaseData"; }
            //}
            Thread.Sleep(500);
            //if(count1%2==0)
            //    Thread.Sleep(1000);
            //if (count1 % 2 == 1)
            //    Thread.Sleep(3000);
            //count1++;
            wdtf.WriteToFile(tt);

            if (tt.IndexOf("01") == -1 || ((tt.Length - tt.Replace("01", "").Length)) < 4 || tt.Length < 64)
            {
                //Thread.Sleep(1000);
                return("VCH_Error_NotEnoughPhaseData");
            }
            //wdtf.WriteToFile("2" + tt);
            //int t1 = tt.IndexOf("01");
            //int t2 = tt.Replace.IndexOf("01");
            string[] splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);

            string message1 = splitTT[1].Trim();
            string message2 = splitTT[2].Trim();

            //wdtf2.WriteToFile(message1);
            //wdtf2.WriteToFile(message2);
            //wdtf2.WriteToFile(" ");
            if (message1.Length < 32 || message2.Length < 32)
            {
                //Thread.Sleep(1000);
                return("VCH_Error_NotEnoughPhaseData");
            }

            int ph1 = Convert.ToInt32(message1.Substring(28, 1) + message1.Substring(25, 1) + message1.Substring(22, 1) + message1.Substring(19, 1) + message1.Substring(16, 1) + message1.Substring(13, 1), 16);
            int ph2 = Convert.ToInt32(message2.Substring(28, 1) + message2.Substring(25, 1) + message2.Substring(22, 1) + message2.Substring(19, 1) + message2.Substring(16, 1) + message2.Substring(13, 1), 16);

            int n1 = Convert.ToInt32(message1.Substring(61, 1) + message1.Substring(58, 1) + message1.Substring(55, 1) + message1.Substring(52, 1) + message1.Substring(49, 1) + message1.Substring(46, 1) + message1.Substring(43, 1) + message1.Substring(40, 1), 16);
            int n2 = Convert.ToInt32(message2.Substring(61, 1) + message2.Substring(58, 1) + message2.Substring(55, 1) + message2.Substring(52, 1) + message2.Substring(49, 1) + message2.Substring(46, 1) + message2.Substring(43, 1) + message2.Substring(40, 1), 16);

            //int a1 = Convert.ToInt32(message1.Substring(73, 1) + message1.Substring(70, 1) + message1.Substring(67, 1), 16);
            //int a2 = Convert.ToInt32(message2.Substring(73, 1) + message2.Substring(70, 1) + message2.Substring(67, 1), 16);

            //int b1 = Convert.ToInt32(message1.Substring(85, 1) + message1.Substring(82, 1) + message1.Substring(79, 1), 16);
            //int b2 = Convert.ToInt32(message2.Substring(85, 1) + message2.Substring(82, 1) + message2.Substring(79, 1), 16);
            int a1 = Convert.ToInt32(message1.Substring(67, 1) + message1.Substring(70, 1) + message1.Substring(73, 1));
            int a2 = Convert.ToInt32(message2.Substring(67, 1) + message2.Substring(70, 1) + message2.Substring(73, 1));

            int b1 = Convert.ToInt32(message1.Substring(79, 1) + message1.Substring(82, 1) + message1.Substring(85, 1));
            int b2 = Convert.ToInt32(message2.Substring(79, 1) + message2.Substring(82, 1) + message2.Substring(85, 1));

            wdtf3.WriteToFile("Время:        " + DateTime.Now.ToString());
            wdtf3.WriteToFile("message1:     " + message1);
            wdtf3.WriteToFile("message2:     " + message2);

            //string MessageAscii1="";
            ////string MessageAscii2="";
            //foreach (var bb in message1.Split(new string[] { " " }, StringSplitOptions.None))
            //{
            //    MessageAscii1 +=" "+ Convert.ToChar((Convert.ToInt32(bb,16)))+" ";
            //}

            //wdtf3.WriteToFile("MAscii1:      " + MessageAscii1);

            wdtf3.WriteToFile("n1,2:         " + n1.ToString() + " " + n2.ToString());
            wdtf3.WriteToFile("Phase1,2:     " + ph2.ToString() + "-" + ph1.ToString() + "=" + (ph2 - ph1).ToString());

            wdtf3.WriteToFile("a1,b1:         " + a1.ToString() + " " + b1.ToString());
            wdtf3.WriteToFile("a2,b2:         " + a2.ToString() + " " + b2.ToString());
            wdtf3.WriteToFile(" ");

            //if (n2 == n1 )
            //{
            //    return "VCH_Error_NotEnoughPhaseData";
            //}


            if (ph2 == ph1)
            {
                tt      = "01 " + message2 + " ";
                splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);
                for (int i = 3; i < splitTT.Count(); i++)
                {
                    tt = " " + splitTT[i];
                }
                return("VCH_Error_EqualPhases");
            }
            else if (n2 == n1)
            {
                tt      = "01 " + message2 + " ";
                splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);
                for (int i = 3; i < splitTT.Count(); i++)
                {
                    tt = " " + splitTT[i];
                }
                return("VCH_Error_EqualPhases");
            }
            double f = ph2 - ph1;

            if (n2 - n1 > 1)
            {
                f /= (n2 - n1);
            }
            //if (a1 == a2)
            //{
            //    tt = "01 " + message2 + " ";
            //    splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);
            //    for (int i = 3; i < splitTT.Count(); i++)
            //    {
            //        tt = " " + splitTT[i];
            //    }
            //    return "VCH_Error_LessThanSecond";
            //}
            if (f > 8388608)
            {
                f -= 16014251;
            }
            if (f < -8388608)
            {
                f += 16014251;
            }



            //if (n2 != n1) f = ((ph2 - ph1) );
            //else
            //{
            //    tt = "01 " + message2 + " ";
            //    splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);
            //    for (int i = 3; i < splitTT.Count(); i++)
            //    {
            //        tt = " " + splitTT[i];
            //    }
            //    Thread.Sleep(1000);
            //    return "VCH_Error_NotEnoughPhaseData";
            //}



            tt = "01 " + message2 + " ";


            splitTT = ("XX " + tt).Split(new string[] { "01" }, StringSplitOptions.None);
            for (int i = 3; i < splitTT.Count(); i++)
            {
                tt = " " + splitTT[i];
            }

            //int s=0;
            //s= stopWatch.Elapsed.Milliseconds;
            //+ ((splitTT.Count() > 3) ? (" " + splitTT[3].Trim()) : "")
            //while (true)
            //{
            //    if (stopWatch.Elapsed.Milliseconds+s >= 1000) break;
            //}
            //stopWatch.Stop();

            //Thread.Sleep(1000);

            wdtf.CloseFile();
            wdtf2.CloseFile();
            wdtf3.CloseFile();
            return((f / 100000000000000.0).ToString());
        }
Exemplo n.º 4
0
        //private enum MCEType
        //{
        //    msoElementChartTitleNone = 0,
        //    msoElementChartTitleCenteredOverlay = 1,
        //    msoElementChartTitleAboveChart = 2,
        //    msoElementLegendNone = 100,
        //    msoElementLegendRight = 101,
        //    msoElementLegendTop = 102,
        //    msoElementLegendLeft = 103,
        //    msoElementLegendBottom = 104,
        //    msoElementLegendRightOverlay = 105,
        //    msoElementLegendLeftOverlay = 106,
        //    msoElementDataLabelNone = 200,
        //    msoElementDataLabelShow = 201,
        //    msoElementDataLabelCenter = 202,
        //    msoElementDataLabelInsideEnd = 203,
        //    msoElementDataLabelInsideBase = 204,
        //    msoElementDataLabelOutSideEnd = 205,
        //    msoElementDataLabelLeft = 206,
        //    msoElementDataLabelRight = 207,
        //    msoElementDataLabelTop = 208,
        //    msoElementDataLabelBottom = 209,
        //    msoElementDataLabelBestFit = 210,
        //    msoElementPrimaryCategoryAxisTitleNone = 300,
        //    msoElementPrimaryCategoryAxisTitleAdjacentToAxis = 301,
        //    msoElementPrimaryCategoryAxisTitleBelowAxis = 302,
        //    msoElementPrimaryCategoryAxisTitleRotated = 303,
        //    msoElementPrimaryCategoryAxisTitleVertical = 304,
        //    msoElementPrimaryCategoryAxisTitleHorizontal = 305,
        //    msoElementPrimaryValueAxisTitleNone = 306,
        //    msoElementPrimaryValueAxisTitleAdjacentToAxis = 306,
        //    msoElementPrimaryValueAxisTitleBelowAxis = 308,
        //    msoElementPrimaryValueAxisTitleRotated = 309,
        //    msoElementPrimaryValueAxisTitleVertical = 310,
        //    msoElementPrimaryValueAxisTitleHorizontal = 311,
        //    msoElementSecondaryCategoryAxisTitleNone = 312,
        //    msoElementSecondaryCategoryAxisTitleAdjacentToAxis = 313,
        //    msoElementSecondaryCategoryAxisTitleBelowAxis = 314,
        //    msoElementSecondaryCategoryAxisTitleRotated = 315,
        //    msoElementSecondaryCategoryAxisTitleVertical = 316,
        //    msoElementSecondaryCategoryAxisTitleHorizontal = 317,
        //    msoElementSecondaryValueAxisTitleNone = 318,
        //    msoElementSecondaryValueAxisTitleAdjacentToAxis = 319,
        //    msoElementSecondaryValueAxisTitleBelowAxis = 320,
        //    msoElementSecondaryValueAxisTitleRotated = 321,
        //    msoElementSecondaryValueAxisTitleVertical = 322,
        //    msoElementSecondaryValueAxisTitleHorizontal = 323,
        //    msoElementSeriesAxisTitleNone = 324,
        //    msoElementSeriesAxisTitleRotated = 325,
        //    msoElementSeriesAxisTitleVertical = 326,
        //    msoElementSeriesAxisTitleHorizontal = 327,
        //    msoElementPrimaryValueGridLinesNone = 328,
        //    msoElementPrimaryValueGridLinesMinor = 329,
        //    msoElementPrimaryValueGridLinesMajor = 330,
        //    msoElementPrimaryValueGridLinesMinorMajor = 331,
        //    msoElementPrimaryCategoryGridLinesNone = 332,
        //    msoElementPrimaryCategoryGridLinesMinor = 333,
        //    msoElementPrimaryCategoryGridLinesMajor = 334,
        //    msoElementPrimaryCategoryGridLinesMinorMajor = 335,
        //    msoElementSecondaryValueGridLinesNone = 336,
        //    msoElementSecondaryValueGridLinesMinor = 337,
        //    msoElementSecondaryValueGridLinesMajor = 338,
        //    msoElementSecondaryValueGridLinesMinorMajor = 339,
        //    msoElementSecondaryCategoryGridLinesNone = 340,
        //    msoElementSecondaryCategoryGridLinesMinor = 341,
        //    msoElementSecondaryCategoryGridLinesMajor = 342,
        //    msoElementSecondaryCategoryGridLinesMinorMajor = 343,
        //    msoElementSeriesAxisGridLinesNone = 344,
        //    msoElementSeriesAxisGridLinesMinor = 345,
        //    msoElementSeriesAxisGridLinesMajor = 346,
        //    msoElementSeriesAxisGridLinesMinorMajor = 347,
        //    msoElementPrimaryCategoryAxisNone = 348,
        //    msoElementPrimaryCategoryAxisShow = 349,
        //    msoElementPrimaryCategoryAxisWithoutLabels = 350,
        //    msoElementPrimaryCategoryAxisReverse = 351,
        //    msoElementPrimaryValueAxisNone = 352,
        //    msoElementPrimaryValueAxisShow = 353,
        //    msoElementPrimaryValueAxisThousands = 354,
        //    msoElementPrimaryValueAxisMillions = 355,
        //    msoElementPrimaryValueAxisBillions = 356,
        //    msoElementPrimaryValueAxisLogScale = 357,
        //    msoElementSecondaryCategoryAxisNone = 358,
        //    msoElementSecondaryCategoryAxisShow = 359,
        //    msoElementSecondaryCategoryAxisWithoutLabels = 360,
        //    msoElementSecondaryCategoryAxisReverse = 361,
        //    msoElementSecondaryValueAxisNone = 362,
        //    msoElementSecondaryValueAxisShow = 363,
        //    msoElementSecondaryValueAxisThousands = 364,
        //    msoElementSecondaryValueAxisMillions = 365,
        //    msoElementSecondaryValueAxisBillions = 366,
        //    msoElementSecondaryValueAxisLogScale = 367,
        //    msoElementSeriesAxisNone = 368,
        //    msoElementSeriesAxisShow = 369,
        //    msoElementSeriesAxisWithoutLabeling = 370,
        //    msoElementSeriesAxisReverse = 371,
        //    msoElementPrimaryCategoryAxisThousands = 372,
        //    msoElementPrimaryCategoryAxisMillions = 373,
        //    msoElementPrimaryCategoryAxisBillions = 374,
        //    msoElementPrimaryCategoryAxisLogScale = 375,
        //    msoElementSecondaryCategoryAxisThousands = 376,
        //    msoElementSecondaryCategoryAxisMillions = 377,
        //    msoElementSecondaryCategoryAxisBillions = 378,
        //    msoElementSecondaryCategoryAxisLogScale = 379,
        //    msoElementDataTableNone = 500,
        //    msoElementDataTableShow = 501,
        //    msoElementDataTableWithLegendKeys = 502,
        //    msoElementTrendlineNone = 600,
        //    msoElementTrendlineAddLinear = 601,
        //    msoElementTrendlineAddExponential = 602,
        //    msoElementTrendlineAddLinearForecast = 603,
        //    msoElementTrendlineAddTwoPeriodMovingAverage = 604,
        //    msoElementErrorBarNone = 700,
        //    msoElementErrorBarStandardError = 701,
        //    msoElementErrorBarPercentage = 702,
        //    msoElementErrorBarStandardDeviation = 703,
        //    msoElementLineNone = 800,
        //    msoElementLineDropLine = 801,
        //    msoElementLineHiLoLine = 802,
        //    msoElementLineSeriesLine = 803,
        //    msoElementLineDropHiLoLine = 804,
        //    msoElementUpDownBarsNone = 900,
        //    msoElementUpDownBarsShow = 901,
        //    msoElementPlotAreaNone = 1000,
        //    msoElementPlotAreaShow = 1001,
        //    msoElementChartWallNone = 1100,
        //    msoElementChartWallShow = 1101,
        //    msoElementChartFloorNone = 1200,
        //    msoElementChartFloorShow = 1201,
        //}
        public void FileToExcel(DataGridViewRowCollection DataRows)
        {
            Microsoft.Office.Interop.Excel.Application app;
            Microsoft.Office.Interop.Excel.Workbook    wb;
            Microsoft.Office.Interop.Excel.Worksheet   ws;
            app = new Microsoft.Office.Interop.Excel.Application()
            {
                DisplayAlerts = false
            };
            int er = 0;

            try
            {
                WriteDataToFile WDTF1 = new WriteDataToFile();
                //SaveFileDialog SFD = new SaveFileDialog();
                //SFD.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
                //if (SFD.ShowDialog() == DialogResult.Cancel)
                //    return;
                Directory.CreateDirectory(folderPath + "\\Data" + "\\ForExcel");
                string filename = folderPath + "\\Data" + "\\ForExcel" + nameFile.Substring(4, nameFile.Length - 4);
                WDTF1.ChooseFile(filename);
                WDTF1.OpenFile(false);
                int N = DataRows.Count;
                foreach (DataGridViewRow Zl in DataRows)
                {
                    if (Zl.Cells[iTimeColumn].Value != null)
                    {
                        WDTF1.WriteToFile(Zl.Cells[iTimeColumn].Value + "_" + Zl.Cells[idataColumn].Value);
                    }
                    else
                    {
                        WDTF1.WriteToFile("");
                    }
                }
                WDTF1.CloseFile();


                wb = app.Workbooks.Open(filename);
                ws = wb.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;

                ws.Columns["A:A"].TextToColumns(Destination: ws.Range["A1"],
                                                DataType: Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited,
                                                TextQualifier: Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
                                                ConsecutiveDelimiter: false, Tab: true, Semicolon: false,
                                                Comma: false, Space: false, Other: true, OtherChar: "_",
                                                FieldInfo: new int[, ] {
                    { 1, 1 }, { 2, 1 }
                },
                                                TrailingMinusNumbers: true);
                ws.Columns.AutoFit();
                //ws.Range["A1"].Insert(ro
                ws.Rows["1:1"].Insert(Shift: Microsoft.Office.Interop.Excel.XlDirection.xlDown, CopyOrigin: Microsoft.Office.Interop.Excel.XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
                er = 1;
                Microsoft.Office.Interop.Excel.ChartObject ExcelDataChart = (Microsoft.Office.Interop.Excel.ChartObject)ws.ChartObjects().Add(150, 10, 500, 350);
                er = 2;
                ExcelDataChart.Chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterSmoothNoMarkers;
                er = 3;
                ws.Range["B1"].Value2 = "Данные";
                er = 4;
                ExcelDataChart.Chart.SeriesCollection().Add(Source: ws.Range["B2:B" + (N + 1).ToString()]);
                er = 41;
                Microsoft.Office.Interop.Excel.Series ser = (Microsoft.Office.Interop.Excel.Series)ExcelDataChart.Chart.SeriesCollection()[1];
                er = 5;
                ws.Range["A1"].Value2 = "Дата/Время";
                er          = 6;
                ser.XValues = ws.Range["A2:A" + (N + 1).ToString()];
                er          = 7;
                //ser.Format.Line.Weight = 2;
                //er = 8;
                //chB.Chart.SeriesCollection(1).Name = "Канал 1"

                //ExcelDataChart.Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryCategoryGridLinesMajor);
                //ExcelDataChart.Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueGridLinesMajor);
                ExcelDataChart.Chart.Legend.Delete();
                er = 9;
                //ExcelDataChart.Chart.SetElement (Microsoft.Office.Core.MsoChartElementType.msoElementChartTitleAboveChart);
                //ExcelDataChart.Chart.ChartTitle.Text = nameFile.Substring(5, nameFile.Length - 5);
                ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).TickLabelPosition = Microsoft.Office.Interop.Excel.XlTickLabelPosition.xlTickLabelPositionLow;
                er = 10;
                //ExcelDataChart.Chart.SetElement (Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleRotated);
                //ExcelDataChart.Chart.SetElement (Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis);
                ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).TickLabelPosition = Microsoft.Office.Interop.Excel.XlTickLabelPosition.xlTickLabelPositionLow;
                er = 11;
                //ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).AxisTitle.Text = "Время";
                //ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).AxisTitle.Text = "Данные";
                //ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).TickLabelPosition =  Microsoft.Office.Interop.Excel.XlTickLabelPosition.xlTickLabelPositionLow;
                ExcelDataChart.Chart.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).TickLabels.Orientation = 45;
                er          = 12;
                app.Visible = true;
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Неудалось открыть Excel" + er.ToString());
                return;
            }
        }