jinwang 6 anni fa
parent
commit
364bfadf38

+ 1 - 0
DataGathering/DataGathering.csproj

@@ -34,6 +34,7 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Windows.Forms.DataVisualization" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />

+ 63 - 3
DataGathering/Form1.Designer.cs

@@ -28,13 +28,21 @@
         /// </summary>
         private void InitializeComponent()
         {
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+            System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
             this.button1 = new System.Windows.Forms.Button();
             this.button2 = new System.Windows.Forms.Button();
+            this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.textBox2 = new System.Windows.Forms.TextBox();
+            this.button3 = new System.Windows.Forms.Button();
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
             this.SuspendLayout();
             // 
             // button1
             // 
-            this.button1.Location = new System.Drawing.Point(158, 216);
+            this.button1.Location = new System.Drawing.Point(647, 770);
             this.button1.Name = "button1";
             this.button1.Size = new System.Drawing.Size(96, 43);
             this.button1.TabIndex = 0;
@@ -44,7 +52,7 @@
             // 
             // button2
             // 
-            this.button2.Location = new System.Drawing.Point(389, 215);
+            this.button2.Location = new System.Drawing.Point(1186, 769);
             this.button2.Name = "button2";
             this.button2.Size = new System.Drawing.Size(100, 44);
             this.button2.TabIndex = 1;
@@ -52,16 +60,64 @@
             this.button2.UseVisualStyleBackColor = true;
             this.button2.Click += new System.EventHandler(this.button2_Click);
             // 
+            // chart1
+            // 
+            chartArea2.Name = "ChartArea1";
+            this.chart1.ChartAreas.Add(chartArea2);
+            legend2.Name = "Legend1";
+            this.chart1.Legends.Add(legend2);
+            this.chart1.Location = new System.Drawing.Point(148, 12);
+            this.chart1.Name = "chart1";
+            series2.ChartArea = "ChartArea1";
+            series2.Legend = "Legend1";
+            series2.Name = "Series1";
+            this.chart1.Series.Add(series2);
+            this.chart1.Size = new System.Drawing.Size(2110, 708);
+            this.chart1.TabIndex = 2;
+            this.chart1.Text = "chart1";
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(12, 49);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(100, 25);
+            this.textBox1.TabIndex = 3;
+            this.textBox1.Text = "45";
+            // 
+            // textBox2
+            // 
+            this.textBox2.Location = new System.Drawing.Point(12, 140);
+            this.textBox2.Name = "textBox2";
+            this.textBox2.Size = new System.Drawing.Size(100, 25);
+            this.textBox2.TabIndex = 4;
+            this.textBox2.Text = "135";
+            // 
+            // button3
+            // 
+            this.button3.Location = new System.Drawing.Point(895, 753);
+            this.button3.Name = "button3";
+            this.button3.Size = new System.Drawing.Size(167, 33);
+            this.button3.TabIndex = 5;
+            this.button3.Text = "采集";
+            this.button3.UseVisualStyleBackColor = true;
+            this.button3.Click += new System.EventHandler(this.button3_Click);
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(800, 450);
+            this.ClientSize = new System.Drawing.Size(2270, 825);
+            this.Controls.Add(this.button3);
+            this.Controls.Add(this.textBox2);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.chart1);
             this.Controls.Add(this.button2);
             this.Controls.Add(this.button1);
             this.Name = "Form1";
             this.Text = "Form1";
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
 
@@ -69,6 +125,10 @@
 
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.TextBox textBox2;
+        private System.Windows.Forms.Button button3;
     }
 }
 

+ 100 - 8
DataGathering/Form1.cs

@@ -1,11 +1,14 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.Drawing;
+using System.Windows.Forms.DataVisualization.Charting;
 
 namespace DataGathering
 {
@@ -70,12 +73,71 @@ namespace DataGathering
                                 aws = aws + validNum[j] + " ";
                             }
                             validdatalist.Add(aws);
+
+                            this.Invoke(new Action(() =>
+                            {
+                                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
+                                sw.Start();
+                                aws.TrimEnd(' ');
+                                List<double> listy = new List<double>();
+                                List<double> listx = new List<double>();
+                                string[] origindata = aws.Split(' ');
+                                origindata = origindata.Where(s => !string.IsNullOrEmpty(s)).ToArray();
+                                int[] origindataTransformed = Array.ConvertAll<string, int>(origindata, int.Parse);
+                                //int startDegree = (Convert.ToInt32(this.textBox1.Text) + 45) * 3;
+                                //int endDegree = (Convert.ToInt32(this.textBox2.Text) + 45) * 3 + 1;
+                                for (int k = 0; k < origindataTransformed.Length; k++)
+                                {
+                                    double x = origindataTransformed[k] * Math.Cos((45 + 0.333 * k) * Math.PI / 180);
+                                    double y = origindataTransformed[k] * Math.Sin((45 + 0.333 * k) * Math.PI / 180);
+                                    Log.WriteCredence(x + " " + y);
+                                    listy.Add(y);
+                                    listx.Add(x);
+                                }
+                                this.chart1.Series[0].Points.Clear();
+
+                                sw.Stop();
+                                Console.WriteLine(sw.ElapsedMilliseconds + "ms");
+                            }));
                         }
                     }
+                    Thread.Sleep(200);
                 }
             });
         }
 
+        private void InitChart(List<double> listx, List<double> listy)
+        {
+            //定义图表区域
+            this.chart1.ChartAreas.Clear();
+            ChartArea chartArea1 = new ChartArea("C1");
+            this.chart1.ChartAreas.Add(chartArea1);
+            //定义存储和显示点的容器
+            this.chart1.Series.Clear();
+            Series series1 = new Series("S1");
+            series1.ChartArea = "C1";
+            this.chart1.Series.Add(series1);
+            //设置图表显示样式
+            //this.chart1.ChartAreas[0].AxisY.Minimum = 0;
+            //this.chart1.ChartAreas[0].AxisY.Maximum = 100;
+            //this.chart1.ChartAreas[0].AxisX.Interval = 5;
+            this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
+            this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
+            //设置标题
+            this.chart1.Titles.Clear();
+            this.chart1.Titles.Add("S01");
+            this.chart1.Titles[0].Text = "雷达显示";
+            this.chart1.Titles[0].ForeColor = Color.RoyalBlue;
+            this.chart1.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
+            //设置图表显示样式
+            this.chart1.Series[0].Color = Color.Red;
+            this.chart1.Series[0].ChartType = SeriesChartType.Point;
+            for (int i = 0; i < listx.Count; i++)
+            {
+                this.chart1.Series[0].Points.AddXY(listx[i], listy[i]);
+            }
+        }
+
         private void button2_Click(object sender, EventArgs e)
         {
             isok = true;
@@ -102,14 +164,6 @@ namespace DataGathering
                 stream.Write(b, 0, b.Length);
                 return 1;
             }
-            //if (cmd.Equals(endCmd))
-            //{
-            //    byte[] byteStartCmd = HexStringToBinary(endCmd);
-            //    string result = HexStringToASCII(byteStartCmd);
-            //    byte[] b = Encoding.UTF8.GetBytes(result);
-            //    stream.Write(b, 0, b.Length);
-            //    return 2;
-            //}
             return 0;
         }
 
@@ -170,5 +224,43 @@ namespace DataGathering
             catch (Exception) { }
             return result;
         }
+
+        private void button3_Click(object sender, EventArgs e)
+        {
+            List<string> datalist = new List<string>();
+            datalist.Clear();
+            flag = sendCmd(startCmd);
+            byte[] buffer = new byte[bufferSize];
+            stream.Read(buffer, 0, buffer.Length);
+            string str = HexStringToASCII(buffer);
+            datalist.Add(str);
+            string ss = validStr(datalist[0], "sRA LMDscandata 1 ", " not defined 0 0 0");
+            string[] data = ss.Split(' ');
+            string number = data[22];
+            int a = Convert.ToInt32(number, 16);
+            int[] validNum = new int[a];
+            string aws = "";
+            for (int j = 0; j < a; j++)
+            {
+                validNum[j] = Convert.ToInt32(data[23 + j], 16);
+                aws = aws + validNum[j] + " ";
+            }
+            aws.TrimEnd(' ');
+            List<double> listy = new List<double>();
+            List<double> listx = new List<double>();
+            string[] origindata = aws.Split(' ');
+            origindata = origindata.Where(s => !string.IsNullOrEmpty(s)).ToArray();
+            int[] origindataTransformed = Array.ConvertAll<string, int>(origindata, int.Parse);
+            //int startDegree = (Convert.ToInt32(this.textBox1.Text) + 45) * 3;
+            //int endDegree = (Convert.ToInt32(this.textBox2.Text) + 45) * 3 + 1;
+            for (int k = 0; k < origindataTransformed.Length; k++)
+            {
+                double x = origindataTransformed[k] * Math.Cos((45 + 0.333 * k) * Math.PI / 180);
+                double y = origindataTransformed[k] * Math.Sin((45 + 0.333 * k) * Math.PI / 180);
+                Log.WriteCredence(x + " " + y);
+                //listy.Add(y);
+                //listx.Add(x);
+            }
+        }
     }
 }

+ 1 - 1
DataGathering/LogManager.cs

@@ -184,7 +184,7 @@ namespace DataGathering
                 try
                 {
                     //创建log文件
-                    string logname = string.Format("{0}.{1}", "CREDENCES", this.logFileExtName);
+                    string logname = string.Format("{0}.{1}", "CREDENCES", "txt");
                     logFileName = filepath + "\\" + logname;
                     using (StreamWriter sw = new StreamWriter(logFileName, true, logFileEncoding))
                     {

+ 7 - 1
Test/Form1.cs

@@ -181,7 +181,13 @@ namespace Test
             }
             return buff;
         }
-
+        /// <summary>
+        /// 获取数据
+        /// </summary>
+        /// <param name="sourse"></param>
+        /// <param name="startstr"></param>
+        /// <param name="endstr"></param>
+        /// <returns></returns>
         private static string validStr(string sourse, string startstr, string endstr)
         {
             string result = string.Empty;