From b0159737b33eb0e527c98532e901744a656897a6 Mon Sep 17 00:00:00 2001 From: jimmy hu <60071jimmy@gmail.com> Date: Sun, 12 May 2019 22:01:17 +0800 Subject: [PATCH] Add OpenGLTest Add OpenGLTest --- .../OpenGLTest/UartOscilloscope.sln | 28 + .../OpenGLTest/UartOscilloscope/App.config | 6 + .../CSharpFiles/CommandClass.cs | 73 ++ .../CSharpFiles/CommandDatabase.cs | 102 ++ .../CSharpFiles/CommandParser.cs | 22 + .../CSharpFiles/ComportList.cs | 69 ++ .../CSharpFiles/DataProcessing.cs | 18 + .../UartOscilloscope/CSharpFiles/DataQueue.cs | 132 +++ .../UartOscilloscope/CSharpFiles/Debug.cs | 46 + .../CSharpFiles/DebugVariables.cs | 184 +++ .../CSharpFiles/ErrorCodeMessage.cs | 90 ++ .../UartOscilloscope/CSharpFiles/FileIO.cs | 71 ++ .../CSharpFiles/OpenGLExtension.cs | 13 + .../OscilloscopeFunctionVariable.cs | 47 + .../CSharpFiles/QueueDataGraphic.cs | 123 ++ .../CSharpFiles/TestingType.cs | 66 ++ .../CSharpFiles/TimingControl.cs | 16 + .../CSharpFiles/UARTConnection.cs | 193 ++++ .../CSharpFiles/UARTConnectionConstVal.cs | 34 + .../CSharpFiles/VersionInfo.cs | 26 + .../CSharpFiles/WaveDataStructure.cs | 69 ++ .../CSharpFiles/WorkingMode.cs | 31 + .../UartOscilloscope/ClassDiagram1.cd | 2 + .../UartOscilloscope/Form1.Designer.cs | 287 +++++ .../OpenGLTest/UartOscilloscope/Form1.cs | 1025 +++++++++++++++++ .../OpenGLTest/UartOscilloscope/Form1.resx | 126 ++ .../UartOscilloscope/Form2.Designer.cs | 135 +++ .../OpenGLTest/UartOscilloscope/Form2.cs | 39 + .../OpenGLTest/UartOscilloscope/Form2.resx | 120 ++ .../UartOscilloscope/Form3.Designer.cs | 120 ++ .../OpenGLTest/UartOscilloscope/Form3.cs | 34 + .../OpenGLTest/UartOscilloscope/Form3.resx | 123 ++ .../UartOscilloscope/Form4.Designer.cs | 126 ++ .../OpenGLTest/UartOscilloscope/Form4.cs | 106 ++ .../OpenGLTest/UartOscilloscope/Form4.resx | 120 ++ .../UartOscilloscope/Form5.Designer.cs | 536 +++++++++ .../OpenGLTest/UartOscilloscope/Form5.cs | 69 ++ .../OpenGLTest/UartOscilloscope/Form5.resx | 123 ++ .../OpenGLTest/UartOscilloscope/Program.cs | 22 + .../Properties/AssemblyInfo.cs | 36 + .../Properties/Resources.Designer.cs | 63 + .../Properties/Resources.resx | 117 ++ .../Properties/Settings.Designer.cs | 26 + .../Properties/Settings.settings | 7 + .../OpenGLTest/UartOscilloscope/README.md | 22 + .../UartOscilloscope/UartOscilloscope.csproj | 159 +++ .../UartOscilloscope/VersionInfo.md | 31 + .../OpenGLTest/UartOscilloscope/WaveGraph.cs | 12 + .../CSharpFiles/DataProcessingTests.cs | 46 + .../UARTConnectionConstValTests.cs | 41 + .../CSharpFiles/WaveDataStructureTests.cs | 120 ++ .../Properties/AssemblyInfo.cs | 36 + .../UartOscilloscopeTests.csproj | 91 ++ 53 files changed, 5379 insertions(+) create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope.sln create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/App.config create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandClass.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandDatabase.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandParser.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ComportList.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataProcessing.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataQueue.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/Debug.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DebugVariables.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ErrorCodeMessage.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/FileIO.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OpenGLExtension.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OscilloscopeFunctionVariable.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/QueueDataGraphic.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TestingType.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TimingControl.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnection.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnectionConstVal.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/VersionInfo.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WaveDataStructure.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WorkingMode.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/ClassDiagram1.cd create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Program.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/AssemblyInfo.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.resx create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.Designer.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.settings create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/README.md create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/UartOscilloscope.csproj create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/VersionInfo.md create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscope/WaveGraph.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/DataProcessingTests.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/UARTConnectionConstValTests.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/WaveDataStructureTests.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/Properties/AssemblyInfo.cs create mode 100644 VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/UartOscilloscopeTests.csproj diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope.sln b/VisualStudioProjects/OpenGLTest/UartOscilloscope.sln new file mode 100644 index 0000000..801cf7d --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UartOscilloscope", "UartOscilloscope\UartOscilloscope.csproj", "{8D89102B-2B1F-43D5-83C2-DA86889BA3D7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UartOscilloscopeTests", "UartOscilloscopeTests\UartOscilloscopeTests.csproj", "{7EC5AE58-596E-4960-8DFC-BBBE353B1F7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7}.Release|Any CPU.Build.0 = Release|Any CPU + {7EC5AE58-596E-4960-8DFC-BBBE353B1F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7EC5AE58-596E-4960-8DFC-BBBE353B1F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7EC5AE58-596E-4960-8DFC-BBBE353B1F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7EC5AE58-596E-4960-8DFC-BBBE353B1F7D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/App.config b/VisualStudioProjects/OpenGLTest/UartOscilloscope/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandClass.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandClass.cs new file mode 100644 index 0000000..d1b9a0c --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandClass.cs @@ -0,0 +1,73 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * CommandClass.cs * + * 本檔案建立程式指令模式下指令單元物件 * + ******************************************************************** + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入UartOscilloscope命名空間 + class CommandClass // CommandClass指令類別 + { // 進入CommandClass指令類別 + private int CommandID; // 宣告指令編號 + private string CommandName; // 宣告指令名稱 + private string ChineseDescription; // 宣告指令中文描述 + private string EnglishDescription; // 宣告指令英文描述 + private Task task; // 宣告指令工作 + /// + /// CommandClass建構子 + /// + /// 為指令編號 + /// 為指令名稱 + /// 為指令中文敘述 + /// 為指令英文敘述 + /// 為指令工作 + public CommandClass(int CommandID, string CommandName, string ChineseDescription, string EnglishDescription, Task task) + // CommandClass constructor, CommandClass建構子 + { // CommandClass constructor start, 進入CommandClass建構子 + + } // CommandClass constructor end, 結束CommandClass建構子 + + /// + /// CommandClass建構子 + /// + /// 為指令編號 + /// 為指令名稱 + /// 為指令中文敘述 + /// 為指令工作 + public CommandClass(int CommandID, string CommandName, string ChineseDescription, Task task) + // CommandClass建構子 + { // 進入CommandClass建構子 + this.CommandID = CommandID; // 初始化指令編號 + this.CommandName = CommandName; // 初始化指令名稱 + this.ChineseDescription = ChineseDescription; // 初始化指令中文描述 + this.EnglishDescription = ""; // 初始化指令英文描述 + this.task = task; // 初始化指令工作 + } // 結束CommandClass建構子 + + public CommandClass(int CommandID, string CommandName, Task task) + // CommandClass建構子 + { // 進入CommandClass建構子 + this.CommandID = CommandID; // 初始化指令編號 + this.CommandName = CommandName; // 初始化指令名稱 + this.ChineseDescription = ""; // 初始化指令中文描述 + this.EnglishDescription = ""; // 初始化指令英文描述 + this.task = task; // 初始化指令工作 + } // 結束CommandClass建構子 + /// + /// 覆寫ToString方法可回傳指令名稱 + /// + /// 回傳值為指令名稱 + public override string ToString() // 覆寫ToString方法 + { // 進入覆寫ToString方法 + return CommandName; // 回傳指令名稱 + } // 結束覆寫ToString方法 + } // 結束CommandClass指令類別 +} // 結束UartOscilloscope命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandDatabase.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandDatabase.cs new file mode 100644 index 0000000..5dd8145 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandDatabase.cs @@ -0,0 +1,102 @@ +using System; // 使用System函式庫 +using System.Collections.Generic; // 使用System.Collections.Generic函式庫 +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入UartOscilloscope命名空間 + class CommandDatabase // CommandDatabase類別 + { // 進入CommandDatabase類別 + public readonly static CommandDatabase Instance = new CommandDatabase();// 設計CommandDatabase存取介面 + private List CommandSet = new List(); // 宣告CommandSet + /// + /// CommandDatabase類別 + /// + public CommandDatabase() // CommandDatabase建構子 + { // 進入CommandDatabase建構子 + CreateCommandSet(); // 呼叫CreateCommandSet方法 + } // 結束CommandDatabase建構子 + + /// + /// CreateCommandSet方法用於建立命令集合 + /// + public void CreateCommandSet() + { + CommandSet.Add(new CommandClass( // Add command, 新增指令 + 1, // 指令編號 + "connect", // 指令名稱 + new System.Threading.Tasks.Task(() => // 建立指令工作 + { // 進入指令工作內容 + + }))); // 結束指令工作內容 + CommandSet.Add(new CommandClass( // 新增指令 + 2, // 指令編號 + "help", // 指令名稱 + new System.Threading.Tasks.Task(() => // 建立指令工作 + { // 進入指令工作內容 + + }))); // 結束指令工作內容 + CommandSet.Add(new CommandClass( // 新增指令 + 3, // 指令編號 + "lscom", // 指令名稱 + new System.Threading.Tasks.Task(() => // 建立指令工作 + { // 進入指令工作內容 + UARTConnection UARTConnection1; // 宣告UARTConnection1物件 + UARTConnection1 = new UARTConnection(0, false); + Console.WriteLine(UARTConnection1.GetComportList().ToString()); + }))); // 結束指令工作內容 + CommandSet.Add(new CommandClass( // 新增指令 + 3, // 指令編號 + "version", // 指令名稱 + new System.Threading.Tasks.Task(() => // 建立指令工作 + { // 進入指令工作內容 + Console.WriteLine(VersionInfo.Instance.GetProgramVersion()); + }))); // 結束指令工作內容 + } + /// + /// 顯示CommandSet指令列表 + /// + /// + public override string ToString() // 覆寫ToString方法 + { // 進入覆寫ToString方法 + string OutputStr = ""; // 宣告輸出字串 + foreach (CommandClass Item in this.CommandSet) // 以foreach迴圈依序取出指令物件 + { // 進入foreach敘述 + OutputStr = OutputStr + Item.ToString() + '\t'; // 生成輸出字串 + } // 結束foreach敘述 + return OutputStr; // 回傳輸出字串 + } // 結束覆寫ToString方法 + /// + /// GetCommandSet方法用於取得命令集合中指令列表 + /// + /// + public string[] GetCommandSet() // GetCommandSet方法 + { // 進入GetCommandSet方法 + string[] OutputStrArray; // 宣告輸出字串陣列 + OutputStrArray = new string[] { }; // 初始化字串陣列 + int OutputStrArraySize = CommandSet.Count; // 宣告OutputStrArraySize,用於記錄輸出陣列大小 + Array.Resize(ref OutputStrArray, OutputStrArraySize); // 調整字串陣列大小 + int Index = 0; // 宣告索引值用於存取陣列元素 + foreach(CommandClass Item in this.CommandSet) // 取出命令集合中指令 + { // 進入foreach敘述 + OutputStrArray[Index] = Item.ToString(); // 填入資料至輸出陣列 + Index = Index + 1; // 遞增索引值 + } // 結束foreach敘述 + return OutputStrArray; // 回傳字串陣列 + } // 結束GetCommandSet方法 + /// + /// GetCommandSetCount方法用於取得命令集合指令數量 + /// + /// + private int GetCommandSetCount() // GetCommandSetCount方法 + { // 進入GetCommandSetCount方法 + return this.CommandSet.Count; // 回傳命令集合指令數量 + } // 結束GetCommandSetCount方法 + private string GetCommandHelp() // GetCommandHelp方法 + { // 進入GetCommandHelp方法 + string OutputStr = ""; + return OutputStr; + } // 結束GetCommandHelp方法 + } // 結束CommandDatabase類別 +} // 結束UartOscilloscope命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandParser.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandParser.cs new file mode 100644 index 0000000..2211d6d --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/CommandParser.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入UartOscilloscope命名空間 + /// + /// CommandParser類別用於建立指令語法分析器 + /// + class CommandParser // CommandParser類別 + { // 進入CommandParser類別 + + /// + /// CommandParser建構子 + /// + public CommandParser() // CommandParser建構子 + { // 進入CommandParser建構子 + + } // 結束CommandParser建構子 + } // 結束CommandParser類別 +} // 結束UartOscilloscope命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ComportList.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ComportList.cs new file mode 100644 index 0000000..0430805 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ComportList.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入UartOscilloscope命名空間 + /// + /// ComportList類別單純為一字串陣列容器,可透過UpdateComportList方法新增Comport名稱 + /// + public class ComportList // ComportList類別 + { // 進入ComportList類別 + private string[] Name; // 宣告Name字串陣列 + /// + /// ComportList建構子 + /// + /// + public ComportList(string[] Name) // ComportList建構子 + { // 進入ComportList建構子 + this.Name = Name; // 初始化內部物件 + } // 結束ComportList建構子 + /// + /// GetComportList方法用於取得Comport列表 + /// + /// + public string[] GetComportList() // GetComportList方法 + { // 進入GetComportList方法 + return Name; // 回傳Name + } // 結束GetComportList方法 + /// + /// UpdateComportList用於更新ComportList內部物件資料 + /// + /// + public void UpdateComportList(string[] ComportList) // UpdateComportList方法 + { // 進入UpdateComportList方法 + Name = ComportList; // 填入資料 + } // 結束UpdateComportList方法 + /// + /// 複寫ToString方法,以foreach依序列出comport + /// + /// + public override string ToString() // 覆寫ToString方法 + { // 進入覆寫ToString方法 + string OutputString = ""; // 宣告OutputString(輸出字串結果) + foreach (string item in Name) // 以foreach依序列出Name內容 + { // 進入foreach敘述 + OutputString = OutputString + item + '\n'; // 填入內容至輸出字串 + } // 結束foreach敘述 + return OutputString; // 回傳OutputString + } // 結束覆寫ToString方法 + + /// + /// IsComportListNull方法用於檢測ComportList是否為空 + /// + /// 若未偵測到Comport回傳true,否則回傳false + public bool IsComportListNull() // IsComportListNull方法 + { // 進入IsComportListNull方法 + if(Name.Length == 0) // 若未偵測到Comport + { // 進入if敘述 + return true; // 回傳true + } // 結束if敘述 + else // 若偵測到Comport + { // 進入else敘述 + return false; // 回傳false + } // 結束else敘述 + } // 結束IsComportListNull方法 + } // 結束ComportList類別 +} // 結束UartOscilloscope命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataProcessing.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataProcessing.cs new file mode 100644 index 0000000..1c184c1 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataProcessing.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入命名空間 + public class DataProcessing // DataProcessing類別 + { // 進入DataProcessing類別 + public char[] String2CharArray(string InputData) // String2CharArray方法 + { // 進入String2CharArray方法 + char[] OutputData = InputData.ToCharArray(); // 宣告OutputData + return OutputData; // 回傳轉換結果 + } // 結束String2CharArray方法 + } // 結束DataProcessing類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataQueue.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataQueue.cs new file mode 100644 index 0000000..d122482 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DataQueue.cs @@ -0,0 +1,132 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * DataQueue.cs * + * 本檔案建立繪圖資料佇列單元物件 * + ******************************************************************** + */ + +using System; // Using System library +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QueueDataGraphic.CSharpFiles +{ // namespace start, 進入命名空間 + class DataQueue // DataQueue class, DataQueue類別 + { // DataQueue class start, 進入DataQueue類別 + /// + /// GraphicData is the queue for storing the graphic data. + /// GraphicData佇列用於儲存繪圖資料 + /// + private Queue GraphicData; // GraphicData object, GraphicData佇列物件 + + /// + /// DataQueueName is the name of DataQueue. + /// DataQueue名稱 + /// + private string DataQueueName; // DataQueueName string, DataQueueName字串 + + /// + /// GraphicDataQueueMax is the max number of count of GraphData elements. + /// GraphicDataQueueMax為GraphData物件數量上限 + /// + private int GraphicDataQueueMax; // GraphicDataQueueMax variable, GraphicDataQueueMax變數 + + /// + /// DataQueue constructor, DataQueue建構子 + /// + /// 為DataQueue名稱 + public DataQueue(string NewDataQueueName) // DataQueue constructor, DataQueue建構子 + { // DataQueue constructor start, 進入DataQueue建構子 + this.GraphicData = new Queue(); // initialize GraphicData, 初始化GraphicData物件 + this.DataQueueName = NewDataQueueName; // initialize DataQueueName, 初始化DataQueueName字串 + this.GraphicDataQueueMax = 100; // initialize GraphicDataQueueMax, 初始化GraphicDataQueueMax變數 + } // DataQueue constructor end, 結束DataQueue建構子 + + /// + /// DataQueue constructor with NewGraphicDataQueueMax, 具NewGraphicDataQueueMax輸入之DataQueue建構子 + /// + /// 為DataQueue名稱 + /// 為GraphicDataQueue資料儲存數量上限值 + public DataQueue(string NewDataQueueName, int NewGraphicDataQueueMax) // DataQueue constructor, DataQueue建構子 + { // DataQueue constructor start, 進入DataQueue建構子 + this.GraphicData = new Queue(); // initialize GraphicData, 初始化GraphicData物件 + this.DataQueueName = NewDataQueueName; // initialize DataQueueName, 初始化DataQueueName字串 + this.GraphicDataQueueMax = NewGraphicDataQueueMax; // initialize GraphicDataQueueMax, 初始化GraphicDataQueueMax變數 + } // DataQueue constructor end, 結束DataQueue建構子 + + + /// + /// SetGraphicDataQueueMax method would update GraphicDataQueueMax variable. + /// SetGraphicDataQueueMax方法用於更新GraphicDataQueueMax變數 + /// + /// 為GraphicDataQueueMax更新值 + public void SetGraphicDataQueueMax(int NewGraphicDataQueueMax) // SetGraphicDataQueueMax method, SetGraphicDataQueueMax方法 + { // SetGraphicDataQueueMax method start, 進入SetGraphicDataQueueMax方法 + this.GraphicDataQueueMax = NewGraphicDataQueueMax; // Update GraphicDataQueueMax variable, 更新GraphicDataQueueMax變數 + if (Debug.DebugMode == true) // if DebugMode is true, 若DebugMode為true + { // if statement start, 進入if敘述 + Console.WriteLine("GraphicDataQueueMax is updated, it's value is " + this.GraphicDataQueueMax); + // Write out debug info, 輸出偵錯訊息 + } // if statement end, 結束if敘述 + } // SetGraphicDataQueueMax method end, 結束SetGraphicDataQueueMax方法 + + /// + /// GetGraphicDataQueueMax return GraphicDataQueueMax. + /// GetGraphicDataQueueMax方法回傳GraphicDataQueueMax變數 + /// + /// GraphicDataQueueMax + public int GetGraphicDataQueueMax() // GetGraphicDataQueueMax method, GetGraphicDataQueueMax方法 + { // GetGraphicDataQueueMax method start, 進入GetGraphicDataQueueMax方法 + return this.GraphicDataQueueMax; // return GraphicDataQueueMax, 回傳GraphicDataQueueMax + } // GetGraphicDataQueueMax method end, 結束GetGraphicDataQueueMax方法 + + /// + /// RemovingOverload method would remove the data when GraphicData.count > GraphicDataQueueMax + /// RemovingOverload用於清除多於物件數量上限之資料 + /// + private void RemovingOverload() // RemovingOverload method, RemovingOverload方法 + { // RemovingOverload method start, 進入RemovingOverload方法 + while(GraphicData.Count > GraphicDataQueueMax) // when GraphicData.Count more than GraphicDataQueueMax, 當有過多資料 + { // while loop start, 進入while迴圈 + GraphicData.Dequeue(); // clear GraphicData data, 清除GraphicData資料 + } // while loop end, 結束while迴圈 + GC.Collect(); // forces an immediate garbage collection of all generations, 強制立即執行所有層代的記憶體回收 + return; // return, 結束方法 + } // RemovingOverload method end, 結束RemovingOverload方法 + + /// + /// AddData method would add new data into queue. + /// AddData方法用於存入新資料至Queue + /// + /// 欲紀錄至Queue之資料 + public void AddData(object InputData) // AddData method, AddData方法 + { // AddData method start, 進入AddData方法 + GraphicData.Enqueue(InputData); // add data into GraphicData, 新增資料至GraphicData佇列 + RemovingOverload(); // call RemovingOverload method, 呼叫RemovingOverload方法 + } // AddData method end, 結束AddData方法 + + /// + /// GetGraphicData method would return the GraphicData object. + /// GetGraphicData方法用於回傳GraphicData物件 + /// + /// GraphicData object, GraphicData物件 + public Queue GetGraphicData() // GetGraphicData method, GetGraphicData方法 + { // GetGraphicData method start, 進入GetGraphicData方法 + return GraphicData; // return GraphicData object, 回傳GraphicData物件 + } // GetGraphicData method end, 結束GetGraphicData方法 + + /// + /// GetDataQueueName method would return DataQueueName. + /// GetDataQueueName方法用於回傳DataQueueName + /// + /// DataQueueName + public string GetDataQueueName() // GetDataQueueName method, GetDataQueueName方法 + { // GetDataQueueName method start, 進入GetDataQueueName方法 + return this.DataQueueName; // return DataQueueName, 回傳DataQueueName + } // GetDataQueueName method end, 結束GetDataQueueName方法 + + } // DataQueue class end, 結束DataQueue類別 +} // namespace end, 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/Debug.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/Debug.cs new file mode 100644 index 0000000..60d2094 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/Debug.cs @@ -0,0 +1,46 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * Debug.cs * + * 本檔案用於宣告偵錯相關工具物件 * + ******************************************************************** + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QueueDataGraphic.CSharpFiles +{ // namespace start, 進入命名空間 + /// + /// Debug class + /// + class Debug // Debug class, Debug類別 + { // Debug class start, 進入Debug類別 + /// + /// Debug class instance + /// + public readonly static Debug Instance = new Debug(); // Debug class instance, 設計Debug存取介面 + + /// + /// DebugMode would be setted "true" during debugging. + /// 在偵錯模式中將DebugMode設為true + /// + public readonly static bool DebugMode = true; // DebugMode variable + + /// + /// ShowQueueData method could print the data in InputQueue. + /// ShowQueueData用於顯示輸入Queue的資料 + /// + /// 欲顯示內容之Queue + public void ShowQueueData(Queue InputQueue) // ShowQueueData method, ShowQueueData方法 + { // ShowQueueData method start, 進入ShowQueueData方法 + foreach (var item in InputQueue) // get each element in InputQueue, 取得InputQueue各項元素 + { // foreach statement start, 進入foreach敘述 + Console.WriteLine(item.ToString()); // show element data, 顯示元素資料 + } // foreach statement end, 結束foreach敘述 + } // ShowQueueData method end, 結束ShowQueueData方法 + } // Debug class eud, 結束Debug類別 +} // namespace end, 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DebugVariables.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DebugVariables.cs new file mode 100644 index 0000000..8c85f60 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/DebugVariables.cs @@ -0,0 +1,184 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // 命名空間為UartOscilloscope +{ // 進入命名空間 + /** DebugVariables類別宣告用於記錄事件發生次數或方法執行次數的變數及方法 + * 各項變數皆具有重置(Reset)、設定(Set,遞增1)與取得值(Get)方法, + * 方法名稱命名為: + * 重置(Reset)-Reset_[變數名稱] + * 設定(Set,遞增1)-Set_[變數名稱] + * 取得值(Get)-Get_[變數名稱] + * 變數條列如下: + * button1_Click_Runtimes + * button2_Click_Runtimes + * button3_Click_Runtimes + * Transmission_Setting_Click_Runtimes + * User_Interface_Setting_Click_Runtimes + * list_SerialPort_Runtimes + * UARTConnectHandle_Runtimes + * comport_DataReceived_Runtimes + * DisplayText_Runtimes + **/ + public class DebugVariables // DebugVariables類別 + { // 進入DebugVariables類別 + public struct Debug_Login_Account_struct // 宣告Debug_Login_Account_struct全域結構 + { // 進入Debug_Login_Account_struct結構設定 + public string Debug_Login_Account, Debug_Login_Password; // 在Debug_Login_Account_struct結構中有兩項字串(Account與Password) + public Debug_Login_Account_struct(string p1, string p2) // 設定結構成員 + { // 設定結構成員 + Debug_Login_Account = p1; // 設定結構成員 + Debug_Login_Password = p2; // 設定結構成員 + } // 設定結構成員完成 + } // 結束Debug_Login_Account_struct結構設定 + public static Debug_Login_Account_struct Debug_Account1 = // 宣告Debug_Account1靜態全域除錯帳戶1 + new Debug_Login_Account_struct("Debug", "debug"); // 設定Debug_Account1除錯帳戶1帳號密碼 + + private static uint button1_Click_Runtimes; // 宣告button1_Click_Runtimes私有靜態變數,記錄button1_Click方法執行次數 + private static void Reset_button1_Click_Runtimes() // Reset_button1_Click_Runtimes方法,用於重置button1_Click_Runtimes計數變數為0 + { // 進入Reset_button1_Click_Runtimes方法 + button1_Click_Runtimes = 0; // 將button1_Click_Runtimes變數重置為0 + } // 結束Reset_button1_Click_Runtimes方法 + public static void Set_button1_Click_Runtimes() // Set_button1_Click_Runtimes方法 + { // 進入Set_button1_Click_Runtimes方法 + button1_Click_Runtimes = button1_Click_Runtimes + 1; // 遞增button1_Click_Runtimes變數 + } // 結束Set_button1_Click_Runtimes方法 + public static uint Get_button1_Click_Runtimes() // Get_button1_Click_Runtimes方法 + { // 進入Get_button1_Click_Runtimes方法 + return button1_Click_Runtimes; // 取得button1_Click_Runtimes變數數值 + } // 結束Get_button1_Click_Runtimes方法 + + private static uint button2_Click_Runtimes; // 宣告button2_Click_Runtimes私有靜態變數,記錄button2_Click方法執行次數 + private static void Reset_button2_Click_Runtimes() // Reset_button2_Click_Runtimes方法,用於重置button2_Click_Runtimes計數變數為0 + { // 進入Reset_button2_Click_Runtimes方法 + button2_Click_Runtimes = 0; // 將button2_Click_Runtimes變數重置為0 + } // 結束Reset_button2_Click_Runtimes方法 + public static void Set_button2_Click_Runtimes() // Set_button2_Click_Runtimes方法 + { // 進入Set_button2_Click_Runtimes方法 + button2_Click_Runtimes = button2_Click_Runtimes + 1; // 遞增button2_Click_Runtimes變數 + } // 結束Set_button2_Click_Runtimes方法 + public static uint Get_button2_Click_Runtimes() // Get_button2_Click_Runtimes方法 + { // 進入Get_button2_Click_Runtimes方法 + return button2_Click_Runtimes; // 取得button2_Click_Runtimes變數數值 + } // 結束Get_button2_Click_Runtimes方法 + + private static uint button3_Click_Runtimes; // 宣告button3_Click_Runtimes私有靜態變數,記錄button3_Click方法執行次數 + private static void Reset_button3_Click_Runtimes() // Reset_button3_Click_Runtimes方法,用於重置button3_Click_Runtimes計數變數為0 + { // 進入Reset_button3_Click_Runtimes方法 + button3_Click_Runtimes = 0; // 將button3_Click_Runtimes變數重置為0 + } // 結束Reset_button3_Click_Runtimes方法 + public static void Set_button3_Click_Runtimes() // Set_button3_Click_Runtimes方法 + { // 進入Set_button3_Click_Runtimes方法 + button3_Click_Runtimes = button3_Click_Runtimes + 1; // 遞增button3_Click_Runtimes變數 + } // 結束Set_button3_Click_Runtimes方法 + public static uint Get_button3_Click_Runtimes() // Get_button3_Click_Runtimes方法 + { // 進入Get_button3_Click_Runtimes方法 + return button3_Click_Runtimes; // 取得button3_Click_Runtimes變數數值 + } // 結束Get_button3_Click_Runtimes方法 + + private static uint Transmission_Setting_Click_Runtimes; + // 宣告Transmission_Setting_Click_Runtimes私有靜態變數,記錄設定_傳輸設定ToolStripMenuItem_Click方法執行次數 + private static void Reset_Transmission_Setting_Click_Runtimes() // Reset_Transmission_Setting_Click_Runtimes方法,用於重置Transmission_Setting_Click_Runtimes計數變數為0 + { // 進入Reset_Transmission_Setting_Click_Runtimes方法 + Transmission_Setting_Click_Runtimes = 0; // 將Transmission_Setting_Click_Runtimes變數重置為0 + } // 結束Reset_Transmission_Setting_Click_Runtimes方法 + public static void Set_Transmission_Setting_Click_Runtimes() // Set_Transmission_Setting_Click_Runtimes方法 + { // 進入Set_Transmission_Setting_Click_Runtimes方法 + Transmission_Setting_Click_Runtimes = Transmission_Setting_Click_Runtimes + 1; + // 遞增Transmission_Setting_Click_Runtimes變數 + } // 結束Set_Transmission_Setting_Click_Runtimes方法 + public static uint Get_Transmission_Setting_Click_Runtimes() // Get_Transmission_Setting_Click_Runtimes方法 + { // 進入Get_Transmission_Setting_Click_Runtimes方法 + return Transmission_Setting_Click_Runtimes; // 取得Transmission_Setting_Click_Runtimes變數數值 + } // 結束Get_Transmission_Setting_Click_Runtimes方法 + + private static uint User_Interface_Setting_Click_Runtimes; + // 宣告User_Interface_Setting_Click_Runtimes私有靜態變數,記錄設定_介面設定ToolStripMenuItem_Click方法執行次數 + private static void Reset_User_Interface_Setting_Click_Runtimes() // Reset_User_Interface_Setting_Click_Runtimes方法,用於重置User_Interface_Setting_Click_Runtimes計數變數為0 + { // 進入Reset_User_Interface_Setting_Click_Runtimes方法 + User_Interface_Setting_Click_Runtimes = 0; // 將User_Interface_Setting_Click_Runtimes變數重置為0 + } // 結束Reset_User_Interface_Setting_Click_Runtimes方法 + public static void Set_User_Interface_Setting_Click_Runtimes() // Set_User_Interface_Setting_Click_Runtimes方法 + { // 進入Set_User_Interface_Setting_Click_Runtimes方法 + User_Interface_Setting_Click_Runtimes = User_Interface_Setting_Click_Runtimes + 1; + // 遞增User_Interface_Setting_Click_Runtimes變數 + } // 結束Set_User_Interface_Setting_Click_Runtimes方法 + public static uint Get_User_Interface_Setting_Click_Runtimes() // Get_User_Interface_Setting_Click_Runtimes方法 + { // 進入Get_User_Interface_Setting_Click_Runtimes方法 + return User_Interface_Setting_Click_Runtimes; // 取得User_Interface_Setting_Click_Runtimes變數數值 + } // 結束Get_User_Interface_Setting_Click_Runtimes方法 + + private static uint list_SerialPort_Runtimes; // 宣告list_SerialPort_Runtimes私有靜態變數,記錄list_SerialPort方法執行次數 + private static void Reset_list_SerialPort_Runtimes() // Reset_list_SerialPort_Runtimes方法,用於重置list_SerialPort_Runtimes計數變數為0 + { // 進入Reset_list_SerialPort_Runtimes方法 + list_SerialPort_Runtimes = 0; // 將list_SerialPort_Runtimes變數重置為0 + } // 結束Reset_list_SerialPort_Runtimes方法 + public static void Set_list_SerialPort_Runtimes() // Set_list_SerialPort_Runtimes方法 + { // 進入Set_list_SerialPort_Runtimes方法 + list_SerialPort_Runtimes = list_SerialPort_Runtimes + 1; // 遞增list_SerialPort_Runtimes變數 + } // 結束Set_list_SerialPort_Runtimes方法 + public static uint Get_list_SerialPort_Runtimes() // Get_list_SerialPort_Runtimes方法 + { // 進入Get_list_SerialPort_Runtimes方法 + return list_SerialPort_Runtimes; // 取得list_SerialPort_Runtimes變數數值 + } // 結束Get_list_SerialPort_Runtimes方法 + + private static uint UARTConnectHandle_Runtimes; // 宣告UARTConnectHandle_Runtimes私有靜態變數,記錄UARTConnectHandle方法執行次數 + private static void Reset_UARTConnectHandle_Runtimes() // Reset_UARTConnectHandle_Runtimes方法,用於重置UARTConnectHandle_Runtimes計數變數為0 + { // 進入Reset_UARTConnectHandle_Runtimes方法 + UARTConnectHandle_Runtimes = 0; // 將UARTConnectHandle_Runtimes變數重置為0 + } // 結束Reset_UARTConnectHandle_Runtimes方法 + public static void Set_UARTConnectHandle_Runtimes() // Set_UARTConnectHandle_Runtimes方法 + { // 進入Set_UARTConnectHandle_Runtimes方法 + UARTConnectHandle_Runtimes = UARTConnectHandle_Runtimes + 1; // 遞增UARTConnectHandle_Runtimes變數 + } // 結束Set_UARTConnectHandle_Runtimes方法 + public static uint Get_UARTConnectHandle_Runtimes() // Get_UARTConnectHandle_Runtimes方法 + { // 進入Get_UARTConnectHandle_Runtimes方法 + return UARTConnectHandle_Runtimes; // 取得UARTConnectHandle_Runtimes變數數值 + } // 結束Get_UARTConnectHandle_Runtimes方法 + + private static uint comport_DataReceived_Runtimes; // 宣告comport_DataReceived_Runtimes私有靜態變數,記錄comport_DataReceived方法執行次數 + private static void Reset_comport_DataReceived_Runtimes() // Reset_comport_DataReceived_Runtimes方法,用於重置comport_DataReceived_Runtimes計數變數為0 + { // 進入Reset_comport_DataReceived_Runtimes方法 + comport_DataReceived_Runtimes = 0; // 將comport_DataReceived_Runtimes變數重置為0 + } // 結束Reset_comport_DataReceived_Runtimes方法 + public static void Set_comport_DataReceived_Runtimes() // Set_comport_DataReceived_Runtimes方法 + { // 進入Set_comport_DataReceived_Runtimes方法 + comport_DataReceived_Runtimes = comport_DataReceived_Runtimes + 1; // 遞增comport_DataReceived_Runtimes變數 + } // 結束Set_comport_DataReceived_Runtimes方法 + public static uint Get_comport_DataReceived_Runtimes() // Get_comport_DataReceived_Runtimes方法 + { // 進入Get_comport_DataReceived_Runtimes方法 + return comport_DataReceived_Runtimes; // 取得comport_DataReceived_Runtimes變數數值 + } // 結束Get_comport_DataReceived_Runtimes方法 + + private static uint DisplayText_Runtimes; // 宣告DisplayText_Runtimes私有靜態變數,記錄DisplayText方法執行次數 + private static void Reset_DisplayText_Runtimes() // Reset_DisplayText_Runtimes方法,用於重置DisplayText_Runtimes計數變數為0 + { // 進入Reset_DisplayText_Runtimes方法 + DisplayText_Runtimes = 0; // 將DisplayText_Runtimes變數重置為0 + } // 結束Reset_DisplayText_Runtimes方法 + public static void Set_DisplayText_Runtimes() // Set_DisplayText_Runtimes方法 + { // 進入Set_DisplayText_Runtimes方法 + DisplayText_Runtimes = DisplayText_Runtimes + 1; // 遞增DisplayText_Runtimes變數 + } // 結束Set_DisplayText_Runtimes方法 + public static uint Get_DisplayText_Runtimes() // Get_DisplayText_Runtimes方法 + { // 進入Get_DisplayText_Runtimes方法 + return DisplayText_Runtimes; // 取得DisplayText_Runtimes變數數值 + } // 結束Get_DisplayText_Runtimes方法 + + public static void ResetDebugVariables() // ResetDebugVariables方法 + { // 進入ResetDebugVariables方法 + Reset_button1_Click_Runtimes(); // 重置button1_Click_Runtimes變數 + Reset_button2_Click_Runtimes(); // 重置button2_Click_Runtimes變數 + Reset_button3_Click_Runtimes(); // 重置button3_Click_Runtimes變數 + Reset_Transmission_Setting_Click_Runtimes(); // 重置Transmission_Setting_Click_Runtimes變數 + Reset_User_Interface_Setting_Click_Runtimes(); // 重置User_Interface_Setting_Click_Runtimes變數 + Reset_list_SerialPort_Runtimes(); // 重置list_SerialPort_Runtimes變數 + Reset_UARTConnectHandle_Runtimes(); // 重置UARTConnectHandle_Runtimes變數 + Reset_comport_DataReceived_Runtimes(); // 重置comport_DataReceived_Runtimes變數 + Reset_DisplayText_Runtimes(); // 重置DisplayText_Runtimes變數 + } // 結束ResetDebugVariables方法 + } // 結束DebugVariables類別 + +} // 結束命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ErrorCodeMessage.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ErrorCodeMessage.cs new file mode 100644 index 0000000..79ebe79 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/ErrorCodeMessage.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 + +namespace UartOscilloscope // 命名空間為UartOscilloscope +{ // 進入命名空間 + public class ErrorCodeMessage // 宣告ErrorCodeMessage類別 + { // 進入ErrorCodeMessage類別 + public enum ErrorCodeEncoding : int // ErrorCode錯誤編碼列舉型態 + { // 進入ErrorCode錯誤編碼列舉型態 + NoError = 000000, // NoError編碼 + NoSerialPortConnected = 010001, // NoSerialPortConnected編碼 + NoSerialPortSelected = 010002, // NoSerialPortSelected編碼 + SerialPortConnectError = 010003, // SerialPortConnectError編碼 + LoginAccountNull = 040001, // LoginAccountNull編碼 + LoginPasswordNull = 040002, // LoginPasswordNull編碼 + LoginAccountError = 040003, // LoginAccountError編碼 + LoginPasswordError = 040004 // LoginPasswordError編碼 + } // 結束ErrorCode錯誤編碼列舉型態 + private struct Error_message_struct // 宣告Error_message_struct結構 + { + public string Error_Message; // 宣告Error_Message(錯誤訊息)字串 + public string Error_Title; // 宣告Error_Title(錯誤訊息標題)字串 + public MessageBoxButtons Error_MessageBoxButton; // 宣告Error_MessageBoxButton(錯誤訊息方塊按鈕)物件 + public MessageBoxIcon Error_MessageBoxIcon; // 宣告Error_MessageBoxIcon(錯誤訊息方塊圖示)物件 + /** Error_message_struct建構子 **/ + public Error_message_struct(string Error_Message_set, // 宣告Error_message_struct建構子,設定建構子參數 + string Error_Title_set, + MessageBoxButtons Error_MessageBoxButton_set, + MessageBoxIcon Error_MessageBoxIcon_set) + { // 進入Error_message_struct建構子 + Error_Message = Error_Message_set; // 設定Error_message_struct建構子 + Error_Title = Error_Title_set; // 設定Error_message_struct建構子 + Error_MessageBoxButton = Error_MessageBoxButton_set; // 設定Error_message_struct建構子 + Error_MessageBoxIcon = Error_MessageBoxIcon_set; // 設定Error_message_struct建構子 + } // 結束Error_message_struct建構子 + + } // 結束Error_message_struct結構 + /** 定義Error_010001錯誤訊息 **/ + private const string Error_010001_Message = "未偵測到任何已連接的SerialPort,ErrorCode=010001"; + private const string Error_010001_Title = "None of SerialPort"; + private const MessageBoxButtons Error_010001_MessageBoxButton = MessageBoxButtons.OK; + private const MessageBoxIcon Error_010001_MessageBoxIcon = MessageBoxIcon.Warning; + private static Error_message_struct Error_010001 = + new Error_message_struct(Error_010001_Message, Error_010001_Title, Error_010001_MessageBoxButton, Error_010001_MessageBoxIcon); + /** 定義Error_010002錯誤訊息 **/ + private const string Error_010002_Message = "未選定連接埠,ErrorCode=010002"; + private const string Error_010002_Title = "Connect Error"; + private const MessageBoxButtons Error_010002_MessageBoxButton = MessageBoxButtons.OK; + private const MessageBoxIcon Error_010002_MessageBoxIcon = MessageBoxIcon.Error; + private static Error_message_struct Error_010002 = + new Error_message_struct(Error_010002_Message, Error_010002_Title, Error_010002_MessageBoxButton, Error_010002_MessageBoxIcon); + /** 定義Error_010003錯誤訊息 **/ + private const string Error_010003_Message = "裝置不存在或無法建立連線,ErrorCode=010003"; + private const string Error_010003_Title = "Connect Error"; + private const MessageBoxButtons Error_010003_MessageBoxButton = MessageBoxButtons.OK; + private const MessageBoxIcon Error_010003_MessageBoxIcon = MessageBoxIcon.Warning; + private static Error_message_struct Error_010003 = + new Error_message_struct(Error_010003_Message, Error_010003_Title, Error_010003_MessageBoxButton, Error_010003_MessageBoxIcon); + public static void Error_Message_Show(ErrorCodeEncoding ErrorCode_input) + { // 進入Error_Message_Show方法 + switch (ErrorCode_input) + { // 進入switch敘述 + case ErrorCodeEncoding.NoSerialPortConnected: + var warning_010001 = MessageBox.Show(Error_010001.Error_Message, + Error_010001.Error_Title, + Error_010001.Error_MessageBoxButton, + Error_010001.Error_MessageBoxIcon); + break; + case ErrorCodeEncoding.NoSerialPortSelected: + var warning_010002 = MessageBox.Show(Error_010002.Error_Message, + Error_010002.Error_Title, + Error_010002.Error_MessageBoxButton, + Error_010002.Error_MessageBoxIcon); + break; + case ErrorCodeEncoding.SerialPortConnectError: + var warning = MessageBox.Show(Error_010003.Error_Message, + Error_010003.Error_Title, + Error_010003.Error_MessageBoxButton, + Error_010003.Error_MessageBoxIcon); + break; + default: + break; + } // 結束switch敘述 + } // 結束Error_Message_Show方法 + } // 結束ErrorCodeMessage類別 +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/FileIO.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/FileIO.cs new file mode 100644 index 0000000..11c84a7 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/FileIO.cs @@ -0,0 +1,71 @@ +/// +/// C#實作Uart接收程式,By Jimmy Hu +/// This program is licensed under the Apache License 2.0. +/// +using System; +using System.Collections.Generic; +/* System.IO函式庫定義檔案讀寫相關函式 + */ +using System.IO; // 使用System.IO函式庫 +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope +{ // 進入命名空間 + public class FileIO // FileIO類別 + { // 進入FileIO類別 + /// + /// FileWrite方法 + /// FileName為欲寫入檔案名稱 + /// InputString為欲寫入檔案之字串資料 + /// + /// + /// + public void FileWrite(string FileName, string InputString) + { // 進入FileWrite方法 + FileStream file_stream = new FileStream(FileName, FileMode.Append); + // 建立檔案指標,指向指定檔案名稱,模式為傳入之File_mode + byte[] Input_data = System.Text.Encoding.Default.GetBytes(InputString); + // 將填入資料轉為位元陣列 + file_stream.Write(Input_data, 0, Input_data.Length); // 寫入資料至檔案中 + file_stream.Flush(); // 清除緩衝區 + file_stream.Close(); // 關閉檔案 + } // 結束FileWrite方法 + /// + /// 宣告FileWrite方法,將資料寫入檔案 + /// FileName為欲寫入檔案名稱 + /// InputString為欲寫入檔案之字串資料 + /// File_mode為開啟檔案模式 + /// + /// + /// + /// + public void FileWrite(string FileName, string InputString, FileMode File_mode) + { // 進入FileWrite方法 + FileStream file_stream = new FileStream(FileName, File_mode); // 建立檔案指標,指向指定檔案名稱,模式為傳入之File_mode + byte[] Input_data = System.Text.Encoding.Default.GetBytes(InputString); + // 將填入資料轉為位元陣列 + file_stream.Write(Input_data, 0, Input_data.Length); // 寫入資料至檔案中 + file_stream.Flush(); // 清除緩衝區 + file_stream.Close(); // 關閉檔案 + } // 結束FileWrite方法 + /// + /// ReadTxTFile方法用於讀取txt文字檔 + /// + /// + /// + /// + public string ReadTxTFile(string FileName, Encoding encoding) // 宣告ReadTxTFile方法 + { // 進入ReadTxTFile方法 + //***區域變數宣告*** + System.IO.StreamReader textreader; // 宣告textreader為System.IO.StreamReader物件 + string InputString; // 宣告讀入字串 + InputString = ""; // 初始化InputString為空字串 + textreader = new System.IO.StreamReader(FileName, encoding); // 以指定encoding讀取檔案FileName + InputString = textreader.ReadToEnd(); // 讀取檔案至結尾,將檔案內容填入InputString + textreader.Close(); // 關閉檔案 + return InputString; // 回傳讀取得字串資料 + } // 結束ReadTxTFile方法 + } // 結束FileIO類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OpenGLExtension.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OpenGLExtension.cs new file mode 100644 index 0000000..9b74ce0 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OpenGLExtension.cs @@ -0,0 +1,13 @@ +using SharpGL; // 使用SharpGL函式庫(使用OpenGL函數) +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UartOscilloscope +{ + class OpenGLExtension: OpenGL + { + + } +} \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OscilloscopeFunctionVariable.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OscilloscopeFunctionVariable.cs new file mode 100644 index 0000000..ebe95cd --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/OscilloscopeFunctionVariable.cs @@ -0,0 +1,47 @@ +/******************************************************************** + * Develop by Jimmy Hu, * + * s103360021@gmail.com * + * This program is licensed under the Apache License 2.0. * + * OscilloscopeFunctionVariable.cs * + * 本檔案撰寫OscilloscopeFunctionVariable類別以宣告Oscilloscope * + * 功能實作變數 * + ******************************************************************** + */ +using System; +using System.Collections.Generic; // 使用System.Collections.Generic函式庫 +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // 命名空間為本程式 +{ // 進入命名空間 + /** OscilloscopeFunctionVariable類別宣告示波器功能實作變數 ** + */ + public class OscilloscopeFunctionVariable // OscilloscopeFunctionVariable類別 + { // 進入OscilloscopeFunctionVariable類別 + public WaveDataStructure XChannel; // 宣告XChannel全域陣列變數,記錄X通道ADC原始資料 + public WaveDataStructure YChannel; // 宣告YChannel全域陣列變數,記錄Y通道ADC原始資料 + public WaveDataStructure ZChannel; // 宣告ZChannel全域陣列變數,記錄Z通道ADC原始資料 + private static int ADC_Raw_Data_Max; // 宣告ADC_Raw_Data_Max整數變數,記錄ADC_Raw_Data陣列大小 + + /// + /// OscilloscopeFunctionVariable建構子 + /// + public OscilloscopeFunctionVariable() // OscilloscopeFunctionVariable建構子 + { // 進入OscilloscopeFunctionVariable建構子 + ADC_Raw_Data_Max = 100; // 初始化數值 + this.XChannel = new WaveDataStructure(ADC_Raw_Data_Max); + this.YChannel = new WaveDataStructure(ADC_Raw_Data_Max); + this.ZChannel = new WaveDataStructure(ADC_Raw_Data_Max); + } // 結束OscilloscopeFunctionVariable建構子 + public static int Get_ADC_Raw_Data_Max() // 宣告Get_ADC_Raw_Data_Max方法 + { // 進入Get_ADC_Raw_Data_Max方法 + return OscilloscopeFunctionVariable.ADC_Raw_Data_Max; // 回傳ADC_Raw_Data_Max數值 + } // 結束Get_ADC_Raw_Data_Max方法 + public static void Set_ADC_Raw_Data_Max(int InputData) // 宣告Set_ADC_Raw_Data_Max方法 + { // 進入Set_ADC_Raw_Data_Max方法 + OscilloscopeFunctionVariable.ADC_Raw_Data_Max = InputData; // 設定ADC_Raw_Data_Max數值 + return; // 結束Set_ADC_Raw_Data_Max方法 + } // 結束Set_ADC_Raw_Data_Max方法 + } // 結束OscilloscopeFunctionVariable類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/QueueDataGraphic.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/QueueDataGraphic.cs new file mode 100644 index 0000000..b7513c8 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/QueueDataGraphic.cs @@ -0,0 +1,123 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * QueueDataGraphic.cs * + * 本檔案用於佇列資料繪圖功能 * + ******************************************************************** + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; +using System.Windows.Forms; + +namespace QueueDataGraphic.CSharpFiles +{ // namespace start, 進入命名空間 + class QueueDataGraphic // QueueDataGraphic class, QueueDataGraphic類別 + { // QueueDataGraphic class start, 進入QueueDataGraphic類別 + private List DataQueueList; // DataQueueList object, DataQueueList物件 + + /// + /// Width is the width of graph. + /// + private int Width; // Width variable, Width變數 + + /// + /// Height is the height of graph. + /// + private int Height; // Height variable, Height變數 + + Point GraphPointTemp; + + /// + /// QueueDataGraphic constructor, QueueDataGraphic建構子 + /// + /// DataQueue通道名稱集合 + public QueueDataGraphic(List DataQueueNames) // QueueDataGraphic constructor, QueueDataGraphic建構子 + { // QueueDataGraphic constructor start, 進入QueueDataGraphic建構子 + DataQueueList = new List(); // initialize DataQueueList, 初始化DataQueueList物件 + foreach (string item in DataQueueNames) // get each name of DataQueueNames + { // foreach statement start, 進入foreach敘述 + DataQueueList.Add(new DataQueue(item, 500)); // add DataQueue, 新增DataQueue + } // foreach statement end, 結束foreach敘述 + } // QueueDataGraphic constructor end, 結束QueueDataGraphic建構子 + + /// + /// SetWidth method would update Width variable. + /// SetWidth方法用於更新Width變數 + /// + /// Width更新值 + public void SetWidth(int NewWidth) // SetWidth method, SetWidth方法 + { // SetWidth method start, 進入SetWidth方法 + if (NewWidth > 0) + { + this.Width = NewWidth; // Update Width, 更新Width資料 + } + } // SetWidth method end, 結束SetWidth方法 + + /// + /// SetHeight method would update Height variable. + /// SetHeight方法用於更新Height變數 + /// + /// Height更新值 + public void SetHeight(int NewHeight) // SetHeight method, SetHeight方法 + { // SetHeight method start, 進入SetHeight方法 + if (NewHeight > 0) + { + this.Height = NewHeight; // Update Height, 更新Height資料 + } + } // SetHeight method end, 結束SetHeight方法 + + /// + /// AddData method would add data to queue. + /// AddData方法用於新增資料至Queue + /// + /// 欲新增資料之Queue名稱 + /// 欲新增至Queue之資料 + public void AddData(string DataQueueName, object InputData) // AddData method, AddData方法 + { // AddData method start, 進入AddData方法 + foreach (DataQueue item in DataQueueList) // search DataQueue in DataQueueList + { // foreach statement start, 進入foreach敘述 + if (item.GetDataQueueName() == DataQueueName) // if item name is as same as DataQueueName, 若搜尋得相同名稱 + { // if statement start, 進入if敘述 + item.AddData(InputData); // add data to queue, 新增資料至對應佇列 + } // if statement end, 結束if敘述 + } // foreach statement end, 結束foreach敘述 + } // AddData method end, 結束AddData方法 + + public void DrawGraph(object sender, PaintEventArgs e) // DrawGraph method, DrawGraph方法 + { // DrawGraph method start, 進入DrawGraph方法 + Graphics Graph1 = e.Graphics; + foreach (DataQueue DataQueueItem in DataQueueList) // get each DataQueue, 依序取出各DataQueue + { // foreach statement start, 進入foreach敘述 + GraphPointTemp = new Point(0,0); + int Loopnum = 0; // initialize Loopnum variable, 初始化Loopnum變數 + foreach (int Data in DataQueueItem.GetGraphicData()) // get each data in DataQueue, 從DataQueue取出資料 + { // foreach statement start, 進入foreach敘述 + if (Loopnum == 0) // if run first loop, 若Loopnum變數為0 + { // if statement start, 進入if敘述 + GraphPointTemp = new Point(( + (int)(Loopnum * this.Width / DataQueueItem.GetGraphicDataQueueMax())), + (int)(this.Height - (Data * this.Height / 4096))); + } // if statement end, 結束if敘述 + else + { // else statement start, 進入else敘述 + Graph1.DrawLine(new Pen(Color.Black), GraphPointTemp, + new Point(( + (int)(Loopnum * this.Width / DataQueueItem.GetGraphicDataQueueMax())), + (int)(this.Height - (Data * this.Height / 4096)))); + GraphPointTemp = new Point(( + (int)(Loopnum * this.Width / DataQueueItem.GetGraphicDataQueueMax())), + (int)(this.Height - (Data * this.Height / 4096))); + } // else statement end, 結束else敘述 + Loopnum = Loopnum + 1; // increase Loopnum variable, 遞增Loopnum變數 + } // foreach statement end, 結束foreach敘述 + } // foreach statement end, 結束foreach敘述 + Graph1.Flush(); + } // DrawGraph method end, 結束DrawGraph方法 + + } // QueueDataGraphic class end, 結束QueueDataGraphic類別 +} // namespace end, 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TestingType.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TestingType.cs new file mode 100644 index 0000000..7b21fac --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TestingType.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope.Tests // UartOscilloscope.Tests命名空間 +{ // 進入命名空間 + /// + /// TestingType類別物件用於記錄測試結果 + /// 若測試成功, + /// + public class TestingType // TestingType類別 + { // 進入TestingType類別 + /// + /// 當測試成功,Result為True,否則為False + /// + private bool Result; // 宣告Result記錄測試結果 + /// + /// TestingType建構子 + /// + public TestingType() // TestingType建構子 + { // 進入TestingType建構子 + Result = false; // 初始化Result為false + } // 結束TestingType建構子 + /// + /// TestSuccess方法用於記錄測試成功結果 + /// + public void TestSuccess() // TestSuccess方法 + { // 進入TestSuccess方法 + Result = true; // 設定結果為true + } // 結束TestSuccess方法 + /// + /// TestFail用於記錄測試失敗結果 + /// + public void TestFail() // TestFail方法 + { // 進入TestFail方法 + Result = false; // 設定結果為false + } // 結束TestFail方法 + /// + /// GetTestingResult用於取得測試結果 + /// + private bool GetTestingResult() // GetTestingResult方法 + { // 進入GetTestingResult方法 + return Result; // 回傳測試結果 + } // 結束GetTestingResult方法 + /// + /// IsTestSuccessed方法用於核對測試結果是否成功,若測試成功傳回true,若測試失敗則傳回false + /// + /// + /// 回傳測試結果是否成功核對結果 + public static bool IsTestSuccessed(TestingType TestResult) // IsTestSuccessed方法 + { // 進入IsTestSuccessed方法 + return TestResult.GetTestingResult(); // 回傳比對結果 + } // 結束IsTestSuccessed方法 + /// + /// IsTestFailed方法用於核對測試結果是否失敗,若測試失敗傳回true,若測試成功則傳回false + /// + /// + /// 回傳測試結果是否失敗核對結果 + public static bool IsTestFailed(TestingType TestResult) // IsTestFailed方法 + { // 進入IsTestFailed方法 + return !TestResult.GetTestingResult(); // 回傳比對結果 + } // 結束IsTestFailed方法 + } // 結束TestingType類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TimingControl.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TimingControl.cs new file mode 100644 index 0000000..d1b1553 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/TimingControl.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // 命名空間為UartOscilloscope +{ // 進入UartOscilloscope命名空間 + class TimingControl // TimingControl類別 + { // 進入TimingControl類別 + public TimingControl() // TimingControl建構子 + { // 進入TimingControl建構子 + + } // 結束TimingControl建構子 + } // 結束TimingControl類別 +} // 結束UartOscilloscope命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnection.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnection.cs new file mode 100644 index 0000000..2988c63 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnection.cs @@ -0,0 +1,193 @@ +/// +/// C#實作Uart接收程式,By Jimmy Hu +/// This program is licensed under the Apache License 2.0. +/// +using System; +using System.Collections.Generic; +/* 串列埠(Comport)物件宣告於System.IO.Ports函式庫中 + */ +using System.IO.Ports; // 使用System.IO.Ports函式庫 +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 + +namespace UartOscilloscope // 命名空間為UartOscilloscope +{ // 進入命名空間 + /// + /// UARTConnection類別 + /// + public class UARTConnection // UARTConnection類別 + { // 進入UARTConnection類別 + public SerialPort UartComport; // 宣告SerialPort通訊埠,名稱為UartComport + private int ConnectedCOMPortCount; // 宣告ConnectedCOMPortCount私有變數,記錄已連接的SerialPort數量 + private bool UartComportConnected; // 宣告UartComportConnected布林變數,表示UartComport連線狀態 + private ComportList ComportList1; + private ComboBox ComportListComboBox1; // 宣告ComportListComboBox1物件 + /// + /// UARTConnection建構子 + /// + /// 為預設之已連線COMPort數量(預設為0) + /// 為Uart串列埠連接狀態 + public UARTConnection( // UARTConnection建構子 + int ConnectedCOMPortCount = 0, // 初始化參數 + bool UartComportConnected = false // 初始化參數 + ) // UARTConnection建構子 + { // 進入UARTConnection建構子 + this.UartComport = new SerialPort(); // 初始化UartComport串列埠物件 + this.ConnectedCOMPortCount = ConnectedCOMPortCount; // 初始化ConnectedCOMPortCount物件 + this.UartComportConnected = UartComportConnected; // 初始化UartComportConnected物件 + this.ComportList1 = new ComportList(new string[] { ""}); // 初始化ComportList1物件 + this.ComportListComboBox1 = new System.Windows.Forms.ComboBox(); // 初始化ComportListComboBox1物件 + } // 結束UARTConnection建構子 + /// + /// InitializeUARTConnectionSetting方法用於初始化UART連線設定 + /// + public void InitializeUARTConnectionSetting() // InitializeUARTConnectionSetting方法,初始化UART連線參數 + { // 進入InitializeUARTConnectionSetting方法 + UartComport.BaudRate = UARTConnectionConstVal.GetDefaultBaudRate(); // 預設BaudRate數值為DefaultBaudRate + UartComport.Parity = UARTConnectionConstVal.GetDefaultParitySetting(); + // 預設Parity數值為0(無同位位元檢查) + UartComport.DataBits = UARTConnectionConstVal.GetDefaultDataBitsSetting(); + // 預設DataBitsSetting數值為8 + ConnectedCOMPortCount = 0; // 預設ConnectedCOMPortCount為0 + UartComportConnected = false; // 預設UartComportConnected值為False + } // 結束InitializeUARTConnectionSetting方法 + /// + /// GetBaudRate方法用於取得鮑率設定 + /// + /// 回傳值為UART鮑率設定 + public int GetBaudRate() // GetBaudRate方法 + { // 進入GetBaudRate方法 + return UartComport.BaudRate; // 回傳BaudRate數值 + } // 結束GetBaudRate方法 + /// + /// SetBaudRate方法用於設定鮑率 + /// + /// 為新鮑率設定 + public void SetBaudRate(int NewBaudRate) // SetBaudRate方法 + { // 進入SetBaudRate方法 + UartComport.BaudRate = NewBaudRate; // 設定BaudRate + } // 進入SetBaudRate方法 + /// + /// GetParitySetting方法用於取得鮑率設定 + /// + /// + public Parity GetParitySetting() // GetParitySetting方法 + { // 進入GetParitySetting方法 + return UartComport.Parity; // 回傳Parity數值 + } // 結束GetParitySetting方法 + /// + /// SetParitySetting方法用於調整同位位元設定 + /// + /// 為新同位位元設定 + public void SetParitySetting(Parity NewParitySetting) // SetParitySetting方法 + { // 進入SetParitySetting方法 + UartComport.Parity = NewParitySetting; // 設定ParitySetting + } // 結束SetParitySetting方法 + /// + /// SetParitySetting方法用於調整同位位元設定 + /// 同位位元設定說明:0為不檢查(None),1為奇同位檢察,2為偶同位檢察,3為同位位元恆為1,4為同位位元恆為0 + /// + /// 為新同位位元設定 + public void SetParitySetting(int NewParitySetting) // SetParitySetting方法 + { // 進入SetParitySetting方法 + switch (NewParitySetting) // 依據NewParitySetting輸入選擇Parity設定 + { // 進入switch敘述 + case 0 : + { + UartComport.Parity = Parity.None; + break; + } + case 1: + { + UartComport.Parity = Parity.Odd; + break; + } + case 2: + { + UartComport.Parity = Parity.Even; + break; + } + case 3: + { + UartComport.Parity = Parity.Mark; + break; + } + case 4: + { + UartComport.Parity = Parity.Space; + break; + } + default: + break; + } // 結束switch敘述 + } // 結束SetParitySetting方法 + /// + /// GetDataBitsSetting方法用於取得Comport之DataBits設定 + /// + /// + public int GetDataBitsSetting() // GetDataBitsSetting方法 + { // 進入GetDataBitsSetting方法 + return UartComport.DataBits; // 回傳DataBitsSetting數值 + } // 結束GetDataBitsSetting方法 + /// + /// SetDataBitsSetting方法用於設定串列傳輸DataBits + /// + /// + public void SetDataBitsSetting(int NewDataBitsSetting) // SetDataBitsSetting方法 + { // 進入SetDataBitsSetting方法 + UartComport.DataBits = NewDataBitsSetting; // 設定DataBitsSetting數值 + } // 結束SetDataBitsSetting方法 + /// + /// GetConnectedCOMPortCount方法用於取得已連接之COMPort數量 + /// + /// + public int GetConnectedCOMPortCount() // GetConnectedCOMPortCount方法 + { // 進入GetConnectedCOMPortCount方法 + return ConnectedCOMPortCount; // 回傳ConnectedCOMPortCount數值 + } // 結束GetConnectedCOMPortCount方法 + /// + /// SetConnectedCOMPortCount方法用於設定ConnectedCOMPortCount數值 + /// + /// + private void SetConnectedCOMPortCount(int NewConnectedCOMPortCount) // SetConnectedCOMPortCount方法 + { // 進入SetConnectedCOMPortCount方法 + ConnectedCOMPortCount = NewConnectedCOMPortCount; // 設定ConnectedCOMPortCount數值 + } // 結束SetConnectedCOMPortCount方法 + /// + /// SetUartComportConnected方法用於設定UartComportConnected狀態 + /// + /// + public void SetUartComportConnected(bool NewUartComportConnected) // SetUartComportConnected方法 + { // 進入SetUartComportConnected方法 + UartComportConnected = NewUartComportConnected; // 設定UartComportConnected + } // 結束SetUartComportConnected方法 + /// + /// GetUartComportConnected方法用於取得UartComportConnected狀態 + /// + /// + public bool GetUartComportConnected() // GetUartComportConnected方法,用以取得UartComportConnected狀態 + { // 進入GetUartComportConnected方法 + return UartComportConnected; // 回傳UartComportConnected狀態 + } // 結束GetUartComportConnected方法 + /// + /// GetComportList方法用於取得Comport列表 + /// + /// + public ComportList GetComportList() // GetComportList方法 + { // 進入GetComportList方法 + ListSerialPort(); // 呼叫ListSerialPort方法 + return ComportList1; // 回傳ComportList1物件 + } // 結束GetComportList方法 + /// + /// ListSerialPort方法用於列出SerialPort + /// + private void ListSerialPort() // ListSerialPort方法 + { // 進入ListSerialPort方法 + ComportList1.UpdateComportList(SerialPort.GetPortNames()); // 偵測已連線的SerialPort並儲存結果 + SetConnectedCOMPortCount(ComportList1.GetComportList().Length); + } // 結束ListSerialPort方法 + + } // 結束UARTConnection類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnectionConstVal.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnectionConstVal.cs new file mode 100644 index 0000000..4c9c3c0 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/UARTConnectionConstVal.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +/* 串列埠(Comport)物件宣告於System.IO.Ports函式庫中 + */ +using System.IO.Ports; // 使用System.IO.Ports函式庫 +using System.Linq; +using System.Text; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入命名空間 + public class UARTConnectionConstVal // UARTConnectionConstVal類別 + { // 進入UARTConnectionConstVal類別 + /// + /// 宣告靜態常數 + /// + private const int DefaultBaudRate = 9600; // 宣告DefaultBaudRate(預設鮑率)常數 + /* 同位位元設定說明:0為不檢查(None),1為奇同位檢察,2為偶同位檢察,3為同位位元恆為1,4為同位位元恆為0 */ + private const Parity DefaultParitySetting = 0; // 宣告DefaultParitySetting(預設同位位元設定)常數 + private const int DefaultDataBitsSetting = 8; // 宣告DefaultDataBitsSetting(預設UART傳輸每組資料位元數) + + public static int GetDefaultBaudRate() // GetDefaultBaudRate方法 + { // 進入GetDefaultBaudRate方法 + return UARTConnectionConstVal.DefaultBaudRate; // 回傳DefaultBaudRate常數 + } // 結束GetDefaultBaudRate方法 + public static Parity GetDefaultParitySetting() // GetDefaultParitySetting方法 + { // 進入GetDefaultParitySetting方法 + return UARTConnectionConstVal.DefaultParitySetting; // 回傳DefaultParitySetting常數 + } // 結束GetDefaultParitySetting方法 + public static int GetDefaultDataBitsSetting() // GetDefaultDataBitsSetting方法 + { // 進入GetDefaultDataBitsSetting方法 + return UARTConnectionConstVal.DefaultDataBitsSetting; // 回傳DefaultDataBitsSetting常數 + } // 結束GetDefaultDataBitsSetting方法 + } // 結束UARTConnectionConstVal類別 +} // 結束命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/VersionInfo.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/VersionInfo.cs new file mode 100644 index 0000000..7bd7b74 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/VersionInfo.cs @@ -0,0 +1,26 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * VersionInfo.cs * + * 本檔案撰寫VersionInfo類別以紀錄程式版本資訊 * + ******************************************************************** + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // 命名空間為本程式 +{ // 進入UartOscilloscope命名空間 + class VersionInfo // VersionInfo類別 + { // 進入VersionInfo類別 + public readonly static VersionInfo Instance = new VersionInfo(); // 設計VersionInfo存取介面 + private const float Program_Version = 39; // 宣告Program_Version靜態全域變數,記錄程式版本 + public float GetProgramVersion() // GetProgramVersion方法 + { // 進入GetProgramVersion方法 + return Program_Version; // 回傳Program_Version變數值 + } // 結束GetProgramVersion方法 + } // 結束VersionInfo類別 +} // 結束UartOscilloscope命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WaveDataStructure.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WaveDataStructure.cs new file mode 100644 index 0000000..9ad1522 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WaveDataStructure.cs @@ -0,0 +1,69 @@ +using System; // 使用System函式庫 +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // UartOscilloscope命名空間 +{ // 進入命名空間 + public class WaveDataStructure // WaveDataStructure類別 + { // 進入WaveDataStructure類別 + /// + /// WaveRawData陣列用於儲存感測通道資料,資料以環型方式寫入更新 + /// + private int[] WaveRawData; // 宣告WaveRawData資料儲存陣列 + private int NewDataIndex; // 宣告NewDataIndex,記錄下一筆資料儲存位址 + /// + /// WaveDataStructure建構子,初始化資料陣列 + /// + /// 變數用於給定資料陣列初始大小 + public WaveDataStructure(int InitialSize) // WaveDataStructure建構子 + { // 進入WaveDataStructure建構子 + ResizeArray(InitialSize); // 呼叫ResizeArray方法 + this.NewDataIndex = -1; // 給定NewDataIndex初始值 + } // 結束WaveDataStructure建構子 + /// + /// ResizeArray方法用於調整資料陣列大小 + /// + /// + public void ResizeArray(int NewSize) // ResizeArray方法 + { // 進入ResizeArray方法 + Array.Resize(ref WaveRawData, NewSize); // 調整陣列大小 + for(int Loopnum = 0; Loopnum < WaveRawData.Length; Loopnum++) // 以for迴圈初始化資料內容 + { // 進入for迴圈 + WaveRawData[Loopnum] = 0; // 初始化資料為0 + } // 結束for迴圈 + NewDataIndex = -1; // 重新定位下一筆資料儲存位址 + } // 結束ResizeArray方法 + /// + /// AddData方法用於新增資料至陣列空間 + /// + /// + public void AddData(int InputData) // AddData方法 + { // 進入AddData方法 + WaveRawData[NextIndex()] = InputData; // 將資料填入陣列空間 + } // 結束AddData方法 + /// + /// NextIndex方法用於取得填入下一筆陣列資料之位置 + /// + /// 回傳值為填入下一筆陣列資料之位置 + private int NextIndex() // NextIndex方法 + { // 進入NextIndex方法 + NewDataIndex = (NewDataIndex + 1) % WaveRawData.Length; // 取出填入下一筆陣列資料之位置 + return NewDataIndex; // 回傳OutputIndex區域變數 + } // 結束NextIndex方法 + public int[] ReturnData() // ReturnData方法 + { // 進入ReturnData方法 + return WaveRawData; + } // 結束ReturnData方法 + public override string ToString() // 覆寫ToString方法 + { // 進入覆寫ToString方法 + string OutputString = ""; // 宣告OutputString(輸出字串結果) + foreach (int item in WaveRawData) // 以foreach依序列出Name內容 + { // 進入foreach敘述 + OutputString = OutputString + item.ToString() + '\n'; // 填入內容至輸出字串 + } // 結束foreach敘述 + return OutputString; // 回傳OutputString + } // 結束覆寫ToString方法 + } // 結束WaveDataStructure類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WorkingMode.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WorkingMode.cs new file mode 100644 index 0000000..0da593c --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/CSharpFiles/WorkingMode.cs @@ -0,0 +1,31 @@ +/******************************************************************** + * Develop by Jimmy Hu * + * This program is licensed under the Apache License 2.0. * + * WorkingMode.cs * + * 本檔案撰寫WorkingMode類別以紀錄程式執行模式 * + ******************************************************************** + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope // 命名空間為本程式 +{ // 進入UartOscilloscope命名空間 + public class WorkingMode // WorkingMode類別 + { // 進入WorkingMode類別 + public enum Program_Work_Mode_Options : byte // Program_Work_Mode_Options列舉 + { // 進入Program_Work_Mode_Options列舉 + Normal_Mode = 0, + Debug_Mode = 1, + }; // 結束Program_Work_Mode_Options列舉 + private static Program_Work_Mode_Options Program_Work_Mode = + Program_Work_Mode_Options.Normal_Mode; // 宣告Program_Work_Mode靜態變數,控制程式執行模式 + public static void Set_Program_Work_Mode + (Program_Work_Mode_Options InputMode) // Set_Program_Work_Mode方法 + { // 進入Set_Program_Work_Mode方法 + Program_Work_Mode = (Program_Work_Mode_Options)InputMode; // 設定Program_Work_Mode模式 + } // 結束Set_Program_Work_Mode方法 + } // 結束WorkingMode類別 +} // 結束UartOscilloscope命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/ClassDiagram1.cd b/VisualStudioProjects/OpenGLTest/UartOscilloscope/ClassDiagram1.cd new file mode 100644 index 0000000..7b89419 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/ClassDiagram1.cd @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.Designer.cs new file mode 100644 index 0000000..d1a63ec --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.Designer.cs @@ -0,0 +1,287 @@ +namespace WindowsFormsApplication6 +{ + partial class Form1 + { + /// + /// 設計工具所需的變數。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清除任何使用中的資源。 + /// + /// 如果應該處置 Managed 資源則為 true,否則為 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form 設計工具產生的程式碼 + + /// + /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器 + /// 修改這個方法的內容。 + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.button3 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.Label2 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.設定ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.傳輸設定ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.介面設定ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.label7 = new System.Windows.Forms.Label(); + this.openGLControl1 = new SharpGL.OpenGLControl(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).BeginInit(); + this.SuspendLayout(); + // + // button3 + // + this.button3.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button3.Location = new System.Drawing.Point(904, 592); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(246, 34); + this.button3.TabIndex = 0; + this.button3.Text = "清除接收字串資料"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label1.Location = new System.Drawing.Point(904, 547); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(152, 21); + this.label1.TabIndex = 1; + this.label1.Text = "收到的Byte數:"; + // + // Label2 + // + this.Label2.AutoSize = true; + this.Label2.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.Label2.Location = new System.Drawing.Point(1032, 568); + this.Label2.Name = "Label2"; + this.Label2.Size = new System.Drawing.Size(20, 21); + this.Label2.TabIndex = 2; + this.Label2.Text = "0"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(16, 471); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.textBox1.Size = new System.Drawing.Size(882, 155); + this.textBox1.TabIndex = 3; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.設定ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1162, 24); + this.menuStrip1.TabIndex = 4; + this.menuStrip1.Text = "menuStrip1"; + // + // 設定ToolStripMenuItem + // + this.設定ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.傳輸設定ToolStripMenuItem, + this.介面設定ToolStripMenuItem}); + this.設定ToolStripMenuItem.Name = "設定ToolStripMenuItem"; + this.設定ToolStripMenuItem.Size = new System.Drawing.Size(43, 20); + this.設定ToolStripMenuItem.Text = "設定"; + // + // 傳輸設定ToolStripMenuItem + // + this.傳輸設定ToolStripMenuItem.Name = "傳輸設定ToolStripMenuItem"; + this.傳輸設定ToolStripMenuItem.Size = new System.Drawing.Size(122, 22); + this.傳輸設定ToolStripMenuItem.Text = "傳輸設定"; + this.傳輸設定ToolStripMenuItem.Click += new System.EventHandler(this.設定_傳輸設定ToolStripMenuItem_Click); + // + // 介面設定ToolStripMenuItem + // + this.介面設定ToolStripMenuItem.Name = "介面設定ToolStripMenuItem"; + this.介面設定ToolStripMenuItem.Size = new System.Drawing.Size(122, 22); + this.介面設定ToolStripMenuItem.Text = "介面設定"; + this.介面設定ToolStripMenuItem.Click += new System.EventHandler(this.設定_介面設定ToolStripMenuItem_Click); + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(904, 64); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(246, 20); + this.comboBox1.TabIndex = 5; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("新細明體", 12F); + this.label3.Location = new System.Drawing.Point(901, 45); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(148, 16); + this.label3.TabIndex = 6; + this.label3.Text = "已連接的SerialPort:"; + // + // button2 + // + this.button2.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button2.Location = new System.Drawing.Point(1040, 132); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(110, 33); + this.button2.TabIndex = 7; + this.button2.Text = "連線"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button1 + // + this.button1.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button1.Location = new System.Drawing.Point(968, 96); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(182, 30); + this.button1.TabIndex = 8; + this.button1.Text = "重新偵測SerialPort"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label4.Location = new System.Drawing.Point(13, 452); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(147, 16); + this.label4.TabIndex = 9; + this.label4.Text = "Uart接收字串資料:"; + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("新細明體", 12F); + this.label5.Location = new System.Drawing.Point(901, 174); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(115, 16); + this.label5.TabIndex = 10; + this.label5.Text = "Uart連線狀態:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("新細明體", 12F); + this.label6.Location = new System.Drawing.Point(965, 201); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(72, 16); + this.label6.TabIndex = 11; + this.label6.Text = "連線狀態"; + // + // panel1 + // + this.panel1.Location = new System.Drawing.Point(15, 64); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(413, 385); + this.panel1.TabIndex = 12; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Font = new System.Drawing.Font("新細明體", 16F); + this.label7.Location = new System.Drawing.Point(12, 39); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(76, 22); + this.label7.TabIndex = 0; + this.label7.Text = "示波器"; + // + // openGLControl1 + // + this.openGLControl1.BitDepth = 24; + this.openGLControl1.DrawFPS = false; + this.openGLControl1.FrameRate = 20; + this.openGLControl1.Location = new System.Drawing.Point(434, 64); + this.openGLControl1.Name = "openGLControl1"; + this.openGLControl1.RenderContextType = SharpGL.RenderContextType.DIBSection; + this.openGLControl1.Size = new System.Drawing.Size(460, 385); + this.openGLControl1.TabIndex = 13; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(1162, 638); + this.Controls.Add(this.openGLControl1); + this.Controls.Add(this.label7); + this.Controls.Add(this.panel1); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.button1); + this.Controls.Add(this.button2); + this.Controls.Add(this.label3); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.Label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button3); + this.Controls.Add(this.menuStrip1); + this.DoubleBuffered = true; + this.MainMenuStrip = this.menuStrip1; + this.Name = "Form1"; + this.Text = "主畫面"; + this.Load += new System.EventHandler(this.Form1_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label Label2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.ToolStripMenuItem 設定ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 傳輸設定ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 介面設定ToolStripMenuItem; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label label7; + private SharpGL.OpenGLControl openGLControl1; + } +} + diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.cs new file mode 100644 index 0000000..0312e1a --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.cs @@ -0,0 +1,1025 @@ +/// +/// C#實作Uart接收程式,By Jimmy +/// +using System; // 使用System函式庫 +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 +using System.IO.Ports; // 使用System.IO.Ports函式庫 +using System.Collections; // 使用System.Collections函式庫 +// System.Collections函式庫定義Queue資料型態 +using System.Collections.Generic; // 使用System.Collections.Generic函式庫 +// System.Collections.Generic函式庫定義非泛型Queue資料型態 +using System.Drawing; // 使用System.Drawing函式庫 +using SharpGL; // 使用SharpGL函式庫 + +namespace WindowsFormsApplication6 // 命名空間為本程式 +{ // 進入命名空間 + public partial class Form1 : Form // Form1類別 + { // 進入Form1類別 + //-----全域變數宣告----- + public static float Program_Vision = 27; // 宣告Program_Vision靜態全域變數,記錄程式版本 + public static int Program_Work_Mode = 0; // 宣告Program_Work_Mode靜態全域變數,控制程式執行模式 + public struct Debug_Login_Account_struct // 宣告Debug_Login_Account_struct全域結構 + { // 進入Debug_Login_Account_struct結構設定 + public string Debug_Login_Account, Debug_Login_Password; // 在Debug_Login_Account_struct結構中有兩項字串(Account與Password) + public Debug_Login_Account_struct(string p1, string p2) // 設定結構成員 + { // 設定結構成員 + Debug_Login_Account = p1; // 設定結構成員 + Debug_Login_Password = p2; // 設定結構成員 + } // 設定結構成員完成 + } // 結束Debug_Login_Account_struct結構設定 + public static Debug_Login_Account_struct Debug_Account1 = // 宣告Debug_Account1靜態全域除錯帳戶1 + new Debug_Login_Account_struct("Debug", "debug"); // 設定Debug_Account1除錯帳戶1帳號密碼 + public static DateTime localDate; // 宣告localDate時間變數,記錄現在時間 + public static int BaudRate; // 宣告BaudRate靜態全域變數,控制SerialPort連線鮑率 + public static int Parity_num; // 宣告Parity_num靜態全域變數,控制SerialPort串列埠之Parity同位位元設定 + public static int DataBits_num; // 宣告DataBits_num靜態全域變數,控制SerialPort串列埠之DataBits數值 + public static int Error_Code; // 宣告Error_Code靜態全域變數,記錄錯誤編碼,協助偵錯 + public static Font textBox1_Font; // 宣告textBox1_Font靜態字型變數,控制接收字串資料文字方塊字型 + public static SerialPort Uart_comport; // 宣告新的SerialPort通訊埠,名稱為Uart_comport + public static bool Uart_comport_connected; // 宣告Uart_comport_connected布林變數,表示Uart_comport連線狀態 + public static char[] Transmission_Buffer_CharArray; // 宣告Transmission_Buffer_CharArray(Uart通訊傳輸Buffer資料)字元陣列,用於字串資料解析 + public static char[] Transmission_Analysis_CharArray; // 宣告Transmission_Analysis_CharArray字元陣列,用於字串資料解析 + public static int Transmission_Analysis_CharArray_Datanum = 0; + // 宣告Transmission_Analysis_CharArray_Datanum全域靜態變數,記錄Transmission_Analysis_CharArray字元陣列中已填入資料長度,並初始化為0 + public static Queue Transmission_Analysis_Queue; // 宣告Transmission_Analysis_Queue(Uart通訊傳輸資料分析字元佇列)為全域靜態佇列 + public static int Total_Transmission_Length = 0; // 宣告UART通訊傳輸字串累計長度統計全域靜態變數,並初始化為0 + public static int Analysed_Length = -1; + // 宣告Analysed_Length全域靜態變數,記錄Transmission_Analysis_CharArray字元陣列中已分析字串長度(陣列值),並初始化為-1(因陣列從0開始) + public static int COM_Port_num; // 宣告COM_Port_num全域靜態變數,記錄已連線的SerialPort數量 + public static uint button1_Click_Runtimes = 0; // 宣告button1_Click_Runtimes全域靜態變數,記錄button1_Click副程式執行次數,並初始化為0 + public static uint button2_Click_Runtimes = 0; // 宣告button2_Click_Runtimes全域靜態變數,記錄button2_Click副程式執行次數,並初始化為0 + public static uint button3_Click_Runtimes = 0; // 宣告button3_Click_Runtimes全域靜態變數,記錄button3_Click副程式執行次數,並初始化為0 + public static uint Transmission_Setting_Click_Runtimes = 0; + // 宣告Transmission_Setting_Click_Runtimes全域靜態變數,記錄設定_傳輸設定ToolStripMenuItem_Click副程式執行次數,並初始化為0 + public static uint User_Interface_Setting_Click_Runtimes = 0; + // 宣告User_Interface_Setting_Click_Runtimes全域靜態變數,記錄設定_介面設定ToolStripMenuItem_Click副程式執行次數,並初始化為0 + public static uint list_SerialPort_Runtimes = 0; // 宣告list_SerialPort_Runtimes全域靜態變數,記錄list_SerialPort副程式執行次數 + public static uint Uart_comport_handle_Runtimes = 0; // 宣告Uart_comport_handle_Runtimes全域靜態變數,記錄Uart_comport_handle副程式執行次數 + public static uint comport_DataReceived_Runtimes = 0; // 宣告comport_DataReceived_Runtimes全域靜態變數,記錄comport_DataReceived副程式執行次數 + public static uint DisplayText_Runtimes = 0; // 宣告DisplayText_Runtimes全域靜態變數,記錄DisplayText副程式執行次數 + public static int Uart_Buffer_Size = 0; // 宣告Uart_Buffer_Size全域靜態變數,記錄Uart接收資料Buffer(資料緩衝區)大小 + public static string Uart_Buffer_ASCII_Data = ""; // 宣告Uart_Buffer_ASCII_Data全域靜態字串,記錄Uart傳輸之Buffer資料(ASCII編碼值) + ///***以下宣告示波器功能實作變數*** + public static int[] ADC_Raw_Data_X; // 宣告ADC_Raw_Data_X全域整數陣列變數,記錄X通道ADC原始資料 + public static int[] ADC_Raw_Data_Y; // 宣告ADC_Raw_Data_Y全域整數陣列變數,記錄Y通道ADC原始資料 + public static int[] ADC_Raw_Data_Z; // 宣告ADC_Raw_Data_Z全域整數陣列變數,記錄Z通道ADC原始資料 + public static int ADC_Raw_Data_X_num = 0; // 宣告ADC_Raw_Data_X_num全域整數變數,記錄ADC_Raw_Data_X資料量 + public static int ADC_Raw_Data_Y_num = 0; // 宣告ADC_Raw_Data_Y_num全域整數變數,記錄ADC_Raw_Data_Y資料量 + public static int ADC_Raw_Data_Z_num = 0; // 宣告ADC_Raw_Data_Z_num全域整數變數,記錄ADC_Raw_Data_Z資料量 + public static int ADC_Raw_Data_Max = 100; // 宣告ADC_Raw_Data_Max全域整數變數,記錄ADC_Raw_Data陣列大小 + public static Queue Data_Graphic_Queue_X; // 宣告X通道資料繪圖用整數型態佇列Data_Graphic_Queue_X + public static Queue Data_Graphic_Queue_Y; // 宣告Y通道資料繪圖用整數型態佇列Data_Graphic_Queue_Y + public static Queue Data_Graphic_Queue_Z; // 宣告Z通道資料繪圖用整數型態佇列Data_Graphic_Queue_Z + public struct OpenGL_Graph_point // 宣告OpenGL_Graph_point結構,用於OpenGL繪圖座標宣告 + { // 進入OpenGL_Graph_point結構 + public double point_X, point_Y; // 在OpenGL_Graph_point結構中有兩項雙精度浮點數 + public OpenGL_Graph_point(double X, double Y) // 設定結構成員 + { // 設定結構成員 + point_X = X; // 宣告OpenGL_Graph_point結構內部元素(X座標) + point_Y = Y; // 宣告OpenGL_Graph_point結構內部元素(Y座標) + } // 設定結構成員完成 + } // 結束OpenGL_Graph_point結構 + public static int loop_num; // 宣告loop_num全域靜態變數,供迴圈使用 + delegate void Display(byte[] buffer); // 定義Display型態 + //delegate 是可用來封裝具名方法或匿名方法的參考型別。 + public Form1() // 宣告Form1 + { // 進入Form1 + InitializeComponent(); // 初始化表單 + Error_Code = 0; // 初始化Error_Code為0 + } // 結束Form1 + public void Form1_Load(object sender, EventArgs e) // Form1表單載入時執行 + { // 進入Form1_Load副程式 + timer1.Interval = 100; // 設定timer1執行頻率 + timer1.Enabled = true; // 啟動timer1,即時更新現在時間 + textBox1_Font = new Font("新細明體", 9, FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136); + // 設定接收字串資料文字方塊預設字型 + BaudRate = 9600; // 預設BaudRate數值為9600 + Parity_num = 0; // 預設Parity_num數值為0(無同位位元檢查) + DataBits_num = 8; // 預設DataBits_num數值為8 + COM_Port_num = 0; // 預設COM_Port_num為0 + Array.Resize(ref ADC_Raw_Data_X, ADC_Raw_Data_Max); // 指派ADC_Raw_Data_X靜態整數陣列大小 + Array.Resize(ref ADC_Raw_Data_Y, ADC_Raw_Data_Max); // 指派ADC_Raw_Data_Y靜態整數陣列大小 + Array.Resize(ref ADC_Raw_Data_Z, ADC_Raw_Data_Max); // 指派ADC_Raw_Data_Z靜態整數陣列大小 + Transmission_Analysis_Queue = new Queue(); // 初始化Transmission_Analysis_Queue(Uart通訊傳輸資料分析字元佇列) + Data_Graphic_Queue_X = new Queue(); // 初始化Data_Graphic_Queue_X(X通道資料繪圖用整數型態佇列) + Data_Graphic_Queue_Y = new Queue(); // 初始化Data_Graphic_Queue_Y(Y通道資料繪圖用整數型態佇列) + Data_Graphic_Queue_Z = new Queue(); // 初始化Data_Graphic_Queue_Z(Z通道資料繪圖用整數型態佇列) + label6.Text = "未連線"; // 顯示連線狀態為"未連線" + Uart_comport_connected = false; // 預設Uart_comport_connected值為False + list_SerialPort(); // 呼叫list_SerialPort副程式 + } // 結束Form1_Load副程式 + private void button1_Click(object sender, EventArgs e) // 當按下"重新偵測SerialPort"按鈕 + { // 進入button1_Click副程式 + button1_Click_Runtimes = button1_Click_Runtimes + 1; // 遞增button1_Click_Runtimes變數 + list_SerialPort(); // 呼叫list_SerialPort(偵測並列出已連線SerialPort)副程式 + } // 結束button1_Click副程式 + private void button2_Click(object sender, EventArgs e) // 當按下"連線/中斷連線"按鈕 + { // 進入button2_Click副程式 + button2_Click_Runtimes = button2_Click_Runtimes + 1; // 遞增button2_Click_Runtimes變數 + button2.Enabled = false; // 暫時關閉"連線/中斷連線"按鈕功能 + Uart_comport_handle(comboBox1.Text, BaudRate, Parity_num); // 呼叫Uart_comport_handle副程式 + } // 結束button2_Click副程式 + private void button3_Click(object sender, EventArgs e) // 當按下"清除"(button3)按鈕 + { // 進入button3_Click副程式 + button3_Click_Runtimes = button3_Click_Runtimes + 1; // 遞增button3_Click_Runtimes變數 + textBox1.Clear(); // 清除textBox1(接收字串資料文字方塊)資料 + } // 結束button3_Click副程式 + // ToolStripMenuItem選單相關副程式 + private void 設定_傳輸設定ToolStripMenuItem_Click(object sender, EventArgs e) + // 宣告設定_傳輸設定ToolStripMenuItem_Click副程式 + { // 進入設定_傳輸設定ToolStripMenuItem_Click副程式 + Transmission_Setting_Click_Runtimes = Transmission_Setting_Click_Runtimes + 1; + // 遞增Transmission_Setting_Click_Runtimes變數 + Form2 Transmission_Setting_form = new Form2(); // 宣告transmission_setting_form代表Form2 + Transmission_Setting_form.Show(); // 顯示transmission_setting_form + } // 結束設定_傳輸設定ToolStripMenuItem_Click副程式 + + private void 設定_介面設定ToolStripMenuItem_Click(object sender, EventArgs e) + // 宣告設定_介面設定ToolStripMenuItem_Click副程式 + { // 進入設定_介面設定ToolStripMenuItem_Click副程式 + User_Interface_Setting_Click_Runtimes = User_Interface_Setting_Click_Runtimes + 1; + // 遞增User_Interface_Setting_Click_Runtimes變數 + Form3 User_Interface_Setting_form = new Form3(); // 宣告User_Interface_Setting_form代表Form3 + User_Interface_Setting_form.Show(); // 顯示User_Interface_Setting_form + } // 結束設定_介面設定ToolStripMenuItem_Click副程式 + public void list_SerialPort() // 偵測並列出已連線SerialPort副程式 + { // 進入list_SerialPort副程式 + list_SerialPort_Runtimes = list_SerialPort_Runtimes + 1; // 遞增list_SerialPort_Runtimes變數 + string[] ports = SerialPort.GetPortNames(); // 偵測已連線的SerialPort並儲存結果至陣列ports + comboBox1.Items.Clear(); // 清空下拉式選單所有項目 + if (ports.Length == 0) // 若偵測不到任何已連線的SerialPort(ports.Length為0) + { // 進入if敘述 + Error_Code = 010001; // 記錄Error_Code + var warning = MessageBox.Show // 顯示警告訊息 + ( // 進入警告訊息MessageBox設定 + "未偵測到任何已連接的SerialPort,Error_Code=" + Error_Code, // 顯示警告訊息"未偵測到任何已連接的SerialPort",同時顯示Error_Code + "None of SerialPort", // 顯示警告訊息標題為"None of SerialPort" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Warning // 顯示警告標誌 + ); // 結束警告訊息MessageBox設定 + button2.Enabled = false; // 關閉"連線/中斷連線"按鈕功能 + textBox1.Enabled = false; // 關閉textBox1(接收字串資料文字方塊)功能 + return; // 提早結束list_SerialPort副程式 + } // 結束if敘述 + else // 若偵測到已連線的SerialPort + { // 進入else敘述 + COM_Port_num = ports.Length; // 記錄已連線的SerialPort數量 + foreach (string port in ports) // 依序處理每個已連線的SerialPort + { // 進入foreach敘述 + comboBox1.Items.Add(port); // 以條列式選單(comboBox1)列出已連線的SerialPort + } // 結束foreach敘述 + button2.Enabled = true; // 開啟連線功能 + textBox1.Enabled = true; // 開啟textBox1(接收字串資料文字方塊)功能 + return; // 結束list_SerialPort副程式 + } // 結束else敘述 + } // 結束list_SerialPort副程式 + public void Uart_comport_handle // 串列埠連線處理Uart_comport_handle副程式 + (string comport_name,int Baud_Rate,int Parity_set) + // 處理Uart_comport連線設定 + // 呼叫格式為Uart_comport_handle(comport名稱,連線鮑率,同位位元設定,) + // 同位位元設定說明:0為不檢查(None),1為奇同位檢察,2為偶同位檢察,3為同位位元恆為1,4為同位位元恆為0 + { // 進入Uart_comport_handle副程式 + Uart_comport_handle_Runtimes = Uart_comport_handle_Runtimes + 1; // 遞增Uart_comport_handle_Runtimes變數 + if(Uart_comport_connected == true) + // 若Uart_comport_connected為True,代表Uart_comport連線中,將執行中斷連線 + { // 進入if敘述 + label6.Text = (comport_name + "正在中斷連線"); + // 顯示連線狀態為(comport_name + "正在中斷連線"),如"COM1正在中斷連線" + Uart_comport_connected = false; // 更新Uart_comport_connected + Uart_comport.Close(); // 關閉Uart_comport連線 + button2.Text = "連線"; // 更改button2文字為"連線" + button2.Enabled = true; // 重新開啟"連線/中斷連線"按鈕功能 + label6.Text = "未連線"; // 顯示連線狀態為"未連線" + return; // 結束Uart_comport_handle副程式 + } // 結束if敘述 + else // 若Uart_comport_connected為False,執行連線 + { // 進入else敘述 + label6.Text = "偵測連接埠設定"; // 顯示連線狀態為"偵測連接埠設定" + if (comport_name == "") // 若comport_name為空白(Combobox1未選定) + { // 進入if敘述 + Error_Code = 010002; // 記錄Error_Code + var ConnectError = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + "未選定連接埠,Error_Code=" + Error_Code, // 顯示錯誤訊息"未選定連接埠",同時顯示Error_Code + "Connect Error", // 顯示錯誤訊息標題為"Connect Error" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束錯誤訊息MessageBox設定 + button2.Enabled = true; // 重新開啟"連線/中斷連線"按鈕功能 + return; // 結束Uart_comport_handle副程式 + } // 結束if敘述 + else // 已選定連接埠 + { // 進入else敘述 + label6.Text = (comport_name + "正在嘗試連線"); + // 顯示連線狀態為(comport_name + "正在嘗試連線"),如"COM1正在嘗試連線" + try // 嘗試以comport_name建立串列通訊連線 + { // 進入try敘述 + Uart_comport = new SerialPort(comport_name); // Uart_comport串列埠建立comport_name連線 + } // 結束try敘述 + catch (System.IO.IOException) // 當IO發生錯誤時的例外狀況 + { // 進入catch敘述 + Error_Code = 010003; // 記錄Error_Code + var warning = MessageBox.Show // 顯示警告訊息 + ( // 顯示警告訊息MessageBox設定 + comport_name + "裝置不存在或無法建立連線,Error_Code=" + Error_Code, + // 顯示錯誤訊息(連線裝置名稱)裝置不存在或無法建立連線 + "Connect Error", // 顯示錯誤訊息標題為"Connect Error" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Warning // 顯示警告標誌 + ); // 結束警告訊息MessageBox設定 + button2.Enabled = true; // 重新開啟"連線/中斷連線"按鈕功能 + return; // 結束Uart_comport_handle副程式 + } // 結束catch敘述 + Uart_comport.BaudRate = Baud_Rate; // 設定Uart_comport連線之BaudRate + Uart_comport.DataBits = DataBits_num; // 設定Uart_comport連線之DataBits + switch (Parity_set) // 根據Parity_set變數進行同位位元設定 + { // 進入switch-case敘述 + case 0: // 若為case0(Parity_set為0) + Uart_comport.Parity = Parity.None; // 無同位元檢查 + break; // 結束case0敘述、跳出switch-case + case 1: // 若為case1(Parity_set為1) + Uart_comport.Parity = Parity.Odd; // 奇同位位元檢查 + break; // 結束case1敘述、跳出switch-case + case 2: // 若為case2(Parity_set為2) + Uart_comport.Parity = Parity.Even; // 偶同位位元檢查 + break; // 結束case2敘述、跳出switch-case + case 3: // 若為case3(Parity_set為3) + Uart_comport.Parity = Parity.Mark; // 將同位位元恆設為1 + break; // 結束case3敘述、跳出switch-case + case 4: // 若為case4(Parity_set為4) + Uart_comport.Parity = Parity.Space; // 將同位位元恆設為0 + break; // 結束case4敘述、跳出switch-case + } // 結束switch-case敘述 + try // 以try方式執行資料接收 + { // 進入try敘述 + if (!Uart_comport.IsOpen) // 若Uart_comport未開啟 + { // 進入if敘述 + Uart_comport.Open(); // 開啟Uart_comport + label6.Text = (comport_name + "已連線"); + // 顯示連線狀態為(comport_name + "已連線"),如"COM1已連線" + Uart_comport_connected = true; // 更新Uart_comport_connected狀態 + button2.Text = "中斷連線"; // 更改button2文字為"中斷連線" + button2.Enabled = true; // 重新開啟"連線/中斷連線"按鈕功能 + } // 結束if敘述 + Uart_comport.DataReceived += new SerialDataReceivedEventHandler(comport_DataReceived); + // 處理資料接收 + } // 結束try敘述 + catch (Exception ex) // 若發生錯誤狀況 + { // 進入catch敘述 + var result = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + ex.ToString(), "DataReceived Error", // 顯示錯誤訊息ex.ToString(),標題為"DataReceived Error" + MessageBoxButtons.OK, // MessageBox選項為OK + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束錯誤訊息MessageBox設定 + Uart_comport.Close(); // 關閉Uart_comport連線 + button2.Text = "連線"; // 更改button2文字為"連線" + button2.Enabled = true; // 重新開啟"連線/中斷連線"按鈕功能 + return; // 結束Uart_comport_handle副程式 + } // 結束catch敘述 + } // 結束else敘述 + } // 結束else敘述 + } // 結束Uart_comport_handle副程式 + private void comport_DataReceived(object sender, SerialDataReceivedEventArgs e) + // comport資料接收處理副程式 + { // 進入comport資料接收處理副程式 + comport_DataReceived_Runtimes = comport_DataReceived_Runtimes + 1; // 遞增comport_DataReceived_Runtimes變數 + if (Uart_comport_connected == false) // 若Uart_comport未連線(Uart_comport_connected值為False) + { // 進入if敘述 + return; // 結束comport資料接收處理副程式 + } // 結束if敘述 + byte[] buffer = new byte[1024]; // 宣告buffer暫存讀取資料,型態為Byte + int length = 0; // 宣告length變數用於記錄串列資料緩衝區長度 + try // 以try語法嘗試讀取Uart串列資料緩衝區 + { // 進入try敘述 + length = (sender as SerialPort).Read(buffer, 0, buffer.Length); // 讀取Uart串列資料緩衝區 + } // 結束try敘述 + catch (ArgumentNullException) // 當發生NULL例外狀況 + { // 進入catch敘述 + + } // 結束catch敘述 + Uart_Buffer_Size = length; // 更新Uart_Buffer_Size數值 + try // 嘗試調整buffer陣列大小 + { // 進入try敘述 + Array.Resize(ref buffer, length); // 調整buffer陣列大小 + } // 結束try敘述 + catch (ArgumentOutOfRangeException outOfRange) // 若調整buffer陣列空間時範圍錯誤 + { // 進入catch敘述 + var result = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + outOfRange.Message,"", + MessageBoxButtons.OK, // MessageBox選項為OK + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束錯誤訊息MessageBox設定 + } // 結束catch敘述 + Display d = new Display(DisplayText); + Invoke(d, new object[] { buffer }); + string message = BitConverter.ToString(buffer,0); // 取得Uart傳輸之Buffer資料(ASCII編碼值) + Uart_Buffer_ASCII_Data = message; // 將Uart傳輸之Buffer資料(ASCII編碼值)填入Uart_Buffer_ASCII_Data + } // 結束comport資料接收處理副程式 + private void DisplayText(byte[] buffer) // DisplayText顯示文字副程式 + { // 進入DisplayText顯示文字副程式 + DisplayText_Runtimes = DisplayText_Runtimes + 1; // 遞增DisplayText_Runtimes變數 + textBox1.Font = textBox1_Font; // 設定文字方塊顯示字型 + //textBox1.Text += String.Format("{0}{1}", BitConverter.ToString(buffer), Environment.NewLine); + // 將buffer中之接收文字(ascii原始碼)顯示於textBox1上 + textBox1.Text += System.Text.Encoding.ASCII.GetString(buffer); + // 將buffer中之接收資料(ascii原始碼)轉換為字串(符號字元),並顯示於textBox1上 + Transmission_Buffer_CharArray = System.Text.Encoding.ASCII.GetString(buffer).ToCharArray(); + // 將buffer中之接收資料(ascii原始碼)轉換為字串(符號字元)後,再轉換為字元陣列(CharArray),存入Transmission_Buffer_CharArray + /*for (loop_num=0; loop_num 0) // 若Transmission_Analysis_Queue元素個數大於0 + { // 進入while迴圈 + MessageBox.Show(Transmission_Analysis_Queue.Dequeue().ToString()); + // 將資料取出佇列並顯示 + } // 結束while迴圈 + */ + //MessageBox.Show(Transmission_Analysis_Queue.Dequeue().GetType().ToString()); + //顯示Transmission_Analysis_Queue佇列內容資料型態 + char Analysis_Char; // 宣告當前分析字元區域變數Analysis_Char + char Channel_Name_temp = ' '; // 宣告Channel_Name區域字元變數,暫存通道名稱 + string ADC_Data_temp; // 宣告ADC_Data_temp區域字串變數,累計數值 + Boolean flag = true; // 宣告旗標變數flag,決定字元分析是否執行 + while(flag) // 由flag旗標決定字元分析是否執行 + { // 進入while迴圈 + ADC_Data_temp = ""; // 初始化ADC_Data_temp字串 + Analysis_Char = Convert.ToChar(Transmission_Analysis_Queue.Peek()); + // 讀取佇列資料(不移除)填入當前分析字元變數 + //MessageBox.Show(Analysis_Char.ToString()); // 顯示當前分析字元 + if (Analysis_Char == 'X' && Transmission_Analysis_Queue.Contains('Y')) + // 若當前分析字元為X,且佇列中存在字元'Y',代表該筆X資料完整 + { // 進入if敘述 + Channel_Name_temp = Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + //由佇列Transmission_Analysis_Queue取出字元填入Channel_Name_temp(通道名稱暫存變數) + while (Convert.ToChar(Transmission_Analysis_Queue.Peek()) != 'Y') + // 若佇列資料不為字元Y,則取出資料填入ADC_Data_temp + { // 進入while迴圈 + ADC_Data_temp += Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + } // 結束while迴圈 + ADC_Raw_Data_X[ADC_Raw_Data_X_num] = int.Parse(ADC_Data_temp); + // 填入數值至ADC_Raw_Data_X + Data_Graphic_Queue_X.Enqueue(int.Parse(ADC_Data_temp)); // 填入數值至Data_Graphic_Queue_X(X通道資料繪圖用整數型態佇列) + ADC_Raw_Data_X_num = (ADC_Raw_Data_X_num + 1) % ADC_Raw_Data_Max; + // 遞增ADC_Raw_Data_X_num變數,並取餘數避免超出陣列大小 + } // 結束if敘述 + else if (Analysis_Char == 'Y' && Transmission_Analysis_Queue.Contains('Z')) + // 若當前分析字元為Y,且佇列中存在字元'Z',代表該筆Y資料完整 + { // 進入else if敘述 + Channel_Name_temp = Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + //由佇列Transmission_Analysis_Queue取出字元填入Channel_Name_temp(通道名稱暫存變數) + while (Convert.ToChar(Transmission_Analysis_Queue.Peek()) != 'Z') + // 若佇列資料不為字元Z,則取出資料填入ADC_Data_temp + { // 進入while迴圈 + ADC_Data_temp += Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + } // 結束while迴圈 + ADC_Raw_Data_Y[ADC_Raw_Data_Y_num] = int.Parse(ADC_Data_temp); + // 填入數值至ADC_Raw_Data_Y + Data_Graphic_Queue_Y.Enqueue(int.Parse(ADC_Data_temp)); // 填入數值至Data_Graphic_Queue_Y(Y通道資料繪圖用整數型態佇列) + ADC_Raw_Data_Y_num = (ADC_Raw_Data_Y_num + 1) % ADC_Raw_Data_Max; + // 遞增ADC_Raw_Data_Y_num變數,並取餘數避免超出陣列大小 + } // 結束else if敘述 + else if (Analysis_Char == 'Z' && Transmission_Analysis_Queue.Contains('X')) + // 若當前分析字元為Z,且佇列中存在字元'X',代表該筆Z資料完整 + { // 進入else if敘述 + Channel_Name_temp = Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + //由佇列Transmission_Analysis_Queue取出字元填入Channel_Name_temp(通道名稱暫存變數) + while (Convert.ToChar(Transmission_Analysis_Queue.Peek()) != 'X') + // 若佇列資料不為字元X,則取出資料填入ADC_Data_temp + { // 進入while迴圈 + ADC_Data_temp += Convert.ToChar(Transmission_Analysis_Queue.Dequeue()); + } // 結束while迴圈 + ADC_Raw_Data_Z[ADC_Raw_Data_Z_num] = int.Parse(ADC_Data_temp); + // 填入數值至ADC_Raw_Data_Z + Data_Graphic_Queue_Z.Enqueue(int.Parse(ADC_Data_temp)); // 填入數值至Data_Graphic_Queue_Z(Z通道資料繪圖用整數型態佇列) + ADC_Raw_Data_Z_num = (ADC_Raw_Data_Z_num + 1) % ADC_Raw_Data_Max; + // 遞增ADC_Raw_Data_Z_num變數,並取餘數避免超出陣列大小 + } // 結束else if敘述 + else // 若當前分析字元非X、Y、Z + { // 進入else敘述 + flag = false; // 結束字元分析 + } // 結束else敘述 + } // 結束while迴圈 + // 顯示ADC_Raw_Data_X、ADC_Raw_Data_Y、ADC_Raw_Data_Z + /*for (loop_num = 0;loop_num< ADC_Raw_Data_X_num; loop_num++) + { + MessageBox.Show("X[" + loop_num.ToString() + "]:" + + ADC_Raw_Data_X[loop_num].ToString()); + MessageBox.Show("Y[" + loop_num.ToString() + "]:" + + ADC_Raw_Data_Y[loop_num].ToString()); + MessageBox.Show("Z["+ loop_num.ToString()+"]:" + + ADC_Raw_Data_Z[loop_num].ToString()); + }*/ + //Data_Graphic副程式與Data_Graphic_Queue副程式擇一使用 + //Data_Graphic(); // 呼叫Data_Graphic副程式 + Data_Graphic_Queue(); // 呼叫Data_Graphic_Queue副程式 + } // 結束Uart_Data_Analysis_Queue副程式 + public void Data_Graphic() // 宣告Data_Graphic(資料繪圖副程式) + { // 進入Data_Graphic副程式 + /****使用全域變數: + **ADC_Raw_Data_X(記錄X通道ADC原始資料)、 + **ADC_Raw_Data_Y(記錄Y通道ADC原始資料)、 + **ADC_Raw_Data_Z(記錄Z通道ADC原始資料)、 + **ADC_Raw_Data_X_num(記錄ADC_Raw_Data_X資料量)、 + **ADC_Raw_Data_Y_num(記錄ADC_Raw_Data_Y資料量)、 + **ADC_Raw_Data_Z_num(記錄ADC_Raw_Data_Z資料量)、 + **ADC_Raw_Data_Max(記錄ADC_Raw_Data陣列大小)、 + **loop_num(迴圈用變數) + */ + //***區域變數宣告*** + Graphics Oscilloscope_Graphic; // 宣告Oscilloscope_Graphic示波器波型繪圖區 + Pen pen_Frame; // 宣告外框畫筆 + Pen pen_Grid_Line; // 宣告繪圖網格線畫筆 + Pen pen_X; // 宣告X通道畫筆 + Pen pen_Y; // 宣告Y通道畫筆 + Pen pen_Z; // 宣告Z通道畫筆 + //Rectangle rectangle_point = + // new Rectangle(5, 5, 5, 5); + //***指定畫布*** + Oscilloscope_Graphic = panel1.CreateGraphics(); // 取得繪圖區物件 + //***設定畫筆屬性*** + pen_Frame = new Pen(Color.Black, 3); // 設定外框畫筆為黑色、粗細為3點 + pen_Grid_Line = new Pen(Color.Gray); // 設定格線繪製畫筆屬性 + pen_X = new Pen(Color.Red, 2); // 設定X通道折線圖畫筆屬性 + pen_Y = new Pen(Color.Green, 2); // 設定Y通道折線圖畫筆屬性 + pen_Z = new Pen(Color.Blue, 2); // 設定Z通道折線圖畫筆屬性 + Oscilloscope_Graphic.Clear(Color.White); // 清除畫布背景為白色 + //***繪製外框*** + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製上框線 + new Point(0, 0), // 以(0, 0)為起始點 + new Point(panel1.Size.Width, 0)); // 以(panel1.Size.Width, 0)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製左框線 + new Point(0, 0), // 以(0, 0)為起始點 + new Point(0, panel1.Size.Height)); // 以(0, panel1.Size.Height)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製下框線 + new Point(0, panel1.Size.Height), // 以(0, panel1.Size.Height)為起點 + new Point(panel1.Size.Width, panel1.Size.Height)); // 以(panel1.Size.Width, panel1.Size.Height)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製右框線 + new Point(panel1.Size.Width, 0), // 以(panel1.Size.Width, 0)為起始點 + new Point(panel1.Size.Width, panel1.Size.Height)); // 以(panel1.Size.Width, panel1.Size.Height)為結束點 + //***水平格線繪製*** + for (loop_num=0;loop_num<10;loop_num++) // 以for迴圈依序繪製水平格線 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Grid_Line, // 以pen_Grid_Line畫筆繪製水平格線 + new Point(0, panel1.Size.Height * loop_num / 10), // 以(0, panel1.Size.Height * loop_num / 10)為起始點 + new Point(panel1.Size.Width, panel1.Size.Height * loop_num / 10)); + //以(panel1.Size.Width, panel1.Size.Height * loop_num / 10)為結束點 + } // 結束for迴圈 + //***垂直格線繪製*** + for (loop_num = 0; loop_num < 10; loop_num++) // 以for迴圈依序繪製垂直格線 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Grid_Line, // 以pen_Grid_Line畫筆繪製垂直格線 + new Point(panel1.Size.Width * loop_num / 10, 0), // 以(panel1.Size.Width * loop_num / 10, 0)為起始點 + new Point(panel1.Size.Width * loop_num / 10, panel1.Size.Height)); + //以(panel1.Size.Width * loop_num / 10, panel1.Size.Height)為結束點 + } // 結束for迴圈 + //***ADC_Raw_Data資料繪製折線圖*** + for (loop_num = 0; loop_num < (ADC_Raw_Data_X_num - 1); loop_num++) + //X通道資料折線圖繪製 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_X, + new Point( (loop_num * panel1.Size.Width / ADC_Raw_Data_Max) , + panel1.Size.Height - (ADC_Raw_Data_X[loop_num] * panel1.Size.Height / 4096)), + new Point( ( (loop_num + 1) * panel1.Size.Width / ADC_Raw_Data_Max) , + panel1.Size.Height - (ADC_Raw_Data_X[loop_num + 1] * panel1.Size.Height / 4096) )); + //rectangle_point = new Rectangle(((loop_num + 1) * panel1.Size.Width / ADC_Raw_Data_Max) , + // panel1.Size.Height - (ADC_Raw_Data_X[loop_num + 1] * panel1.Size.Height / 4096) , + // 3, 3); + //Oscilloscope_Graphic.DrawRectangle(Pens.Red, rectangle_point); + } // 結束for迴圈 + for (loop_num = 0; loop_num < (ADC_Raw_Data_Y_num - 1); loop_num++) + //Y通道資料折線圖繪製 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Y, + new Point((loop_num * panel1.Size.Width / ADC_Raw_Data_Max), + panel1.Size.Height - (ADC_Raw_Data_Y[loop_num] * panel1.Size.Height / 4096)), + new Point(((loop_num + 1) * panel1.Size.Width / ADC_Raw_Data_Max), + panel1.Size.Height - (ADC_Raw_Data_Y[loop_num + 1] * panel1.Size.Height / 4096))); + } // 結束for迴圈 + for (loop_num = 0; loop_num < (ADC_Raw_Data_Z_num - 1); loop_num++) + //Z通道資料折線圖繪製 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Z, + new Point((loop_num * panel1.Size.Width / ADC_Raw_Data_Max), + panel1.Size.Height - (ADC_Raw_Data_Z[loop_num] * panel1.Size.Height / 4096)), + new Point(((loop_num + 1) * panel1.Size.Width / ADC_Raw_Data_Max), + panel1.Size.Height - (ADC_Raw_Data_Z[loop_num + 1] * panel1.Size.Height / 4096))); + } // 結束for迴圈 + } // 結束Data_Graphic副程式 + public void Data_Graphic_Queue() // 宣告Data_Graphic_Queue(以佇列結構實作之資料繪圖副程式) + { // 進入Data_Graphic_Queue副程式 + /****使用全域變數: + **Data_Graphic_Queue_X(X通道資料繪圖用整數型態佇列)、 + **Data_Graphic_Queue_Y(Y通道資料繪圖用整數型態佇列)、 + **Data_Graphic_Queue_Z(Z通道資料繪圖用整數型態佇列)、 + **loop_num(迴圈用變數) + */ + //***區域變數宣告*** + Graphics Oscilloscope_Graphic; // 宣告Oscilloscope_Graphic示波器波型繪圖區 + Pen pen_Frame; // 宣告外框畫筆 + Pen pen_Grid_Line; // 宣告繪圖網格線畫筆 + Pen pen_X; // 宣告X通道畫筆 + Pen pen_Y; // 宣告Y通道畫筆 + Pen pen_Z; // 宣告Z通道畫筆 + int Data_Graphic_Queue_Count_Max = 100; // 宣告Data_Graphic_Queue_Count_Max整數區域變數,記錄繪圖用整數型態佇列元素數量最大值 + Point Graph_point_temp = new Point(); // 宣告Graph_point_temp(繪圖暫存座標) + //***指定畫布*** + Oscilloscope_Graphic = panel1.CreateGraphics(); // 取得繪圖區物件 + //***設定畫筆屬性*** + pen_Frame = new Pen(Color.Black, 3); // 設定外框畫筆為黑色、粗細為3點 + pen_Grid_Line = new Pen(Color.Gray); // 設定格線繪製畫筆屬性 + pen_X = new Pen(Color.Red, 2); // 設定X通道折線圖畫筆屬性 + pen_Y = new Pen(Color.Green, 2); // 設定Y通道折線圖畫筆屬性 + pen_Z = new Pen(Color.Blue, 2); // 設定Z通道折線圖畫筆屬性 + Oscilloscope_Graphic.Clear(Color.White); // 清除畫布背景為白色 + //***繪製外框*** + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製上框線 + new Point(0, 0), // 以(0, 0)為起始點 + new Point(panel1.Size.Width, 0)); // 以(panel1.Size.Width, 0)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製左框線 + new Point(0, 0), // 以(0, 0)為起始點 + new Point(0, panel1.Size.Height)); // 以(0, panel1.Size.Height)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製下框線 + new Point(0, panel1.Size.Height), // 以(0, panel1.Size.Height)為起點 + new Point(panel1.Size.Width, panel1.Size.Height)); // 以(panel1.Size.Width, panel1.Size.Height)為結束點 + Oscilloscope_Graphic.DrawLine(pen_Frame, // 以pen_Frame畫筆繪製右框線 + new Point(panel1.Size.Width, 0), // 以(panel1.Size.Width, 0)為起始點 + new Point(panel1.Size.Width, panel1.Size.Height)); // 以(panel1.Size.Width, panel1.Size.Height)為結束點 + //***水平格線繪製*** + for (loop_num = 0; loop_num < 10; loop_num++) // 以for迴圈依序繪製水平格線 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Grid_Line, // 以pen_Grid_Line畫筆繪製水平格線 + new Point(0, panel1.Size.Height * loop_num / 10), // 以(0, panel1.Size.Height * loop_num / 10)為起始點 + new Point(panel1.Size.Width, panel1.Size.Height * loop_num / 10)); + //以(panel1.Size.Width, panel1.Size.Height * loop_num / 10)為結束點 + } // 結束for迴圈 + //***垂直格線繪製*** + for (loop_num = 0; loop_num < 10; loop_num++) // 以for迴圈依序繪製垂直格線 + { // 進入for迴圈 + Oscilloscope_Graphic.DrawLine(pen_Grid_Line, // 以pen_Grid_Line畫筆繪製垂直格線 + new Point(panel1.Size.Width * loop_num / 10, 0), // 以(panel1.Size.Width * loop_num / 10, 0)為起始點 + new Point(panel1.Size.Width * loop_num / 10, panel1.Size.Height)); + //以(panel1.Size.Width * loop_num / 10, panel1.Size.Height)為結束點 + } // 結束for迴圈 + //***以while迴圈清除顯示佇列過多資料*** + while (Data_Graphic_Queue_X.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_X佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_X.Dequeue(); // 移除Data_Graphic_Queue_X佇列資料 + } // 結束while迴圈 + while (Data_Graphic_Queue_Y.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_Y佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_Y.Dequeue(); // 移除Data_Graphic_Queue_Y佇列資料 + } // 結束while迴圈 + while (Data_Graphic_Queue_Z.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_Z佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_Z.Dequeue(); // 移除Data_Graphic_Queue_Z佇列資料 + } // 結束while迴圈 + //***依序繪製資料*** + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_X) // 依序以Data_Graphic_Queue_X資料繪圖 + { // 進入foreach敘述 + //MessageBox.Show(ADC_Data.ToString()); // 依序顯示Data_Graphic_Queue_X佇列資料 + if(loop_num==0) // 若為佇列中第一筆資料 + { // 進入if敘述 + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Oscilloscope_Graphic.DrawLine(pen_X, Graph_point_temp, + new Point((loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096) )); + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_Y) // 依序以Data_Graphic_Queue_Y資料繪圖 + { // 進入foreach敘述 + //MessageBox.Show(ADC_Data.ToString()); // 依序顯示Data_Graphic_Queue_Y佇列資料 + if (loop_num == 0) // 若為佇列中第一筆資料 + { // 進入if敘述 + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Oscilloscope_Graphic.DrawLine(pen_Y, Graph_point_temp, + new Point((loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096) )); + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_Z) // 依序以Data_Graphic_Queue_Z資料繪圖 + { // 進入foreach敘述 + //MessageBoZ.Show(ADC_Data.ToString()); // 依序顯示Data_Graphic_Queue_Z佇列資料 + if (loop_num == 0) // 若為佇列中第一筆資料 + { // 進入if敘述 + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Oscilloscope_Graphic.DrawLine(pen_Z, Graph_point_temp, + new Point((loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096) )); + Graph_point_temp = new Point( // 指定Graph_point_temp座標 + (loop_num * panel1.Size.Width / Data_Graphic_Queue_Count_Max), + panel1.Size.Height - (ADC_Data * panel1.Size.Height / 4096)); + // 填入座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + //Data_Graphic_OpenGL副程式與Data_Graphic_Queue_OpenGL副程式擇一使用 + //Data_Graphic_OpenGL(); // 呼叫Data_Graphic_OpenGL(OpenGL資料繪圖)副程式 + Data_Graphic_Queue_OpenGL(); // 呼叫Data_Graphic_Queue_OpenGL(OpenGL佇列資料繪圖)副程式 + } // 結束Data_Graphic_Queue副程式 + public void Data_Graphic_OpenGL() // 宣告Data_Graphic_OpenGL(OpenGL資料繪圖副程式) + { // 進入Data_Graphic_OpenGL副程式 + /****使用全域變數: + **ADC_Raw_Data_X(記錄X通道ADC原始資料)、 + **ADC_Raw_Data_Y(記錄Y通道ADC原始資料)、 + **ADC_Raw_Data_Z(記錄Z通道ADC原始資料)、 + **ADC_Raw_Data_X_num(記錄ADC_Raw_Data_X資料量)、 + **ADC_Raw_Data_Y_num(記錄ADC_Raw_Data_Y資料量)、 + **ADC_Raw_Data_Z_num(記錄ADC_Raw_Data_Z資料量)、 + **ADC_Raw_Data_Max(記錄ADC_Raw_Data陣列大小)、 + **loop_num(迴圈用變數) + */ + //***區域變數宣告*** + + //***指定畫布*** + OpenGL Gsensor_GL = openGLControl1.OpenGL; // 取得OpenGL繪圖物件 + Gsensor_GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); + // 清除深度緩存 + Gsensor_GL.LoadIdentity(); + // 重置模型觀察矩陣,並將其初始化 + Gsensor_GL.Translate(0f, 0f, -2.5f); // 轉移繪圖中心座標 + //***繪製外框*** + Gsensor_GL.Color(1.0f, 1.0f, 1.0f); // 設定繪圖顏色 + Gsensor_GL.Begin(OpenGL.GL_LINE_LOOP); // 繪製封閉直線線段 + Gsensor_GL.Vertex(1, 1, 0); + Gsensor_GL.Vertex(1, -1, 0); + Gsensor_GL.Vertex(-1, -1, 0); + Gsensor_GL.Vertex(-1, 1, 0); + Gsensor_GL.End(); // 結束繪製外框 + //***水平格線繪製*** + for (loop_num = -5; loop_num <= 5; loop_num++) // 以for迴圈依序繪製水平格線 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); + Gsensor_GL.Vertex(-1, ((float)loop_num / 5), 0); + Gsensor_GL.Vertex(1, ((float)loop_num / 5), 0); + Gsensor_GL.End(); + } // 結束for迴圈 + //***垂直格線繪製*** + for (loop_num = -5; loop_num <= 5; loop_num++) // 以for迴圈依序繪製垂直格線 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); + Gsensor_GL.Vertex(((float)loop_num / 5), -1, 0); + Gsensor_GL.Vertex(((float)loop_num / 5), 1, 0); + Gsensor_GL.End(); + } // 結束for迴圈 + //***ADC_Raw_Data資料繪製折線圖*** + Gsensor_GL.Color(1.0f, 0.0f, 0.0f); // 設定繪圖顏色 + for (loop_num = 0; loop_num < (ADC_Raw_Data_X_num - 1); loop_num++) + //X通道資料折線圖繪製 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); + Gsensor_GL.Vertex( ( (float)loop_num / ADC_Raw_Data_Max) * 2 - 1, + ( ((double)ADC_Raw_Data_X[loop_num] / 4096) ) * 2 - 1, + 0); + Gsensor_GL.Vertex( ( ((float)loop_num + 1) / ADC_Raw_Data_Max) * 2 - 1, + ( ((double)ADC_Raw_Data_X[loop_num + 1] / 4096)) * 2 - 1, + 0); + Gsensor_GL.End(); // 結束線段繪製 + } // 結束for迴圈 + Gsensor_GL.Color(0.0f, 1.0f, 0.0f); // 設定繪圖顏色 + for (loop_num = 0; loop_num < (ADC_Raw_Data_Y_num - 1); loop_num++) + //X通道資料折線圖繪製 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); + Gsensor_GL.Vertex(((float)loop_num / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Raw_Data_Y[loop_num] / 4096)) * 2 - 1, + 0); + Gsensor_GL.Vertex((((float)loop_num + 1) / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Raw_Data_Y[loop_num + 1] / 4096)) * 2 - 1, + 0); + Gsensor_GL.End(); // 結束線段繪製 + } // 結束for迴圈 + Gsensor_GL.Color(0.0f, 0.0f, 1.0f); // 設定繪圖顏色 + for (loop_num = 0; loop_num < (ADC_Raw_Data_Z_num - 1); loop_num++) + //X通道資料折線圖繪製 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); + Gsensor_GL.Vertex(((float)loop_num / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Raw_Data_Z[loop_num] / 4096)) * 2 - 1, + 0); + Gsensor_GL.Vertex((((float)loop_num + 1) / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Raw_Data_Z[loop_num + 1] / 4096)) * 2 - 1, + 0); + Gsensor_GL.End(); // 結束線段繪製 + } // 結束for迴圈 + Gsensor_GL.Flush(); // 強制更新繪圖 + } // 結束Data_Graphic_OpenGL副程式 + public void Data_Graphic_Queue_OpenGL() // 宣告Data_Graphic_Queue_OpenGL(OpenGL佇列資料繪圖副程式) + { // 進入Data_Graphic_Queue_OpenGL副程式 + /****使用全域變數: + **OpenGL_Graph_point結構(OpenGL座標宣告) + **Data_Graphic_Queue_X(X通道資料繪圖用整數型態佇列)、 + **Data_Graphic_Queue_Y(Y通道資料繪圖用整數型態佇列)、 + **Data_Graphic_Queue_Z(Z通道資料繪圖用整數型態佇列)、 + **loop_num(迴圈用變數) + */ + //***區域變數宣告*** + int Data_Graphic_Queue_Count_Max = 100; // 宣告Data_Graphic_Queue_Count_Max整數區域變數,記錄繪圖用整數型態佇列元素數量最大值 + OpenGL_Graph_point OpenGL_Graph_point_temp = new OpenGL_Graph_point(); + // 宣告OpenGL_Graph_point_temp(OpenGL繪圖暫存座標) + OpenGL_Graph_point_temp.point_X = 0; // 初始化OpenGL_Graph_point_temp(OpenGL繪圖暫存座標)X座標數值 + OpenGL_Graph_point_temp.point_Y = 0; // 初始化OpenGL_Graph_point_temp(OpenGL繪圖暫存座標)Y座標數值 + //***以while迴圈清除顯示佇列過多資料*** + while (Data_Graphic_Queue_X.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_X佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_X.Dequeue(); // 移除Data_Graphic_Queue_X佇列資料 + } // 結束while迴圈 + while (Data_Graphic_Queue_Y.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_Y佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_Y.Dequeue(); // 移除Data_Graphic_Queue_Y佇列資料 + } // 結束while迴圈 + while (Data_Graphic_Queue_Z.Count > Data_Graphic_Queue_Count_Max) // 以while迴圈依序移除Data_Graphic_Queue_Z佇列過多的資料 + { // 進入while迴圈 + Data_Graphic_Queue_Z.Dequeue(); // 移除Data_Graphic_Queue_Z佇列資料 + } // 結束while迴圈 + //***指定畫布*** + OpenGL Gsensor_GL = openGLControl1.OpenGL; // 取得OpenGL繪圖物件 + Gsensor_GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); + // 清除深度緩存 + Gsensor_GL.LoadIdentity(); + // 重置模型觀察矩陣,並將其初始化 + Gsensor_GL.Translate(0f, 0f, -2.5f); // 轉移繪圖中心座標 + //***繪製外框*** + Gsensor_GL.Color(1.0f, 1.0f, 1.0f); // 設定繪圖顏色 + Gsensor_GL.Begin(OpenGL.GL_LINE_LOOP); // 繪製封閉直線線段 + Gsensor_GL.Vertex(1, 1, 0); + Gsensor_GL.Vertex(1, -1, 0); + Gsensor_GL.Vertex(-1, -1, 0); + Gsensor_GL.Vertex(-1, 1, 0); + Gsensor_GL.End(); // 結束繪製外框 + //***水平格線繪製*** + for (loop_num = -5; loop_num <= 5; loop_num++) // 以for迴圈依序繪製水平格線 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); // 開始繪製直線線段 + Gsensor_GL.Vertex(-1, ((float)loop_num / 5), 0); + Gsensor_GL.Vertex(1, ((float)loop_num / 5), 0); + Gsensor_GL.End(); + } // 結束for迴圈 + //***垂直格線繪製*** + for (loop_num = -5; loop_num <= 5; loop_num++) // 以for迴圈依序繪製垂直格線 + { // 進入for迴圈 + Gsensor_GL.Begin(OpenGL.GL_LINES); // 開始繪製直線線段 + Gsensor_GL.Vertex(((float)loop_num / 5), -1, 0); + Gsensor_GL.Vertex(((float)loop_num / 5), 1, 0); + Gsensor_GL.End(); + } // 結束for迴圈 + //***依序繪製資料*** + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_X) // 依序以Data_Graphic_Queue_X資料繪圖 + { // 進入foreach敘述 + if (loop_num == 0) // 若為佇列中第一筆資料 + { // 進入if敘述 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Gsensor_GL.Begin(OpenGL.GL_LINES); // 開始繪製直線線段 + Gsensor_GL.Color(1.0f, 0.0f, 0.0f); // 設定繪圖顏色 + Gsensor_GL.Vertex(OpenGL_Graph_point_temp.point_X, + OpenGL_Graph_point_temp.point_Y, + 0); // 設定直線繪製起始點 + Gsensor_GL.Vertex(((double)loop_num / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Data / 4096)) * 2 - 1, + 0); // 設定直線繪製結束點 + Gsensor_GL.End(); // 繪圖結束 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_Y) // 依序以Data_Graphic_Queue_Y資料繪圖 + { // 進入foreach敘述 + if (loop_num == 0) // 若為佇列中第一筆資料 + { // 進入if敘述 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Gsensor_GL.Begin(OpenGL.GL_LINES); // 開始繪製直線線段 + Gsensor_GL.Color(0.0f, 1.0f, 0.0f); // 設定繪圖顏色 + Gsensor_GL.Vertex(OpenGL_Graph_point_temp.point_X, + OpenGL_Graph_point_temp.point_Y, + 0); // 設定直線繪製起始點 + Gsensor_GL.Vertex(((double)loop_num / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Data / 4096)) * 2 - 1, + 0); // 設定直線繪製結束點 + Gsensor_GL.End(); // 繪圖結束 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + loop_num = 0; + foreach (int ADC_Data in Data_Graphic_Queue_Z) // 依序以Data_Graphic_Queue_Z資料繪圖 + { // 進入foreach敘述 + if (loop_num == 0) // 若為佇列中第一筆資料 + { // 進入if敘述 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束if敘述 + else // 若不為佇列中第一筆資料 + { // 進入else敘述 + Gsensor_GL.Begin(OpenGL.GL_LINES); // 開始繪製直線線段 + Gsensor_GL.Color(0.0f, 0.0f, 1.0f); // 設定繪圖顏色 + Gsensor_GL.Vertex(OpenGL_Graph_point_temp.point_X, + OpenGL_Graph_point_temp.point_Y, + 0); // 設定直線繪製起始點 + Gsensor_GL.Vertex(((double)loop_num / ADC_Raw_Data_Max) * 2 - 1, + (((double)ADC_Data / 4096)) * 2 - 1, + 0); // 設定直線繪製結束點 + Gsensor_GL.End(); // 繪圖結束 + OpenGL_Graph_point_temp.point_X = ((double)loop_num / ADC_Raw_Data_Max) * 2 - 1; + // 指定OpenGL_Graph_point_temp之X座標 + OpenGL_Graph_point_temp.point_Y = (((double)ADC_Data / 4096)) * 2 - 1; + // 指定OpenGL_Graph_point_temp之Y座標 + } // 結束else敘述 + loop_num = loop_num + 1; // 遞增loop_num變數 + } // 結束foreach敘述 + Gsensor_GL.Flush(); // 強制更新繪圖 + } // 結束Data_Graphic_Queue_OpenGL副程式 + private void timer1_Tick(object sender, EventArgs e) // 宣告timer1_Tick副程式,即時更新現在時間 + { // 進入timer1_Tick副程式 + DateTime localDate = DateTime.Now; // 更新現在時間 + } // 結束timer1_Tick副程式 + } // 結束Form1類別 + //-----例外狀況處理----- + public class IOException : SystemException + { + + } +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.resx new file mode 100644 index 0000000..91ff5be --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 136, 17 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.Designer.cs new file mode 100644 index 0000000..018758b --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.Designer.cs @@ -0,0 +1,135 @@ +namespace WindowsFormsApplication6 +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.textBox1.Location = new System.Drawing.Point(132, 12); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(186, 33); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "9600"; + this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label1.Location = new System.Drawing.Point(12, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(114, 21); + this.label1.TabIndex = 1; + this.label1.Text = "Baud Rate:"; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("新細明體", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button1.Location = new System.Drawing.Point(665, 277); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(93, 34); + this.button1.TabIndex = 2; + this.button1.Text = "儲存"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label2.Location = new System.Drawing.Point(12, 54); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(78, 21); + this.label2.TabIndex = 3; + this.label2.Text = "Parity:"; + // + // comboBox1 + // + this.comboBox1.Font = new System.Drawing.Font("新細明體", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Items.AddRange(new object[] { + "無同位元檢查", + "奇同位位元檢查", + "偶同位位元檢查", + "同位位元恆設為1", + "同位位元恆設為0"}); + this.comboBox1.Location = new System.Drawing.Point(132, 51); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(186, 29); + this.comboBox1.TabIndex = 4; + this.comboBox1.Text = "無同位元檢查"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("新細明體", 15.75F); + this.label3.Location = new System.Drawing.Point(12, 93); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(99, 21); + this.label3.TabIndex = 5; + this.label3.Text = "DataBits:"; + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(770, 323); + this.Controls.Add(this.label3); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.label2); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBox1); + this.Name = "Form2"; + this.Text = "傳輸設定"; + this.Load += new System.EventHandler(this.Form2_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label3; + } +} \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.cs new file mode 100644 index 0000000..a8516fe --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.cs @@ -0,0 +1,39 @@ +using System; // 使用System函式庫 +using System.Collections.Generic; // 使用System.Collections.Generic函式庫 +using System.ComponentModel; // 使用System.ComponentModel函式庫 +using System.Data; // 使用System.Data函式庫 +using System.Drawing; // 使用System.Drawing函式庫 +using System.Linq; // 使用System.Linq函式庫 +using System.Text; // 使用System.Text函式庫 +using System.Threading.Tasks; // 使用System.Threading.Tasks函式庫 +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 + +namespace WindowsFormsApplication6 // 命名空間為本程式 +{ // 進入命名空間 + public partial class Form2 : Form // Form2類別 + { // 進入Form2類別 + public Form2() // 宣告Form2 + { // 進入Form2 + InitializeComponent(); // 初始化表單 + } // 結束Form2 + private void Form2_Load(object sender, EventArgs e) // Form2表單載入時執行 + { // 進入Form2_Load副程式 + textBox1.Text = Form1.BaudRate.ToString(); // 載入當前鮑率(BaudRate)設定 + comboBox1.SelectedIndex = Form1.Parity_num; // 載入當前同位位元設定 + } // 結束Form2_Load副程式 + private void button1_Click(object sender, EventArgs e) // 當按下"儲存"按鈕 + { // 進入button1_Click副程式 + Form1.BaudRate = int.Parse(textBox1.Text); // 更新BaudRate鮑率設定 + Form1.Parity_num = comboBox1.SelectedIndex; // 更新Parity_num同位位元設定 + + var Information = MessageBox.Show // 顯示通知訊息 + ( // 進入通知訊息MessageBox設定 + "連線設定將於下次連線生效", // 顯示文字"連線設定將於下次連線生效" + "Information", // 設定MessageBox標題為"Information" + MessageBoxButtons.OK, // MessageBox選項為OK + MessageBoxIcon.Information // 顯示通知標誌 + ); // 結束通知訊息MessageBox設定 + Close(); // 關閉表單 + } // 結束button1_Click副程式 + } // 結束Form2類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form2.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.Designer.cs new file mode 100644 index 0000000..2754cc0 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.Designer.cs @@ -0,0 +1,120 @@ +namespace WindowsFormsApplication6 +{ + partial class Form3 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.fontDialog1 = new System.Windows.Forms.FontDialog(); + this.button3 = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(544, 141); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Uart資料顯示設定"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label1.Location = new System.Drawing.Point(6, 28); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(88, 16); + this.label1.TabIndex = 3; + this.label1.Text = "字型設定:"; + // + // button2 + // + this.button2.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button2.Location = new System.Drawing.Point(100, 21); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(89, 32); + this.button2.TabIndex = 2; + this.button2.Text = "字型"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button1 + // + this.button1.Font = new System.Drawing.Font("新細明體", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.button1.Location = new System.Drawing.Point(470, 262); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(86, 32); + this.button1.TabIndex = 1; + this.button1.Text = "儲存"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button3 + // + this.button3.Font = new System.Drawing.Font("新細明體", 12F); + this.button3.Location = new System.Drawing.Point(12, 262); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(125, 32); + this.button3.TabIndex = 2; + this.button3.Text = "登入除錯介面"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // Form3 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(568, 306); + this.Controls.Add(this.button3); + this.Controls.Add(this.button1); + this.Controls.Add(this.groupBox1); + this.Name = "Form3"; + this.Text = "介面設定"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.FontDialog fontDialog1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button3; + } +} \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.cs new file mode 100644 index 0000000..874e89f --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.cs @@ -0,0 +1,34 @@ +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 +using System.Linq; +using System.Collections; +using System.Collections.Generic; +namespace WindowsFormsApplication6 // 命名空間為本程式 +{ // 進入命名空間 + public partial class Form3 : Form // Form3類別 + { // 進入Form3類別 + public Form3() // 宣告Form3 + { // 進入Form3 + InitializeComponent(); // 初始化表單 + } // 結束Form3 + + private void button1_Click(object sender, System.EventArgs e) // 宣告button1_Click副程式,按下"儲存"按鈕時執行 + { // 進入button1_Click副程式 + + Close(); // 關閉表單 + } // 結束button1_Click副程式 + + private void button2_Click(object sender, System.EventArgs e) // 宣告button2_Click副程式,按下"字型"按鈕時執行 + { // 進入button2_Click副程式 + if (fontDialog1.ShowDialog() == DialogResult.OK) // 若字型設定正確 + { // 進入if敘述 + Form1.textBox1_Font = fontDialog1.Font; // 更新字型設定(textBox1_Font) + } // 結束if敘述 + } // 結束button2_Click副程式 + + private void button3_Click(object sender, System.EventArgs e) // 宣告button3_Click副程式,按下"登入除錯介面"按鈕時執行 + { // 進入button3_Click副程式 + Form4 Debug_Login_form = new Form4(); // 宣告Debug_Login_form代表Form4 + Debug_Login_form.Show(); // 顯示Debug_Login_form + } // 結束button3_Click副程式 + } // 結束Form3類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.resx new file mode 100644 index 0000000..5db00f7 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form3.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.Designer.cs new file mode 100644 index 0000000..81cf8ec --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.Designer.cs @@ -0,0 +1,126 @@ +namespace WindowsFormsApplication6 +{ + partial class Form4 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("新細明體", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(250, 24); + this.label1.TabIndex = 0; + this.label1.Text = "請登入以進入除錯模式"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label2.Location = new System.Drawing.Point(13, 53); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(56, 16); + this.label2.TabIndex = 1; + this.label2.Text = "帳號:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label3.Location = new System.Drawing.Point(12, 89); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(56, 16); + this.label3.TabIndex = 2; + this.label3.Text = "密碼:"; + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.textBox1.Location = new System.Drawing.Point(74, 50); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(340, 27); + this.textBox1.TabIndex = 3; + // + // textBox2 + // + this.textBox2.Font = new System.Drawing.Font("新細明體", 12F); + this.textBox2.Location = new System.Drawing.Point(74, 86); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(340, 27); + this.textBox2.TabIndex = 4; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("新細明體", 12F); + this.button1.Location = new System.Drawing.Point(164, 157); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(98, 38); + this.button1.TabIndex = 5; + this.button1.Text = "登入"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form4 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(426, 210); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "Form4"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "除錯模式登入"; + this.Load += new System.EventHandler(this.Form4_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.cs new file mode 100644 index 0000000..ccbc499 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.cs @@ -0,0 +1,106 @@ +using System; // 使用System函式庫 +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 + +namespace WindowsFormsApplication6 // 命名空間為本程式 +{ // 進入命名空間 + public partial class Form4 : Form // Form4類別 + { // 進入Form4類別 + public static Form1.Debug_Login_Account_struct // 宣告Debug_Login_Account_Input全域變數,儲存輸入帳號密碼資訊 + Debug_Login_Account_Input = new Form1.Debug_Login_Account_struct(); // 宣告Debug_Login_Account_Input全域變數,儲存輸入帳號密碼資訊 + public static DateTime Login_Date; // 宣告Login_Date時間變數,記錄除錯模式登入時間 + public Form4() // 宣告Form4 + { // 進入Form4 + InitializeComponent(); // 初始化表單 + } // 結束Form4 + private void Form4_Load(object sender, EventArgs e) // 宣告Form4_Load副程式,Form4表單載入時執行 + { // 進入Form4_Load副程式 + textBox2.UseSystemPasswordChar = true; // 設定textBox2(密碼輸入欄位)顯示字元隱藏 + } // 結束Form4_Load副程式 + private void button1_Click(object sender, EventArgs e) // 宣告button1_Click副程式,按下"登入除錯模式"按鈕時執行 + { // 進入button1_Click副程式 + // 輸入資訊檢查 + if (textBox1.Text == "") // 若帳號資訊(textBox1欄位)為空白 + { // 進入if敘述 + Form1.Error_Code = 040001; // 記錄Error_Code + var Error = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + "請輸入帳號,Error_Code=" + Form1.Error_Code, // 顯示錯誤訊息"請輸入帳號",同時顯示Error_Code + "請輸入帳號", // 顯示錯誤訊息標題為"請輸入帳號" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束錯誤訊息MessageBox設定 + return; // 結束button1_Click副程式 + } // 結束if敘述 + if (textBox2.Text == "") // 若密碼資訊(textBox2欄位)為空白 + { // 進入if敘述 + Form1.Error_Code = 040002; // 記錄Error_Code + var Error = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + "請輸入密碼,Error_Code=" + Form1.Error_Code, // 顯示錯誤訊息"請輸入密碼",同時顯示Error_Code + "請輸入密碼", // 顯示錯誤訊息標題為"請輸入密碼" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束錯誤訊息MessageBox設定 + return; // 結束button1_Click副程式 + } // 結束if敘述 + Debug_Login_Account_Input.Debug_Login_Account = textBox1.Text; // 將輸入之帳號資訊(textBox1.Text欄位)填入Debug_Login_Account_Input.Debug_Login_Account + Debug_Login_Account_Input.Debug_Login_Password = textBox2.Text; // 將輸入之密碼資訊(textBox2.Text欄位)填入Debug_Login_Account_Input.Debug_Login_Password + if (Debug_Login_Account_Input.Debug_Login_Account == // 檢測輸入帳號,若輸入帳號正確則進入if敘述 + Form1.Debug_Account1.Debug_Login_Account) // 檢測輸入帳號,若輸入帳號正確則進入if敘述 + { // 進入if敘述 + if (Debug_Login_Account_Input.Debug_Login_Password == // 檢測輸入密碼,若輸入密碼正確則進入if敘述 + Form1.Debug_Account1.Debug_Login_Password) // 檢測輸入密碼,若輸入密碼正確則進入if敘述 + { // 進入if敘述 + var warning = MessageBox.Show // 顯示通知訊息 + ( // 進入警告訊息MessageBox設定 + "已成功登入" + Form1.Debug_Account1.Debug_Login_Account,// 顯示"已成功登入",並顯示登入帳號名稱 + "登入成功", // 訊息標題為"登入成功" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Information // 顯示information標誌 + ); // 結束警告訊息MessageBox設定 + Login_Date = DateTime.Now; // 記錄除錯模式登入時間 + Form1.Program_Work_Mode = 1; // 進入除錯模式,設定Program_Work_Mode值為1 + Form5 Debug_form = new Form5(); // 宣告Debug_form代表Form5 + Debug_form.Show(); // 顯示Debug_form + Close(); // 關閉本表單 + } // 結束if敘述 + else // 若密碼輸入錯誤,則進入else敘述 + { // 進入else敘述 + Form1.Error_Code = 040004; // 記錄Error_Code + var warning = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + "密碼錯誤,Error_Code=" + Form1.Error_Code, // 顯示錯誤訊息"密碼錯誤",同時顯示Error_Code + "密碼錯誤", // 顯示錯誤訊息標題為"密碼錯誤" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束警告訊息MessageBox設定 + textBox1.Text = ""; // 清空帳號輸入欄位(textBox1) + textBox2.Text = ""; // 清空密碼輸入欄位(textBox2) + return; // 結束button1_Click副程式 + } // 結束else敘述 + } // 結束if敘述 + else // 若帳號輸入錯誤,則進入else敘述 + { // 進入else敘述 + Form1.Error_Code = 040003; // 記錄Error_Code + var warning = MessageBox.Show // 顯示錯誤訊息 + ( // 進入錯誤訊息MessageBox設定 + "帳號錯誤,Error_Code=" + Form1.Error_Code, // 顯示錯誤訊息"帳號錯誤",同時顯示Error_Code + "帳號錯誤", // 顯示錯誤訊息標題為"帳號錯誤" + MessageBoxButtons.OK, // 顯示"OK"按鈕 + MessageBoxIcon.Error // 顯示錯誤標誌 + ); // 結束警告訊息MessageBox設定 + textBox1.Text = ""; // 清空帳號輸入欄位(textBox1) + textBox2.Text = ""; // 清空密碼輸入欄位(textBox2) + return; // 結束button1_Click副程式 + } // 結束else敘述 + } // 結束button1_Click副程式 + + } // 結束Form4類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form4.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.Designer.cs new file mode 100644 index 0000000..cfe8a07 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.Designer.cs @@ -0,0 +1,536 @@ +namespace WindowsFormsApplication6 +{ + partial class Form5 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.label15 = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label22 = new System.Windows.Forms.Label(); + this.label21 = new System.Windows.Forms.Label(); + this.label20 = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); + this.label17 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.label26 = new System.Windows.Forms.Label(); + this.label25 = new System.Windows.Forms.Label(); + this.label24 = new System.Windows.Forms.Label(); + this.label23 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.label100 = new System.Windows.Forms.Label(); + this.label101 = new System.Windows.Forms.Label(); + this.label102 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.label200 = new System.Windows.Forms.Label(); + this.label201 = new System.Windows.Forms.Label(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.groupBox4.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("新細明體", 12F); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(184, 16); + this.label1.TabIndex = 0; + this.label1.Text = "此為除錯介面,使用者:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("新細明體", 12F); + this.label2.Location = new System.Drawing.Point(202, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(34, 16); + this.label2.TabIndex = 1; + this.label2.Text = "user"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("新細明體", 12F); + this.label5.Location = new System.Drawing.Point(12, 40); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(88, 16); + this.label5.TabIndex = 2; + this.label5.Text = "現在時間:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("新細明體", 12F); + this.label6.Location = new System.Drawing.Point(106, 40); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(40, 16); + this.label6.TabIndex = 3; + this.label6.Text = "Time"; + // + // timer1 + // + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Font = new System.Drawing.Font("新細明體", 12F); + this.label7.Location = new System.Drawing.Point(9, 75); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(180, 16); + this.label7.TabIndex = 4; + this.label7.Text = "已連線之Serialport數量:"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Font = new System.Drawing.Font("新細明體", 12F); + this.label8.Location = new System.Drawing.Point(195, 75); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(123, 16); + this.label8.TabIndex = 5; + this.label8.Text = "Serialport Number"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Font = new System.Drawing.Font("新細明體", 12F); + this.label11.Location = new System.Drawing.Point(12, 133); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(283, 16); + this.label11.TabIndex = 6; + this.label11.Text = "comport_DataReceived副程式執行次數:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("新細明體", 12F); + this.label3.Location = new System.Drawing.Point(377, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(88, 16); + this.label3.TabIndex = 7; + this.label3.Text = "登入時間:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("新細明體", 12F); + this.label4.Location = new System.Drawing.Point(471, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(81, 16); + this.label4.TabIndex = 8; + this.label4.Text = "Login Time"; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Font = new System.Drawing.Font("新細明體", 12F); + this.label12.Location = new System.Drawing.Point(301, 133); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(222, 16); + this.label12.TabIndex = 9; + this.label12.Text = "comport_DataReceived_Runtimes"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Font = new System.Drawing.Font("新細明體", 12F); + this.label13.Location = new System.Drawing.Point(12, 161); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(273, 16); + this.label13.TabIndex = 10; + this.label13.Text = "Uart_comport_handle副程式執行次數:"; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Font = new System.Drawing.Font("新細明體", 12F); + this.label14.Location = new System.Drawing.Point(291, 161); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(212, 16); + this.label14.TabIndex = 12; + this.label14.Text = "Uart_comport_handle_Runtimes"; + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Font = new System.Drawing.Font("新細明體", 12F); + this.label15.Location = new System.Drawing.Point(12, 190); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(212, 16); + this.label15.TabIndex = 13; + this.label15.Text = "DisplayText副程式執行次數:"; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Font = new System.Drawing.Font("新細明體", 12F); + this.label16.Location = new System.Drawing.Point(230, 190); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(151, 16); + this.label16.TabIndex = 14; + this.label16.Text = "DisplayText_Runtimes"; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label22); + this.groupBox1.Controls.Add(this.label21); + this.groupBox1.Controls.Add(this.label20); + this.groupBox1.Controls.Add(this.label19); + this.groupBox1.Controls.Add(this.label18); + this.groupBox1.Controls.Add(this.label17); + this.groupBox1.Font = new System.Drawing.Font("新細明體", 12F); + this.groupBox1.Location = new System.Drawing.Point(12, 218); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(724, 127); + this.groupBox1.TabIndex = 15; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "button_Runtimes副程式執行次數"; + // + // label22 + // + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(237, 96); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(164, 16); + this.label22.TabIndex = 5; + this.label22.Text = "button3_Click_Runtimes"; + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(6, 96); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(225, 16); + this.label21.TabIndex = 4; + this.label21.Text = "button3_Click副程式執行次數:"; + // + // label20 + // + this.label20.AutoSize = true; + this.label20.Location = new System.Drawing.Point(237, 65); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(164, 16); + this.label20.TabIndex = 3; + this.label20.Text = "button2_Click_Runtimes"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(6, 65); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(225, 16); + this.label19.TabIndex = 2; + this.label19.Text = "button2_Click副程式執行次數:"; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(237, 34); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(164, 16); + this.label18.TabIndex = 1; + this.label18.Text = "button1_Click_Runtimes"; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(6, 34); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(225, 16); + this.label17.TabIndex = 0; + this.label17.Text = "button1_Click副程式執行次數:"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.label26); + this.groupBox2.Controls.Add(this.label25); + this.groupBox2.Controls.Add(this.label24); + this.groupBox2.Controls.Add(this.label23); + this.groupBox2.Font = new System.Drawing.Font("新細明體", 12F); + this.groupBox2.Location = new System.Drawing.Point(12, 351); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(724, 95); + this.groupBox2.TabIndex = 16; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "ToolStripMenuItem_Click副程式執行次數"; + // + // label26 + // + this.label26.AutoSize = true; + this.label26.Location = new System.Drawing.Point(415, 62); + this.label26.Name = "label26"; + this.label26.Size = new System.Drawing.Size(259, 16); + this.label26.TabIndex = 18; + this.label26.Text = "User_Interface_Setting_Click_Runtimes"; + // + // label25 + // + this.label25.AutoSize = true; + this.label25.Location = new System.Drawing.Point(6, 62); + this.label25.Name = "label25"; + this.label25.Size = new System.Drawing.Size(403, 16); + this.label25.TabIndex = 17; + this.label25.Text = "設定_介面設定ToolStripMenuItem_Click副程式執行次數:"; + // + // label24 + // + this.label24.AutoSize = true; + this.label24.Location = new System.Drawing.Point(415, 33); + this.label24.Name = "label24"; + this.label24.Size = new System.Drawing.Size(250, 16); + this.label24.TabIndex = 1; + this.label24.Text = "Transmission_Setting_Click_Runtimes"; + // + // label23 + // + this.label23.AutoSize = true; + this.label23.Location = new System.Drawing.Point(6, 33); + this.label23.Name = "label23"; + this.label23.Size = new System.Drawing.Size(403, 16); + this.label23.TabIndex = 0; + this.label23.Text = "設定_傳輸設定ToolStripMenuItem_Click副程式執行次數:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Font = new System.Drawing.Font("新細明體", 12F); + this.label9.Location = new System.Drawing.Point(12, 107); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(222, 16); + this.label9.TabIndex = 17; + this.label9.Text = "list_SerialPort副程式執行次數:"; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Font = new System.Drawing.Font("新細明體", 12F); + this.label10.Location = new System.Drawing.Point(252, 107); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(161, 16); + this.label10.TabIndex = 18; + this.label10.Text = "list_SerialPort_Runtimes"; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("新細明體", 12F); + this.button1.Location = new System.Drawing.Point(567, 107); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(169, 42); + this.button1.TabIndex = 19; + this.button1.Text = "副程式執行次數歸零"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.textBox1); + this.groupBox3.Controls.Add(this.label102); + this.groupBox3.Controls.Add(this.label101); + this.groupBox3.Controls.Add(this.label100); + this.groupBox3.Font = new System.Drawing.Font("新細明體", 12F); + this.groupBox3.Location = new System.Drawing.Point(12, 452); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(724, 169); + this.groupBox3.TabIndex = 20; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Uart資料傳輸"; + // + // label100 + // + this.label100.AutoSize = true; + this.label100.Location = new System.Drawing.Point(6, 23); + this.label100.Name = "label100"; + this.label100.Size = new System.Drawing.Size(187, 16); + this.label100.TabIndex = 0; + this.label100.Text = "Uart接收資料Buffer大小:"; + // + // label101 + // + this.label101.AutoSize = true; + this.label101.Location = new System.Drawing.Point(199, 23); + this.label101.Name = "label101"; + this.label101.Size = new System.Drawing.Size(117, 16); + this.label101.TabIndex = 1; + this.label101.Text = "Uart_Buffer_Size"; + // + // label102 + // + this.label102.AutoSize = true; + this.label102.Location = new System.Drawing.Point(6, 49); + this.label102.Name = "label102"; + this.label102.Size = new System.Drawing.Size(268, 16); + this.label102.TabIndex = 2; + this.label102.Text = "Uart傳輸之Buffer資料(ASCII編碼值):"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(9, 77); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(709, 86); + this.textBox1.TabIndex = 3; + // + // groupBox4 + // + this.groupBox4.Controls.Add(this.label201); + this.groupBox4.Controls.Add(this.label200); + this.groupBox4.Font = new System.Drawing.Font("新細明體", 12F); + this.groupBox4.Location = new System.Drawing.Point(12, 627); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(724, 100); + this.groupBox4.TabIndex = 21; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "錯誤與例外狀況"; + // + // label200 + // + this.label200.AutoSize = true; + this.label200.Location = new System.Drawing.Point(6, 23); + this.label200.Name = "label200"; + this.label200.Size = new System.Drawing.Size(97, 16); + this.label200.TabIndex = 0; + this.label200.Text = "Error_Code:"; + // + // label201 + // + this.label201.AutoSize = true; + this.label201.Location = new System.Drawing.Point(109, 23); + this.label201.Name = "label201"; + this.label201.Size = new System.Drawing.Size(81, 16); + this.label201.TabIndex = 1; + this.label201.Text = "Error_Code"; + // + // Form5 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.AutoSize = true; + this.ClientSize = new System.Drawing.Size(796, 737); + this.Controls.Add(this.groupBox4); + this.Controls.Add(this.groupBox3); + this.Controls.Add(this.button1); + this.Controls.Add(this.label10); + this.Controls.Add(this.label9); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.label16); + this.Controls.Add(this.label15); + this.Controls.Add(this.label14); + this.Controls.Add(this.label13); + this.Controls.Add(this.label12); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label11); + this.Controls.Add(this.label8); + this.Controls.Add(this.label7); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "Form5"; + this.Text = "除錯介面"; + this.Load += new System.EventHandler(this.Form5_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.groupBox4.ResumeLayout(false); + this.groupBox4.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.Label label20; + private System.Windows.Forms.Label label19; + private System.Windows.Forms.Label label22; + private System.Windows.Forms.Label label21; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label label23; + private System.Windows.Forms.Label label24; + private System.Windows.Forms.Label label26; + private System.Windows.Forms.Label label25; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Label label101; + private System.Windows.Forms.Label label100; + private System.Windows.Forms.Label label102; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.Label label201; + private System.Windows.Forms.Label label200; + } +} \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.cs new file mode 100644 index 0000000..679080a --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.cs @@ -0,0 +1,69 @@ +using System; // 使用System函式庫 +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; // 使用System.Windows.Forms函式庫 +using System.Globalization; // 使用System.Windows.Forms函式庫 + +namespace WindowsFormsApplication6 // 命名空間為本程式 +{ // 進入命名空間 + public partial class Form5 : Form // Form5類別 + { // 進入Form5類別 + public Form5() // 宣告Form5 + { // 進入Form5 + InitializeComponent(); // 初始化表單 + } // 結束Form5 + private void Form5_Load(object sender, EventArgs e) // 宣告Form5_Load副程式,Form5表單載入時執行 + { // 進入Form5_Load副程式 + label2.Text = Form4.Debug_Login_Account_Input.Debug_Login_Account; // 顯示登入之除錯帳號 + Debug_Information_Refresh(); // 呼叫Debug_Information_Reflash副程式 + timer1.Interval = 100; // 設定timer1執行頻率 + timer1.Enabled = true; // 啟動timer1,即時更新除錯資訊 + } // 結束Form5_Load副程式 + private void timer1_Tick(object sender, EventArgs e) // 宣告timer1_Tick副程式 + { // 進入timer1_Tick副程式 + Debug_Information_Refresh(); // 呼叫Debug_Information_Reflash副程式 + } // 結束timer1_Tick副程式 + private void button1_Click(object sender, EventArgs e) // 宣告button1_Click副程式,當按下button1時執行 + { // 進入button1_Click副程式 + Debug_Information_Reset(); // 呼叫Debug_Information_Reset除錯資料重置副程式 + } // 結束button1_Click副程式 + public void Debug_Information_Refresh() // 宣告Debug_Information_Refresh除錯資料更新副程式 + { // 進入除錯資料更新副程式 + Form1.localDate = DateTime.Now; // 更新現在時間 + label4.Text = Form4.Login_Date.ToString(); // 顯示除錯模式登入時間 + label6.Text = (Form1.localDate.ToString()); // 顯示現在時間 + label8.Text = Form1.COM_Port_num.ToString(); // 顯示已連線之Serialport數量 + label10.Text = Form1.list_SerialPort_Runtimes.ToString(); // 顯示list_SerialPort副程式執行次數 + label12.Text = Form1.comport_DataReceived_Runtimes.ToString(); // 顯示comport_DataReceived副程式執行次數 + label14.Text = Form1.Uart_comport_handle_Runtimes.ToString(); // 顯示Uart_comport_handle副程式執行次數 + label16.Text = Form1.DisplayText_Runtimes.ToString(); // 顯示DisplayText副程式執行次數 + label18.Text = Form1.button1_Click_Runtimes.ToString(); // 顯示button1_Click副程式執行次數 + label20.Text = Form1.button2_Click_Runtimes.ToString(); // 顯示button2_Click副程式執行次數 + label22.Text = Form1.button3_Click_Runtimes.ToString(); // 顯示button3_Click副程式執行次數 + label24.Text = Form1.Transmission_Setting_Click_Runtimes.ToString(); + // 顯示設定_傳輸設定ToolStripMenuItem_Click副程式 + label26.Text = Form1.User_Interface_Setting_Click_Runtimes.ToString(); + // 顯示設定_介面設定ToolStripMenuItem_Click副程式執行次數 + label101.Text = Form1.Uart_Buffer_Size.ToString(); // 顯示Uart接收資料Buffer大小 + textBox1.Text = Form1.Uart_Buffer_ASCII_Data; // 顯示Uart傳輸之Buffer資料(ASCII編碼值) + label201.Text = Form1.Error_Code.ToString(); // 顯示Error_Code + } // 結束除錯資料更新副程式 + public void Debug_Information_Reset() // 宣告Debug_Information_Reset除錯資料重置副程式 + { // 進入除錯資料重置副程式 + Form1.list_SerialPort_Runtimes = 0; // 將list_SerialPort_Runtimes變數歸零 + Form1.comport_DataReceived_Runtimes = 0; // 將comport_DataReceived_Runtimes變數歸零 + Form1.Uart_comport_handle_Runtimes = 0; // 將Uart_comport_handle_Runtimes變數歸零 + Form1.DisplayText_Runtimes = 0; // 將DisplayText_Runtimes變數歸零 + Form1.button1_Click_Runtimes = 0; // 將button1_Click_Runtimes變數歸零 + Form1.button2_Click_Runtimes = 0; // 將button2_Click_Runtimes變數歸零 + Form1.button3_Click_Runtimes = 0; // 將button3_Click_Runtimes變數歸零 + Form1.Transmission_Setting_Click_Runtimes = 0; // 將Transmission_Setting_Click_Runtimes變數歸零 + Form1.User_Interface_Setting_Click_Runtimes = 0; // 將User_Interface_Setting_Click_Runtimes變數歸零 + } // 結束除錯資料重置副程式 + } // 結束Form5類別 +} // 結束命名空間 diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.resx new file mode 100644 index 0000000..1f666f2 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Form5.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Program.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Program.cs new file mode 100644 index 0000000..8be35fa --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApplication6 +{ + static class Program + { + /// + /// 應用程式的主要進入點。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/AssemblyInfo.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dc419a3 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 組件的一般資訊是由下列的屬性集控制。 +// 變更這些屬性的值即可修改組件的相關 +// 資訊。 +[assembly: AssemblyTitle("WindowsFormsApplication6")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApplication6")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 將 ComVisible 設定為 false 會使得這個組件中的型別 +// 對 COM 元件而言為不可見。如果您需要從 COM 存取這個組件中 +// 的型別,請在該型別上將 ComVisible 屬性設定為 true。 +[assembly: ComVisible(false)] + +// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID +[assembly: Guid("cc29d53d-c7bd-4e31-846e-f39c195d5904")] + +// 組件的版本資訊是由下列四項值構成: +// +// 主要版本 +// 次要版本 +// 組建編號 +// 修訂編號 +// +// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號 +// 指定為預設值: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.Designer.cs new file mode 100644 index 0000000..2baf522 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 這段程式碼是由工具產生的。 +// 執行階段版本:4.0.30319.42000 +// +// 對這個檔案所做的變更可能會造成錯誤的行為,而且如果重新產生程式碼, +// 變更將會遺失。 +// +//------------------------------------------------------------------------------ + +namespace UartOscilloscope.Properties { + using System; + + + /// + /// 用於查詢當地語系化字串等的強類型資源類別。 + /// + // 這個類別是自動產生的,是利用 StronglyTypedResourceBuilder + // 類別透過 ResGen 或 Visual Studio 這類工具。 + // 若要加入或移除成員,請編輯您的 .ResX 檔,然後重新執行 ResGen + // (利用 /str 選項),或重建您的 VS 專案。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 傳回這個類別使用的快取的 ResourceManager 執行個體。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UartOscilloscope.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆寫目前執行緒的 CurrentUICulture 屬性,對象是所有 + /// 使用這個強類型資源類別的資源查閱。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.resx b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.Designer.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.Designer.cs new file mode 100644 index 0000000..105c083 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 這段程式碼是由工具產生的。 +// 執行階段版本:4.0.30319.42000 +// +// 對這個檔案所做的變更可能會造成錯誤的行為,而且如果重新產生程式碼, +// 變更將會遺失。 +// +//------------------------------------------------------------------------------ + +namespace UartOscilloscope.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.settings b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/README.md b/VisualStudioProjects/OpenGLTest/UartOscilloscope/README.md new file mode 100644 index 0000000..9a461a4 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/README.md @@ -0,0 +1,22 @@ +# UartOscilloscope(Uartܪi) + +## \໡G +nҦ`(Normal)ҦP(Debug)ҦC`ҦUѤUC\G +- iUartsuC +- iվUartsu]w(jvBP줸)C +- iվ@ާ@tm(UartܦrjpBB鵥)C +ҦU]t`Ҧ\~A󴣨ѥHUB~Ti氣ջPվ]wG +- ܤwsu(iѵ{ϥ)SerialPort(CqT)ƶqC +- ܡubutton1_Clickvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡubutton2_Clickvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡubutton3_Clickvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡu]w_ǿ]wToolStripMenuItem_Clickvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡu]w_]wToolStripMenuItem_Clickvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡulist_SerialPortvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡucomport_DataReceivedvk۵{}lBɤ榸ơAiʭm(ks)C +- ܡuUARTConnectHandlevk۵{}lBɤ榸ơAiʭm(ks)C +- ܡuDisplayTextvk۵{}lBɤ榸ơAiʭm(ks)C +- icomport_DataReceivedkUartǿ餧BufferjpC +- icomport_DataReceivedkUartǿ餧Buffer(ASCIIsX)C +- ܿ~TsX(ErrorCode)C + diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/UartOscilloscope.csproj b/VisualStudioProjects/OpenGLTest/UartOscilloscope/UartOscilloscope.csproj new file mode 100644 index 0000000..c3beb30 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/UartOscilloscope.csproj @@ -0,0 +1,159 @@ + + + + + Debug + AnyCPU + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7} + WinExe + Properties + UartOscilloscope + UartOscilloscope + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + false + + + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\..\..\專題製作\作品\三軸加速度計研究\程式專案\test3(SharpGL3D繪圖測試1)\加入參考\SharpGL.dll + + + ..\..\..\..\..\..\..\..\專題製作\作品\三軸加速度計研究\程式專案\test3(SharpGL3D繪圖測試1)\加入參考\SharpGL.WinForms.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + Form + + + Form2.cs + + + Form + + + Form3.cs + + + Form + + + Form4.cs + + + Form + + + Form5.cs + + + + + + Form1.cs + + + Form2.cs + + + Form3.cs + + + Form4.cs + + + Form5.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/VersionInfo.md b/VisualStudioProjects/OpenGLTest/UartOscilloscope/VersionInfo.md new file mode 100644 index 0000000..e9c4f30 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/VersionInfo.md @@ -0,0 +1,31 @@ +## Visual Studio C#程式版本資訊: +- 2016.8.12(五) + - 宣告Analysis_Graphic_Mode靜態全域變數,控制程式分析與繪圖方法。 + - 設計編碼可參考方法架構圖。 + - DisplayText方法中textBox1顯示資料方法改進: + textBox1.Text += System.Text.Encoding.ASCII.GetString(buffer);改為textBox1.AppendText(System.Text.Encoding.ASCII.GetString(buffer)); 。 + - comport資料接收處理方法中以try方法執行invoke。 +- 2016.11.13(日) + - 宣告警告訊息類別(ErrorCodeMessage),統整錯誤訊息資訊。 + - 於警告訊息類別(ErrorCodeMessage)建立Error_010001_Message、Error_010001_Title、Error_010001_MessageBoxButton、Error_010001_MessageBoxIcon四項靜態物件 + 結構化錯誤訊息,建立Error_message_struct(錯誤訊息結構), + 且將錯誤訊息內容封裝於Error_message_struct(錯誤訊息結構)中,外部無法任意修改, + 另錯誤訊息顯示不再直接呼叫MessageBox.Show,而是由ErrorCodeMessage類別中的Error_Message_Show方法執行錯誤訊息顯示。 +- 2016.12.23(五) + - 重新命名專案為UartOscilloscope,並上傳至GitHub-https://github.com/60071jimmy/UartOscilloscope +- 2016.12.24(六) + - 調整命名空間(namespace)為UartOscilloscope +- 2017.7.7(五) + - 上傳方法架構圖至doc/IMG目錄 +- 2017.7.8(六) + - 新增ErrorCodeMessage.cs檔案,並將ErrorCodeMessage類別提取移動至ErrorCodeMessage.cs檔案中 + - 新增OscilloscopeFunctionVariable.cs檔案,並將OscilloscopeFunctionVariable類別提取移動至OscilloscopeFunctionVariable.cs檔案中 +- 2017.7.9(日) + - 於OscilloscopeFunctionVariable.cs檔案中新增Get_ADC_Raw_Data_Max方法,用以取得ADC_Raw_Data_Max數值,並將ADC_Raw_Data_Max變數設定為private + - 建立CSharpFiles資料夾存放自訂程式檔 + - 建立VersionInfo.cs檔案並 + +未解決issue: + 1、COM port中斷連線有時會導致程式當機 + 2、以Queue資料結構分析字串有時會發生錯誤 + 3、 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscope/WaveGraph.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscope/WaveGraph.cs new file mode 100644 index 0000000..e9c5204 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscope/WaveGraph.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsFormsApplication6 +{ + class WaveGraph + { + } +} diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/DataProcessingTests.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/DataProcessingTests.cs new file mode 100644 index 0000000..54670ed --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/DataProcessingTests.cs @@ -0,0 +1,46 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; // 使用Microsoft.VisualStudio.TestTools.UnitTesting函式庫 +using UartOscilloscope; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope.Tests // UartOscilloscope.Tests命名空間 +{ // 進入命名空間 + [TestClass()] + public class DataProcessingTests // DataProcessingTests類別 + { // 進入DataProcessingTests類別 + /// + /// String to Char Array Test Method(String2CharArrayTest測試方法) + /// 該測試方法用於測試String2CharArray方法,能否順利完成字串至字元陣列轉換 + /// + [TestMethod()] + public void String2CharArrayTest() // String2CharArrayTest方法 + { // 進入String2CharArrayTest方法 + String2CharArrayTestPart1(); // 呼叫String2CharArrayTestPart1方法 + + } // 結束String2CharArrayTest方法 + /// + /// String2CharArrayTestPart1以靜態字串於測試String2CharArray方法,能否順利完成字串至字元陣列轉換 + /// + [TestMethod()] + public void String2CharArrayTestPart1() // String2CharArrayTestPart1方法 + { // 進入String2CharArrayTestPart1方法 + DataProcessing DataProcessing1 = new DataProcessing(); // 建立DataProcessing1物件 + string TestData1 = "12345"; // 宣告測試資料TestData1 + char[] expected = new char[5]; ; // 宣告預期輸出資料expected + expected[0] = '1'; // 設定預期輸出 + expected[1] = '2'; // 設定預期輸出 + expected[2] = '3'; // 設定預期輸出 + expected[3] = '4'; // 設定預期輸出 + expected[4] = '5'; // 設定預期輸出 + char[] actual; // 宣告actual(實際輸出) + actual = DataProcessing1.String2CharArray(TestData1); // 執行String2CharArray方法 + for (int LoopNum = 0; LoopNum < 5; LoopNum++) // 以for迴圈依序比對期望輸出與實際輸出 + { // 進入for迴圈 + Assert.AreEqual(expected[LoopNum], actual[LoopNum]); // 比對期望輸出與實際輸出 + } // 結束for迴圈 + } // 結束String2CharArrayTestPart1方法 + } // 結束DataProcessingTests類別 +} // 結束命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/UARTConnectionConstValTests.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/UARTConnectionConstValTests.cs new file mode 100644 index 0000000..2f9c5be --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/UARTConnectionConstValTests.cs @@ -0,0 +1,41 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; // 使用Microsoft.VisualStudio.TestTools.UnitTesting函式庫 +using UartOscilloscope; +using System; +using System.Collections.Generic; +using System.IO.Ports; // 使用System.IO.Ports函式庫 +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope.Tests // UartOscilloscope.Tests命名空間 +{ // 進入命名空間 + [TestClass()] + public class UARTConnectionConstValTests // UARTConnectionConstValTests類別 + { // 進入UARTConnectionConstValTests類別 + [TestMethod()] + public void GetDefaultBaudRateTest() // GetDefaultBaudRateTest方法 + { // 進入GetDefaultBaudRateTest方法 + int expected = 9600; // 宣告expected(期望輸出) + int actual; // 宣告actual(實際輸出) + actual = UARTConnectionConstVal.GetDefaultBaudRate(); // 執行GetDefaultBaudRate方法 + Assert.AreEqual(expected, actual); // 比對期望輸出與實際輸出 + } // 結束GetDefaultBaudRateTest方法 + + [TestMethod()] + public void GetDefaultParitySettingTest() // GetDefaultParitySettingTest方法 + { // 進入GetDefaultParitySettingTest方法 + Parity expected = Parity.None; // 宣告expected(期望輸出) + Parity actual = UARTConnectionConstVal.GetDefaultParitySetting(); // 取得actual(實際輸出) + Assert.AreEqual(expected, actual); // 比對期望輸出與實際輸出 + } // 結束GetDefaultParitySettingTest方法 + + [TestMethod()] + public void GetDefaultDataBitsSettingTest() // GetDefaultDataBitsSettingTest方法 + { // 進入GetDefaultDataBitsSettingTest方法 + int expected = 8; // 宣告expected(期望輸出) + int actual; // 宣告actual(實際輸出) + actual = UARTConnectionConstVal.GetDefaultDataBitsSetting(); // 取得actual(實際輸出) + Assert.AreEqual(expected, actual); // 比對期望輸出與實際輸出 + } // 結束GetDefaultDataBitsSettingTest方法 + } // 結束UARTConnectionConstValTests類別 +} // 結束命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/WaveDataStructureTests.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/WaveDataStructureTests.cs new file mode 100644 index 0000000..0f1e83a --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/CSharpFiles/WaveDataStructureTests.cs @@ -0,0 +1,120 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; // 使用Microsoft.VisualStudio.TestTools.UnitTesting函式庫 +using UartOscilloscope; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UartOscilloscope.Tests // UartOscilloscope.Tests命名空間 +{ // 進入命名空間 + [TestClass()] + public class WaveDataStructureTests // WaveDataStructureTests類別 + { // 進入WaveDataStructureTests類別 + [TestMethod()] + public void AddDataTest() // AddDataTest方法 + { // 進入AddDataTest方法 + WaveDataStructure WaveDataStructureTest1; // 宣告WaveDataStructureTest1物件 + int ArrayMax = 3; // 宣告ArrayMax變數,用於給定WaveDataStructureTest物件空間 + WaveDataStructureTest1 = new WaveDataStructure(ArrayMax); // 初始化測試物件 + if(TestingType.IsTestFailed(WaveDataStructureInitialTest(WaveDataStructureTest1))) + { // 進入if敘述 + Assert.Fail(); // 測試失敗 + } // 結束if敘述 + int[] TestData1 = new int[] { 3, 2, 1 }; // 建立測試資料 + WaveDataStructureTest1.AddData(TestData1[0]); // 填入測試資料 + WaveDataStructureTest1.AddData(TestData1[1]); // 填入測試資料 + WaveDataStructureTest1.AddData(TestData1[2]); // 填入測試資料 + if (TestingType.IsTestFailed(WaveDataStructureMatch(WaveDataStructureTest1, TestData1))) + { // 進入if敘述 + Assert.Fail(); // 測試失敗 + } // 結束if敘述 + int[] TestData2 = TestData1; // 宣告TestData2 + TestData2[0] = 4; + WaveDataStructureTest1.AddData(TestData2[0]); // 填入測試資料 + if (TestingType.IsTestFailed(WaveDataStructureMatch(WaveDataStructureTest1, TestData2))) + { // 進入if敘述 + Assert.Fail(); // 測試失敗 + } // 結束if敘述 + } // 結束AddDataTest方法 + /// + /// WaveDataStructureInitialTest方法用於測試WaveDataStructure初始化功能 + /// 初始化完成後,若內部陣列空間資料皆為0,代表初始化順利完成 + /// 若初始化順利,則TestSuccess,否則TestFail + /// + /// 回傳測試結果 + private TestingType WaveDataStructureInitialTest(WaveDataStructure InputData) + // WaveDataStructureInitialTest方法 + { // 進入WaveDataStructureInitialTest方法 + TestingType Test1 = new TestingType(); // 建立Test1物件 + foreach(int Data in InputData.ReturnData()) // 依序比對資料內容 + { // 進入foreach敘述 + if(Data == 0) // 若Data為0 + { // 進入if敘述 + Test1.TestSuccess(); // 測試Success + } // 結束if敘述 + else // 若Data不為0 + { // 進入else敘述 + Test1.TestFail(); // 測試Fail + return Test1; // 回傳測試結果 + } // 結束else敘述 + } // 結束foreach敘述 + return Test1; // 回傳測試結果 + } // 結束WaveDataStructureInitialTest方法 + /// + /// WaveDataStructureMatch方法用於比對WaveDataStructure內容 + /// + /// 為WaveDataStructure型態資料 + /// 為欲確認之答案 + /// + private TestingType WaveDataStructureMatch(WaveDataStructure InputData1, int[] InputData2) + // WaveDataStructureMatch方法 + { // 進入WaveDataStructureMatch方法 + TestingType Test1 = new TestingType(); // 建立Test1物件 + int CountNum = 0; // 宣告CountNum計數變數 + foreach (int Data in InputData1.ReturnData()) // 以foreach依序取出Data + { // 進入foreach敘述 + if(Data == InputData2[CountNum]) // 若資料相同 + { // 進入if敘述 + Test1.TestSuccess(); // 測試Success + } // 結束if敘述 + else // 若資料不同 + { // 進入else敘述 + Test1.TestFail(); // 測試Fail + return Test1; // 回傳測試結果 + } // 結束else敘述 + CountNum = (CountNum + 1) % InputData2.Length; // 取得下一筆測試資料序號 + } // 結束foreach敘述 + return Test1; // 回傳測試結果 + } // 結束WaveDataStructureMatch方法 + private int[] GenerateRandomNumber(int NumberOfRandomNumber) // GenerateRandomNumber方法 + { // 進入GenerateRandomNumber方法 + Random rnd = new Random(); // 宣告Random物件 + int[] Result = new int[0]; // 宣告回傳結果 + Array.Resize(ref Result, NumberOfRandomNumber); // 配置記憶體位置 + for(int LoopNum = 0; LoopNum < NumberOfRandomNumber; LoopNum++) // 以for迴圈依序填入亂數 + { // 進入for迴圈 + Result[LoopNum] = rnd.Next(-1000, 1000); // 生成亂數 + } // 結束for迴圈 + return Result; // 回傳結果 + } // 結束GenerateRandomNumber方法 + [TestMethod()] + public void ResizeArrayTest() // ResizeArrayTest方法 + { // 進入ResizeArrayTest方法 + WaveDataStructure WaveDataStructureTest1; // 宣告WaveDataStructureTest1物件 + int ArrayMax = 3; // 宣告ArrayMax變數,用於給定WaveDataStructureTest物件空間 + WaveDataStructureTest1 = new WaveDataStructure(ArrayMax); // 初始化測試物件 + ArrayMax = 10; // 調整ArrayMax變數 + WaveDataStructureTest1.ResizeArray(ArrayMax); // 測試ResizeArray方法 + int[] TestData1 = GenerateRandomNumber(ArrayMax); // 生成亂數測試資料 + for(int LoopNum = 0; LoopNum < TestData1.Length; LoopNum++) // 以for迴圈填入資料 + { // 進入for迴圈 + WaveDataStructureTest1.AddData(TestData1[LoopNum]); // 新增資料 + } // 結束for迴圈 + if (TestingType.IsTestFailed(WaveDataStructureMatch(WaveDataStructureTest1, TestData1))) + { // 進入if敘述 + Assert.Fail(); // 測試失敗 + } // 結束if敘述 + } // 結束ResizeArrayTest方法 + } // 結束WaveDataStructureTests類別 +} // 結束命名空間 \ No newline at end of file diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/Properties/AssemblyInfo.cs b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c2ce5f0 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 組件的一般資訊是由下列的屬性集控制。 +// 變更這些屬性的值即可修改組件的相關 +// 資訊。 +[assembly: AssemblyTitle("UartOscilloscopeTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UartOscilloscopeTests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 將 ComVisible 設定為 false 會使得這個組件中的類型 +// 對 COM 元件而言為不可見。如果您需要從 COM 存取這個組件中 +// 的類型,請在該類型上將 ComVisible 屬性設定為 true。 +[assembly: ComVisible(false)] + +// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID +[assembly: Guid("7ec5ae58-596e-4960-8dfc-bbbe353b1f7d")] + +// 組件的版本資訊由下列四個值所組成: +// +// 主要版本 +// 次要版本 +// 組建編號 +// 修訂編號 +// +// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號 +// 指定為預設值: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/UartOscilloscopeTests.csproj b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/UartOscilloscopeTests.csproj new file mode 100644 index 0000000..0e62f55 --- /dev/null +++ b/VisualStudioProjects/OpenGLTest/UartOscilloscopeTests/UartOscilloscopeTests.csproj @@ -0,0 +1,91 @@ + + + + Debug + AnyCPU + {7EC5AE58-596E-4960-8DFC-BBBE353B1F7D} + Library + Properties + UartOscilloscopeTests + UartOscilloscopeTests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {8D89102B-2B1F-43D5-83C2-DA86889BA3D7} + UartOscilloscope + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file