├── .gitignore
├── .travis.yml
├── .vs
└── Freescale_debug
│ └── v14
│ └── .suo
├── FreescalePlatformTest
├── FreescalePlatformTest.csproj
├── Properties
│ └── AssemblyInfo.cs
├── UnitTest1.cs
├── bin
│ └── Debug
│ │ ├── FreescalePlatformTest.dll
│ │ ├── FreescalePlatformTest.pdb
│ │ ├── Freescale_debug.exe
│ │ ├── Freescale_debug.pdb
│ │ ├── Leomon.dll
│ │ ├── Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
│ │ ├── ZedGraph.dll
│ │ ├── log4net.dll
│ │ └── zh-Hans
│ │ └── Microsoft.VisualStudio.QualityTools.UnitTestFramework.resources.dll
└── obj
│ └── Debug
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── FreescalePlatformTest.csproj.FileListAbsolute.txt
│ ├── FreescalePlatformTest.csprojResolveAssemblyReference.cache
│ ├── FreescalePlatformTest.dll
│ ├── FreescalePlatformTest.pdb
│ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ └── build.force
├── Freescale_debug.sln
├── Freescale_debug.sln.DotSettings.user
├── Freescale_debug.v12.suo
├── Freescale_debug
├── 20150627125704915_easyicon_net_128.ico
├── App.config
├── CCDAlgorithm.cs
├── CameraAlgorithm.cs
├── ClassDiagram1.cd
├── Configuration.cs
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Freescale_debug.csproj
├── Freescale_debug.csproj.user
├── Libs
│ ├── Leomon.dll
│ ├── ZedGraph.dll
│ └── log4net.dll
├── LoadingPage.Designer.cs
├── LoadingPage.cs
├── LoadingPage.resx
├── LogHelper.cs
├── PID.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Source
│ ├── 1796091826490712038.png
│ ├── 20150627125330911_easyicon_net_96.ico
│ ├── 20150627125704915_easyicon_net_128.ico
│ ├── logo.png
│ ├── logo_1.png
│ ├── logo_2.png
│ └── master.png
├── SugarTransfer.cs
├── ZedGraphPoint.cs
├── ZedGraph_SingleWindow.Designer.cs
├── ZedGraph_SingleWindow.cs
└── ZedGraph_SingleWindow.resx
├── README.md
├── TestResults
└── 6c960e3f-1116-4806-b074-034ccbb003ff
│ └── MY_MY-PC 2016-03-16 16_09_41.coverage
├── 智能车调试平台使用手册.pdf
└── 通讯格式.doc
/.gitignore:
--------------------------------------------------------------------------------
1 | TestResults/*
2 | Freescale_debug/bin
3 | Freescale_debug/obj
4 | Freescale_debug/bin/*
5 | Freescale_debug/obj/*
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp #语言种类
2 | xcode_project: Freescale_debug.sln # 项目文件相对于.travis.yml文件的路径
3 | mono: none
4 | dotnet: 2.1
5 | script:
6 | - dotnet restore
7 | ...
--------------------------------------------------------------------------------
/.vs/Freescale_debug/v14/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/.vs/Freescale_debug/v14/.suo
--------------------------------------------------------------------------------
/FreescalePlatformTest/FreescalePlatformTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {6F8827B1-74E5-4172-A45D-73A468F8D780}
7 | Library
8 | Properties
9 | FreescalePlatformTest
10 | FreescalePlatformTest
11 | v4.5
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 | true
29 |
30 |
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | {5c73f5b7-1a8d-459f-afbd-ef5c5ae9ae51}
58 | Freescale_debug
59 |
60 |
61 |
62 |
63 |
64 |
65 | False
66 |
67 |
68 | False
69 |
70 |
71 | False
72 |
73 |
74 | False
75 |
76 |
77 |
78 |
79 |
80 |
81 |
88 |
--------------------------------------------------------------------------------
/FreescalePlatformTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下特性集
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("FreescalePlatformTest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FreescalePlatformTest")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 请将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("a1f743e8-0d23-413f-98a5-e511fdc06dce")]
24 |
25 | // 程序集的版本信息由以下四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/FreescalePlatformTest/UnitTest1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Freescale_debug;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using System.Text.RegularExpressions;
5 |
6 |
7 | namespace FreescalePlatformTest
8 | {
9 | [TestClass]
10 | public class UnitTest1
11 | {
12 | [TestMethod]
13 | public void TestMethod1()
14 | {
15 | Regex re = new Regex(@"\d+", RegexOptions.Compiled);
16 | string str = "aa";
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/FreescalePlatformTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/FreescalePlatformTest.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/FreescalePlatformTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/FreescalePlatformTest.pdb
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/Freescale_debug.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/Freescale_debug.exe
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/Freescale_debug.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/Freescale_debug.pdb
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/Leomon.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/Leomon.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/ZedGraph.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/ZedGraph.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/log4net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/log4net.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/bin/Debug/zh-Hans/Microsoft.VisualStudio.QualityTools.UnitTestFramework.resources.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/bin/Debug/zh-Hans/Microsoft.VisualStudio.QualityTools.UnitTestFramework.resources.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\FreescalePlatformTest.dll
2 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\FreescalePlatformTest.pdb
3 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\Freescale_debug.exe
4 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\Leomon.dll
5 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\ZedGraph.dll
6 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\log4net.dll
7 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\Freescale_debug.pdb
8 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\obj\Debug\FreescalePlatformTest.csprojResolveAssemblyReference.cache
9 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\obj\Debug\FreescalePlatformTest.dll
10 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\obj\Debug\FreescalePlatformTest.pdb
11 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
12 | F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\FreescalePlatformTest\bin\Debug\zh-Hans\Microsoft.VisualStudio.QualityTools.UnitTestFramework.resources.dll
13 |
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.dll
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/FreescalePlatformTest.pdb
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/FreescalePlatformTest/obj/Debug/build.force:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/FreescalePlatformTest/obj/Debug/build.force
--------------------------------------------------------------------------------
/Freescale_debug.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Freescale_debug", "Freescale_debug\Freescale_debug.csproj", "{5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreescalePlatformTest", "FreescalePlatformTest\FreescalePlatformTest.csproj", "{6F8827B1-74E5-4172-A45D-73A468F8D780}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {6F8827B1-74E5-4172-A45D-73A468F8D780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {6F8827B1-74E5-4172-A45D-73A468F8D780}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {6F8827B1-74E5-4172-A45D-73A468F8D780}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {6F8827B1-74E5-4172-A45D-73A468F8D780}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Freescale_debug.sln.DotSettings.user:
--------------------------------------------------------------------------------
1 |
2 | <AssemblyExplorer>
3 | <Assembly Path="F:\Project_Compotition\6.MyFreescal_10th\FreeScale_debug_platform\Freescale_debug\Freescale_debug\obj\Debug\Interop.Office.dll" />
4 | <Assembly Path="F:\Project_Compotition\6.MyFreescal_10th\New_for_platform\FreescalePlatform\Freescale_debug\Libs\log4net.dll" />
5 | </AssemblyExplorer>
--------------------------------------------------------------------------------
/Freescale_debug.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug.v12.suo
--------------------------------------------------------------------------------
/Freescale_debug/20150627125704915_easyicon_net_128.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/20150627125704915_easyicon_net_128.ico
--------------------------------------------------------------------------------
/Freescale_debug/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Freescale_debug/CCDAlgorithm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Drawing.Imaging;
5 | using System.Linq;
6 | using System.Runtime.InteropServices;
7 | using System.Windows.Forms;
8 |
9 | namespace Freescale_debug
10 | {
11 | internal class CCDAlgorithm
12 | {
13 | private List CCDBuff = new List();
14 | private int ccdLength;
15 |
16 | private string ccdStr = "";
17 | private int height = 0;
18 | private readonly List originCCDBuff;
19 | private readonly string originCCDStr = "";
20 |
21 | public CCDAlgorithm(string orginStr, List recvBuff)
22 | {
23 | originCCDStr = orginStr;
24 | originCCDBuff = recvBuff;
25 | }
26 |
27 | public void ApartMessage()
28 | {
29 | ApartMessageString();
30 | ApartMessageList();
31 | }
32 |
33 | private void ApartMessageString()
34 | {
35 | var firstRightIndex = originCCDStr.IndexOf('(');
36 | var indexEnd = originCCDStr.LastIndexOf('|');
37 | var ccdMessgageAdd = originCCDStr.Substring(firstRightIndex,
38 | indexEnd - firstRightIndex);
39 |
40 | var leftIndex = ccdMessgageAdd.IndexOf('(');
41 | var rightIndex = ccdMessgageAdd.IndexOf(')');
42 | var length = Convert.ToInt16(ccdMessgageAdd.Substring(leftIndex + 1, rightIndex - leftIndex - 1));
43 | var ccdData = ccdMessgageAdd.Substring(rightIndex + 1);
44 |
45 | ccdStr = ccdData;
46 | ccdLength = length;
47 | }
48 |
49 | private void ApartMessageList()
50 | {
51 | //找到recvBuff中的相应段
52 | for (var i = 0; i < originCCDBuff.Count - 6; i++)
53 | {
54 | if (originCCDBuff.ElementAt(i) == '#' &&
55 | originCCDBuff.ElementAt(i + 1) == '|' &&
56 | originCCDBuff.ElementAt(i + 2) == '2' &&
57 | originCCDBuff.ElementAt(i + 3) == '|' &&
58 | originCCDBuff.ElementAt(i + 5) == '|' &&
59 | originCCDBuff.ElementAt(i + 6) == '(')
60 | {
61 | for (var j = i + 11; j < ccdLength + i + 11; j++)
62 | {
63 | CCDBuff.Add(originCCDBuff[j]);
64 | }
65 | break;
66 | }
67 | }
68 | }
69 |
70 | public int GetCCDLength()
71 | {
72 | return ccdLength;
73 | }
74 |
75 | public string GetCCDStr()
76 | {
77 | return ccdStr;
78 | }
79 |
80 | public List GetCCDGreyValue()
81 | {
82 | return CCDBuff;
83 | }
84 |
85 | private string testCCD_Image()
86 | {
87 | var randInts = new int[128];
88 | var result = "";
89 | var rand = new Random();
90 | for (var i = 0; i < 128; i++)
91 | {
92 | randInts[i] = rand.Next(1, 255);
93 | result += Convert.ToChar(randInts[i]).ToString();
94 | //result += Convert.ToChar(0).ToString();
95 | }
96 | return result;
97 | }
98 |
99 | private int Average_ccd(List p)
100 | {
101 | var sum = p.Select((t, i) => p.ElementAt(i)).Sum();
102 |
103 | var thresold = sum/p.Count;
104 |
105 | if (thresold > 230)
106 | thresold = 100;
107 | else if (thresold < 150)
108 | thresold = 200;
109 | else
110 | {
111 | thresold = Otsu(p);
112 | }
113 |
114 | return thresold;
115 | }
116 |
117 | private int Otsu(List p)
118 | {
119 | //处理全是黑色时候的情况
120 |
121 | var threshold = 0;
122 | int g = 0, max = 0;
123 | int total = 0, total_low = 0;
124 | int u0 = 0, u1 = 0, count = 0, cnt = 0;
125 | var tmpData = new int[256];
126 | var j = 0;
127 | for (j = 5; j <= 122; j++)
128 | {
129 | tmpData[p.ElementAt(j)]++;
130 | total += p.ElementAt(j);
131 | }
132 | for (j = 0; j <= 254; j++)
133 | {
134 | cnt = tmpData[j];
135 | if (cnt == 0) continue; // 优化加速
136 | count += tmpData[j];
137 | total_low += cnt*j;
138 | u0 = total_low/count;
139 | if (count >= 118) break; // 优化加速 122 - 5+1
140 | u1 = (total - total_low)/(118 - count);
141 | g = (u0 - u1)*(u0 - u1)*count*(118 - count)/16384;
142 | if (g > max)
143 | {
144 | max = g;
145 | threshold = j;
146 | }
147 | }
148 | return threshold;
149 | }
150 |
151 | private string CCD_FindBoard(List p)
152 | {
153 | var black = "Border";
154 | for (var i = 0; i < p.Count - 1; i++)
155 | {
156 | if ((p.ElementAt(i) == 255 && p.ElementAt(i + 1) == 0) ||
157 | (p.ElementAt(i) == 0 && p.ElementAt(i + 1) == 255))
158 | {
159 | black += i + " ";
160 | }
161 | }
162 | return black;
163 | }
164 |
165 | #region 6.CCD图像
166 |
167 | public void DrawCCDPicture(PictureBox pictureBoxImage)
168 | {
169 | if (ccdStr.Length != ccdLength)
170 | return;
171 |
172 | var bitmap = new Bitmap(ccdStr.Length, pictureBoxImage.Height);
173 | var bitmapData =
174 | bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
175 | ImageLockMode.ReadWrite, bitmap.PixelFormat);
176 |
177 | var bytesPerPixel = Image.GetPixelFormatSize(bitmap.PixelFormat)/8;
178 | var byteCount = bitmapData.Stride*bitmap.Height;
179 | var pixels = new byte[byteCount];
180 | var ptrFirstPixel = bitmapData.Scan0;
181 | Marshal.Copy(ptrFirstPixel, pixels, 0, pixels.Length);
182 | var heightInPixels = bitmapData.Height;
183 | var widthInBytes = bitmapData.Width*bytesPerPixel;
184 |
185 | for (var y = 0; y < heightInPixels; y++)
186 | {
187 | var currentLine = y*bitmapData.Stride;
188 |
189 | for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
190 | {
191 | var grey = CCDBuff.ElementAt(Convert.ToInt16(x/4));
192 |
193 | // calculate new pixel value
194 | pixels[currentLine + x] = (byte) grey;
195 | pixels[currentLine + x + 1] = (byte) grey;
196 | pixels[currentLine + x + 2] = (byte) grey;
197 | pixels[currentLine + x + 3] = 255;
198 | }
199 | }
200 | // copy modified bytes back
201 | Marshal.Copy(pixels, 0, ptrFirstPixel, pixels.Length);
202 | bitmap.UnlockBits(bitmapData);
203 |
204 | pictureBoxImage.Image = bitmap;
205 | }
206 |
207 | public void DrawCCDPath(Bitmap bitmap, PictureBox pictureBoxImage)
208 | {
209 | if (ccdStr.Length != ccdLength)
210 | return;
211 |
212 | var bitmapData =
213 | bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
214 | ImageLockMode.ReadWrite, bitmap.PixelFormat);
215 |
216 | var bytesPerPixel = Image.GetPixelFormatSize(bitmap.PixelFormat)/8;
217 | var byteCount = bitmapData.Stride*bitmap.Height;
218 | var pixels = new byte[byteCount];
219 | var ptrFirstPixel = bitmapData.Scan0;
220 | Marshal.Copy(ptrFirstPixel, pixels, 0, pixels.Length);
221 | var heightInPixels = bitmapData.Height;
222 | var widthInBytes = bitmapData.Width*bytesPerPixel;
223 |
224 | for (var y = 1; y < heightInPixels; y++)
225 | {
226 | var currentLine = y*bitmapData.Stride;
227 | var formerLine = (y - 1)*bitmapData.Stride;
228 |
229 | for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
230 | {
231 | int oldBlue = pixels[currentLine + x];
232 | int oldGreen = pixels[currentLine + x + 1];
233 | int oldRed = pixels[currentLine + x + 2];
234 |
235 | pixels[formerLine + x] = (byte) oldBlue;
236 | pixels[formerLine + x + 1] = (byte) oldGreen;
237 | pixels[formerLine + x + 2] = (byte) oldRed;
238 | pixels[formerLine + x + 3] = 255;
239 | }
240 | }
241 |
242 | for (var y = heightInPixels - 1; y < heightInPixels; y++)
243 | {
244 | var currentLine = y*bitmapData.Stride;
245 |
246 | for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
247 | {
248 | var leng = CCDBuff.Count;
249 | var grey = CCDBuff.ElementAt(Convert.ToInt16(x/4));
250 |
251 | // calculate new pixel value
252 | pixels[currentLine + x] = (byte) grey;
253 | pixels[currentLine + x + 1] = (byte) grey;
254 | pixels[currentLine + x + 2] = (byte) grey;
255 | pixels[currentLine + x + 3] = 255;
256 | }
257 | }
258 | // copy modified bytes back
259 | Marshal.Copy(pixels, 0, ptrFirstPixel, pixels.Length);
260 | bitmap.UnlockBits(bitmapData);
261 |
262 | pictureBoxImage.Image = bitmap;
263 | }
264 |
265 | #endregion
266 | }
267 | }
--------------------------------------------------------------------------------
/Freescale_debug/CameraAlgorithm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Drawing.Imaging;
5 | using System.Linq;
6 | using System.Runtime.InteropServices;
7 | using System.Windows.Forms;
8 |
9 | namespace Freescale_debug
10 | {
11 | internal class CameraAlgorithm
12 | {
13 | private readonly List originBuff;
14 | private List> cameraBuff = new List>();
15 |
16 | private string cameraStr = "";
17 | private readonly string originCameraStr = "";
18 | private int height;
19 | private int width;
20 |
21 | public CameraAlgorithm(string orginStr, List recvBuff)
22 | {
23 | originCameraStr = orginStr;
24 | originBuff = recvBuff;
25 | }
26 |
27 | private List> opticalflow = new List>();
28 | private List> prevframe = new List>();
29 | private List> output = new List>();
30 |
31 | private List> initList(int height, int width, int initValue)
32 | {
33 | List> aa = new List>();
34 | List a = new List();
35 | for (int j = 0; j < height; j++)
36 | {
37 | for (int i = 0; i < width; i++)
38 | {
39 | a.Add(initValue);
40 | }
41 | aa.Add(a);
42 | }
43 | return aa;
44 | }
45 |
46 | public List> OPFlow(List> buf)
47 | {
48 | int Ex, Ey, Et;
49 | int gray1, gray2;
50 | int u;
51 | int i, j;
52 | // opticalflow 需要清零
53 | opticalflow = initList(height, width, 0);
54 | // memset(output, 255, size);
55 | output = initList(height, width, 255);
56 |
57 | for (i = 0; i < height; i++)
58 | {
59 | for (j = 0; j < width; j++)
60 | {
61 | if (buf[i][j] == 0)
62 | buf[i][j] = 0;
63 | else
64 | buf[i][j] = 255;
65 | }
66 | }
67 |
68 | for (i = 2; i < height - 2; i++)
69 | {
70 | for (j = 2; j < width - 2; j++)
71 | {
72 | gray1 = (int)(buf[i][j]);
73 | gray2 = (int)(prevframe[i][j]);
74 | Et = gray1 - gray2;
75 |
76 | gray2 = (int)(buf[i][j+1]); //右边一点
77 | Ex = gray2 - gray1;
78 | gray2 = (int)(buf[i+1][j]); //下边一点
79 | Ey = gray2 - gray1;
80 | Ex = ((int)(Ex / 10)) * 10;
81 | Ey = ((int)(Ey / 10)) * 10;
82 | Et = ((int)(Et / 10)) * 10;
83 | u = (int)((Et * 10.0) / (Math.Sqrt((Ex * Ex + Ey * Ey) * 1.0)) + 0.1);
84 | opticalflow[i][j] = u;
85 | if (Math.Abs(u) > 10)
86 | {
87 | output[i][j] = 0;
88 | }
89 | }
90 | }
91 | prevframe = buf;
92 |
93 | return output;
94 | }
95 |
96 | public void ApartMessage()
97 | {
98 | var firstRightIndex = originCameraStr.IndexOf('(');
99 | var indexEnd = originCameraStr.LastIndexOf('|');
100 |
101 | if (firstRightIndex > indexEnd)
102 | return;
103 |
104 | var cameraMessgageAdd = originCameraStr.Substring(firstRightIndex,
105 | indexEnd - firstRightIndex);
106 |
107 | var leftIndex = cameraMessgageAdd.IndexOf('(');
108 | var middleIndex = cameraMessgageAdd.IndexOf('+');
109 | var rightIndex = cameraMessgageAdd.IndexOf(')');
110 |
111 | if (leftIndex > middleIndex || middleIndex > rightIndex)
112 | return;
113 |
114 | int widthCamera =
115 | Convert.ToInt16(cameraMessgageAdd.Substring(leftIndex + 1, middleIndex - leftIndex - 1));
116 | int heightCamera =
117 | Convert.ToInt16(cameraMessgageAdd.Substring(middleIndex + 1,
118 | rightIndex - middleIndex - 1));
119 | var cameraData = cameraMessgageAdd.Substring(rightIndex + 1);
120 |
121 | height = heightCamera;
122 | width = widthCamera;
123 | cameraStr = cameraData;
124 |
125 | //找到recvBuff中的相应段
126 | for (var i = 0; i < originBuff.Count - 12; i++)
127 | {
128 | if (originBuff.ElementAt(i) == '#' &&
129 | originBuff.ElementAt(i + 1) == '|' &&
130 | originBuff.ElementAt(i + 2) == '1' &&
131 | originBuff.ElementAt(i + 3) == '|' &&
132 | originBuff.ElementAt(i + 5) == '|' &&
133 | originBuff.ElementAt(i + 6) == '(' &&
134 | originBuff.ElementAt(i + 7) == '8' &&
135 | originBuff.ElementAt(i + 8) == '0' &&
136 | originBuff.ElementAt(i + 9) == '+' &&
137 | originBuff.ElementAt(i + 10) == '6' &&
138 | originBuff.ElementAt(i + 11) == '0' &&
139 | originBuff.ElementAt(i + 12) == ')')
140 | {
141 | List cameraBuffOneLine = new List();
142 | for (var j = i + 13; j < width*height/8 + i + 13; j++)
143 | {
144 | cameraBuffOneLine.Add(originBuff[j]);
145 | }
146 |
147 | List cameraBuffColumn = new List();
148 | for (int j = 0; j < width*height/8; j++)
149 | {
150 | int currentBuff = cameraBuffOneLine.ElementAt(j);
151 | for (int k = 7; k >= 0; k--)
152 | cameraBuffColumn.Add(currentBuff>>k & 0x01);
153 | if ((j+1)%10 == 0)
154 | {
155 | cameraBuff.Add(cameraBuffColumn);
156 | cameraBuffColumn = new List();
157 | }
158 | }
159 |
160 | break;
161 | }
162 | }
163 | }
164 |
165 | public void DrawCameraPicture(PictureBox pictureBoxCamera)
166 | {
167 | if (isValidData())
168 | {
169 | int amplify = 5;
170 | var bitmap = new Bitmap(width*amplify, height*amplify);
171 |
172 | var bitmapData =
173 | bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
174 | ImageLockMode.ReadWrite, bitmap.PixelFormat);
175 |
176 | var bytesPerPixel = Image.GetPixelFormatSize(bitmap.PixelFormat)/8;
177 | var byteCount = bitmapData.Stride*bitmap.Height;
178 | var pixels = new byte[byteCount];
179 | var ptrFirstPixel = bitmapData.Scan0;
180 | Marshal.Copy(ptrFirstPixel, pixels, 0, pixels.Length);
181 | var heightInPixels = bitmapData.Height;
182 | var widthInBytes = bitmapData.Width*bytesPerPixel;
183 |
184 | for (var y = 0; y < heightInPixels; y++)
185 | {
186 | var currentLine = y*bitmapData.Stride;
187 |
188 | for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
189 | {
190 | int grey = cameraBuff.ElementAt(y/amplify).ElementAt(x/4/amplify);
191 |
192 | // calculate new pixel value
193 | pixels[currentLine + x] = (byte)(grey == 1 ? 0 : 255);
194 | pixels[currentLine + x + 1] = (byte)(grey == 1 ? 0 : 255);
195 | pixels[currentLine + x + 2] = (byte)(grey == 1 ? 0 : 255);
196 | pixels[currentLine + x + 3] = 255;
197 | }
198 | }
199 | // copy modified bytes back
200 | Marshal.Copy(pixels, 0, ptrFirstPixel, pixels.Length);
201 | bitmap.UnlockBits(bitmapData);
202 |
203 | pictureBoxCamera.Image = bitmap;
204 | }
205 | }
206 |
207 | private bool isValidData()
208 | {
209 | if (cameraBuff.Count*cameraBuff.First().Count == width*height)
210 | return true;
211 | return false;
212 | }
213 |
214 | public int GetHeight()
215 | {
216 | return height;
217 | }
218 |
219 | public int GetWidth()
220 | {
221 | return width;
222 | }
223 |
224 | public string GetCameraStr()
225 | {
226 | return cameraStr;
227 | }
228 | }
229 | }
--------------------------------------------------------------------------------
/Freescale_debug/ClassDiagram1.cd:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Freescale_debug/Configuration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using leomon;
4 |
5 | namespace Freescale_debug
6 | {
7 | //class Configuration
8 | public partial class Form1 : Form
9 | {
10 | private void SaveConfig(string fileName)
11 | {
12 | var editor = new Editor();
13 |
14 | WritePortSetup(editor);
15 | WritePidSetup(editor);
16 | WriteRealTimeSetup(editor);
17 | WriteDiySetup(editor);
18 | WriteScopeSetup(editor);
19 | WriteOthers(editor);
20 |
21 | WriteToFile(fileName, editor);
22 | }
23 |
24 | private void LoadConfig(string fileName)
25 | {
26 | var sp = new SharedPreferences(fileName);
27 | if (sp.ConfigFileExists)
28 | {
29 | ReadPortSetup(sp);
30 | ReadPIDSetup(sp);
31 | ReadDIYNumberSetup(sp);
32 | ReadRealTimeSetup(sp);
33 | ReadOthers(sp);
34 |
35 | textBox_receive.Clear();
36 | }
37 | else
38 | {
39 | //载入默认设置
40 | ResetToDefaultSettings();
41 | }
42 | }
43 |
44 | private void WritePortSetup(Editor editor)
45 | {
46 | if (_hasPorts)
47 | {
48 | //保存选中的端口
49 | editor.PutInt32("selectedPort", comboBox_port.SelectedIndex);
50 | //保存设置的波特率
51 | editor.PutInt32("baudRate", comboBox_baudrate.SelectedIndex);
52 | //保存设置的校验方式
53 | editor.PutInt32("parity", comboBox_parity.SelectedIndex);
54 | //保存设置的数据位
55 | editor.PutInt32("dataBits", comboBox_databit.SelectedIndex);
56 | //保存设置的停止位
57 | editor.PutInt32("stopBits", comboBox_stopbit.SelectedIndex);
58 | //保存自动发送数据时间间隔
59 | editor.PutInt32("intervalTime", Convert.ToInt32(textBox_sendPeriod.Text));
60 | //保存接收方式
61 | editor.PutBoolean("acceptChar", checkBox_receiveHex.Checked);
62 | //保存标志变量,即是否在接收框中显示信息。
63 | editor.PutBoolean("showInfo", showInfo);
64 | }
65 | }
66 |
67 | private void WritePidSetup(Editor editor)
68 | {
69 | //保存PID参数选择情况
70 | editor.PutBoolean("radioButton_carType", radioButton_FourWheel.Checked);
71 |
72 | if (radioButton_FourWheel.Checked) //四轮车PID
73 | {
74 | WritePidFourWheel(editor);
75 | }
76 | else if (radioButton_BalanceCar.Checked) //直立车PID参数的获取
77 | {
78 | WritePidBalance(editor);
79 | }
80 | }
81 |
82 | private void WritePidFourWheel(Editor editor)
83 | {
84 | //舵机PID参数
85 | editor.PutString("Steer_P", textBox_Steer_P.Text);
86 | editor.PutString("Steer_I", textBox_Steer_I.Text);
87 | editor.PutString("Steer_D", textBox_Steer_D.Text);
88 |
89 | //电机PID参数
90 | editor.PutString("Motor_P", textBox_Motor_P.Text);
91 | editor.PutString("Motor_I", textBox_Motor_I.Text);
92 | editor.PutString("Motor_D", textBox_Motor_D.Text);
93 | }
94 |
95 | private void WritePidBalance(Editor editor)
96 | {
97 | //直立PID
98 | editor.PutString("Stand_P", textBox_Stand_P.Text);
99 | editor.PutString("Stand_I", textBox_Stand_I.Text);
100 | editor.PutString("Stand_D", textBox_Stand_D.Text);
101 |
102 | //速度PID
103 | editor.PutString("Speed_P", textBox_Speed_P.Text);
104 | editor.PutString("Speed_I", textBox_Speed_I.Text);
105 | editor.PutString("Speed_D", textBox_Speed_D.Text);
106 |
107 | //方向PID
108 | editor.PutString("Direction_P", textBox_Direction_P.Text);
109 | editor.PutString("Direction_I", textBox_Direction_I.Text);
110 | editor.PutString("Direction_D", textBox_Direction_D.Text);
111 | }
112 |
113 | private void WriteDiySetup(Editor editor)
114 | {
115 | //保存自定义参数的数量
116 | editor.PutInt32("DIY_Number", Convert.ToInt32(textBox_DIY_Number.Text));
117 |
118 | //保存自定义参数的其他信息
119 | var total = Convert.ToInt32(textBox_DIY_Number.Text);
120 | for (var i = 0; i < total; i++)
121 | {
122 | var controlCheckState = panel_add_DIYControls.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true);
123 | if (controlCheckState.Length > 0)
124 | {
125 | var checkboxSelect = (CheckBox)controlCheckState[0];
126 |
127 | var checkState = string.Format("DIY_CheckState{0}", i + 1);
128 | editor.PutBoolean(checkState, checkboxSelect.Checked);
129 | }
130 |
131 | var controlName = panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true);
132 | if (controlName.Length > 0)
133 | {
134 | var txtBox = (TextBox)controlName[0];
135 |
136 | var txtName = string.Format("DIY_TextName{0}", i + 1);
137 | editor.PutString(txtName, txtBox.Text);
138 | }
139 |
140 | var controlValue = panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true);
141 | if (controlValue.Length > 0)
142 | {
143 | var txtBox = (TextBox)controlValue[0];
144 |
145 | var txtValue = string.Format("DIY_TextValue{0}", i + 1);
146 | editor.PutString(txtValue, txtBox.Text);
147 | }
148 |
149 | var controlButton = panel_add_DIYControls.Controls.Find("buttonSubmit" + Convert.ToString(i + 1), true);
150 | if (controlButton.Length > 0)
151 | {
152 | var button = (Button)controlButton[0];
153 |
154 | var buttonName = string.Format("buttonSubmit{0}", i + 1);
155 | editor.PutString(buttonName, "修改");
156 | }
157 | }
158 | }
159 |
160 | private void WriteRealTimeSetup(Editor editor)
161 | {
162 | //保存实时变量数量
163 | editor.PutString("RealtimeNum", textBox_Realtime_Number.Text);
164 |
165 | //保存实时变量的其他信息
166 | var total = Convert.ToInt32(textBox_Realtime_Number.Text);
167 | for (var i = 0; i < total; i++)
168 | {
169 | var controlName = panel_Electricity.Controls.Find("txtElectName" + Convert.ToString(i + 1), true);
170 | if (controlName.Length > 0)
171 | {
172 | var txtBox = (TextBox)controlName[0];
173 |
174 | var txtNameElect = string.Format("textElectName{0}", i + 1);
175 | editor.PutString(txtNameElect, txtBox.Text);
176 | }
177 |
178 | var controlValue = panel_Electricity.Controls.Find("txtElectValue" + Convert.ToString(i + 1), true);
179 | if (controlValue.Length > 0)
180 | {
181 | var txtBox = (TextBox) controlValue[0];
182 | var txtValueElect = string.Format("txtElectValue{0}", i + 1);
183 | editor.PutString(txtValueElect, txtBox.Text);
184 | }
185 | }
186 | }
187 |
188 | private void WriteScopeSetup(Editor editor)
189 | {
190 | //保存虚拟示波器的变量情况
191 | var totalScope = ScopeNumber;
192 | for (var i = 0; i < totalScope; i++)
193 | {
194 |
195 | var controlCheckState = panel_Scope.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true);
196 | if (controlCheckState.Length > 0)
197 | {
198 | var checkboxSelect = (CheckBox)controlCheckState[0];
199 |
200 | var checkState = string.Format("SCOPE_CheckState{0}", i + 1);
201 | editor.PutBoolean(checkState, checkboxSelect.Checked);
202 | }
203 |
204 |
205 | var controlName = panel_Scope.Controls.Find("txtName" + Convert.ToString(i + 1), true);
206 | if (controlName.Length > 0)
207 | {
208 | var txtBox = (TextBox)controlName[0];
209 |
210 | var txtName = string.Format("SCOPE_TextName{0}", i + 1);
211 | editor.PutString(txtName, txtBox.Text);
212 | }
213 | }
214 | }
215 |
216 | private void WriteOthers(Editor editor)
217 | {
218 | editor.PutInt32("comboboxCCDPath", comboBoxCCDPath.SelectedIndex);
219 | }
220 |
221 | private static void WriteToFile(string fileName, Editor editor)
222 | {
223 | //=================================================================
224 | var sp = new SharedPreferences(fileName);
225 | sp.Save(editor);
226 | }
227 |
228 | private void ReadPortSetup(SharedPreferences sp)
229 | {
230 | //读取选中的端口
231 | if (_hasPorts)
232 | {
233 | //判断当前端口的数量,小于则表示是OK。
234 | if (sp.GetInt32("selectedPort", 0) < comboBox_port.Items.Count)
235 | comboBox_port.SelectedIndex = sp.GetInt32("selectedPort", 0);
236 | else
237 | {
238 | comboBox_port.SelectedIndex = 0;
239 | }
240 | }
241 | //读取设置的波特率
242 | comboBox_baudrate.SelectedIndex = sp.GetInt32("baudRate", 0);
243 | //读取设置的校验方式
244 | comboBox_parity.SelectedIndex = sp.GetInt32("parity", 0);
245 | //读取设置的数据位
246 | comboBox_databit.SelectedIndex = sp.GetInt32("dataBits", 0);
247 | //读取设置的停止位
248 | comboBox_stopbit.SelectedIndex = sp.GetInt32("stopBits", 0);
249 | //读取自动发送数据时间间隔
250 | textBox_sendPeriod.Text = sp.GetInt32("intervalTime", 500).ToString();
251 | //读取接收方式
252 | checkBox_receiveHex.Checked = sp.GetBoolean("acceptChar", true);
253 | //读取标志变量,即是否在接收框中显示信息。
254 | showInfo = sp.GetBoolean("showInfo", true);
255 | button_receivepause.Text = showInfo ? "暂停接收显示" : "继续接收显示";
256 | }
257 |
258 | private void ReadPIDSetup(SharedPreferences sp)
259 | {
260 | //保存的车型
261 | radioButton_FourWheel.Checked = sp.GetBoolean("radioButton_carType", true);
262 | if (!radioButton_FourWheel.Checked)
263 | radioButton_BalanceCar.Checked = true;
264 |
265 | if (radioButton_FourWheel.Checked) //四轮车PID
266 | ReadPIDFourWheel(sp);
267 | else if (radioButton_BalanceCar.Checked) //直立车PID参数的获取
268 | ReadPIDBalanceCar(sp);
269 | }
270 |
271 | private void ReadPIDFourWheel(SharedPreferences sp)
272 | {
273 | //舵机PID参数
274 | textBox_Steer_P.Text = sp.GetString("Steer_P", "1.0");
275 | textBox_Steer_I.Text = sp.GetString("Steer_I", "1.0");
276 | textBox_Steer_D.Text = sp.GetString("Steer_D", "1.0");
277 |
278 | //电机PID参数
279 | textBox_Motor_P.Text = sp.GetString("Motor_P", "1.0");
280 | textBox_Motor_I.Text = sp.GetString("Motor_I", "1.0");
281 | textBox_Motor_D.Text = sp.GetString("Motor_D", "1.0");
282 | }
283 |
284 | private void ReadPIDBalanceCar(SharedPreferences sp)
285 | {
286 | //直立PID
287 | textBox_Stand_P.Text = sp.GetString("Stand_P", "1.0");
288 | textBox_Stand_I.Text = sp.GetString("Stand_I", "1.0");
289 | textBox_Stand_D.Text = sp.GetString("Stand_D", "1.0");
290 |
291 | //速度PID
292 | textBox_Speed_P.Text = sp.GetString("Speed_P", "1.0");
293 | textBox_Speed_I.Text = sp.GetString("Speed_I", "1.0");
294 | textBox_Speed_D.Text = sp.GetString("Speed_D", "1.0");
295 |
296 | //方向PID
297 | textBox_Direction_P.Text = sp.GetString("Direction_P", "1.0");
298 | textBox_Direction_I.Text = sp.GetString("Direction_I", "1.0");
299 | textBox_Direction_D.Text = sp.GetString("Direction_D", "1.0");
300 | }
301 |
302 | private void ReadDIYNumberSetup(SharedPreferences sp)
303 | {
304 | textBox_DIY_Number.Text = sp.GetInt32("DIY_Number", 1).ToString();
305 | }
306 |
307 | private void ReadRealTimeSetup(SharedPreferences sp)
308 | {
309 | textBox_Realtime_Number.Text = sp.GetString("RealtimeNum", "1");
310 | }
311 |
312 | private void ReadOthers(SharedPreferences sp)
313 | {
314 | comboBoxCCDPath.SelectedIndex = sp.GetInt32("comboboxCCDPath", 0);
315 | }
316 |
317 | private void ResetToDefaultSettings()
318 | {
319 | var editor = new Editor();
320 |
321 | ResetPortSetup();
322 | ResetPIDSetup(editor);
323 | ResetCustomSetup(editor);
324 | ResetRealTimeSetup(editor);
325 | ResetScopeSetup(editor);
326 |
327 | WriteToFile(SavefileName, editor);
328 | LoadConfig(SavefileName);
329 | }
330 |
331 | private void ResetPortSetup()
332 | {
333 | //默认波特率
334 | comboBox_baudrate.SelectedItem = "9600";
335 | //默认不校验
336 | comboBox_parity.SelectedIndex = 0;
337 | //默认数据位设置为8位
338 | comboBox_databit.SelectedIndex = 0;
339 | //默认停止位设置为1位
340 | comboBox_stopbit.SelectedIndex = 0;
341 | }
342 |
343 | private void ResetPIDSetup(Editor editor)
344 | {
345 | editor.PutBoolean("radioButton_carType", false);
346 |
347 | //舵机PID参数
348 | editor.PutString("Steer_P", "1.0");
349 | editor.PutString("Steer_I", "1.0");
350 | editor.PutString("Steer_D", "1.0");
351 |
352 | //电机PID参数
353 | editor.PutString("Motor_P", "1.0");
354 | editor.PutString("Motor_I", "1.0");
355 | editor.PutString("Motor_D", "1.0");
356 |
357 | //直立PID
358 | editor.PutString("Stand_P", "1.0");
359 | editor.PutString("Stand_I", "1.0");
360 | editor.PutString("Stand_D", "1.0");
361 |
362 | //速度PID
363 | editor.PutString("Speed_P", "1.0");
364 | editor.PutString("Speed_I", "1.0");
365 | editor.PutString("Speed_D", "1.0");
366 |
367 | //方向PID
368 | editor.PutString("Direction_P", "1.0");
369 | editor.PutString("Direction_I", "1.0");
370 | editor.PutString("Direction_D", "1.0");
371 | }
372 |
373 | private void ResetCustomSetup(Editor editor)
374 | {
375 | int diyNumber = 1;
376 | editor.PutInt32("DIY_Number", diyNumber);
377 |
378 | for (var i = 0; i < diyNumber; i++)
379 | {
380 | var checkState = string.Format("DIY_CheckState{0}", i + 1);
381 | editor.PutBoolean(checkState, false);
382 |
383 | var txtNameDIY = string.Format("DIY_TextName{0}", i + 1);
384 | editor.PutString(txtNameDIY, "Names");
385 |
386 | var txtValueDIY = string.Format("DIY_TextValue{0}", i + 1);
387 | editor.PutString(txtValueDIY, "1.0");
388 |
389 | var buttonDIY = string.Format("buttonSubmit{0}", i + 1);
390 | editor.PutString(buttonDIY, @"修改");
391 | }
392 | }
393 |
394 | private void ResetRealTimeSetup(Editor editor)
395 | {
396 | int realtimeNumber = 1;
397 | editor.PutInt32("RealtimeNum", realtimeNumber);
398 |
399 | for (var i = 0; i < realtimeNumber; i++)
400 | {
401 | var txtName = string.Format("textElectName{0}", i + 1);
402 | editor.PutString(txtName, "Name");
403 |
404 | var txtValue = string.Format("txtElectValue{0}", i + 1);
405 | editor.PutString(txtValue, "0");
406 | }
407 | }
408 |
409 | private void ResetScopeSetup(Editor editor)
410 | {
411 | var totalScope = ScopeNumber;
412 |
413 | for (var i = 0; i < totalScope; i++)
414 | {
415 | var checkState = string.Format("SCOPE_CheckState{0}", i + 1);
416 | editor.PutBoolean(checkState, false);
417 |
418 | var txtNameDIY = string.Format("SCOPE_TextName{0}", i + 1);
419 | editor.PutString(txtNameDIY, "波形" + (i+1));
420 | }
421 | }
422 | }
423 | }
--------------------------------------------------------------------------------
/Freescale_debug/Form1.cs:
--------------------------------------------------------------------------------
1 | #define MULTITHREAD //多线程收发模式,注释本句则使用单线程模式
2 | //相对单线收发模式,占用系统资源稍微大些,但是执行效果更好,尤其是在大数据收发时的UI反应尤其明显
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 | using System.Drawing;
8 | using System.Globalization;
9 | using System.IO;
10 | using System.IO.Ports;
11 | using System.Linq;
12 | using System.Text;
13 | using System.Text.RegularExpressions;
14 | using System.Windows.Forms;
15 | using leomon;
16 | using TestLog4Net;
17 | using ZedGraph;
18 |
19 | namespace Freescale_debug
20 | {
21 | public partial class Form1 : Form
22 | {
23 | public delegate void UpdateAcceptTextBoxTextHandler(string text);
24 |
25 | //ZedGraph
26 | private const int ScopeNumber = 8; //示波器能画曲线的数量
27 | private const string SavefileName = "串口助手配置.xml";
28 | private readonly ZedGrpahName[] zedGrpahNames = new ZedGrpahName[ScopeNumber];
29 |
30 | private readonly Color[] _colorLine =
31 | {
32 | Color.Green, Color.DodgerBlue, Color.Brown, Color.Chartreuse,
33 | Color.CornflowerBlue, Color.Red, Color.Yellow, Color.Gray
34 | };
35 |
36 | //发送串口数据的队列,直到收到有效数据为止
37 | private readonly Queue _queueEchoControl = new Queue(); //根据这个来判断是不是要进行重发
38 | private GetEchoForm tmpSendHandle = new GetEchoForm(1, "");
39 | private Bitmap _bitmapOld;
40 |
41 | private bool _isLoadHistory;
42 | //自定义参数的一些变量
43 | private bool _listening; //是否没有执行完invoke相关操作
44 | private int _xmaxScale = 100;
45 | private double _xminScale = 0;
46 | private double _ymaxScale = 100;
47 | private double _yminScale = -10;
48 | //ZedGraph 窗体间传参
49 | public CallObject[] coOb = new CallObject[ScopeNumber];
50 |
51 | private readonly List _recieveBuff = new List();
52 | //SerialPort Flags
53 | private bool _closing; //是否正在关闭串口,执行Application.DoEvents,并阻止再次
54 |
55 | private ReceivedDataType myReceivedDataType = ReceivedDataType.CharType;
56 | private SendDataType mySendDataType = SendDataType.CharType;
57 | private string RecievedStringAdd = ""; //接收到的数据
58 | private int retryCount;
59 | private bool showInfo = true;
60 |
61 | private int totalReceivedBytes;
62 | public UpdateAcceptTextBoxTextHandler UpdateTextHandler;
63 |
64 | //线程的委托//使线程可以改变控件的值
65 | private delegate void DoWorkUiThreadDelegate(string recvString, List recvByte);
66 |
67 | private enum ReceivedDataType
68 | {
69 | CharType,
70 | HexType
71 | }
72 |
73 | private enum SendDataType
74 | {
75 | CharType,
76 | HexType
77 | }
78 |
79 | #region Form
80 |
81 | public Form1()
82 | {
83 | InitializeComponent();
84 | UpdateTextHandler = UpdateText;
85 | textBox_receive.ScrollToCaret();
86 | }
87 |
88 | private void Form1_Load(object sender, EventArgs e)
89 | {
90 | _bitmapOld = new Bitmap(128, pictureBox_CCD_Path.Height);
91 | for (var i = 0; i < 128; i++)
92 | {
93 | for (var j = 0; j < pictureBox_CCD_Path.Height; j++)
94 | {
95 | _bitmapOld.SetPixel(i, j, Color.FromArgb(255, 255, 255));
96 | }
97 | }
98 | comboBoxCCDPath.SelectedIndex = 0;
99 |
100 | CheckAvailablePorts();
101 |
102 | LoadConfig(SavefileName);
103 |
104 | Init_TablePagePIDSettings();
105 | Init_CustomPara_DynamicControls();
106 | InitRealtime();
107 | InitzedGraph();
108 | Init_pane_Scope();
109 | }
110 |
111 | private void Form1_Activated(object sender, EventArgs e)
112 | {
113 | }
114 |
115 | private void Form1_FormClosed(object sender, FormClosedEventArgs e)
116 | {
117 | _closing = true;
118 | while (_listening) Application.DoEvents();
119 |
120 | timer_Send2GetEcho.Stop();
121 |
122 | SaveConfig(SavefileName);
123 | }
124 |
125 | private void Form1_SizeChanged(object sender, EventArgs e)
126 | {
127 | if (WindowState == FormWindowState.Normal ||
128 | WindowState == FormWindowState.Maximized)
129 | {
130 | pictureBox_CameraActual.Height = pictureBox_CameraActual.Width /4*3;
131 | }
132 | }
133 |
134 | private void comboBoxCCDPath_SelectedIndexChanged(object sender, EventArgs e)
135 | {
136 | labelPathName.Text = string.Format("图像{0}路径:", comboBoxCCDPath.SelectedItem.ToString());
137 | }
138 |
139 | #endregion
140 |
141 | #region 串口设置相关 1
142 |
143 | private int _totalSendBytes;
144 | private bool _autoSend;
145 |
146 | private void button_openPort_Click(object sender, EventArgs e) //打开关闭串口
147 | {
148 | if (button_openPort.Text == @"打开串口")
149 | {
150 | button_freshPort.Enabled = false;
151 |
152 | textBox_receive.Clear();
153 | OpenSelectedPort();
154 | //更改配置信息
155 | SetSerialPortPropertiesBeforeSending();
156 | }
157 | else
158 | {
159 | timer_Send2GetEcho.Stop();
160 |
161 | //清除队列中所有元素
162 | label28.Text = @"QueueLength Cleared";
163 | _queueEchoControl.Clear();
164 | retryCount = 0;
165 |
166 | CloseCurrentPort();
167 | button_freshPort.Enabled = true;
168 | }
169 | }
170 |
171 | private void button_freshPort_Click(object sender, EventArgs e)
172 | {
173 | comboBox_port.Items.Clear();
174 | var allAvailablePorts = SerialPort.GetPortNames();
175 | //判断是否有可用的端口
176 | if (allAvailablePorts.Length > 0)
177 | {
178 | _hasPorts = true;
179 | //使能控件portNamesComboBox,openOrCloseButton
180 | button_openPort.Enabled = true;
181 | comboBox_port.Enabled = true;
182 | comboBox_baudrate.Enabled = true;
183 | comboBox_databit.Enabled = true;
184 | comboBox_parity.Enabled = true;
185 | comboBox_stopbit.Enabled = true;
186 | //依次添加可用的串口
187 | comboBox_port.Items.AddRange(allAvailablePorts);
188 | //默认选中第一个项
189 | comboBox_port.SelectedIndex = 0;
190 | //显示相应的状态信息
191 | //statusDisplayToolStripStatusLabel.Text = string.Format(" 欢迎使用!自动查找到该计算机可用端口数:{0},当前选中端口号{1} :)",
192 | // allAvailablePorts.Length, portNameComboBox.SelectedItem.ToString());
193 | }
194 | else
195 | {
196 | _hasPorts = false;
197 | checkBox_sendAuto.Enabled = false;
198 | button_sendmessage.Enabled = false;
199 | //stopSendButton.Enabled = false;
200 | button_openPort.Enabled = false;
201 | //清空所有项
202 | comboBox_port.Items.Clear();
203 | comboBox_port.Enabled = false;
204 | //statusDisplayToolStripStatusLabel.Text = " 抱歉,未查找到当前计算机中可用端口。";
205 | //同时弹出警告对话框,提示是否进行再次检查?!
206 | ShowWarningMessageBox();
207 | }
208 | }
209 |
210 | private void button_countclear_Click(object sender, EventArgs e)
211 | {
212 | _totalSendBytes = 0;
213 | totalReceivedBytes = 0;
214 |
215 | label_receiveCount.Text = @"接受区计数:" + totalReceivedBytes;
216 | label_sendCount.Text = @"发送区计数:" + _totalSendBytes;
217 | }
218 |
219 | private void UpdateText(string text)
220 | {
221 | //if (showInfo)
222 | {
223 | textBox_receive.AppendText(text);
224 |
225 | if (textBox_receive.GetLineFromCharIndex(textBox_receive.TextLength) > 100) //超过100行清零
226 | {
227 | textBox_receive.Clear();
228 | }
229 |
230 | if (checkBox_receiveAnotherline.Checked) //自动添加换行符
231 | textBox_receive.Text += @"\r\n";
232 |
233 | label_receiveCount.Text = @"接受区计数:" + totalReceivedBytes;
234 | }
235 | }
236 |
237 | ///
238 | /// 每次从SerialPort接收数据时发生,由于运行在辅助线程
239 | /// 所以必须要通过委托来实现跨线程。
240 | ///
241 | ///
242 | ///
243 | private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
244 | {
245 | if (_closing) return; //如果正在关闭,忽略操作,直接返回,尽快的完成串口监听线程的一次循环
246 | try
247 | {
248 | _listening = true;
249 | var sp = (SerialPort) sender;
250 | var text = string.Empty;
251 | var size = sp.BytesToRead;
252 | if (myReceivedDataType == ReceivedDataType.HexType)
253 | {
254 | for (var i = 0; i < size; i++)
255 | {
256 | var tempByte = sp.ReadByte();
257 | var tempStr = "0X";
258 | if (tempByte <= 0X0F)
259 | {
260 | tempStr = "0X0";
261 | }
262 | text +=
263 | tempStr + Convert.ToString(tempByte, 16).ToUpper() + " ";
264 | }
265 | }
266 | else
267 | {
268 | var n = sp.BytesToRead;
269 | var builder = new StringBuilder();
270 | var buf = new byte[n];
271 | sp.Read(buf, 0, n);
272 | builder.Append(Encoding.ASCII.GetString(buf));
273 |
274 | text = builder.ToString();
275 | RecievedStringAdd += text;
276 |
277 | for (var i = 0; i < n; i++)
278 | {
279 | _recieveBuff.Add(buf.ElementAt(i));
280 | }
281 |
282 | //在这里判断是不是收到了合适的数据
283 | //判断数据头尾
284 | if (RecievedStringAdd.Contains("#|") && RecievedStringAdd.Contains("|$"))
285 | {
286 | var headCheck = RecievedStringAdd.IndexOf('#');
287 | var endCheck = RecievedStringAdd.LastIndexOf('$');
288 | if (headCheck != -1 && endCheck != -1 && endCheck - headCheck > 10)
289 | {
290 | if (InvokeRequired)
291 | {
292 | Invoke(new DoWorkUiThreadDelegate(UnPakegeReceived), RecievedStringAdd, _recieveBuff);
293 | }
294 | RecievedStringAdd = null;
295 | _recieveBuff.Clear();
296 | }
297 | }
298 | }
299 | totalReceivedBytes += size;
300 | Invoke(UpdateTextHandler, text);
301 | }
302 | catch (Exception ex)
303 | {
304 | LogHelper.WriteLog(typeof (Form1), ex);
305 | }
306 |
307 | finally
308 | {
309 | _listening = false; //我用完了,ui可以关闭串口了。
310 | }
311 | }
312 |
313 | #region 数据包格式解析部分
314 |
315 | public class GetEchoForm
316 | {
317 | public GetEchoForm()
318 | {
319 | Messgae = "";
320 | Flag = 0;
321 | }
322 |
323 | public GetEchoForm(int flag, string msg)
324 | {
325 | Flag = flag;
326 | Messgae = msg;
327 | }
328 |
329 | public string Messgae { get; set; }
330 | public int Flag { get; set; }
331 | }
332 |
333 | private void timer_Send2GetEcho_Tick(object sender, EventArgs e)
334 | {
335 | try
336 | {
337 | DequeueAndSendport();
338 | }
339 | catch (Exception ee)
340 | {
341 | MessageBox.Show(ee.Message);
342 | }
343 | }
344 |
345 | private void DequeueAndSendport()
346 | {
347 | if (tmpSendHandle.Flag == 1 && _queueEchoControl.Count > 0)
348 | {
349 | var send_message = (GetEchoForm) _queueEchoControl.Dequeue();
350 | tmpSendHandle = send_message;
351 | }
352 |
353 | if (tmpSendHandle.Flag == 0)
354 | {
355 | mySerialPort.Write(tmpSendHandle.Messgae);
356 | label28.Text = @"重试:" + retryCount + @" 次," +
357 | @"发送队列:" + _queueEchoControl.Count;
358 | retryCount++;
359 | }
360 | }
361 |
362 | private void UnPakegeReceived(string recvStr, List recBuff)
363 | {
364 | // 1 2 3 45 6 7 8
365 | //#|1|3.31|0||1|1|P1200I2100D3310|$
366 | try
367 | {
368 | if (ReceiveValidateCheck(recvStr))
369 | {
370 | var headCheck = recvStr.IndexOf("#|", StringComparison.Ordinal);
371 | var endCheck = recvStr.LastIndexOf("|$", StringComparison.Ordinal);
372 | var messagePack = recvStr.Substring(headCheck, endCheck - headCheck + 2);
373 |
374 | var splittedMessage = messagePack.Split('|');
375 |
376 | if (SingleMessageValidateCheck(splittedMessage))
377 | {
378 | DeliveryReceivedToControls(splittedMessage, messagePack, recBuff);
379 | }
380 | }
381 | }
382 | catch (Exception ex)
383 | {
384 | LogHelper.WriteLog(typeof(Form1), ex);
385 | }
386 | }
387 |
388 | private bool ReceiveValidateCheck(string recvStr)
389 | {
390 | var headCheck = recvStr.IndexOf("#|", StringComparison.Ordinal);
391 | var endCheck = recvStr.LastIndexOf("|$", StringComparison.Ordinal);
392 | return headCheck != -1 && endCheck != -1;
393 | }
394 |
395 | private bool SingleMessageValidateCheck(string[] splittedMessage)
396 | {
397 | for (var i = 0; 4*(i + 1) < splittedMessage.Length; i++)
398 | {
399 | //加入是空字符串,舍弃本次
400 | if (splittedMessage.ElementAt(1 + 4*i).Trim() == "" ||
401 | splittedMessage.ElementAt(2 + 4*i).Trim() == "")
402 | return false;
403 |
404 | int father = splittedMessage.ElementAt(1 + 4*i).toInt32();
405 | int child = splittedMessage.ElementAt(2 + 4*i).toInt32();
406 |
407 | //表示不符合数据格式要求
408 | if ((father < 0 || father > 8) && (child < 0 || child > 200))
409 | {
410 | return false;
411 | }
412 | }
413 | return true;
414 | }
415 |
416 | private void DeliveryReceivedToControls(string[] splittedMessage, string neededStr, List recBuff)
417 | {
418 | var countLength = 0;
419 | const int EACH_MESSAGE_NUMBER = 4;
420 | countLength += neededStr.Where((t, i) => neededStr.ElementAt(i) == '|').Count();
421 | countLength = countLength/EACH_MESSAGE_NUMBER;
422 |
423 | for (var k = 0; k < countLength; k++)
424 | {
425 | int father = splittedMessage.ElementAt(1 + EACH_MESSAGE_NUMBER*k).toInt32();
426 |
427 | if (father == 1 && checkBox_Camera_ONOFF.Checked)
428 | //摄像头数据
429 | {
430 | var cameraAlgorithm = new CameraAlgorithm(neededStr, recBuff);
431 | cameraAlgorithm.ApartMessage();
432 | cameraAlgorithm.DrawCameraPicture(pictureBox_CameraActual);
433 |
434 | textBoxCameraWidth.Text = cameraAlgorithm.GetWidth().ToString();
435 | textBoxCameraHeight.Text = cameraAlgorithm.GetHeight().ToString();
436 | }
437 | else if (father == 2 && checkBox_CCD_ONOFF.Checked)
438 | //CCD数据
439 | {
440 | var ccdAlgorithm = new CCDAlgorithm(neededStr, recBuff);
441 |
442 | ccdAlgorithm.ApartMessage();
443 |
444 | var length = ccdAlgorithm.GetCCDLength();
445 | label_CCD_Width.Text = @"CCD宽度:" + length;
446 |
447 | int child = splittedMessage.ElementAt(2 + 4*k).toInt32();
448 | if (child == 1) //CCD1
449 | {
450 | ccdAlgorithm.DrawCCDPicture(pictureBox_CCD1);
451 | }
452 | else if (child == 2) //CCD2
453 | {
454 | ccdAlgorithm.DrawCCDPicture(pictureBox_CCD2);
455 | }
456 | else if (child == 3) //CCD3
457 | {
458 | ccdAlgorithm.DrawCCDPicture(pictureBox_CCD3);
459 | }
460 |
461 | //绘制路径曲线
462 | if (comboBoxCCDPath.SelectedItem.ToString() == child.ToString())
463 | {
464 | ccdAlgorithm.DrawCCDPath(_bitmapOld, pictureBox_CCD_Path);
465 | }
466 | }
467 | else if (father == 3) //实时参数
468 | {
469 | int electNum = splittedMessage.ElementAt(2 + 4*k).toInt32();
470 | var realTimeValue = splittedMessage.ElementAt(3 + 4*k);
471 |
472 | ReadRealtimeFromChip(electNum, realTimeValue);
473 | }
474 | else if (father == 4) //传送到示波器的数据
475 | {
476 | int id = (splittedMessage.ElementAt(2 + 4*k)).toInt32();
477 | var value = Convert.ToDouble(splittedMessage.ElementAt(3 + 4*k))/1000;
478 |
479 | ReadFromChipAndDrawToScope(id, value);
480 | }
481 | else if (father == 5) //读取参数值(PID)
482 | {
483 | int type = (splittedMessage.ElementAt(2 + 4 * k)).toInt32();
484 | var valuePID = splittedMessage.ElementAt(3 + 4*k);
485 |
486 | ReadPIDFromChip(type, valuePID);
487 | }
488 | else if (father == 6) //读取参数值(CustomPara)
489 | {
490 | int child = (splittedMessage.ElementAt(2 + 4*k)).toInt32();
491 | var valueCustomPara =
492 | (Convert.ToDouble(splittedMessage.ElementAt(3 + 4*k))/1000.0).ToString(CultureInfo.CurrentCulture);
493 |
494 | ReadCustomParaFromChip(child, valueCustomPara);
495 | }
496 | else if (father == 7 || //PID返回的设置信息
497 | father == 8 || //自定义参数返回的设置信息
498 | father == 9) //紧急停车
499 | {
500 | // ReSharper disable once InconsistentNaming
501 | var isContainsACK = splittedMessage.ElementAt(3 + 4*k).Contains("ACK");
502 |
503 | if (isContainsACK)
504 | {
505 | StopSendCurrentQueueAndUpdateState();
506 | }
507 | }
508 |
509 | if (father == 5 || //PID返回的ECHO信息
510 | father == 6) //自定义参数返回的ECHO信息
511 | {
512 | StopSendCurrentQueueAndUpdateState();
513 | }
514 | }
515 | }
516 |
517 | private void ReadRealtimeFromChip(int electNum, string realTimeStr)
518 | {
519 | int totalContolsNum = (textBox_Realtime_Number.Text).toInt32();
520 | if (electNum <= totalContolsNum) //发送的传感器数据比现有的小
521 | {
522 | var txtBox = (TextBox)
523 | panel_Electricity.Controls.Find(
524 | "txtElectValue" + Convert.ToString(electNum), true)[0];
525 |
526 | //将参数赋值到相应的版块
527 | var value = Convert.ToDouble(realTimeStr)/1000;
528 | txtBox.Text = value.ToString(CultureInfo.InvariantCulture);
529 | }
530 | }
531 |
532 | private void ReadFromChipAndDrawToScope(int id, double value)
533 | {
534 | var total = ScopeNumber;
535 | var checkDrawing = new CheckBox[ScopeNumber];
536 |
537 | if (_isLoadHistory)
538 | {
539 | ClearCurves();
540 | }
541 |
542 | InitCheckboxAndStartReflesh(checkDrawing, total);
543 |
544 | ChangeAxisAndPlotToScope(id, value, checkDrawing);
545 | }
546 |
547 | private void InitCheckboxAndStartReflesh(CheckBox[] checkDrawing, int total)
548 | {
549 | for (var i = 0; i < total; i++)
550 | {
551 | checkDrawing[i] =
552 | (CheckBox)
553 | panel_Scope.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true)[0];
554 |
555 | if (checkDrawing[i].Checked && !timer_fresh.Enabled)
556 | {
557 | timer_fresh.Start();
558 | }
559 | }
560 | }
561 |
562 | private void ChangeAxisAndPlotToScope(int id, double value, CheckBox[] checkDrawing)
563 | {
564 | var total = ScopeNumber;
565 | for (var i = 0; i < total; i++)
566 | {
567 | if (checkDrawing[i].Checked &&
568 | id == i + 1)
569 | {
570 | zedGrpahNames[i].ValueZed = value;
571 |
572 | ChangeAxis(i);
573 | DrawScope(i, value);
574 | }
575 | }
576 | }
577 |
578 | private void ChangeAxis(int i)
579 | {
580 | if (_xmaxScale - zedGrpahNames[i].x < _xmaxScale/5) //改变XMax坐标轴范围
581 | {
582 | _xmaxScale += _xmaxScale/5;
583 | zedGraph_local.GraphPane.XAxis.Scale.Max = _xmaxScale;
584 | }
585 | if (_ymaxScale - zedGrpahNames[i].ValueZed < _ymaxScale/5) //改变YMax坐标轴范围
586 | {
587 | _ymaxScale += -_ymaxScale + 1.3*zedGrpahNames[i].ValueZed;
588 | zedGraph_local.GraphPane.YAxis.Scale.Max = _ymaxScale;
589 | }
590 | if (_yminScale - zedGrpahNames[i].ValueZed > _yminScale/5) //改变YMin坐标轴范围
591 | {
592 | _yminScale += _yminScale/5;
593 | zedGraph_local.GraphPane.YAxis.Scale.Min = _yminScale;
594 | }
595 | }
596 |
597 | private void DrawScope(int i, double value)
598 | {
599 | zedGrpahNames[i].x += 1;
600 |
601 | zedGrpahNames[i].listZed.Add(Convert.ToDouble(zedGrpahNames[i].x), value);
602 | zedGrpahNames[i].ZedPoint.ZedListX.Add(Convert.ToDouble(zedGrpahNames[i].x));
603 | zedGrpahNames[i].ZedPoint.ZedListY.Add(value);
604 |
605 | if (zedGrpahNames[i].IsSingleWindowShowed)
606 | coOb[i].CallEvent(zedGrpahNames[i].x, value);
607 | }
608 |
609 | private void ClearCurves()
610 | {
611 | _isLoadHistory = false;
612 | for (var i = 0; i < ScopeNumber; i++) //首先清除所有的曲线数据
613 | {
614 | zedGrpahNames[i].listZed.RemoveRange(0, zedGrpahNames[i].listZed.Count);
615 | zedGrpahNames[i].x = -1;
616 | }
617 | }
618 |
619 | private void ReadPIDFromChip(int type, string PIDStrings)
620 | {
621 | var indexP = PIDStrings.IndexOf('P');
622 | var indexI = PIDStrings.IndexOf("I", StringComparison.Ordinal);
623 | var indexD = PIDStrings.IndexOf("D", StringComparison.Ordinal);
624 |
625 | if (indexP != -1 && indexI != -1 && indexD != -1)
626 | {
627 | var valueP =
628 | ((PIDStrings.Substring(indexP + 1, indexI - indexP - 1).toInt32())/1000.0)
629 | .ToString(CultureInfo.InvariantCulture);
630 | var valueI =
631 | ((PIDStrings.Substring(indexI + 1, indexD - indexI - 1).toInt32())/1000.0)
632 | .ToString(CultureInfo.InvariantCulture);
633 | var valueD =
634 | ((PIDStrings.Substring(indexD + 1).toInt32())/1000.0).ToString(
635 | CultureInfo.InvariantCulture);
636 |
637 | if (type == 1)
638 | {
639 | textBox_Steer_P.Text = valueP;
640 | textBox_Steer_I.Text = valueI;
641 | textBox_Steer_D.Text = valueD;
642 | }
643 | else if (type == 2)
644 | {
645 | textBox_Motor_P.Text = valueP;
646 | textBox_Motor_I.Text = valueI;
647 | textBox_Motor_D.Text = valueD;
648 | }
649 | else if (type == 3)
650 | {
651 | textBox_Stand_P.Text = valueP;
652 | textBox_Stand_I.Text = valueI;
653 | textBox_Stand_D.Text = valueD;
654 | }
655 | else if (type == 4)
656 | {
657 | textBox_Speed_P.Text = valueP;
658 | textBox_Speed_I.Text = valueI;
659 | textBox_Speed_D.Text = valueD;
660 | }
661 | else if (type == 5)
662 | {
663 | textBox_Direction_P.Text = valueP;
664 | textBox_Direction_I.Text = valueI;
665 | textBox_Direction_D.Text = valueD;
666 | }
667 | }
668 | }
669 |
670 | private void ReadCustomParaFromChip(int child, string customParaStrings)
671 | {
672 | var total = (textBox_DIY_Number.Text).toInt32();
673 |
674 | if (child < total)
675 | {
676 | var checkboxSelect = (CheckBox) panel_add_DIYControls.Controls.Find("checkBox_Def" +
677 | Convert.ToString(child), true)[0];
678 | var txtBox = (TextBox) panel_add_DIYControls.Controls.Find("txtValue" +
679 | Convert.ToString(child), true)[0];
680 |
681 | if (checkboxSelect.Checked)
682 | {
683 | txtBox.Text = customParaStrings;
684 | }
685 | }
686 | }
687 |
688 | private void StopSendCurrentQueueAndUpdateState()
689 | {
690 | if (_queueEchoControl.Count == 0) //队列中无元素
691 | {
692 | tmpSendHandle.Flag = 1;
693 | timer_Send2GetEcho.Stop();
694 | }
695 | else
696 | {
697 | tmpSendHandle.Flag = 1;
698 | }
699 |
700 | label28.Text = @"OK!! + 剩余数量:" + _queueEchoControl.Count;
701 | retryCount = 0;
702 | }
703 |
704 | #endregion
705 |
706 | private void CloseCurrentPort()
707 | {
708 | _autoSend = false;
709 | checkBox_sendAuto.Checked = false;
710 |
711 | _closing = true;
712 | while (_listening) Application.DoEvents();
713 |
714 | try
715 | {
716 | //关闭选中串口
717 | mySerialPort.Close();
718 | }
719 | catch (Exception ee)
720 | {
721 | MessageBox.Show(ee.Message);
722 | }
723 | //do something
724 | button_openPort.Text = @"打开串口";
725 | //更新状态栏的显示
726 | //statusDisplayToolStripStatusLabel.Text = string.Format(" 关闭端口 {0}成功!",
727 | // mySerialPort.PortName);
728 | //所有设置控件非使能态
729 | CloseSelectedPortSuccessfully();
730 | }
731 |
732 | private void CloseSelectedPortSuccessfully()
733 | {
734 | comboBox_port.Enabled = true;
735 | textBox_receive.Enabled = true;
736 | textBox_send.Enabled = true;
737 | comboBox_baudrate.Enabled = true;
738 | comboBox_databit.Enabled = true;
739 | comboBox_stopbit.Enabled = true;
740 | comboBox_parity.Enabled = true;
741 | //sendSettingGroupBox.Enabled = false;
742 | totalReceivedBytes = 0;
743 | _totalSendBytes = 0;
744 | }
745 |
746 | private void SetSerialPortPropertiesBeforeSending()
747 | {
748 | mySerialPort.Encoding = Encoding.Default;
749 | //设置成为选中的波特率
750 | mySerialPort.BaudRate = GetSelectedBaudRate();
751 | //设置成为选中的奇偶校验位
752 | mySerialPort.Parity = GetSelectedParity();
753 | //设置成为选中的数据位
754 | mySerialPort.DataBits = GetSelectedDataBits();
755 | //设置成为选中的端口停止位
756 | try
757 | {
758 | mySerialPort.StopBits = GetSelectedStopBits();
759 | }
760 | catch (IOException ee)
761 | {
762 | MessageBox.Show(ee.Message + @"已经将 停止位 设置为 默认一位 了!",
763 | @"提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
764 | mySerialPort.StopBits = StopBits.One;
765 | comboBox_stopbit.SelectedItem = "1";
766 | }
767 | }
768 |
769 | private StopBits GetSelectedStopBits()
770 | {
771 | StopBits stopBits;
772 | switch (comboBox_stopbit.SelectedItem.ToString())
773 | {
774 | case "1":
775 | {
776 | stopBits = StopBits.One;
777 | }
778 | break;
779 | case "2":
780 | {
781 | stopBits = StopBits.Two;
782 | }
783 | break;
784 | case "1.5":
785 | {
786 | stopBits = StopBits.OnePointFive;
787 | }
788 | break;
789 | default:
790 | stopBits = StopBits.One;
791 | break;
792 | }
793 | return stopBits;
794 | }
795 |
796 | private int GetSelectedBaudRate()
797 | {
798 | int baudRate;
799 | if (!int.TryParse(comboBox_baudrate.SelectedItem.ToString(), out baudRate))
800 | {
801 | baudRate = 9600;
802 | }
803 | return baudRate;
804 | }
805 |
806 | private int GetSelectedDataBits()
807 | {
808 | var dataBits = 8;
809 | if (!int.TryParse(comboBox_databit.SelectedItem.ToString(), out dataBits))
810 | {
811 | MessageBox.Show("转换失败!");
812 | }
813 | return dataBits;
814 | }
815 |
816 | private Parity GetSelectedParity()
817 | {
818 | Parity parity;
819 | var selectedParityWay = comboBox_parity.SelectedItem.ToString();
820 | switch (selectedParityWay)
821 | {
822 | case "偶校验(Even)":
823 | {
824 | parity = Parity.Even;
825 | }
826 | break;
827 | case "奇校验(Odd)":
828 | {
829 | parity = Parity.Odd;
830 | }
831 | break;
832 | case "保留为0(Space)":
833 | {
834 | parity = Parity.Space;
835 | }
836 | break;
837 | case "保留为1(Mark)":
838 | {
839 | parity = Parity.Mark;
840 | }
841 | break;
842 | default:
843 | {
844 | parity = Parity.None;
845 | }
846 | break;
847 | }
848 | return parity;
849 | }
850 |
851 | private void OpenSelectedPort()
852 | {
853 | _closing = false;
854 | try
855 | {
856 | //if(mySerialPort == null)
857 | // mySerialPort = new SerialPort();
858 |
859 | //设置打开的端口号
860 | mySerialPort.PortName = comboBox_port.SelectedItem.ToString();
861 | //打开选中串口
862 | mySerialPort.Open();
863 |
864 | mySerialPort.NewLine = "/r/n";
865 | mySerialPort.RtsEnable = true;
866 | mySerialPort.DataReceived += mySerialPort_DataReceived;
867 |
868 | //更新状态栏的显示
869 | //statusDisplayToolStripStatusLabel.Text = string.Format(" 打开端口 {0}成功!",
870 | // mySerialPort.PortName);
871 | button_openPort.Text = @"关闭串口";
872 | //打开串口成功后
873 | OpenSelectedPortSuccessfully();
874 | }
875 | catch (Exception ee)
876 | {
877 | mySerialPort = new SerialPort();
878 | MessageBox.Show(ee.Message);
879 | }
880 | }
881 |
882 | private void OpenSelectedPortSuccessfully()
883 | {
884 | comboBox_port.Enabled = false;
885 | comboBox_databit.Enabled = false;
886 | comboBox_stopbit.Enabled = false;
887 | comboBox_parity.Enabled = false;
888 | comboBox_baudrate.Enabled = false;
889 | groupBox_send.Enabled = true;
890 | //acceptZoneSettingGroupBox.Enabled = true;
891 | //sendZoneSettingGroupBox.Enabled = true;
892 | textBox_receive.Enabled = true;
893 | textBox_send.Enabled = true;
894 | }
895 |
896 | private bool _hasPorts;
897 |
898 | ///
899 | /// 获取可用的端口名,并添加到选择框中,同时设置相关
900 | /// 默认项。
901 | ///
902 | private void CheckAvailablePorts()
903 | {
904 | comboBox_port.Items.Clear();
905 | var allAvailablePorts = SerialPort.GetPortNames();
906 | //判断是否有可用的端口
907 | if (allAvailablePorts.Length > 0)
908 | {
909 | _hasPorts = true;
910 | //使能控件portNamesComboBox,openOrCloseButton
911 | button_openPort.Enabled = true;
912 | comboBox_port.Enabled = true;
913 | //依次添加可用的串口
914 | comboBox_port.Items.AddRange(allAvailablePorts);
915 | //默认选中第一个项
916 | comboBox_port.SelectedIndex = 0;
917 | //显示相应的状态信息
918 | //statusDisplayToolStripStatusLabel.Text = string.Format(" 欢迎使用!自动查找到该计算机可用端口数:{0},当前选中端口号{1} :)",
919 | // allAvailablePorts.Length, portNameComboBox.SelectedItem.ToString());
920 | }
921 | else
922 | {
923 | _hasPorts = false;
924 | checkBox_sendAuto.Enabled = false;
925 | button_sendmessage.Enabled = false;
926 | //stopSendButton.Enabled = false;
927 | button_openPort.Enabled = false;
928 | //清空所有项
929 | comboBox_port.Items.Clear();
930 | comboBox_port.Enabled = false;
931 | //statusDisplayToolStripStatusLabel.Text = " 抱歉,未查找到当前计算机中可用端口。";
932 | //同时弹出警告对话框,提示是否进行再次检查?!
933 | ShowWarningMessageBox();
934 | }
935 | }
936 |
937 | private void ShowWarningMessageBox()
938 | {
939 | var result = MessageBox.Show(@"抱歉,没有检测到当前计算机中可用端口,请插入相关设备或者检查有关驱动是否安装?" +
940 | Environment.NewLine + @"提示:您可以取消后单击“查找可用端口”按钮重新查找。",
941 | @"自动查找计算机可用端口", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
942 | if (result == DialogResult.Retry)
943 | {
944 | //重新运行检测方法
945 | CheckAvailablePorts();
946 | }
947 | }
948 |
949 | private void button_receivepause_Click(object sender, EventArgs e)
950 | {
951 | if (button_receivepause.Text == "暂停接收显示")
952 | {
953 | showInfo = false;
954 | button_receivepause.Text = "继续接收显示";
955 | }
956 | else
957 | {
958 | showInfo = true;
959 | button_receivepause.Text = "暂停接收显示";
960 | //
961 | }
962 | }
963 |
964 | private void textBox_receive_TextChanged(object sender, EventArgs e)
965 | {
966 | //textBox_receive.SelectionStart = textBox_receive.Text.Length;
967 |
968 | //textBox_receive.ScrollToCaret();
969 | }
970 |
971 | private void button_receiveclear_Click(object sender, EventArgs e)
972 | {
973 | textBox_receive.Clear();
974 | //acceptStatusLabel.Text = "0字节";
975 | totalReceivedBytes = 0;
976 | }
977 |
978 | private void checkBox_receiveHex_CheckedChanged(object sender, EventArgs e)
979 | {
980 | textBox_receive.Clear();
981 | var rb = sender as CheckBox;
982 | if (rb != null)
983 | {
984 | if (!rb.Checked)
985 | {
986 | myReceivedDataType = ReceivedDataType.CharType;
987 | }
988 | else
989 | {
990 | myReceivedDataType = ReceivedDataType.HexType;
991 | }
992 | }
993 | }
994 |
995 | private void button_sendmessage_Click(object sender, EventArgs e)
996 | {
997 | if (textBox_send.TextLength != 0)
998 | {
999 | if (checkBox_sendAuto.Checked)
1000 | {
1001 | _autoSend = true;
1002 | checkBox_sendAuto.Enabled = false;
1003 | button_sendmessage.Text = "自动发送中";
1004 |
1005 | timer_autoSend.Enabled = true;
1006 | timer_autoSend.Interval = (textBox_sendPeriod.Text).toInt32();
1007 | timer_autoSend.Start();
1008 | }
1009 | else
1010 | {
1011 | _autoSend = false;
1012 | checkBox_sendAuto.Enabled = true;
1013 | button_sendmessage.Text = "发送数据";
1014 | try
1015 | {
1016 | SerialPortSendChar(textBox_send.Text);
1017 | }
1018 | catch (Exception ex)
1019 | {
1020 | MessageBox.Show(ex.Message);
1021 | }
1022 | }
1023 | }
1024 | else
1025 | {
1026 | MessageBox.Show("发送区为空");
1027 | }
1028 | }
1029 |
1030 | private void SerialPortSendChar(string str)
1031 | {
1032 | var ch = str.ToCharArray();
1033 | foreach (var item in ch)
1034 | {
1035 | if (item <= 255)
1036 | {
1037 | _totalSendBytes += 1;
1038 | }
1039 | else
1040 | {
1041 | _totalSendBytes += 2;
1042 | }
1043 | }
1044 | if (mySerialPort == null || mySerialPort.IsOpen == false)
1045 | {
1046 | MessageBox.Show("拒绝操作,没有任何串口被开启,无法发送数据!", "发送数据");
1047 | }
1048 | else
1049 | {
1050 | try
1051 | {
1052 | mySerialPort.Write(ch, 0, ch.Length);
1053 | label_sendCount.Text = "发送区计数:" + _totalSendBytes;
1054 | }
1055 | catch (Exception ee)
1056 | {
1057 | MessageBox.Show(ee.Message);
1058 | }
1059 | }
1060 | }
1061 |
1062 | private void timer_autoSend_Tick(object sender, EventArgs e)
1063 | {
1064 | if (_autoSend)
1065 | {
1066 | try
1067 | {
1068 | SerialPortSendChar(textBox_send.Text);
1069 | }
1070 | catch
1071 | {
1072 | }
1073 | }
1074 | }
1075 |
1076 | private void checkBox_sendAuto_CheckedChanged(object sender, EventArgs e)
1077 | {
1078 | if (textBox_send.TextLength == 0)
1079 | {
1080 | checkBox_sendAuto.Checked = false;
1081 | _autoSend = false;
1082 | MessageBox.Show("没有需要发送的内容 >_<");
1083 | }
1084 | }
1085 |
1086 | #endregion
1087 |
1088 | #region PID参数设置 2
1089 |
1090 | private void Init_TablePagePIDSettings()
1091 | {
1092 | //车的类型选择
1093 | if (radioButton_FourWheel.Checked)
1094 | {
1095 | groupBox_BalanceCar.Visible = false;
1096 | groupBox_fourWheels.Visible = true;
1097 | }
1098 | if (radioButton_BalanceCar.Checked)
1099 | {
1100 | groupBox_BalanceCar.Visible = true;
1101 | groupBox_fourWheels.Visible = false;
1102 | }
1103 | }
1104 |
1105 | private void checkBox_IsUsePID_CheckedChanged(object sender, EventArgs e)
1106 | {
1107 | if (checkBox_IsUsePID.Checked)
1108 | {
1109 | groupBox_BalanceCar.Enabled = true;
1110 | groupBox_fourWheels.Enabled = true;
1111 | }
1112 | else
1113 | {
1114 | groupBox_BalanceCar.Enabled = false;
1115 | groupBox_fourWheels.Enabled = false;
1116 | }
1117 | }
1118 |
1119 | private void radioButton_FourWheel_Click(object sender, EventArgs e)
1120 | {
1121 | var rb = (RadioButton) sender;
1122 | if (rb.Checked)
1123 | {
1124 | groupBox_BalanceCar.Visible = false;
1125 | groupBox_fourWheels.Visible = true;
1126 | }
1127 | else
1128 | {
1129 | groupBox_BalanceCar.Visible = true;
1130 | groupBox_fourWheels.Visible = false;
1131 | }
1132 | }
1133 |
1134 | private void radioButton_BalanceCar_CheckedChanged(object sender, EventArgs e)
1135 | {
1136 | var rb = (RadioButton) sender;
1137 | if (!rb.Checked)
1138 | {
1139 | groupBox_BalanceCar.Visible = false;
1140 | groupBox_fourWheels.Visible = true;
1141 | }
1142 | else
1143 | {
1144 | groupBox_BalanceCar.Visible = true;
1145 | groupBox_fourWheels.Visible = false;
1146 | }
1147 | }
1148 |
1149 | //生成需要发送控制指令的字符串
1150 |
1151 | private void button_ModifyPID_Motor_Click(object sender, EventArgs e)
1152 | {
1153 | //电机PID参数
1154 | var Motor_P = Convert.ToDouble(textBox_Motor_P.Text)*1000;
1155 | var Motor_I = Convert.ToDouble(textBox_Motor_I.Text)*1000;
1156 | var Motor_D = Convert.ToDouble(textBox_Motor_D.Text)*1000;
1157 |
1158 |
1159 | var tmpMessageSteer = "P" + Math.Floor(Motor_P) +
1160 | "I" + Math.Floor(Motor_I) +
1161 | "D" + Math.Floor(Motor_D);
1162 |
1163 | try
1164 | {
1165 | SaveConfig(SavefileName);
1166 | SendMessageAndEnqueue(1, 2, tmpMessageSteer);
1167 | }
1168 | catch (Exception ee)
1169 | {
1170 | MessageBox.Show(ee.Message);
1171 | }
1172 | }
1173 |
1174 | private void button_ModifyPID_Steer_Click(object sender, EventArgs e)
1175 | {
1176 | //舵机PID参数
1177 | var steer_P = Convert.ToDouble(textBox_Steer_P.Text)*1000;
1178 | var steer_I = Convert.ToDouble(textBox_Steer_I.Text)*1000;
1179 | var steer_D = Convert.ToDouble(textBox_Steer_D.Text)*1000;
1180 |
1181 |
1182 | var tmpMessageSteer = "P" + Math.Floor(steer_P).ToString(CultureInfo.InvariantCulture) +
1183 | "I" + Math.Floor(steer_I).ToString(CultureInfo.InvariantCulture) +
1184 | "D" + Math.Floor(steer_D).ToString(CultureInfo.InvariantCulture);
1185 |
1186 | try
1187 | {
1188 | SaveConfig(SavefileName);
1189 | SendMessageAndEnqueue(1, 1, tmpMessageSteer);
1190 | }
1191 | catch (Exception ee)
1192 | {
1193 | MessageBox.Show(ee.Message);
1194 | }
1195 | }
1196 |
1197 | private void button_ModifyPID_Stand_Click(object sender, EventArgs e)
1198 | {
1199 | //直立PID
1200 | var stand_P = Convert.ToDouble(textBox_Stand_P.Text)*1000;
1201 | var stand_I = Convert.ToDouble(textBox_Stand_I.Text)*1000;
1202 | var stand_D = Convert.ToDouble(textBox_Stand_D.Text)*1000;
1203 |
1204 | var tmpMessageStand = "P" + Math.Floor(stand_P) +
1205 | "I" + Math.Floor(stand_I) +
1206 | "D" + Math.Floor(stand_D);
1207 |
1208 | try
1209 | {
1210 | SaveConfig(SavefileName);
1211 | SendMessageAndEnqueue(1, 3, tmpMessageStand);
1212 | }
1213 | catch (Exception ee)
1214 | {
1215 | MessageBox.Show(ee.Message);
1216 | }
1217 | }
1218 |
1219 | private void button_ModifyPID_Speed_Click(object sender, EventArgs e)
1220 | {
1221 | //速度PID
1222 | var speed_P = Convert.ToDouble(textBox_Speed_P.Text)*1000;
1223 | var speed_I = Convert.ToDouble(textBox_Speed_I.Text)*1000;
1224 | var speed_D = Convert.ToDouble(textBox_Speed_D.Text)*1000;
1225 |
1226 | var tmpMessageSpeed = "P" + Math.Floor(speed_P) +
1227 | "I" + Math.Floor(speed_I) +
1228 | "D" + Math.Floor(speed_D);
1229 | try
1230 | {
1231 | SaveConfig(SavefileName);
1232 | SendMessageAndEnqueue(1, 4, tmpMessageSpeed);
1233 | }
1234 | catch (Exception ee)
1235 | {
1236 | MessageBox.Show(ee.Message);
1237 | }
1238 | }
1239 |
1240 | private void button_ModifyPID_Direction_Click(object sender, EventArgs e)
1241 | {
1242 | //方向PID
1243 | var direction_P = Convert.ToDouble(textBox_Direction_P.Text)*1000;
1244 | var direction_I = Convert.ToDouble(textBox_Direction_I.Text)*1000;
1245 | var direction_D = Convert.ToDouble(textBox_Direction_D.Text)*1000;
1246 |
1247 | var tmpMessageDirection = "P" + Math.Floor(direction_P) +
1248 | "I" + Math.Floor(direction_I) +
1249 | "D" + Math.Floor(direction_D);
1250 |
1251 | try
1252 | {
1253 | SaveConfig(SavefileName);
1254 | SendMessageAndEnqueue(1, 5, tmpMessageDirection);
1255 | }
1256 | catch (Exception ee)
1257 | {
1258 | MessageBox.Show(ee.Message);
1259 | }
1260 | }
1261 |
1262 | #endregion
1263 |
1264 | #region 3. 自定义算法参数
1265 |
1266 | private void button_DIY_NumConfirm_Click(object sender, EventArgs e)
1267 | {
1268 | if (isCustomParaValidate())
1269 | {
1270 | var result = MessageBox.Show(@"确认更改数量?", @"修改", MessageBoxButtons.OKCancel);
1271 | if (result == DialogResult.OK)
1272 | {
1273 | List state = new List();
1274 | List names = new List();
1275 | List value = new List();
1276 | GetCustomOldNames(state, names, value);
1277 |
1278 | DrawCustomParaPannel(false);
1279 |
1280 | SetCustomNewNames(state, names, value);
1281 | }
1282 | SaveConfig(SavefileName);
1283 | }
1284 | }
1285 |
1286 | private void button_DIY_ResetNames_Click(object sender, EventArgs e)
1287 | {
1288 | if (isCustomParaValidate())
1289 | {
1290 | var result = MessageBox.Show(@"确认更改数量?", @"修改", MessageBoxButtons.OKCancel);
1291 | if (result == DialogResult.OK)
1292 | {
1293 | DrawCustomParaPannel(false);
1294 | }
1295 | SaveConfig(SavefileName);
1296 | }
1297 | }
1298 |
1299 | private void GetCustomOldNames(List state, List names, List value)
1300 | {
1301 | SharedPreferences sp = new SharedPreferences(SavefileName);
1302 | int oldNumber = 0;
1303 | if(sp.ConfigFileExists)
1304 | oldNumber = sp.GetInt32("DIY_Number", 1);
1305 |
1306 | for (var i = 0; i < oldNumber; i++)
1307 | {
1308 | var checkboxSelect = (CheckBox)panel_add_DIYControls.Controls.Find("checkBox_Def" +
1309 | Convert.ToString(i + 1), true)[0];
1310 | state.Add(checkboxSelect.Checked);
1311 |
1312 | var txtBoxValue = (TextBox) panel_add_DIYControls.Controls.Find("txtValue" +
1313 | Convert.ToString(i + 1), true)[0];
1314 | value.Add(txtBoxValue.Text);
1315 |
1316 | var txtBoxName = (TextBox)panel_add_DIYControls.Controls.Find("txtName" +
1317 | Convert.ToString(i + 1), true)[0];
1318 | names.Add(txtBoxName.Text);
1319 | }
1320 | }
1321 |
1322 | private void SetCustomNewNames(List state, List names, List value)
1323 | {
1324 | var total = int.Parse(textBox_DIY_Number.Text);
1325 |
1326 | if (state.Count < total)
1327 | {
1328 | total = state.Count;
1329 | }
1330 |
1331 | for (var i = 0; i < total; i++)
1332 | {
1333 | var checkboxSelect = (CheckBox)panel_add_DIYControls.Controls.Find("checkBox_Def" +
1334 | Convert.ToString(i + 1), true)[0];
1335 | checkboxSelect.Checked = state[i];
1336 |
1337 | var txtBoxValue = (TextBox)panel_add_DIYControls.Controls.Find("txtValue" +
1338 | Convert.ToString(i + 1), true)[0];
1339 | txtBoxValue.Text = value[i];
1340 |
1341 | var txtBoxName = (TextBox)panel_add_DIYControls.Controls.Find("txtName" +
1342 | Convert.ToString(i + 1), true)[0];
1343 | txtBoxName.Text = names[i];
1344 | }
1345 | }
1346 |
1347 | private void Init_CustomPara_DynamicControls()
1348 | {
1349 | var sp = new SharedPreferences(SavefileName);
1350 | if (sp.ConfigFileExists && isCustomParaValidate())
1351 | {
1352 | DrawCustomParaPannel(true);
1353 | }
1354 | }
1355 |
1356 | private void DrawCustomParaPannel(bool byInit)
1357 | {
1358 | panel_add_DIYControls.AutoScroll = true;
1359 | panel_add_DIYControls.Controls.Clear();
1360 | var total = int.Parse(textBox_DIY_Number.Text);
1361 |
1362 | var sp = new SharedPreferences(SavefileName);
1363 | if (sp.ConfigFileExists)
1364 | {
1365 | AddControlsToPannel(sp, 0, total, byInit);
1366 | }
1367 | }
1368 |
1369 | private Boolean isCustomParaValidate()
1370 | {
1371 | var total = int.Parse(textBox_DIY_Number.Text);
1372 | if (total < 1)
1373 | {
1374 | MessageBox.Show(@"请输入需要的参数数量!", @"错误");
1375 | return false;
1376 | }
1377 | return true;
1378 | }
1379 |
1380 | private void textBox_DIY_Number_TextChanged(object sender, EventArgs e)
1381 | {
1382 | var t = sender as TextBox;
1383 |
1384 | if (t != null && !IsIntegerCheck(t.Text))
1385 | t.Text = @"10";
1386 | }
1387 |
1388 | private void AddControlsToPannel(SharedPreferences sp, int start, int end, bool byInit)
1389 | {
1390 | for (var i = start; i < end; i++)
1391 | {
1392 | var checkboxSelect = new CheckBox();
1393 | checkboxSelect.Size = new Size(50, 20);
1394 | checkboxSelect.Location = new Point(30 + 70*0, 30*(i + 1));
1395 | checkboxSelect.Name = "checkBox_Def" + Convert.ToString(i + 1);
1396 | checkboxSelect.Text = (i + 1).ToString();
1397 | if (byInit)
1398 | {
1399 | var checkState = string.Format("DIY_CheckState{0}", i + 1);
1400 | checkboxSelect.Checked = sp.GetBoolean(checkState, true);
1401 | }
1402 | checkboxSelect.CheckedChanged += CheckboxSelectOnCheckedChanged;
1403 |
1404 | var txtBoxName = new TextBox();
1405 | txtBoxName.Size = new Size(50, 50); //textbox大小
1406 | txtBoxName.Location = new Point(30 + 70*1, 30*(i + 1));
1407 | txtBoxName.Name = @"txtName" + Convert.ToString(i + 1);
1408 | txtBoxName.Text = @"Name" + Convert.ToString(i + 1);
1409 | txtBoxName.TextAlign = HorizontalAlignment.Center;
1410 | if (byInit)
1411 | {
1412 | var txtName_CustomPara = string.Format("DIY_TextName{0}", i + 1);
1413 | txtBoxName.Text = sp.GetString(txtName_CustomPara, "数据");
1414 | }
1415 | else
1416 | {
1417 | txtBoxName.Enabled = false;
1418 | }
1419 |
1420 | var txtBoxValue = new TextBox();
1421 | txtBoxValue.Size = new Size(50, 50); //textbox大小
1422 | txtBoxValue.Location = new Point(30 + 70*2, 30*(i + 1));
1423 | txtBoxValue.Name = "txtValue" + Convert.ToString(i + 1);
1424 | txtBoxValue.Text = @"1.0";
1425 | txtBoxValue.TextAlign = HorizontalAlignment.Center;
1426 | if (byInit)
1427 | {
1428 | var txtValue_CustomPara = string.Format("DIY_TextValue{0}", i + 1);
1429 | txtBoxValue.Text = sp.GetString(txtValue_CustomPara, "1.0");
1430 | }
1431 | else
1432 | {
1433 | txtBoxValue.Enabled = false;
1434 | }
1435 | txtBoxValue.TextChanged += DIYTextboxValueChanged;
1436 |
1437 | var submitButton = new Button();
1438 | submitButton.Size = new Size(50, 20); //textbox大小
1439 | submitButton.Location = new Point(30 + 70*3, 30*(i + 1));
1440 | submitButton.Name = "buttonSubmit" + Convert.ToString(i + 1);
1441 | submitButton.Text = @"修改";
1442 | submitButton.Click += SubmitButtonOnClick;
1443 | if (!byInit)
1444 | {
1445 | submitButton.Enabled = false;
1446 | }
1447 |
1448 | if (!checkboxSelect.Checked)
1449 | {
1450 | txtBoxName.Enabled = false;
1451 | txtBoxValue.Enabled = false;
1452 | submitButton.Enabled = false;
1453 | }
1454 |
1455 | panel_add_DIYControls.Controls.Add(checkboxSelect);
1456 | panel_add_DIYControls.Controls.Add(txtBoxName);
1457 | panel_add_DIYControls.Controls.Add(txtBoxValue);
1458 | panel_add_DIYControls.Controls.Add(submitButton);
1459 | }
1460 | }
1461 |
1462 | private void SubmitButtonOnClick(object sender, EventArgs eventArgs)
1463 | {
1464 | var btnClk = (Button)sender;
1465 |
1466 | var id = GetNumber(btnClk.Name) - 1;
1467 |
1468 | var txtBox = (TextBox)panel_add_DIYControls.Controls.Find("txtValue" +
1469 | Convert.ToString(id + 1), true)[0];
1470 |
1471 | var value = Convert.ToDouble(txtBox.Text) * 1000.0;
1472 | try
1473 | {
1474 | var tmpMessageStand = Math.Floor(value).ToString();
1475 | SendMessageAndEnqueue(2, id+1, tmpMessageStand);
1476 |
1477 | label28.Text = "Loading...";
1478 | }
1479 | catch (Exception ee)
1480 | {
1481 | MessageBox.Show(ee.Message);
1482 | }
1483 | }
1484 |
1485 | private void DIYTextboxValueChanged(object sender, EventArgs eventArgs)
1486 | {
1487 | var t = sender as TextBox;
1488 |
1489 | if (t != null && !IsFloatCheck(t.Text))
1490 | t.Text = @"1";
1491 | }
1492 |
1493 | private void CheckboxSelectOnCheckedChanged(object sender, EventArgs eventArgs)
1494 | {
1495 | if (isCustomParaValidate())
1496 | {
1497 | var total = (textBox_DIY_Number.Text).toInt32();
1498 | for (var i = 0; i < total; i++)
1499 | {
1500 | var checkboxSelect = (CheckBox)panel_add_DIYControls.Controls.Find("checkBox_Def" +
1501 | Convert.ToString(i + 1), true)[0];
1502 |
1503 | var txtBox = new TextBox[2]; //用控件数组来定义每一行的TextBox,总共3个TextBox
1504 | txtBox[0] = (TextBox)panel_add_DIYControls.Controls.Find("txtName" +
1505 | Convert.ToString(i + 1), true)[0];
1506 | txtBox[1] = (TextBox)panel_add_DIYControls.Controls.Find("txtValue" +
1507 | Convert.ToString(i + 1), true)[0];
1508 |
1509 | var btn = (Button)panel_add_DIYControls.Controls.Find("buttonSubmit" +
1510 | Convert.ToString(i + 1), true)[0];
1511 |
1512 | if (checkboxSelect.Checked)
1513 | {
1514 | txtBox[0].Enabled = true;
1515 | txtBox[1].Enabled = true;
1516 | btn.Enabled = true;
1517 | }
1518 | else
1519 | {
1520 | txtBox[0].Enabled = false;
1521 | txtBox[1].Enabled = false;
1522 | btn.Enabled = false;
1523 | }
1524 | }
1525 | }
1526 |
1527 | }
1528 |
1529 | private void button_DIY_Modify_Click(object sender, EventArgs e)
1530 | {
1531 | //=====================================
1532 | //数据头和封包
1533 | var NeedSend = "";
1534 | var head = "#";
1535 | var end = "$";
1536 | //=====================================
1537 | try
1538 | {
1539 | var combinedString = SendCustomParaAll();
1540 | NeedSend = head + combinedString + end;
1541 |
1542 | mySerialPort.Write(NeedSend);
1543 |
1544 | var tmpHandle = new GetEchoForm(0, NeedSend);
1545 | _queueEchoControl.Enqueue(tmpHandle);
1546 | timer_Send2GetEcho.Start();
1547 | }
1548 | catch (Exception ee)
1549 | {
1550 | MessageBox.Show(ee.Message);
1551 | }
1552 | }
1553 |
1554 | private string SendCustomParaAll()
1555 | {
1556 | var NeedSend = "";
1557 | var total = (textBox_DIY_Number.Text).toInt32();
1558 | for (var i = 0; i < total; i++)
1559 | {
1560 | var checkboxSelect = (CheckBox) panel_add_DIYControls.Controls.Find("checkBox_Def" +
1561 | Convert.ToString(i + 1), true)[0];
1562 |
1563 | var txtBox = new TextBox[2]; //用控件数组来定义每一行的TextBox,总共3个TextBox
1564 | txtBox[0] = (TextBox) panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0];
1565 | txtBox[1] = (TextBox) panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true)[0];
1566 |
1567 | var tmpMessageStand = txtBox[1].Text;
1568 |
1569 | if (checkboxSelect.Checked)
1570 | {
1571 | NeedSend += FormPackage_NOHead_NOEnd(2, i + 1, tmpMessageStand);
1572 | }
1573 | }
1574 | return NeedSend;
1575 | }
1576 |
1577 | #endregion
1578 |
1579 | #region 4.实时变量参数
1580 |
1581 | private void InitRealtime()
1582 | {
1583 | var sp = new SharedPreferences(SavefileName);
1584 | if (sp.ConfigFileExists && isRealTimeValide())
1585 | {
1586 | DrawRealTimePannel(sp, true);
1587 | }
1588 | }
1589 |
1590 | private void button_electricity_NumConfirm_Click(object sender, EventArgs e)
1591 | {
1592 | if (isRealTimeValide())
1593 | {
1594 | var sp = new SharedPreferences(SavefileName);
1595 | if (sp.ConfigFileExists)
1596 | {
1597 | DrawRealTimePannel(sp, false);
1598 | }
1599 | SaveConfig(SavefileName);
1600 | }
1601 | }
1602 |
1603 | private void DrawRealTimePannel(SharedPreferences sp, bool byInit)
1604 | {
1605 | panel_Electricity.AutoScroll = true;
1606 | panel_Electricity.Controls.Clear();
1607 | var total = int.Parse(textBox_Realtime_Number.Text);
1608 |
1609 | for (var i = 0; i < total; i++)
1610 | {
1611 | var labelElect = new TextBox();
1612 | labelElect.Size = new Size(100, 20); //label大小
1613 | labelElect.Location = new Point(30 + 120*0, 30*(i + 1));
1614 | labelElect.Name = "txtElectName" + Convert.ToString(i + 1);
1615 | labelElect.Text = @"实时变量" + Convert.ToString(i + 1);
1616 | labelElect.TextAlign = HorizontalAlignment.Center;
1617 | if (byInit)
1618 | {
1619 | var elecName = string.Format("textElectName{0}", i + 1);
1620 | labelElect.Text = sp.GetString(elecName, "1.0");
1621 | }
1622 |
1623 | var txtBoxValue = new TextBox();
1624 | txtBoxValue.Size = new Size(50, 50);
1625 | txtBoxValue.Location = new Point(30 + 120*1, 30*(i + 1));
1626 | txtBoxValue.Name = "txtElectValue" + Convert.ToString(i + 1);
1627 | txtBoxValue.TextAlign = HorizontalAlignment.Center;
1628 | if (byInit)
1629 | {
1630 | var elecValue = string.Format("txtElectValue{0}", i + 1);
1631 | txtBoxValue.Text = sp.GetString(elecValue, "1.0");
1632 | }
1633 |
1634 | panel_Electricity.Controls.Add(labelElect);
1635 | panel_Electricity.Controls.Add(txtBoxValue);
1636 | }
1637 | }
1638 |
1639 | private void textBox_Realtime_Number_TextChanged(object sender, EventArgs e)
1640 | {
1641 | var t = sender as TextBox;
1642 |
1643 | if (t != null && !IsIntegerCheck(t.Text))
1644 | t.Text = @"10";
1645 | }
1646 |
1647 | private bool isRealTimeValide()
1648 | {
1649 | int number = (textBox_Realtime_Number.Text).toInt32();
1650 | if (number < 1)
1651 | {
1652 | MessageBox.Show(@"请输入需要的参数数量!", @"错误");
1653 | return false;
1654 | }
1655 | return true;
1656 | }
1657 |
1658 | #endregion
1659 |
1660 | #region 7.虚拟示波器
1661 |
1662 | private void InitzedGraph()
1663 | {
1664 | var myPane = zedGraph_local.GraphPane;
1665 | myPane.Title.IsVisible = false;
1666 | myPane.XAxis.Title.Text = "time";
1667 | myPane.YAxis.Title.Text = "Value";
1668 |
1669 | //show grid
1670 | myPane.XAxis.MajorGrid.IsVisible = true;
1671 | myPane.YAxis.MajorGrid.IsVisible = true;
1672 |
1673 | // Align the Y axis labels so they are flush to the axis
1674 | myPane.YAxis.Scale.Align = AlignP.Inside;
1675 |
1676 | // Manually set the axis range
1677 | myPane.XAxis.Scale.Min = _xminScale;
1678 | myPane.XAxis.Scale.Max = _xmaxScale;
1679 | myPane.YAxis.Scale.Min = _yminScale;
1680 | myPane.YAxis.Scale.Max = _ymaxScale;
1681 |
1682 | // Fill the axis background with a gradient
1683 | myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
1684 |
1685 | // OPTIONAL: Show tooltips when the mouse hovers over a point
1686 | zedGraph_local.IsShowPointValues = true;
1687 | zedGraph_local.PointValueEvent += MyPointValueHandler;
1688 |
1689 | for (var i = 0; i < ScopeNumber; i++)
1690 | {
1691 | zedGrpahNames[i] = new ZedGrpahName();
1692 | coOb[i] = new CallObject();
1693 | }
1694 |
1695 | var sp = new SharedPreferences(SavefileName);
1696 | for (var i = 0; i < ScopeNumber; i++)
1697 | {
1698 | zedGrpahNames[i].listZed.Add(Convert.ToDouble(zedGrpahNames[i].x), 0);
1699 | var curve = string.Format("波形{0}", i + 1);
1700 |
1701 | //自己定义的变量名称
1702 | var txtName_CustomPara = string.Format("SCOPE_TextName{0}", i + 1);
1703 | var getName = sp.GetString(txtName_CustomPara, @"波形" + Convert.ToString(i + 1));
1704 | zedGraph_local.GraphPane.AddCurve(getName.Trim() != "" ? getName : curve, zedGrpahNames[i].listZed,
1705 | _colorLine[i%8],
1706 | SymbolType.None);
1707 | }
1708 |
1709 | refleshZedPane(zedGraph_local);
1710 | }
1711 |
1712 | private void Init_pane_Scope()
1713 | {
1714 | var sp = new SharedPreferences(SavefileName);
1715 |
1716 | panel_Scope.AutoScroll = true;
1717 | var total = ScopeNumber;
1718 | for (var i = 0; i < total; i++)
1719 | {
1720 | var checkDrawing = new CheckBox();
1721 | checkDrawing.Size = new Size(15, 15);
1722 | checkDrawing.Location = new Point(20 + i%8*77, 10 + i/8*60);
1723 | checkDrawing.Name = "checkBox_Def" + Convert.ToString(i + 1);
1724 | checkDrawing.Text = "";
1725 |
1726 | var checkState = string.Format("SCOPE_CheckState{0}", i + 1);
1727 | checkDrawing.Checked = sp.GetBoolean(checkState, false);
1728 | checkDrawing.CheckedChanged += CheckDrawingOnCheckedChanged;
1729 |
1730 | var txtBoxName = new TextBox();
1731 | txtBoxName.Size = new Size(50, 20); //textbox大小
1732 | txtBoxName.Location = new Point(41 + i%8*77, 7 + i/8*60);
1733 | txtBoxName.Name = "txtName" + Convert.ToString(i + 1);
1734 | txtBoxName.TextAlign = HorizontalAlignment.Center;
1735 | var txtName_CustomPara = string.Format("SCOPE_TextName{0}", i + 1);
1736 | var getName = sp.GetString(txtName_CustomPara, @"波形" + Convert.ToString(i + 1));
1737 | txtBoxName.Text = getName.Trim() != "" ? getName : string.Format("波形{0}", i + 1);
1738 | txtBoxName.BackColor = _colorLine[i%8];
1739 | txtBoxName.TextChanged += ScopeTextNameChanged;
1740 | txtBoxName.Enabled = checkDrawing.Checked;
1741 |
1742 | var buttonNewForm = new Button();
1743 | buttonNewForm.Size = new Size(66, 23);
1744 | buttonNewForm.Location = new Point(25 + i%8*77, 34 + i/8*60);
1745 | buttonNewForm.Name = "buttonDraw" + Convert.ToString(i + 1);
1746 | buttonNewForm.Text = @"独立图像";
1747 | buttonNewForm.Click += ButtonNewFormOnClick;
1748 | buttonNewForm.Enabled = checkDrawing.Checked;
1749 |
1750 | panel_Scope.Controls.Add(checkDrawing);
1751 | panel_Scope.Controls.Add(txtBoxName);
1752 | panel_Scope.Controls.Add(buttonNewForm);
1753 | }
1754 | }
1755 |
1756 | private void timer_fresh_Tick(object sender, EventArgs e)
1757 | {
1758 | refleshZedPane(zedGraph_local);
1759 | }
1760 |
1761 | private string MyPointValueHandler(ZedGraphControl control, GraphPane pane,
1762 | CurveItem curve, int iPt)
1763 | {
1764 | var pt = curve[iPt];
1765 | return curve.Label.Text + " is " + pt.Y.ToString("f2") + " units at " + pt.X.ToString("f1");
1766 | }
1767 |
1768 | private void refleshZedPane(ZedGraphControl zedGraph)
1769 | {
1770 | zedGraph.AxisChange();
1771 | zedGraph.Invalidate();
1772 | }
1773 |
1774 | private void ButtonNewFormOnClick(object sender, EventArgs eventArgs)
1775 | {
1776 | var btnClk = (Button) sender;
1777 |
1778 | var id = GetNumber(btnClk.Name) - 1;
1779 | if (zedGrpahNames[id].IsSingleWindowShowed == false)
1780 | {
1781 | zedGrpahNames[id].IsSingleWindowShowed = true;
1782 |
1783 | FindTextboxAndShowWindow(id);
1784 |
1785 | if (_isLoadHistory)
1786 | {
1787 | coOb[id].CallPointPairEvent(zedGrpahNames[id].listZed);
1788 | }
1789 | }
1790 | else
1791 | {
1792 | MessageBox.Show(@"不能重复创建!已经有了一个窗口!");
1793 | }
1794 | }
1795 |
1796 | private void FindTextboxAndShowWindow(int id)
1797 | {
1798 | var txtBox = (TextBox) panel_Scope.Controls.Find("txtName" +
1799 | Convert.ToString(id + 1), true)[0];
1800 |
1801 | var singleWindow = new ZedGraphSingleWindow(id, coOb[id], txtBox.Text);
1802 | singleWindow.SignalClosedEvent += SingleWindowClosed_RecvInfo;
1803 | singleWindow.SignalLoadEvent += delegate(ZedGraphSingleWindow window, int i)
1804 | {
1805 | window.PauseFlag = false;
1806 | };
1807 |
1808 | singleWindow.Show();
1809 | }
1810 |
1811 | private static int GetNumber(string str)
1812 | {
1813 | var result = 0;
1814 | if (!string.IsNullOrEmpty(str))
1815 | {
1816 | // 正则表达式剔除非数字字符(不包含小数点.)
1817 | str = Regex.Replace(str, @"[^\d.\d]", "");
1818 | // 如果是数字,则转换为decimal类型
1819 | if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
1820 | {
1821 | result = int.Parse(str);
1822 | }
1823 | }
1824 | return result;
1825 | }
1826 |
1827 | #region Event
1828 |
1829 | private void ScopeTextNameChanged(object sender, EventArgs eventArgs)
1830 | {
1831 | var txtBox = sender as TextBox;
1832 |
1833 | var id = GetNumber(txtBox.Name) - 1;
1834 |
1835 | zedGraph_local.GraphPane.CurveList[id].Label.Text = txtBox.Text;
1836 |
1837 | refleshZedPane(zedGraph_local);
1838 | }
1839 |
1840 | private void CheckDrawingOnCheckedChanged(object sender, EventArgs eventArgs)
1841 | {
1842 | var checkchangBox = (CheckBox) sender;
1843 | var id = GetNumber(checkchangBox.Name) - 1;
1844 |
1845 | var txtBox = (TextBox) panel_Scope.Controls.Find("txtName" +
1846 | Convert.ToString(id + 1), true)[0];
1847 |
1848 | var buttonNewForm = new Button();
1849 | buttonNewForm = (Button) panel_Scope.Controls.Find("buttonDraw" +
1850 | Convert.ToString(id + 1), true)[0];
1851 |
1852 | if (checkchangBox.Checked)
1853 | {
1854 | txtBox.Enabled = true;
1855 | buttonNewForm.Enabled = true;
1856 |
1857 | if (mySerialPort.IsOpen)
1858 | {
1859 | timer_fresh.Start();
1860 | }
1861 | else
1862 | {
1863 | for (var j = 0; j < zedGrpahNames[id].ZedPoint.ZedListX.Count; j++)
1864 | {
1865 | var x = zedGrpahNames[id].ZedPoint.ZedListX.ElementAt(j);
1866 | var y = zedGrpahNames[id].ZedPoint.ZedListY.ElementAt(j);
1867 | zedGrpahNames[id].listZed.Add(x, y);
1868 | }
1869 | }
1870 | }
1871 | else
1872 | {
1873 | txtBox.Enabled = false;
1874 | buttonNewForm.Enabled = false;
1875 |
1876 | if (!mySerialPort.IsOpen)
1877 | {
1878 | var upLimit = zedGrpahNames[id].listZed.Count;
1879 | zedGrpahNames[id].listZed.RemoveRange(0, upLimit);
1880 | }
1881 | }
1882 |
1883 | refleshZedPane(zedGraph_local);
1884 | }
1885 |
1886 | private void button_ClearDrawing_Click(object sender, EventArgs e)
1887 | {
1888 | for (var i = 0; i < ScopeNumber; i++) //首先清除所有的曲线数据
1889 | {
1890 | zedGrpahNames[i].listZed.RemoveRange(0, zedGrpahNames[i].listZed.Count);
1891 | zedGrpahNames[i].x = -1;
1892 | }
1893 |
1894 | zedGraph_local.GraphPane.XAxis.Scale.MinAuto = true;
1895 | zedGraph_local.GraphPane.XAxis.Scale.MaxAuto = true;
1896 | zedGraph_local.GraphPane.YAxis.Scale.MinAuto = true;
1897 | zedGraph_local.GraphPane.YAxis.Scale.MaxAuto = true;
1898 |
1899 | refleshZedPane(zedGraph_local);
1900 | }
1901 |
1902 | private void SingleWindowClosed_RecvInfo(int id)
1903 | {
1904 | zedGrpahNames[id].IsSingleWindowShowed = false;
1905 | }
1906 |
1907 | #endregion
1908 |
1909 | #endregion
1910 |
1911 | #region 8.全局参数
1912 |
1913 | private void button_ReadAllSettings_Click(object sender, EventArgs e)
1914 | {
1915 | try
1916 | {
1917 | label28.Text = @"Loading....";
1918 | var noMeaning = "0";
1919 |
1920 | SendMessageAndEnqueue(3, 1, noMeaning);
1921 | }
1922 | catch (Exception ee)
1923 | {
1924 | MessageBox.Show(ee.Message);
1925 | }
1926 | }
1927 |
1928 | private void button_force_stop_Click(object sender, EventArgs e)
1929 | {
1930 | //清空现在的所有队列
1931 | _queueEchoControl.Clear();
1932 | tmpSendHandle.Flag = 1;
1933 |
1934 | try
1935 | {
1936 | var noMeaning = "0";
1937 | SendMessageAndEnqueue(3, 2, noMeaning);
1938 |
1939 | label28.Text = @"停车指令发送中...";
1940 | }
1941 | catch (Exception ee)
1942 | {
1943 | MessageBox.Show(ee.Message);
1944 | }
1945 | }
1946 |
1947 | private void button_ExportMatlab_Click(object sender, EventArgs e)
1948 | {
1949 | saveFileDialog_History.Title = @"导出曲线数据";
1950 | saveFileDialog_History.Filter = @"配置文件(*.m)|*.m|所有类型(*.*)|(*.*)";
1951 | saveFileDialog_History.RestoreDirectory = true;
1952 | if (saveFileDialog_History.ShowDialog() == DialogResult.OK)
1953 | {
1954 | var fileName = saveFileDialog_History.FileName;
1955 | saveFileDialog_History.FileName = fileName.Substring(fileName.LastIndexOf("\\",
1956 | StringComparison.Ordinal) + 1);
1957 | //MessageBox.Show(fileName + filter);
1958 | var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
1959 | var sw = new StreamWriter(fs, Encoding.Default);
1960 |
1961 | WriteToMatlabFile(sw, fileName);
1962 |
1963 | sw.Close();
1964 | }
1965 | }
1966 |
1967 | private void WriteToMatlabFile(StreamWriter sw, string fileName)
1968 | {
1969 | //示波器参数
1970 | var countScope = 0;
1971 | var checkDrawing = new CheckBox[ScopeNumber];
1972 | var txtBoxScope = new TextBox[ScopeNumber];
1973 | var buttonNewForm = new Button[ScopeNumber];
1974 |
1975 | for (var i = 0; i < ScopeNumber; i++)
1976 | {
1977 | checkDrawing[i] =
1978 | (CheckBox)
1979 | panel_Scope.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true)[0];
1980 |
1981 | txtBoxScope[i] =
1982 | (TextBox)panel_Scope.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0];
1983 |
1984 | buttonNewForm[i] =
1985 | (Button)panel_Scope.Controls.Find("buttonDraw" + Convert.ToString(i + 1), true)[0];
1986 |
1987 | if (checkDrawing[i].Checked)
1988 | ++countScope;
1989 | }
1990 |
1991 | sw.WriteLine("clc");
1992 | sw.WriteLine("clear all");
1993 | sw.WriteLine("close all");
1994 | sw.WriteLine("\r\n");
1995 | sw.WriteLine("ScopeLineNumber = {0};", countScope);
1996 |
1997 | for (var i = 0; i < ScopeNumber; i++)
1998 | {
1999 | if (checkDrawing[i].Checked)
2000 | {
2001 | sw.WriteLine("%%");
2002 | sw.WriteLine("size{0}_{1} = 1:{2};", i+1, txtBoxScope[i].Text, zedGrpahNames[i].listZed.Count);
2003 | sw.Write("Scope{0}_{1} = ", i+1, txtBoxScope[i].Text);
2004 | sw.Write("[");
2005 |
2006 | int perLineCount = 0;
2007 | int perLineThresold = 20;
2008 | for (var j = 0; j < zedGrpahNames[i].listZed.Count; j++)
2009 | {
2010 | sw.Write("{0},", zedGrpahNames[i].listZed.ElementAt(j).Y);
2011 |
2012 | perLineCount++;
2013 | if (perLineCount > perLineThresold)
2014 | {
2015 | perLineCount = 0;
2016 |
2017 | sw.Write("...\r\n");
2018 | }
2019 | }
2020 | sw.Write("];");
2021 | sw.WriteLine("\r\n%%");
2022 | sw.WriteLine("\r\n");
2023 | }
2024 | }
2025 |
2026 | sw.WriteLine("%% 示波器中变量名称:");
2027 | for (var i = 0; i < ScopeNumber; i++)
2028 | {
2029 | if (checkDrawing[i].Checked)
2030 | {
2031 | sw.Write("%% {0}. size{0}_{1}; ", i+1, txtBoxScope[i].Text);
2032 | sw.Write("Scope{0}_{1}\r\n", i+1, txtBoxScope[i].Text);
2033 | }
2034 | }
2035 | }
2036 |
2037 | #endregion
2038 |
2039 | #region 历史数据
2040 |
2041 | private void button_History_Click(object sender, EventArgs e) //如果可能请使用多线程!!!
2042 | {
2043 | saveFileDialog_History.Title = "导出配置";
2044 | saveFileDialog_History.Filter = "配置文件(*.ini)|*.ini|所有类型(*.*)|(*.*)";
2045 | saveFileDialog_History.RestoreDirectory = true;
2046 | if (saveFileDialog_History.ShowDialog() == DialogResult.OK)
2047 | {
2048 | var fileName = saveFileDialog_History.FileName;
2049 | saveFileDialog_History.FileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
2050 | //MessageBox.Show(fileName + filter);
2051 | var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
2052 | var sw = new StreamWriter(fs, Encoding.Default);
2053 |
2054 | WritePIDValueToText(sw, fileName);
2055 | WriteCustomParaSetupToText(sw, fileName);
2056 | WriteScopeSetupToText(sw, fileName);
2057 |
2058 | //...
2059 | sw.Close();
2060 | }
2061 | }
2062 |
2063 | private void button_loadHistory_Click(object sender, EventArgs e)
2064 | {
2065 | openFileDialog_History.Title = "导入配置文件";
2066 | openFileDialog_History.Filter = "配置文件(*.ini)|*.ini|所有类型(*.*)|(*.*)";
2067 | openFileDialog_History.RestoreDirectory = true;
2068 | openFileDialog_History.FileName = "";
2069 | if (openFileDialog_History.ShowDialog() == DialogResult.OK)
2070 | {
2071 | var fileName = openFileDialog_History.FileName;
2072 | openFileDialog_History.FileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
2073 | //MessageBox.Show(fileName + filter);
2074 | var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
2075 | var sr = new StreamReader(fs, Encoding.Default);
2076 |
2077 | var lines = new List();
2078 |
2079 | while (sr.Peek() > -1)
2080 | {
2081 | lines.Add(sr.ReadLine());
2082 | }
2083 |
2084 | if (lines.ElementAt(0).Contains("CarType"))
2085 | {
2086 | var countLine = 0;
2087 |
2088 | countLine = ReadPIDFromText(lines, countLine);
2089 | countLine = ReadCustomParaFromText(lines, countLine);
2090 | countLine = ReadScopeFromText(lines, countLine);
2091 | }
2092 | _isLoadHistory = true;
2093 |
2094 | sr.Close();
2095 | }
2096 | }
2097 |
2098 | private void WritePIDValueToText(StreamWriter sw, string filename)
2099 | {
2100 | //小车参数
2101 | sw.WriteLine("CarType:{0}", radioButton_FourWheel.Checked ? "1" : "0");
2102 | if (radioButton_FourWheel.Checked) //四轮车PID
2103 | {
2104 | //舵机PID参数
2105 | var strSteer = "P" + textBox_Steer_P.Text + " I" + textBox_Steer_I.Text + " D" +
2106 | textBox_Steer_D.Text;
2107 | sw.WriteLine("Steer:{0}", strSteer);
2108 |
2109 | //电机PID参数
2110 | var strMotor = "P" + textBox_Motor_P.Text + " I" + textBox_Motor_I.Text + " D" +
2111 | textBox_Motor_D.Text;
2112 | sw.WriteLine("Motor:{0}", strMotor);
2113 | }
2114 | else if (radioButton_BalanceCar.Checked) //直立车PID参数的获取
2115 | {
2116 | //直立PID
2117 | var strStand = "P" + textBox_Stand_P.Text + " I" + textBox_Stand_I.Text + " D" +
2118 | textBox_Stand_D.Text;
2119 | sw.WriteLine("Stand:{0}", strStand);
2120 |
2121 | //速度PID
2122 | var strSpeed = "P" + textBox_Speed_P.Text + " I" + textBox_Speed_I.Text + " D" +
2123 | textBox_Speed_D.Text;
2124 | sw.WriteLine("Speed:{0}", strSpeed);
2125 |
2126 | //方向PID
2127 | var strDirection = "P" + textBox_Direction_P.Text + " I" + textBox_Direction_I.Text + " D" +
2128 | textBox_Direction_D.Text;
2129 | sw.WriteLine("Direction:{0}", strDirection);
2130 | }
2131 | }
2132 |
2133 | private void WriteCustomParaSetupToText(StreamWriter sw, string fileName)
2134 | {
2135 | //自定义参数
2136 | var totalCustomPara = 0;
2137 | if (textBox_DIY_Number.Text == "")
2138 | {
2139 | //essageBox.Show(@"请重新输入需要的参数数量!", @"错误");
2140 | totalCustomPara = 0;
2141 | }
2142 | totalCustomPara = (textBox_DIY_Number.Text).toInt32();
2143 |
2144 | sw.WriteLine("DIY_Num:{0}", totalCustomPara);
2145 |
2146 | for (var i = 0; i < totalCustomPara; i++)
2147 | {
2148 | var txtBox = new TextBox[2]; //用控件数组来定义每一行的TextBox,总共3个TextBox
2149 | txtBox[0] =
2150 | (TextBox) panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0];
2151 | txtBox[1] =
2152 | (TextBox) panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true)[0];
2153 |
2154 | var strName = txtBox[0].Text;
2155 | var strValue = txtBox[1].Text;
2156 |
2157 | sw.WriteLine("{0}:{1}", strName, strValue);
2158 | }
2159 | }
2160 |
2161 | private void WriteScopeSetupToText(StreamWriter sw, string fileName)
2162 | {
2163 | //示波器参数
2164 | var countScope = 0;
2165 | var checkDrawing = new CheckBox[ScopeNumber];
2166 | var txtBoxScope = new TextBox[ScopeNumber];
2167 | var buttonNewForm = new Button[ScopeNumber];
2168 |
2169 | for (var i = 0; i < ScopeNumber; i++)
2170 | {
2171 | checkDrawing[i] =
2172 | (CheckBox)
2173 | panel_Scope.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true)[0];
2174 |
2175 | txtBoxScope[i] =
2176 | (TextBox) panel_Scope.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0];
2177 |
2178 | buttonNewForm[i] =
2179 | (Button) panel_Scope.Controls.Find("buttonDraw" + Convert.ToString(i + 1), true)[0];
2180 |
2181 | if (checkDrawing[i].Checked)
2182 | ++countScope;
2183 | }
2184 | sw.WriteLine("ScopeLineNumber:{0}", countScope);
2185 |
2186 | for (var i = 0; i < ScopeNumber; i++)
2187 | {
2188 | if (checkDrawing[i].Checked)
2189 | {
2190 | sw.WriteLine("ScopeLineOrder:{0}", i);
2191 | sw.WriteLine("CurrenScopeName:{0}", txtBoxScope[i].Text);
2192 | sw.WriteLine("PointNumber:{0}", zedGrpahNames[i].listZed.Count);
2193 |
2194 | for (var j = 0; j < zedGrpahNames[i].listZed.Count; j++)
2195 | {
2196 | sw.Write("{0}", zedGrpahNames[i].listZed.ElementAt(j).ToString().Replace(" ", ""));
2197 | }
2198 | sw.WriteLine("");
2199 | }
2200 | }
2201 | }
2202 |
2203 | private int ReadPIDFromText(List lines, int countLine)
2204 | {
2205 | int carType = (lines.ElementAt(countLine).Split(':').ElementAt(1)).toInt32();
2206 | countLine++;
2207 |
2208 | if (carType == 0) //直立车
2209 | {
2210 | countLine = ReadBalancePIDFromText(lines, countLine);
2211 | }
2212 | else if (carType == 1) //四轮车
2213 | {
2214 | countLine = ReadFourwheelPIDFromText(lines, countLine);
2215 | }
2216 | return countLine;
2217 | }
2218 |
2219 | private int ReadBalancePIDFromText(List lines, int countLine)
2220 | {
2221 | var indexP = lines.ElementAt(countLine).IndexOf('P');
2222 | var indexI = lines.ElementAt(countLine).IndexOf(" I", StringComparison.Ordinal);
2223 | var indexD = lines.ElementAt(countLine).IndexOf(" D", StringComparison.Ordinal);
2224 |
2225 | //直立
2226 | var standP = lines.ElementAt(countLine).Substring(indexP + 1, indexI - indexP - 1);
2227 | var standI = lines.ElementAt(countLine).Substring(indexI + 2, indexD - indexI - 1).Trim();
2228 | var standD = lines.ElementAt(countLine).Substring(indexD + 2);
2229 | textBox_Stand_P.Text = standP;
2230 | textBox_Stand_I.Text = standI;
2231 | textBox_Stand_D.Text = standD;
2232 | ++countLine;
2233 |
2234 | //速度
2235 | indexP = lines.ElementAt(countLine).IndexOf('P');
2236 | indexI = lines.ElementAt(countLine).IndexOf(" I", StringComparison.Ordinal);
2237 | indexD = lines.ElementAt(countLine).IndexOf(" D", StringComparison.Ordinal);
2238 | var speedP = lines.ElementAt(countLine).Substring(indexP + 1, indexI - indexP - 1);
2239 | var speedI = lines.ElementAt(countLine).Substring(indexI + 2, indexD - indexI - 1).Trim();
2240 | var speedD = lines.ElementAt(countLine).Substring(indexD + 2);
2241 | textBox_Speed_P.Text = speedP;
2242 | textBox_Speed_I.Text = speedI;
2243 | textBox_Speed_D.Text = speedD;
2244 | ++countLine;
2245 |
2246 | //方向
2247 | indexP = lines.ElementAt(countLine).IndexOf('P');
2248 | indexI = lines.ElementAt(countLine).IndexOf(" I", StringComparison.Ordinal);
2249 | indexD = lines.ElementAt(countLine).IndexOf(" D", StringComparison.Ordinal);
2250 | var directionP = lines.ElementAt(countLine).Substring(indexP + 1, indexI - indexP - 1);
2251 | var directionI = lines.ElementAt(countLine).Substring(indexI + 2, indexD - indexI - 1).Trim();
2252 | var directionD = lines.ElementAt(countLine).Substring(indexD + 2);
2253 | textBox_Direction_P.Text = directionP;
2254 | textBox_Direction_I.Text = directionI;
2255 | textBox_Direction_D.Text = directionD;
2256 | ++countLine;
2257 |
2258 | return countLine;
2259 | }
2260 |
2261 | private int ReadFourwheelPIDFromText(List lines, int countLine)
2262 | {
2263 | var indexP = lines.ElementAt(countLine).IndexOf('P');
2264 | var indexI = lines.ElementAt(countLine).IndexOf(" I", StringComparison.Ordinal);
2265 | var indexD = lines.ElementAt(countLine).IndexOf(" D", StringComparison.Ordinal);
2266 |
2267 | //舵机
2268 | var steerP = lines.ElementAt(countLine).Substring(indexP + 1, indexI - indexP - 1);
2269 | var steerI = lines.ElementAt(countLine).Substring(indexI + 2, indexD - indexI - 1).Trim();
2270 | var steerD = lines.ElementAt(countLine).Substring(indexD + 2);
2271 | textBox_Steer_P.Text = steerP;
2272 | textBox_Steer_I.Text = steerI;
2273 | textBox_Steer_D.Text = steerD;
2274 | ++countLine;
2275 |
2276 | //电机
2277 | indexP = lines.ElementAt(countLine).IndexOf('P');
2278 | indexI = lines.ElementAt(countLine).IndexOf(" I", StringComparison.Ordinal);
2279 | indexD = lines.ElementAt(countLine).IndexOf(" D", StringComparison.Ordinal);
2280 | var motorP = lines.ElementAt(countLine).Substring(indexP + 1, indexI - indexP - 1);
2281 | var motorI = lines.ElementAt(countLine).Substring(indexI + 2, indexD - indexI - 1).Trim();
2282 | var motorD = lines.ElementAt(countLine).Substring(indexD + 2);
2283 | textBox_Motor_P.Text = motorP;
2284 | textBox_Motor_I.Text = motorI;
2285 | textBox_Motor_D.Text = motorD;
2286 | ++countLine;
2287 |
2288 | return countLine;
2289 | }
2290 |
2291 | private int ReadCustomParaFromText(List lines, int countLine)
2292 | {
2293 | //自定义参数
2294 | if (lines.ElementAt(countLine).Contains("DIY_Num"))
2295 | {
2296 | int CustomParaNum = lines.ElementAt(countLine).Split(':').ElementAt(1).toInt32();
2297 | ++countLine;
2298 |
2299 | if (CustomParaNum == (textBox_DIY_Number.Text).toInt32())
2300 | {
2301 | for (var i = 0; i < CustomParaNum; i++)
2302 | {
2303 | var checkboxSelect = new CheckBox();
2304 | checkboxSelect =
2305 | (CheckBox)
2306 | panel_add_DIYControls.Controls.Find("checkBox_Def" + Convert.ToString(i + 1),
2307 | true)[0];
2308 |
2309 | var txtBox = new TextBox[2]; //用控件数组来定义每一行的TextBox,总共3个TextBox
2310 | txtBox[0] =
2311 | (TextBox)
2312 | panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0
2313 | ];
2314 | txtBox[1] =
2315 | (TextBox)
2316 | panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true)[
2317 | 0];
2318 |
2319 | var numberName = lines.ElementAt(countLine).Split(':').ElementAt(0);
2320 | var numberValue = lines.ElementAt(countLine).Split(':').ElementAt(1);
2321 |
2322 | txtBox[0].Text = numberName;
2323 | txtBox[1].Text = numberValue;
2324 |
2325 | ++countLine;
2326 | }
2327 | }
2328 | else
2329 | {
2330 | var txtBoxName = new TextBox();
2331 | var txtBoxValue = new TextBox();
2332 | var checkboxSelect = new CheckBox();
2333 |
2334 | for (var i = 0; i < CustomParaNum; i++)
2335 | {
2336 | //是否启用的选项
2337 | checkboxSelect = new CheckBox();
2338 | checkboxSelect.Size = new Size(50, 20);
2339 | checkboxSelect.Location = new Point(10 + 70*0, 30*i); //textbox坐标
2340 | checkboxSelect.Name = "checkBox_Def" + Convert.ToString(i + 1);
2341 | checkboxSelect.Text = "";
2342 | checkboxSelect.CheckedChanged += CheckboxSelectOnCheckedChanged;
2343 | checkboxSelect.Checked = true;
2344 |
2345 | //名字
2346 | txtBoxName = new TextBox();
2347 | txtBoxName.Size = new Size(50, 50); //textbox大小
2348 | txtBoxName.Location = new Point(10 + 70*1, 30*i); //textbox坐标
2349 | txtBoxName.Name = "txtName" + Convert.ToString(i + 1); //设定控件名称
2350 | txtBoxName.TextAlign = HorizontalAlignment.Center;
2351 | txtBoxName.Text = lines.ElementAt(countLine).Split(':').ElementAt(0);
2352 | txtBoxName.Enabled = true;
2353 |
2354 | //值
2355 | txtBoxValue = new TextBox();
2356 | txtBoxValue.Size = new Size(50, 50); //textbox大小
2357 | txtBoxValue.Location = new Point(10 + 70*2, 30*i); //textbox坐标
2358 | txtBoxValue.Name = "txtValue" + Convert.ToString(i + 1); //设定控件名称
2359 | txtBoxValue.Text = "1.00";
2360 | txtBoxValue.TextAlign = HorizontalAlignment.Center;
2361 | txtBoxValue.Enabled = true;
2362 | txtBoxValue.Text = lines.ElementAt(countLine).Split(':').ElementAt(1);
2363 |
2364 | ++countLine;
2365 |
2366 | panel_add_DIYControls.Controls.Add(checkboxSelect);
2367 | panel_add_DIYControls.Controls.Add(txtBoxName); //把"名字"加入到panel中
2368 | panel_add_DIYControls.Controls.Add(txtBoxValue); //把"值"加入到panel中
2369 | }
2370 | }
2371 | }
2372 |
2373 | return countLine;
2374 | }
2375 |
2376 | private int ReadScopeFromText(List lines, int countLine)
2377 | {
2378 | //Scope
2379 | for (var i = 0; i < ScopeNumber; i++) //首先清除所有的曲线数据
2380 | {
2381 | zedGrpahNames[i].listZed.RemoveRange(0, zedGrpahNames[i].listZed.Count);
2382 | }
2383 |
2384 | if (lines.ElementAt(countLine).Contains("ScopeLineNumber"))
2385 | {
2386 | int scopeNum = (lines.ElementAt(countLine).Split(':').ElementAt(1)).toInt32();
2387 | ++countLine;
2388 |
2389 | for (var i = 0; i < scopeNum; i++)
2390 | {
2391 | if (lines.ElementAt(countLine).Contains("ScopeLineOrder")) //第几个曲线
2392 | {
2393 | int scopeOrder = (lines.ElementAt(countLine).Split(':').ElementAt(1)).toInt32();
2394 | ++countLine;
2395 |
2396 | if (lines.ElementAt(countLine).Contains("CurrenScopeName")) //之前的名字,没有这一条就不加
2397 | {
2398 | try
2399 | {
2400 | string scopeName = lines.ElementAt(countLine).Split(':').ElementAt(1);
2401 | ++countLine;
2402 |
2403 | var txtBox_Scope = (TextBox)panel_Scope.Controls.Find("txtName" +
2404 | Convert.ToString(scopeOrder + 1), true)[0];
2405 | txtBox_Scope.Text = scopeName;
2406 | }
2407 | catch
2408 | {
2409 | }
2410 | }
2411 |
2412 | if (lines.ElementAt(countLine).Contains("PointNumber")) //点数量
2413 | {
2414 | int scopePointNum =
2415 | (lines.ElementAt(countLine).Split(':').ElementAt(1)).toInt32();
2416 | ++countLine;
2417 |
2418 | char[] charsplit = {'(', ',', ')'};
2419 | var xyPoint = lines.ElementAt(countLine)
2420 | .Split(charsplit, StringSplitOptions.RemoveEmptyEntries);
2421 | ++countLine;
2422 |
2423 | for (var j = 0; j < scopePointNum; j++)
2424 | {
2425 | var x = Convert.ToDouble(xyPoint[j*2]);
2426 | var y = Convert.ToDouble(xyPoint[j*2 + 1]);
2427 | zedGrpahNames[scopeOrder].listZed.Add(x, y);
2428 | zedGrpahNames[scopeOrder].ZedPoint.ZedListX.Add(x);
2429 | zedGrpahNames[scopeOrder].ZedPoint.ZedListY.Add(y);
2430 | }
2431 | }
2432 | }
2433 | }
2434 | //UpdateScope Here
2435 | zedGraph_local.GraphPane.XAxis.Scale.MaxAuto = true;
2436 | zedGraph_local.GraphPane.XAxis.Scale.MinAuto = true;
2437 | zedGraph_local.GraphPane.YAxis.Scale.MaxAuto = true;
2438 | zedGraph_local.GraphPane.YAxis.Scale.MinAuto = true;
2439 |
2440 | refleshZedPane(zedGraph_local);
2441 | } //Scope End
2442 | return countLine;
2443 | }
2444 | #endregion
2445 |
2446 | #region 9.匹配性判断工具
2447 |
2448 | private string FormPackage(int father, int child, string sendMessgage)
2449 | {
2450 | var result = "";
2451 |
2452 | var head = "#";
2453 | var end = "$";
2454 | var sFather = father.ToString();
2455 | var sChild = child.ToString();
2456 |
2457 | result = head + "|" + sFather + "|" + sChild + "|" + sendMessgage + "|" + end;
2458 |
2459 | return result;
2460 | }
2461 |
2462 | private string FormPackage_NOHead_NOEnd(int father, int child, string sendMessgage)
2463 | {
2464 | var result = "";
2465 |
2466 | var sFather = father.ToString();
2467 | var sChild = child.ToString();
2468 |
2469 | result = "|" + sFather + "|" + sChild + "|" + sendMessgage + "|";
2470 |
2471 | return result;
2472 | }
2473 |
2474 | private void SendMessageAndEnqueue(int father, int child, string messgae)
2475 | {
2476 | messgae = FormPackage(father, child, messgae);
2477 | mySerialPort.Write(messgae);
2478 |
2479 | var tmpHandle = new GetEchoForm(0, messgae);
2480 | _queueEchoControl.Enqueue(tmpHandle);
2481 |
2482 | if (!timer_Send2GetEcho.Enabled)
2483 | timer_Send2GetEcho.Start();
2484 | }
2485 |
2486 | private Boolean IsIntegerCheck(string text)
2487 | {
2488 | var reg = new Regex("^[0-9]{1,}$");
2489 |
2490 | if (!reg.IsMatch(text))
2491 | {
2492 | MessageBox.Show(@"请输入整数!");
2493 | return false;
2494 | }
2495 | return true;
2496 | }
2497 |
2498 | private Boolean IsFloatCheck(string text)
2499 | {
2500 | var reg = new Regex("^((-{0,1}[0-9]+[\\.]?[0-9]{0,3})|-{0,1}[0-9]{1,})$");
2501 |
2502 | if (!reg.IsMatch(text))
2503 | {
2504 | MessageBox.Show(@"请输入精度为3的浮点或整数!");
2505 | return false;
2506 | }
2507 | return true;
2508 | }
2509 |
2510 | #endregion
2511 | }
2512 | }
--------------------------------------------------------------------------------
/Freescale_debug/Freescale_debug.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5C73F5B7-1A8D-459F-AFBD-EF5C5AE9AE51}
8 | WinExe
9 | Properties
10 | Freescale_debug
11 | Freescale_debug
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | true
25 | true
26 |
27 |
28 | AnyCPU
29 | none
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 | false
36 |
37 |
38 | 20150627125704915_easyicon_net_128.ico
39 |
40 |
41 |
42 | Libs\Leomon.dll
43 |
44 |
45 | Libs\log4net.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | Libs\ZedGraph.dll
60 |
61 |
62 |
63 |
64 |
65 |
66 | Form
67 |
68 |
69 | Form
70 |
71 |
72 | Form1.cs
73 |
74 |
75 | Form
76 |
77 |
78 | LoadingPage.cs
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Form
88 |
89 |
90 | ZedGraph_SingleWindow.cs
91 |
92 |
93 | Form1.cs
94 |
95 |
96 | LoadingPage.cs
97 |
98 |
99 | ResXFileCodeGenerator
100 | Resources.Designer.cs
101 | Designer
102 |
103 |
104 | True
105 | Resources.resx
106 |
107 |
108 | ZedGraph_SingleWindow.cs
109 |
110 |
111 |
112 | SettingsSingleFileGenerator
113 | Settings.Designer.cs
114 |
115 |
116 | True
117 | Settings.settings
118 | True
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 | {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
127 | 99
128 | 1
129 | 0
130 | tlbimp
131 | False
132 | True
133 |
134 |
135 | {00020430-0000-0000-C000-000000000046}
136 | 2
137 | 0
138 | 0
139 | primary
140 | False
141 | True
142 |
143 |
144 |
145 |
146 |
147 |
148 |
155 |
--------------------------------------------------------------------------------
/Freescale_debug/Freescale_debug.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ShowAllFiles
5 |
6 |
--------------------------------------------------------------------------------
/Freescale_debug/Libs/Leomon.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Libs/Leomon.dll
--------------------------------------------------------------------------------
/Freescale_debug/Libs/ZedGraph.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Libs/ZedGraph.dll
--------------------------------------------------------------------------------
/Freescale_debug/Libs/log4net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Libs/log4net.dll
--------------------------------------------------------------------------------
/Freescale_debug/LoadingPage.Designer.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace Freescale_debug
4 | {
5 | partial class LoadingPage
6 | {
7 | ///
8 | /// Required designer variable.
9 | ///
10 | private IContainer components = null;
11 |
12 | ///
13 | /// Clean up any resources being used.
14 | ///
15 | /// true if managed resources should be disposed; otherwise, false.
16 | protected override void Dispose(bool disposing)
17 | {
18 | if (disposing && (components != null))
19 | {
20 | components.Dispose();
21 | }
22 | base.Dispose(disposing);
23 | }
24 |
25 | #region Windows Form Designer generated code
26 |
27 | ///
28 | /// Required method for Designer support - do not modify
29 | /// the contents of this method with the code editor.
30 | ///
31 | private void InitializeComponent()
32 | {
33 | this.SuspendLayout();
34 | //
35 | // LoadingPage
36 | //
37 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
38 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
39 | this.ClientSize = new System.Drawing.Size(301, 252);
40 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
41 | this.Name = "LoadingPage";
42 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
43 | this.Text = "LoadingPage";
44 | this.ResumeLayout(false);
45 |
46 | }
47 |
48 | #endregion
49 | }
50 | }
--------------------------------------------------------------------------------
/Freescale_debug/LoadingPage.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace Freescale_debug
4 | {
5 | public partial class LoadingPage : Form
6 | {
7 | public LoadingPage()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Freescale_debug/LoadingPage.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/Freescale_debug/LogHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using log4net;
3 | using log4net.Config;
4 |
5 | [assembly: XmlConfigurator(Watch = true)]
6 |
7 | namespace TestLog4Net
8 | {
9 | public class LogHelper
10 | {
11 | ///
12 | /// 输出日志到Log4Net
13 | ///
14 | ///
15 | ///
16 |
17 | #region static void WriteLog(Type t, Exception ex)
18 | public static void WriteLog(Type t, Exception ex)
19 | {
20 | var log = LogManager.GetLogger(t);
21 | log.Error("Error", ex);
22 | }
23 |
24 | #endregion
25 |
26 | ///
27 | /// 输出日志到Log4Net
28 | ///
29 | ///
30 | ///
31 |
32 | #region static void WriteLog(Type t, string msg)
33 | public static void WriteLog(Type t, string msg)
34 | {
35 | var log = LogManager.GetLogger(t);
36 | log.Error(msg);
37 | }
38 |
39 | #endregion
40 | }
41 | }
--------------------------------------------------------------------------------
/Freescale_debug/PID.cs:
--------------------------------------------------------------------------------
1 | namespace Freescale_debug
2 | {
3 | internal class FourWheelPID
4 | {
5 | public PID motorPID { get; set; }
6 | public PID steerPID { get; set; }
7 | }
8 |
9 | internal class BalancePID
10 | {
11 | public PID speedPID { get; set; }
12 | public PID directionPID { get; set; }
13 | public PID standPID { get; set; }
14 | }
15 |
16 | internal class PID
17 | {
18 | public int P { get; set; }
19 | public int I { get; set; }
20 | public int D { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/Freescale_debug/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace Freescale_debug
5 | {
6 | internal static class Program
7 | {
8 | ///
9 | /// 应用程序的主入口点。
10 | ///
11 | [STAThread]
12 | private static void Main()
13 | {
14 | Application.EnableVisualStyles();
15 | Application.SetCompatibleTextRenderingDefault(false);
16 | Application.Run(new Form1());
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/Freescale_debug/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // 有关程序集的常规信息通过以下
5 | // 特性集控制。更改这些特性值可修改
6 | // 与程序集关联的信息。
7 |
8 | [assembly: AssemblyTitle("Freescale_debug")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("Freescale_debug")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
24 |
25 | [assembly: Guid("ac14c91e-e99f-46aa-8013-98226c1cfcec")]
26 |
27 | // 程序集的版本信息由下面四个值组成:
28 | //
29 | // 主版本
30 | // 次版本
31 | // 生成号
32 | // 修订号
33 | //
34 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
35 | // 方法是按如下所示使用“*”:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/Freescale_debug/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System.CodeDom.Compiler;
12 | using System.ComponentModel;
13 | using System.Diagnostics;
14 | using System.Diagnostics.CodeAnalysis;
15 | using System.Globalization;
16 | using System.Resources;
17 | using System.Runtime.CompilerServices;
18 |
19 | namespace Freescale_debug.Properties
20 | {
21 |
22 |
23 | ///
24 | /// 一个强类型的资源类,用于查找本地化的字符串等。
25 | ///
26 | // 此类是由 StronglyTypedResourceBuilder
27 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
28 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
29 | // (以 /str 作为命令选项),或重新生成 VS 项目。
30 | [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
31 | [DebuggerNonUserCode()]
32 | [CompilerGenerated()]
33 | internal class Resources
34 | {
35 |
36 | private static ResourceManager resourceMan;
37 |
38 | private static CultureInfo resourceCulture;
39 |
40 | [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
41 | internal Resources()
42 | {
43 | }
44 |
45 | ///
46 | /// 返回此类使用的、缓存的 ResourceManager 实例。
47 | ///
48 | [EditorBrowsable(EditorBrowsableState.Advanced)]
49 | internal static ResourceManager ResourceManager
50 | {
51 | get
52 | {
53 | if ((resourceMan == null))
54 | {
55 | ResourceManager temp = new ResourceManager("Freescale_debug.Properties.Resources", typeof(Resources).Assembly);
56 | resourceMan = temp;
57 | }
58 | return resourceMan;
59 | }
60 | }
61 |
62 | ///
63 | /// 为所有资源查找重写当前线程的 CurrentUICulture 属性,
64 | /// 方法是使用此强类型资源类。
65 | ///
66 | [EditorBrowsable(EditorBrowsableState.Advanced)]
67 | internal static CultureInfo Culture
68 | {
69 | get
70 | {
71 | return resourceCulture;
72 | }
73 | set
74 | {
75 | resourceCulture = value;
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Freescale_debug/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Freescale_debug/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18408
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System.CodeDom.Compiler;
12 | using System.Configuration;
13 | using System.Runtime.CompilerServices;
14 |
15 | namespace Freescale_debug.Properties
16 | {
17 |
18 |
19 | [CompilerGenerated()]
20 | [GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
21 | internal sealed partial class Settings : ApplicationSettingsBase
22 | {
23 |
24 | private static Settings defaultInstance = ((Settings)(Synchronized(new Settings())));
25 |
26 | public static Settings Default
27 | {
28 | get
29 | {
30 | return defaultInstance;
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Freescale_debug/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Freescale_debug/Source/1796091826490712038.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/1796091826490712038.png
--------------------------------------------------------------------------------
/Freescale_debug/Source/20150627125330911_easyicon_net_96.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/20150627125330911_easyicon_net_96.ico
--------------------------------------------------------------------------------
/Freescale_debug/Source/20150627125704915_easyicon_net_128.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/20150627125704915_easyicon_net_128.ico
--------------------------------------------------------------------------------
/Freescale_debug/Source/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/logo.png
--------------------------------------------------------------------------------
/Freescale_debug/Source/logo_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/logo_1.png
--------------------------------------------------------------------------------
/Freescale_debug/Source/logo_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/logo_2.png
--------------------------------------------------------------------------------
/Freescale_debug/Source/master.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/Freescale_debug/Source/master.png
--------------------------------------------------------------------------------
/Freescale_debug/SugarTransfer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Text.RegularExpressions;
7 |
8 | namespace Freescale_debug
9 | {
10 | public static class SugarTransfer
11 | {
12 | private static Regex re = new Regex("/d+", RegexOptions.Compiled);
13 | static public Int32 toInt32(this string str)
14 | {
15 | try
16 | {
17 | return Convert.ToInt32(str);
18 | }
19 | catch
20 | {
21 | return -1;
22 | }
23 | }
24 |
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Freescale_debug/ZedGraphPoint.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using ZedGraph;
3 |
4 | namespace Freescale_debug
5 | {
6 | internal class ZedGrpahName
7 | {
8 | public PointPairList listZed = new PointPairList();
9 | public bool IsSingleWindowShowed { get; set; }
10 | public double ValueZed { get; set; }
11 | public int x { get; set; }
12 |
13 | public PointPairList ListZed
14 | {
15 | get { return listZed; }
16 | set { ListZed = value; }
17 | }
18 |
19 | private ZedGraphPoint zedPoint = new ZedGraphPoint();
20 | public ZedGraphPoint ZedPoint
21 | {
22 | get { return zedPoint; }
23 | set { zedPoint = value; }
24 | }
25 |
26 | }
27 |
28 | internal class ZedGraphPoint
29 | {
30 | public List ZedListX = new List();
31 | public List ZedListY = new List();
32 |
33 | public List zedListX
34 | {
35 | get { return ZedListX; }
36 | set { ZedListX = value; }
37 | }
38 |
39 | public List zedListY
40 | {
41 | get { return ZedListY; }
42 | set { ZedListY = value; }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/Freescale_debug/ZedGraph_SingleWindow.Designer.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.Windows.Forms;
3 | using ZedGraph;
4 | using Label = System.Windows.Forms.Label;
5 |
6 | namespace Freescale_debug
7 | {
8 | partial class ZedGraphSingleWindow
9 | {
10 | ///
11 | /// Required designer variable.
12 | ///
13 | private IContainer components = null;
14 |
15 | ///
16 | /// Clean up any resources being used.
17 | ///
18 | /// true if managed resources should be disposed; otherwise, false.
19 | protected override void Dispose(bool disposing)
20 | {
21 | if (disposing && (components != null))
22 | {
23 | components.Dispose();
24 | }
25 | base.Dispose(disposing);
26 | }
27 |
28 | #region Windows Form Designer generated code
29 |
30 | ///
31 | /// Required method for Designer support - do not modify
32 | /// the contents of this method with the code editor.
33 | ///
34 | private void InitializeComponent()
35 | {
36 | this.components = new System.ComponentModel.Container();
37 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ZedGraphSingleWindow));
38 | this.zedGraph_Single = new ZedGraph.ZedGraphControl();
39 | this.button_ClearData = new System.Windows.Forms.Button();
40 | this.timer_fresh = new System.Windows.Forms.Timer(this.components);
41 | this.button_ShowRange = new System.Windows.Forms.Button();
42 | this.textBox1 = new System.Windows.Forms.TextBox();
43 | this.label1 = new System.Windows.Forms.Label();
44 | this.button_pause = new System.Windows.Forms.Button();
45 | this.buttonSetting = new System.Windows.Forms.Button();
46 | this.SuspendLayout();
47 | //
48 | // zedGraph_Single
49 | //
50 | this.zedGraph_Single.IsShowHScrollBar = true;
51 | this.zedGraph_Single.IsShowVScrollBar = true;
52 | this.zedGraph_Single.Location = new System.Drawing.Point(0, 0);
53 | this.zedGraph_Single.Name = "zedGraph_Single";
54 | this.zedGraph_Single.ScrollGrace = 0D;
55 | this.zedGraph_Single.ScrollMaxX = 0D;
56 | this.zedGraph_Single.ScrollMaxY = 0D;
57 | this.zedGraph_Single.ScrollMaxY2 = 0D;
58 | this.zedGraph_Single.ScrollMinX = 0D;
59 | this.zedGraph_Single.ScrollMinY = 0D;
60 | this.zedGraph_Single.ScrollMinY2 = 0D;
61 | this.zedGraph_Single.Size = new System.Drawing.Size(522, 403);
62 | this.zedGraph_Single.TabIndex = 0;
63 | //
64 | // button_ClearData
65 | //
66 | this.button_ClearData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
67 | this.button_ClearData.Location = new System.Drawing.Point(560, 173);
68 | this.button_ClearData.Name = "button_ClearData";
69 | this.button_ClearData.Size = new System.Drawing.Size(63, 23);
70 | this.button_ClearData.TabIndex = 1;
71 | this.button_ClearData.Text = "清除数据";
72 | this.button_ClearData.UseVisualStyleBackColor = true;
73 | this.button_ClearData.Click += new System.EventHandler(this.button_ClearData_Click);
74 | //
75 | // timer_fresh
76 | //
77 | this.timer_fresh.Interval = 50;
78 | this.timer_fresh.Tick += new System.EventHandler(this.timer_fresh_Tick);
79 | //
80 | // button_ShowRange
81 | //
82 | this.button_ShowRange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
83 | this.button_ShowRange.Location = new System.Drawing.Point(560, 92);
84 | this.button_ShowRange.Name = "button_ShowRange";
85 | this.button_ShowRange.Size = new System.Drawing.Size(63, 23);
86 | this.button_ShowRange.TabIndex = 2;
87 | this.button_ShowRange.Text = "确认";
88 | this.button_ShowRange.UseVisualStyleBackColor = true;
89 | this.button_ShowRange.Click += new System.EventHandler(this.button_ShowRange_Click);
90 | //
91 | // textBox1
92 | //
93 | this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
94 | this.textBox1.ForeColor = System.Drawing.SystemColors.GrayText;
95 | this.textBox1.Location = new System.Drawing.Point(528, 44);
96 | this.textBox1.Name = "textBox1";
97 | this.textBox1.Size = new System.Drawing.Size(95, 21);
98 | this.textBox1.TabIndex = 3;
99 | this.textBox1.Text = "请输入X轴宽度";
100 | this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
101 | this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter);
102 | this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
103 | //
104 | // label1
105 | //
106 | this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
107 | this.label1.AutoSize = true;
108 | this.label1.Location = new System.Drawing.Point(528, 29);
109 | this.label1.Name = "label1";
110 | this.label1.Size = new System.Drawing.Size(95, 12);
111 | this.label1.TabIndex = 4;
112 | this.label1.Text = "0表示无宽度限制";
113 | //
114 | // button_pause
115 | //
116 | this.button_pause.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
117 | this.button_pause.Location = new System.Drawing.Point(560, 133);
118 | this.button_pause.Name = "button_pause";
119 | this.button_pause.Size = new System.Drawing.Size(63, 23);
120 | this.button_pause.TabIndex = 5;
121 | this.button_pause.Text = "暂停";
122 | this.button_pause.UseVisualStyleBackColor = true;
123 | this.button_pause.Click += new System.EventHandler(this.button_pause_Click);
124 | //
125 | // buttonSetting
126 | //
127 | this.buttonSetting.Location = new System.Drawing.Point(547, 358);
128 | this.buttonSetting.Name = "buttonSetting";
129 | this.buttonSetting.Size = new System.Drawing.Size(76, 23);
130 | this.buttonSetting.TabIndex = 6;
131 | this.buttonSetting.Text = "设置(无)";
132 | this.buttonSetting.UseVisualStyleBackColor = true;
133 | this.buttonSetting.Click += new System.EventHandler(this.buttonSetting_Click);
134 | //
135 | // ZedGraphSingleWindow
136 | //
137 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
138 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
139 | this.ClientSize = new System.Drawing.Size(635, 403);
140 | this.Controls.Add(this.buttonSetting);
141 | this.Controls.Add(this.button_pause);
142 | this.Controls.Add(this.label1);
143 | this.Controls.Add(this.textBox1);
144 | this.Controls.Add(this.button_ShowRange);
145 | this.Controls.Add(this.button_ClearData);
146 | this.Controls.Add(this.zedGraph_Single);
147 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
148 | this.Name = "ZedGraphSingleWindow";
149 | this.Text = "Graph";
150 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ZedGraph_SingleWindow_FormClosed);
151 | this.Load += new System.EventHandler(this.ZedGraph_SingleWindow_Load);
152 | this.Resize += new System.EventHandler(this.ZedGraph_SingleWindow_Resize);
153 | this.ResumeLayout(false);
154 | this.PerformLayout();
155 |
156 | }
157 |
158 | #endregion
159 |
160 | private ZedGraphControl zedGraph_Single;
161 | private Button button_ClearData;
162 | private Timer timer_fresh;
163 | private Button button_ShowRange;
164 | private TextBox textBox1;
165 | private Label label1;
166 | private Button button_pause;
167 | private Button buttonSetting;
168 | }
169 | }
--------------------------------------------------------------------------------
/Freescale_debug/ZedGraph_SingleWindow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 | using ZedGraph;
5 |
6 | namespace Freescale_debug
7 | {
8 | public delegate void SingleWindowClosedDelegate(int id);
9 | public delegate void SingleWindowLoadDelegate(ZedGraphSingleWindow window, int id);
10 |
11 | public partial class ZedGraphSingleWindow : Form
12 | {
13 | private readonly Color[] _colorLine =
14 | {
15 | Color.Green, Color.DodgerBlue, Color.Brown, Color.Chartreuse,
16 | Color.CornflowerBlue, Color.Red, Color.Yellow, Color.Gray
17 | };
18 |
19 | private PointPairList _listZed = new PointPairList();
20 | private readonly string curveName; //曲线命
21 | private bool isLoadHistory = false;
22 |
23 | private readonly int curveNumber; //曲线号
24 | private bool _pauseFlag = true;
25 | private double _valueXStart;
26 | private int _zedWidth;
27 |
28 | public ZedGraphSingleWindow(int id, CallObject coV, string name)
29 | {
30 | InitializeComponent();
31 |
32 | coV.ValueUpdatedEvent += co_UpdateCurveEvent;
33 | coV.PointListUpdateEvent += CoVOnPointListUpdateEvent;
34 | curveNumber = id;
35 | curveName = name;
36 | Text = curveName + @"——曲线" + (curveNumber + 1) + @"——" + @"飞思卡尔调试平台 V1.2.1";
37 | }
38 |
39 | public sealed override string Text
40 | {
41 | get { return base.Text; }
42 | set { base.Text = value; }
43 | }
44 |
45 | public bool PauseFlag
46 | {
47 | get { return _pauseFlag; }
48 | set { _pauseFlag = value; }
49 | }
50 |
51 | public event SingleWindowClosedDelegate SignalClosedEvent;
52 |
53 | public event SingleWindowLoadDelegate SignalLoadEvent;
54 |
55 | private void ZedGraph_SingleWindow_Load(object sender, EventArgs e)
56 | {
57 | InitzedGraph();
58 |
59 | if (SignalLoadEvent != null)
60 | SignalLoadEvent(this, curveNumber);
61 | }
62 |
63 | private void ZedGraph_SingleWindow_FormClosed(object sender, FormClosedEventArgs e)
64 | {
65 | if (SignalClosedEvent != null)
66 | SignalClosedEvent(curveNumber);
67 |
68 | DialogResult = DialogResult.OK;
69 | }
70 |
71 | private void ZedGraph_SingleWindow_Resize(object sender, EventArgs e)
72 | {
73 | zedGraph_Single.Location = new Point(10, 10);
74 | // Leave a small margin around the outside of the control
75 | zedGraph_Single.Size = new Size(ClientRectangle.Width - 100,
76 | ClientRectangle.Height - 20);
77 | }
78 |
79 | private void InitzedGraph()
80 | {
81 | var myPane = zedGraph_Single.GraphPane;
82 |
83 | myPane.Title.IsVisible = false;
84 | myPane.XAxis.Title.Text = "time";
85 | myPane.YAxis.Title.Text = "Value";
86 |
87 | //show grid
88 | myPane.XAxis.MajorGrid.IsVisible = true;
89 | myPane.YAxis.MajorGrid.IsVisible = true;
90 |
91 | // Align the Y axis labels so they are flush to the axis
92 | myPane.YAxis.Scale.Align = AlignP.Inside;
93 |
94 | // Fill the axis background with a gradient
95 | myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
96 |
97 | // OPTIONAL: Add a custom context menu item
98 | // OPTIONAL: Show tooltips when the mouse hovers over a point
99 | zedGraph_Single.IsShowPointValues = true;
100 | zedGraph_Single.PointValueEvent += MyPointValueHandler;
101 |
102 | zedGraph_Single.GraphPane.AddCurve(curveName, _listZed, _colorLine[curveNumber],
103 | SymbolType.None);
104 |
105 | refleshZedPane(zedGraph_Single);
106 | }
107 |
108 | private void refleshZedPane(ZedGraphControl zedGraph)
109 | {
110 | zedGraph.AxisChange();
111 | zedGraph.Invalidate();
112 | }
113 |
114 | ///
115 | /// Display customized tooltips when the mouse hovers over a point
116 | ///
117 | private string MyPointValueHandler(ZedGraphControl control, GraphPane pane,
118 | CurveItem curve, int iPt)
119 | {
120 | // Get the PointPair that is under the mouse
121 | var pt = curve[iPt];
122 |
123 | return curve.Label.Text + " is " + pt.Y.ToString("f2") + " units at " + pt.X.ToString("f1") + " days";
124 | }
125 |
126 | public void co_UpdateCurveEvent(double x, double y)
127 | {
128 | if (isLoadHistory)
129 | {
130 | isLoadHistory = false;
131 | _listZed.RemoveRange(0, _listZed.Count);
132 | }
133 |
134 | if (!_pauseFlag)
135 | {
136 | if (_zedWidth == 0)
137 | {
138 | //x轴无限制
139 | _listZed.Add(_valueXStart++, y);
140 | }
141 | else
142 | {
143 | //x轴宽度有限制
144 | if (_valueXStart < _zedWidth)
145 | {
146 | _listZed.Add(_valueXStart++, y);
147 | }
148 | else
149 | {
150 | zedGraph_Single.GraphPane.XAxis.Scale.Min = (int) _valueXStart - _zedWidth < 0
151 | ? 0
152 | : (int) _valueXStart - _zedWidth;
153 | zedGraph_Single.GraphPane.XAxis.Scale.Max = (int) _valueXStart + 0.2*_zedWidth;
154 | _listZed.Add(_valueXStart++, y);
155 | }
156 | }
157 |
158 | refleshZedPane(zedGraph_Single);
159 | }
160 | }
161 |
162 | private void CoVOnPointListUpdateEvent(PointPairList points)
163 | {
164 | isLoadHistory = true;
165 |
166 | foreach (PointPair t in points)
167 | {
168 | _listZed.Add(t);
169 | }
170 |
171 | refleshZedPane(zedGraph_Single);
172 | }
173 |
174 | private void button_ClearData_Click(object sender, EventArgs e)
175 | {
176 | _listZed.RemoveRange(0, _listZed.Count);
177 | _valueXStart = 0;
178 | zedGraph_Single.GraphPane.XAxis.Scale.MinAuto = true;
179 | zedGraph_Single.GraphPane.XAxis.Scale.MaxAuto = true;
180 |
181 | zedGraph_Single.GraphPane.YAxis.Scale.MinAuto = true;
182 | zedGraph_Single.GraphPane.YAxis.Scale.MaxAuto = true;
183 |
184 | refleshZedPane(zedGraph_Single);
185 | }
186 |
187 | private void timer_fresh_Tick(object sender, EventArgs e)
188 | {
189 | refleshZedPane(zedGraph_Single);
190 | }
191 |
192 | private void textBox1_Leave(object sender, EventArgs e)
193 | {
194 | var txtbox = sender as TextBox;
195 | if (txtbox != null && txtbox.Text.Trim() == @"")
196 | {
197 | txtbox.Text = @"请输入X轴宽度";
198 | txtbox.ForeColor = Color.Gray;
199 | }
200 | }
201 |
202 | private void textBox1_Enter(object sender, EventArgs e)
203 | {
204 | var txtbox = sender as TextBox;
205 | if (txtbox != null && txtbox.Text.Trim() == @"请输入X轴宽度")
206 | {
207 | txtbox.Text = @"";
208 | txtbox.ForeColor = Color.Black;
209 | }
210 | }
211 |
212 | private void button_ShowRange_Click(object sender, EventArgs e)
213 | {
214 | //对x的范围进行更改
215 | if (textBox1.Text.Trim() != @"请输入X轴宽度")
216 | {
217 | _zedWidth = Convert.ToInt16(textBox1.Text);
218 | }
219 | else
220 | MessageBox.Show(@"无数字输入,请重新输入");
221 | }
222 |
223 | private void button_pause_Click(object sender, EventArgs e)
224 | {
225 | if (button_pause.Text == @"暂停")
226 | {
227 | _pauseFlag = true;
228 | button_pause.Text = @"继续";
229 | }
230 | else
231 | {
232 | _pauseFlag = false;
233 | button_pause.Text = @"暂停";
234 | }
235 | }
236 |
237 | private void buttonSetting_Click(object sender, EventArgs e)
238 | {
239 |
240 | }
241 | }
242 |
243 | //进行窗体间传参的公共接口
244 | public delegate void ValueUpdatedHandler(double x, double y);
245 |
246 | public delegate void PointListUpdateHander(PointPairList points);
247 |
248 | public class CallObject
249 | {
250 | public event ValueUpdatedHandler ValueUpdatedEvent;
251 |
252 | public event PointListUpdateHander PointListUpdateEvent;
253 |
254 | public void CallEvent(double x, double y)
255 | {
256 | var onValueUpdatedEvent = ValueUpdatedEvent;
257 | if (onValueUpdatedEvent != null) onValueUpdatedEvent(x, y);
258 | }
259 |
260 | public void CallPointPairEvent(PointPairList points)
261 | {
262 | var onValueUpdatedEvent = PointListUpdateEvent;
263 | if (onValueUpdatedEvent != null) onValueUpdatedEvent(points);
264 | }
265 | }
266 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SmartcarPlatform [](https://travis-ci.com/potterhere/SmartCarPlatform)
2 | 智能车调试平台,主要为了解决普通智能车参数调试效率低的问题,在此基础上提出的一个解决方案。
3 |
4 | 
5 |
6 | **主要功能:**
7 |
8 | - 实时绘制运行数据、显示变量数值
9 | - 修改PID参数
10 | - 修改自定义参数
11 | - 绘制CCD图像(最大支持三个CCD,单个CCD数据大小1*128)
12 | - **绘制摄像头图像(目前仅支持分辨率80*60)**
13 |
14 | **Todo:**
15 |
16 | - [ ] 代码重构,优化软件结构
17 | - [ ] 数据分析(模仿Mission Planner的Log分析)
18 | - [ ] 可调用自定义算法
19 | - [x] 优化调试方法(如Log4Net控件等)
20 |
21 |
22 | **对应的下位机程序见Github:[K60以及KL26](https://github.com/potterhere/Freescale_K60-KL26_NRF),使用NRF进行通讯**
23 |
24 | 上位机与下位机如何配置、使用,请参考:[智能车调试平台使用手册.pdf](./智能车调试平台使用手册.pdf)
25 |
--------------------------------------------------------------------------------
/TestResults/6c960e3f-1116-4806-b074-034ccbb003ff/MY_MY-PC 2016-03-16 16_09_41.coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/TestResults/6c960e3f-1116-4806-b074-034ccbb003ff/MY_MY-PC 2016-03-16 16_09_41.coverage
--------------------------------------------------------------------------------
/智能车调试平台使用手册.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/智能车调试平台使用手册.pdf
--------------------------------------------------------------------------------
/通讯格式.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sudouble/SmartCarPlatform/a40e60b0e71dda96117a2303510e3b65667c3802/通讯格式.doc
--------------------------------------------------------------------------------