├── LICENSE ├── README.md ├── 串口助手.exe ├── 串口助手.sln ├── 串口助手 ├── App.config ├── AutoTx.cs ├── BootLoader.cs ├── ChannelCfg.cs ├── ChannelForm.Designer.cs ├── ChannelForm.cs ├── ChannelForm.resx ├── CommLog.cs ├── Config.cs ├── ContextMenu.cs ├── DataTypeConversion.cs ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── RealTimeCurve.Designer.cs ├── RealTimeCurve.cs ├── RealTimeCurve.resx ├── RealTimeCurveEditor.Designer.cs ├── RealTimeCurveEditor.cs ├── RealTimeCurveEditor.resx ├── RealTimeCurve_Channel.cs ├── RxShow.cs ├── SocketClient.cs ├── SuperMsg.cs ├── TxListHandle.cs ├── TxListSimple.cs ├── cmd.cs ├── image │ ├── MSB.png │ ├── help.png │ ├── hex.png │ ├── log.png │ ├── 保存.png │ ├── 公众号.png │ ├── 关闭.png │ ├── 删除.png │ ├── 多级发送.png │ ├── 开启.png │ ├── 换行.png │ ├── 新建.png │ ├── 时间戳.png │ ├── 清除.png │ ├── 置顶.png │ └── 设置.png ├── 串口助手.csproj ├── 串口助手.csproj.user └── 图标.ico ├── 串口助手V2.1.exe └── 软件截图 ├── 0 ├── 发送列表-指令打包.png ├── 基本界面.png ├── 多设备-使用演示.png ├── 多设备-连接.png ├── 精简发送列表-演示.png └── 超级报文.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 L231 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SerialAssistant 2 | # 概述 3 | * 两种通信方式:串口、TCP Client 4 | * **超级报文**功能,自动解析数据 5 | * 匹配注册的RX表,**自动下发指令** 6 | * **实时曲线**,自定义通信协议 7 | * **多设备连接** 8 | * 具有**多级发送列表**,支持**数据打包**、循环的发送模式 9 | * 发送列表支持**新建、加载、另存为** 10 | * 窗体**可置顶**,可调透明度 11 | * 接收区可编辑,隐藏类似命令提示符的功能 12 | 13 | *网盘下载地址:https://pan.baidu.com/s/1uoS-Xpm8JSPdkq5KYSMFFA?pwd=g1di* 14 | --- 15 | 16 | # 主界面 17 | 18 | ![主界面](软件截图/基本界面.png) 19 | 20 | --- 21 | 22 | # 多级发送列表 23 | 24 | ![多级发送列表](软件截图/发送列表-指令打包.png) 25 | 26 | ## 结构 27 | 28 | 29 | | HEX发送 | 延时时间 | 数据框 | 发送按键 30 | |:----------:|:-----------:|:----------:|:-----------:| 31 | | √ | 500 | 31 32 32 35 | 指令1 32 | 33 | 34 | ## 编辑发送按键 35 | **右键按键**,即可编辑按钮名称 36 | 数据框写入按键名,**双击数据框,完成按键命名** 37 | 38 | ## 数据打包发送 39 | 数据框中编辑: 40 | ``` 41 | A1 04 C9 EF 42 | delay1000, 43 | 33113 44 | delay100,loop3 45 | ``` 46 | 单击发送按键,数据收发测试如下: 47 | ``` 48 | 13:54:21.951>>A1 04 C9 EF 49 | 13:54:22.036<>33 11 03 51 | 13:54:23.099<<33 11 03 52 | 13:54:23.584>>33 11 03 53 | 13:54:23.619<<33 11 03 54 | 13:54:24.125>>33 11 03 55 | 13:54:24.225<<33 11 03 56 | ``` 57 | 58 | ## 自动循环发送 59 | * **填好延时时间**,单击发送列表状态栏的**自动**按键,启动循环模式 60 | * 未填写延时时间的,循环时会自动跳过 61 | 62 | --- 63 | 64 | # 精简发送列表 65 | * 右键按钮,开启/关闭**报文编辑器** 66 | * **动态添加按钮**,支持插入新按钮 67 | ![精简发送列表](软件截图/精简发送列表-演示.png) 68 | 69 | --- 70 | 71 | # 超级报文 72 | 73 | * **动态创建报文** 74 | * 自定义发送、接收解析框的个数 75 | * **解析规则编辑器** 76 | 77 | ![超级报文](软件截图/超级报文.png) 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /串口助手.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/L231/SerialAssistant/83ec527bc18fee8aa54f1ecc8aebd516b16a7641/串口助手.exe -------------------------------------------------------------------------------- /串口助手.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31729.503 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "串口助手", "串口助手\串口助手.csproj", "{448AEF62-D3A8-4CD4-9F10-1B326548DC33}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {448AEF62-D3A8-4CD4-9F10-1B326548DC33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {448AEF62-D3A8-4CD4-9F10-1B326548DC33}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {448AEF62-D3A8-4CD4-9F10-1B326548DC33}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {448AEF62-D3A8-4CD4-9F10-1B326548DC33}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E6B1E98E-8DF8-439F-9F06-FEBBE615566E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /串口助手/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /串口助手/AutoTx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace 串口助手 9 | { 10 | class AutoTx 11 | { 12 | [System.Runtime.InteropServices.DllImport("msvcrt.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] 13 | static extern int memcmp(byte[] b1, byte[] b2, long count); 14 | 15 | 16 | public class AutoTxClass_t 17 | { 18 | public byte[] rx; 19 | public byte[] tx; 20 | }; 21 | 22 | private List ListAutoTx = new List(); 23 | 24 | 25 | public void CmdUpdate(string[] cmd, string DataType, string MsgTailType) 26 | { 27 | DataTypeConversion dataType = new DataTypeConversion(); 28 | ListAutoTx.Clear(); 29 | foreach(string p in cmd) 30 | { 31 | if (p == "") 32 | continue; 33 | if (!p.Contains('$')) 34 | continue; 35 | string[] temp = p.Split('$'); 36 | if (temp[0] == "" || temp[1] == "") 37 | { 38 | MessageBox.Show("请检查:" + p + "!", "自动下发的规则异常"); 39 | return; 40 | } 41 | AutoTxClass_t class_T = new AutoTxClass_t(); 42 | class_T.rx = dataType.StringToByte(DataType, temp[0]); 43 | class_T.tx = dataType.StringToByte(DataType, temp[1]); 44 | if (class_T.rx == null || class_T.tx == null) 45 | { 46 | MessageBox.Show("请检查:" + p + "!", "自动下发的规则异常"); 47 | return; 48 | } 49 | dataType.ByteAddMsgTail(MsgTailType, ref class_T.rx); 50 | ListAutoTx.Add(class_T); 51 | } 52 | } 53 | 54 | public byte[] GetTxMsg(byte[] rx, int length) 55 | { 56 | foreach(AutoTxClass_t p in ListAutoTx) 57 | { 58 | if (p.rx.Length != length) 59 | continue; 60 | if (memcmp(p.rx, rx, p.rx.Length) == 0) 61 | return p.tx; 62 | } 63 | return null; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /串口助手/ChannelCfg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO.Ports; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Sockets; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace 串口助手 13 | { 14 | public partial class Form1 15 | { 16 | struct MultiCommunication_t 17 | { 18 | public string name; 19 | public string type; 20 | public string hex; 21 | public string MsgTailType; 22 | public SerialPort uart; 23 | public Socket tcp; 24 | public Thread threadTcp; 25 | public string saveInfo; 26 | }; 27 | /// 28 | /// 通信通道的链表 29 | /// 30 | List listMultiComm = new List(); 31 | 32 | MultiCommunication_t masterComm; 33 | MultiCommunication_t multi; 34 | 35 | public bool 设备注册(string name, 36 | string open, 37 | string com, 38 | string br_or_ip, 39 | string tcpport, 40 | string msgtail, 41 | string hex, 42 | string saveInfo) 43 | { 44 | if(open == "开启") 45 | { 46 | try 47 | { 48 | foreach(MultiCommunication_t p in listMultiComm) 49 | { 50 | if(p.name == name) 51 | { 52 | MessageBox.Show("设备名重复,请更改!", "ERROR"); 53 | return false; 54 | } 55 | } 56 | //处理报尾 57 | multi.MsgTailType = msgtail; 58 | multi.name = name; 59 | multi.hex = hex; 60 | if (com == "TCP Client") 61 | { 62 | multi.type = com; 63 | IPAddress addr = IPAddress.Parse(br_or_ip); 64 | IPEndPoint endPoint = new IPEndPoint(addr, int.Parse(tcpport)); 65 | multi.tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 66 | multi.tcp.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000); 67 | //multi.tcp.Connect(endPoint); 68 | SocketClient socketClient = new SocketClient(); 69 | if (!socketClient.Connect(multi.tcp, endPoint, 1000)) 70 | goto CONNECT_ERR; 71 | multi.tcp.ReceiveTimeout = 500; 72 | multi.threadTcp = new Thread(TCP_ClientRx); 73 | multi.threadTcp.IsBackground = true; 74 | multi.threadTcp.Start(multi.tcp); 75 | } 76 | else 77 | { 78 | multi.type = "uart"; 79 | multi.uart = new SerialPort(); 80 | string[] str = com.Split(new char[2] { '(', ')' }); 81 | multi.uart.PortName = str[1]; 82 | multi.uart.BaudRate = Convert.ToInt32(br_or_ip); 83 | multi.uart.ReadTimeout = 500; 84 | multi.uart.Open(); 85 | multi.uart.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived); 86 | } 87 | multi.saveInfo = saveInfo; 88 | listMultiComm.Add(multi); 89 | return true; 90 | } 91 | catch 92 | { 93 | } 94 | CONNECT_ERR: 95 | MessageBox.Show("端口打开失败,请检查!", "ERROR"); 96 | } 97 | else 98 | { 99 | try 100 | { 101 | for (int pos = 0; pos < listMultiComm.Count(); pos++) 102 | { 103 | if (listMultiComm[pos].name == name) 104 | { 105 | if (listMultiComm[pos].type == "TCP Client") 106 | { 107 | listMultiComm[pos].threadTcp.Abort(); 108 | listMultiComm[pos].tcp.Shutdown(SocketShutdown.Both); 109 | listMultiComm[pos].tcp.Close(); 110 | } 111 | else 112 | listMultiComm[pos].uart.Close(); 113 | //删除该设备 114 | listMultiComm.RemoveAt(pos); 115 | return true; 116 | } 117 | } 118 | } 119 | catch 120 | { 121 | MessageBox.Show("端口关闭异常!", "ERROR"); 122 | } 123 | } 124 | return false; 125 | } 126 | 127 | 128 | private void 加载缓存的设备() 129 | { 130 | ChannelForm formCH; 131 | try 132 | { 133 | int max = Convert.ToInt32(gCfg.SysCfgFileRead("多通道配置区", "最大设备数")); 134 | for (int cnt = 0; cnt < max; cnt++) 135 | { 136 | string saveInfo = gCfg.SysCfgFileRead("多通道配置区", "设备" + cnt.ToString()); 137 | 138 | formCH = new ChannelForm(); 139 | formCH.TopLevel = false; 140 | formCH.formMain = this; 141 | //formCH.MdiParent = this; 142 | flowLayoutPanel_Channel.Controls.Add(formCH); 143 | formCH.Dock = DockStyle.Top; 144 | formCH.Show(); 145 | formCH.setChannelFormParam(saveInfo); 146 | } 147 | } 148 | catch { } 149 | } 150 | private void ChannelListCreate() 151 | { 152 | ChannelForm formCH = new ChannelForm(); 153 | formCH.TopLevel = false; 154 | formCH.formMain = this; 155 | //formCH.MdiParent = this; 156 | flowLayoutPanel_Channel.Controls.Add(formCH); 157 | formCH.Dock = DockStyle.Top; 158 | formCH.Show(); 159 | } 160 | 161 | public void ChannelListDelete(Control control) 162 | { 163 | flowLayoutPanel_Channel.Controls.Remove(control); 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /串口助手/ChannelForm.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace 串口助手 3 | { 4 | partial class ChannelForm 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.ChannelList_toolStrip1 = new System.Windows.Forms.ToolStrip(); 33 | this.Channel_Delete = new System.Windows.Forms.ToolStripButton(); 34 | this.Channel_Name = new System.Windows.Forms.ToolStripTextBox(); 35 | this.Channel_COM = new System.Windows.Forms.ToolStripComboBox(); 36 | this.Channel_BaudRate_or_IP = new System.Windows.Forms.ToolStripComboBox(); 37 | this.Channel_TCPPort = new System.Windows.Forms.ToolStripTextBox(); 38 | this.Channel_Connect = new System.Windows.Forms.ToolStripButton(); 39 | this.Channel_Hex = new System.Windows.Forms.ToolStripButton(); 40 | this.Channel_MsgEnd = new System.Windows.Forms.ToolStripComboBox(); 41 | this.ChannelList_toolStrip1.SuspendLayout(); 42 | this.SuspendLayout(); 43 | // 44 | // ChannelList_toolStrip1 45 | // 46 | this.ChannelList_toolStrip1.AllowItemReorder = true; 47 | this.ChannelList_toolStrip1.ImageScalingSize = new System.Drawing.Size(21, 21); 48 | this.ChannelList_toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 49 | this.Channel_Delete, 50 | this.Channel_Name, 51 | this.Channel_COM, 52 | this.Channel_BaudRate_or_IP, 53 | this.Channel_TCPPort, 54 | this.Channel_Connect, 55 | this.Channel_Hex, 56 | this.Channel_MsgEnd}); 57 | this.ChannelList_toolStrip1.Location = new System.Drawing.Point(0, 0); 58 | this.ChannelList_toolStrip1.Name = "ChannelList_toolStrip1"; 59 | this.ChannelList_toolStrip1.Size = new System.Drawing.Size(800, 28); 60 | this.ChannelList_toolStrip1.TabIndex = 1; 61 | // 62 | // Channel_Delete 63 | // 64 | this.Channel_Delete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 65 | this.Channel_Delete.Image = global::串口助手.Properties.Resources.删除; 66 | this.Channel_Delete.ImageTransparentColor = System.Drawing.Color.Magenta; 67 | this.Channel_Delete.Name = "Channel_Delete"; 68 | this.Channel_Delete.Size = new System.Drawing.Size(25, 25); 69 | this.Channel_Delete.Text = "toolStripButton2"; 70 | this.Channel_Delete.ToolTipText = "删除通道"; 71 | this.Channel_Delete.Click += new System.EventHandler(this.Channel_Delete_Click); 72 | // 73 | // Channel_Name 74 | // 75 | this.Channel_Name.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; 76 | this.Channel_Name.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 77 | this.Channel_Name.Name = "Channel_Name"; 78 | this.Channel_Name.Size = new System.Drawing.Size(50, 28); 79 | this.Channel_Name.ToolTipText = "通道名字,通信时用来片选"; 80 | // 81 | // Channel_COM 82 | // 83 | this.Channel_COM.DropDownWidth = 300; 84 | this.Channel_COM.Name = "Channel_COM"; 85 | this.Channel_COM.Size = new System.Drawing.Size(200, 28); 86 | this.Channel_COM.ToolTipText = "设备端口号"; 87 | this.Channel_COM.DropDown += new System.EventHandler(this.Channel_COM_DropDown); 88 | // 89 | // Channel_BaudRate_or_IP 90 | // 91 | this.Channel_BaudRate_or_IP.Items.AddRange(new object[] { 92 | "1200", 93 | "4800", 94 | "9600", 95 | "14400", 96 | "19200", 97 | "38400", 98 | "57600", 99 | "115200"}); 100 | this.Channel_BaudRate_or_IP.Name = "Channel_BaudRate_or_IP"; 101 | this.Channel_BaudRate_or_IP.Size = new System.Drawing.Size(110, 28); 102 | this.Channel_BaudRate_or_IP.ToolTipText = "波特率 / IP地址"; 103 | // 104 | // Channel_TCPPort 105 | // 106 | this.Channel_TCPPort.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 107 | this.Channel_TCPPort.Name = "Channel_TCPPort"; 108 | this.Channel_TCPPort.Size = new System.Drawing.Size(35, 28); 109 | this.Channel_TCPPort.ToolTipText = "TCP端口号"; 110 | // 111 | // Channel_Connect 112 | // 113 | this.Channel_Connect.BackColor = System.Drawing.Color.LimeGreen; 114 | this.Channel_Connect.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 115 | this.Channel_Connect.Image = global::串口助手.Properties.Resources.开启; 116 | this.Channel_Connect.ImageTransparentColor = System.Drawing.Color.Magenta; 117 | this.Channel_Connect.Margin = new System.Windows.Forms.Padding(1, 1, 1, 2); 118 | this.Channel_Connect.Name = "Channel_Connect"; 119 | this.Channel_Connect.Size = new System.Drawing.Size(25, 25); 120 | this.Channel_Connect.Text = "开启"; 121 | this.Channel_Connect.ToolTipText = "开启或关闭通道"; 122 | this.Channel_Connect.Click += new System.EventHandler(this.Channel_Button1_Click); 123 | // 124 | // Channel_Hex 125 | // 126 | this.Channel_Hex.BackColor = System.Drawing.Color.Transparent; 127 | this.Channel_Hex.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 128 | this.Channel_Hex.Image = global::串口助手.Properties.Resources.hex; 129 | this.Channel_Hex.ImageTransparentColor = System.Drawing.Color.Magenta; 130 | this.Channel_Hex.Margin = new System.Windows.Forms.Padding(1, 1, 1, 2); 131 | this.Channel_Hex.Name = "Channel_Hex"; 132 | this.Channel_Hex.Size = new System.Drawing.Size(25, 25); 133 | this.Channel_Hex.Text = "ASCII"; 134 | this.Channel_Hex.ToolTipText = "设备通信格式是否为HEX"; 135 | this.Channel_Hex.Click += new System.EventHandler(this.Channel_Hex_Click); 136 | // 137 | // Channel_MsgEnd 138 | // 139 | this.Channel_MsgEnd.AutoSize = false; 140 | this.Channel_MsgEnd.DropDownWidth = 80; 141 | this.Channel_MsgEnd.Items.AddRange(new object[] { 142 | "无", 143 | "0A", 144 | "0A0D", 145 | "0D", 146 | "0D0A", 147 | "CS", 148 | "ModBus"}); 149 | this.Channel_MsgEnd.Name = "Channel_MsgEnd"; 150 | this.Channel_MsgEnd.Size = new System.Drawing.Size(75, 25); 151 | this.Channel_MsgEnd.Text = "0A"; 152 | this.Channel_MsgEnd.ToolTipText = "报文的结束符"; 153 | // 154 | // ChannelForm 155 | // 156 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 157 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 158 | this.ClientSize = new System.Drawing.Size(800, 28); 159 | this.Controls.Add(this.ChannelList_toolStrip1); 160 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 161 | this.Name = "ChannelForm"; 162 | this.Text = "ChannelForm1"; 163 | this.ChannelList_toolStrip1.ResumeLayout(false); 164 | this.ChannelList_toolStrip1.PerformLayout(); 165 | this.ResumeLayout(false); 166 | this.PerformLayout(); 167 | 168 | } 169 | 170 | #endregion 171 | 172 | private System.Windows.Forms.ToolStrip ChannelList_toolStrip1; 173 | private System.Windows.Forms.ToolStripButton Channel_Delete; 174 | private System.Windows.Forms.ToolStripComboBox Channel_COM; 175 | private System.Windows.Forms.ToolStripComboBox Channel_BaudRate_or_IP; 176 | private System.Windows.Forms.ToolStripTextBox Channel_TCPPort; 177 | private System.Windows.Forms.ToolStripButton Channel_Connect; 178 | private System.Windows.Forms.ToolStripTextBox Channel_Name; 179 | private System.Windows.Forms.ToolStripButton Channel_Hex; 180 | private System.Windows.Forms.ToolStripComboBox Channel_MsgEnd; 181 | } 182 | } -------------------------------------------------------------------------------- /串口助手/ChannelForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO.Ports; 7 | using System.Linq; 8 | using System.Management; 9 | using System.Net; 10 | using System.Net.Sockets; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Windows.Forms; 14 | 15 | namespace 串口助手 16 | { 17 | public partial class ChannelForm : Form 18 | { 19 | public Form1 formMain; 20 | 21 | 22 | 23 | 24 | public ChannelForm() 25 | { 26 | InitializeComponent(); 27 | } 28 | 29 | public string getChannelFormParam() 30 | { 31 | return Channel_Name.Text + "$" + 32 | Channel_COM.Text + "$" + 33 | Channel_BaudRate_or_IP.Text + "$" + 34 | Channel_TCPPort.Text + "$" + 35 | Channel_Hex.Text + "$" + 36 | Channel_MsgEnd.Text; 37 | } 38 | public void setChannelFormParam(string info) 39 | { 40 | string[] val = info.Split('$'); 41 | Channel_Name.Text = val[0]; 42 | Channel_COM.Text = val[1]; 43 | Channel_BaudRate_or_IP.Text = val[2]; 44 | Channel_TCPPort.Text = val[3]; 45 | Channel_Hex.Text = val[4]; 46 | Channel_MsgEnd.Text = val[5]; 47 | if (Channel_Hex.Text == "HEX") 48 | Channel_Hex.BackColor = Color.LimeGreen; 49 | } 50 | 51 | private void Channel_Button1_Click(object sender, EventArgs e) 52 | { 53 | if(Channel_Name.Text == "") 54 | { 55 | MessageBox.Show("请填写设备名!", "ERROR"); 56 | return; 57 | } 58 | if (formMain.设备注册(Channel_Name.Text, 59 | Channel_Connect.Text, Channel_COM.Text, 60 | Channel_BaudRate_or_IP.Text, 61 | Channel_TCPPort.Text, Channel_MsgEnd.Text, 62 | Channel_Hex.Text, 63 | getChannelFormParam()) == false) 64 | return; 65 | if (Channel_Connect.Text == "开启") 66 | { 67 | try 68 | { 69 | //设备注册情况 70 | formMain.richTextBox_Rx.AppendText(Channel_Name.Text + " " + Channel_COM.Text + " 注册成功!"+ System.Environment.NewLine); 71 | 72 | Channel_Name.Enabled = false; 73 | Channel_COM.Enabled = false; 74 | Channel_BaudRate_or_IP.Enabled = false; 75 | Channel_TCPPort.Enabled = false; 76 | Channel_Hex.Enabled = false; 77 | Channel_MsgEnd.Enabled = false; 78 | 79 | Channel_Connect.BackColor = Color.Tomato; 80 | Channel_Connect.Image = Properties.Resources.关闭; 81 | Channel_Connect.Text = "关闭"; 82 | } 83 | catch { } 84 | } 85 | else 86 | { 87 | Channel_Connect.BackColor = Color.LimeGreen; 88 | Channel_Connect.Image = Properties.Resources.开启; 89 | Channel_Connect.Text = "开启"; 90 | Channel_Name.Enabled = true; 91 | Channel_COM.Enabled = true; 92 | Channel_BaudRate_or_IP.Enabled = true; 93 | Channel_TCPPort.Enabled = true; 94 | Channel_Hex.Enabled = true; 95 | Channel_MsgEnd.Enabled = true; 96 | } 97 | } 98 | /// 99 | /// 扫描可用的通信端口 100 | /// 101 | /// 102 | /// 103 | private void Channel_COM_DropDown(object sender, EventArgs e) 104 | { 105 | /* 清除当前组合框的下拉菜单内容 */ 106 | Channel_COM.Items.Clear(); 107 | using (ManagementObjectSearcher searcher = new ManagementObjectSearcher 108 | ("select * from Win32_PnPEntity where Name like '%(COM%'")) 109 | { 110 | var hardInfos = searcher.Get(); 111 | foreach (var hardInfo in hardInfos) 112 | { 113 | if (hardInfo.Properties["Name"].Value != null) 114 | { 115 | string deviceName = hardInfo.Properties["Name"].Value.ToString(); 116 | Channel_COM.Items.Add(deviceName); 117 | } 118 | } 119 | } 120 | Channel_COM.Items.Add("TCP Client"); 121 | } 122 | 123 | private void Channel_Hex_Click(object sender, EventArgs e) 124 | { 125 | ToolStripButton ylbtt = (ToolStripButton)sender; 126 | if (ylbtt.Text == "ASCII") 127 | { 128 | ylbtt.Text = "HEX"; 129 | ylbtt.BackColor = Color.LimeGreen; 130 | } 131 | else 132 | { 133 | ylbtt.Text = "ASCII"; 134 | ylbtt.BackColor = Color.Transparent; 135 | } 136 | } 137 | 138 | private void Channel_Delete_Click(object sender, EventArgs e) 139 | { 140 | formMain.设备注册(Channel_Name.Text, 141 | "关闭", 142 | Channel_COM.Text, 143 | Channel_BaudRate_or_IP.Text, 144 | Channel_TCPPort.Text, 145 | Channel_MsgEnd.Text, 146 | Channel_Hex.Text, 147 | ""); 148 | this.Close(); 149 | formMain.ChannelListDelete(this); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /串口助手/ChannelForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /串口助手/CommLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace 串口助手 11 | { 12 | class CommLog 13 | { 14 | private string gLogFileName = null; 15 | public void Button_log_Click(object sender, EventArgs e) 16 | { 17 | ToolStripButton button = sender as ToolStripButton; 18 | if (button.ToolTipText == "记录log") 19 | { 20 | SaveFileDialog log = new SaveFileDialog(); 21 | //log.InitialDirectory = "D:\\"; //默认路径 22 | log.Filter = "log|*.log|文本|*.txt"; 23 | log.FileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-s"); 24 | if (log.ShowDialog() == DialogResult.OK) 25 | { 26 | button.ToolTipText = "关闭log"; 27 | button.BackColor = Color.LimeGreen; 28 | gLogFileName = log.FileName; 29 | StreamWriter stream = new StreamWriter(gLogFileName); 30 | stream.WriteLine("串口助手LOG"); 31 | stream.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-s")); 32 | stream.WriteLine("******************************"); 33 | stream.Flush(); 34 | stream.Close(); 35 | } 36 | } 37 | else 38 | { 39 | button.ToolTipText = "记录log"; 40 | button.BackColor = Color.Transparent; 41 | gLogFileName = null; 42 | } 43 | } 44 | 45 | public void LogWriteMsg(string msg) 46 | { 47 | if (gLogFileName == null) 48 | return; 49 | StreamWriter stream = new StreamWriter(gLogFileName, true); 50 | stream.WriteLine(msg); 51 | stream.Flush(); 52 | stream.Close(); 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /串口助手/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using System.IO; 4 | using System.Drawing; 5 | using System.Collections.Generic; 6 | 7 | namespace IniFile 8 | { 9 | class Config 10 | { 11 | [System.Runtime.InteropServices.DllImport("kernel32")] 12 | private static extern long WritePrivateProfileString(string section, string key, string val, string path); 13 | [System.Runtime.InteropServices.DllImport("kernel32")] 14 | private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string path); 15 | 16 | string gSysCfgInfoPath = @".\sys_config.ini"; 17 | public string TxListPath = @".\TxList.ini"; 18 | public int TxListNum = 64; 19 | public CheckBox[] Checkbox = new CheckBox[1]; 20 | public Button[] Button = new Button[1]; 21 | public TextBox[] TextboxTX = new TextBox[1]; 22 | public TextBox[] TextboxTimer = new TextBox[1]; 23 | 24 | //默认上锁 25 | bool TextboxTXClickBypass = true; 26 | 27 | 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public void IniWrite(string section, string key, string val, string path) 36 | { 37 | if (!File.Exists(path)) 38 | { 39 | FileStream ini = File.Create(path); 40 | ini.Close(); 41 | } 42 | WritePrivateProfileString(section, key, val, path); 43 | } 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | public string IniRead(string section, string key, string path) 52 | { 53 | System.Text.StringBuilder temp = new System.Text.StringBuilder(2048); 54 | GetPrivateProfileString(section, key, "", temp, 2048, path); 55 | return temp.ToString(); 56 | } 57 | public void SysCfgFileClear(string section) 58 | { 59 | IniWrite(section, null, null, gSysCfgInfoPath); 60 | } 61 | public void SysCfgFileWrite(string section, string key, string val) 62 | { 63 | IniWrite(section, key, val, gSysCfgInfoPath); 64 | } 65 | /// 66 | /// 67 | /// 68 | /// 69 | /// 70 | /// 71 | public string SysCfgFileRead(string section, string key) 72 | { 73 | return IniRead(section, key, gSysCfgInfoPath); 74 | } 75 | 76 | public bool SysCfgFileExists() 77 | { 78 | return File.Exists(gSysCfgInfoPath); 79 | } 80 | 81 | public int TxList_GetNum(string path) 82 | { 83 | TxListNum = 64; 84 | try 85 | { 86 | string num = IniRead("基本配置", "TableTxNum", path); 87 | if (num == "") 88 | TxListNum = 64; 89 | else if (Convert.ToInt32(num) > 100) 90 | TxListNum = 100; 91 | else 92 | TxListNum = Convert.ToInt32(num); 93 | } 94 | catch 95 | { } 96 | return TxListNum; 97 | } 98 | public void TableTxCreate(TableLayoutPanel table1, TableLayoutPanel table2) 99 | { 100 | Checkbox = new CheckBox[TxListNum]; 101 | Button = new Button[TxListNum]; 102 | TextboxTX = new TextBox[TxListNum]; 103 | TextboxTimer = new TextBox[TxListNum]; 104 | table1.Controls.Clear(); 105 | table2.Controls.Clear(); 106 | table1.RowCount = TxListNum; 107 | table2.RowCount = TxListNum; 108 | table1.Size = new Size(161, (20 * TxListNum) + 2); 109 | table2.Size = new Size(77, (20 * TxListNum) + 2); 110 | //table1.Height = (20 * TxListNum) + 2; 111 | Color[] colorsButton = { Color.Coral, Color.Coral }; 112 | Color[] colors = { Color.White, Color.LightGray }; 113 | for (int i = 0; i < TxListNum; i++) 114 | { 115 | Button[i] = new Button(); 116 | Button[i].Margin = new Padding(0, 0, 0, 0); 117 | Button[i].Name = "1225yl"; 118 | Button[i].Dock = DockStyle.Fill; 119 | Button[i].BackColor = colorsButton[i & 0x1]; 120 | Button[i].AutoSize = true; 121 | Button[i].TabStop = false; 122 | 123 | TextboxTimer[i] = new TextBox(); 124 | TextboxTimer[i].BackColor = colors[i & 0x1]; 125 | TextboxTimer[i].Margin = new Padding(0, 0, 0, 0); 126 | TextboxTimer[i].Name = "1225"; 127 | TextboxTimer[i].Dock = DockStyle.Fill; 128 | TextboxTimer[i].AutoSize = true; 129 | TextboxTimer[i].Multiline = true; 130 | TextboxTimer[i].MaxLength = 5; 131 | TextboxTimer[i].TabIndex = 200 + i; 132 | 133 | TextboxTX[i] = new TextBox(); 134 | TextboxTX[i].BackColor = colors[i & 0x1]; 135 | TextboxTX[i].Margin = new Padding(0, 0, 0, 0); 136 | TextboxTX[i].Name = "1225yl"; 137 | TextboxTX[i].MaxLength = 4096; 138 | TextboxTX[i].Dock = DockStyle.Fill; 139 | TextboxTX[i].AutoSize = true; 140 | TextboxTX[i].Multiline = true; 141 | TextboxTX[i].WordWrap = false; 142 | //TextboxTX[i].AutoCompleteMode = AutoCompleteMode.SuggestAppend; 143 | //TextboxTX[i].AutoCompleteSource = AutoCompleteSource.CustomSource; 144 | //TextboxTX[i].AutoCompleteCustomSource.AddRange(autocompsource); 145 | TextboxTX[i].TabIndex = TextboxTimer[i].TabIndex + TxListNum; 146 | TextboxTX[i].MouseDoubleClick += new MouseEventHandler(TextboxTX_MouseDoubleClick); 147 | 148 | Checkbox[i] = new CheckBox(); 149 | Checkbox[i].BackColor = colors[i & 0x1]; 150 | Checkbox[i].Margin = new Padding(1, 1, 0, 0); 151 | Checkbox[i].Dock = DockStyle.Fill; 152 | Checkbox[i].TabStop = false; 153 | Checkbox[i].Checked = true; 154 | 155 | table1.Controls.Add(Checkbox[i], 0, i); 156 | table1.Controls.Add(TextboxTimer[i], 1, i); 157 | table1.Controls.Add(TextboxTX[i], 2, i); 158 | table2.Controls.Add(Button[i]); 159 | } 160 | } 161 | public int TxListFirstLoad() 162 | { 163 | try 164 | { 165 | string[] val = new string[4]; 166 | for (int i = 0; i < TxListNum; i++) 167 | { 168 | val = IniRead("发送区", "TableTx" + (i + 1).ToString(), TxListPath).Split('$'); 169 | Checkbox[i].Checked = Convert.ToBoolean(val[0]); 170 | TextboxTimer[i].Text = val[1]; 171 | TextboxTX[i].Text = val[2].Replace("\\n", "\r\n"); 172 | TextboxTX[i].Text = TextboxTX[i].Text.Replace("\\\\&", "$"); 173 | Button[i].Text = val[3]; 174 | } 175 | return TxListNum; 176 | } 177 | catch { } 178 | return TxListNum; 179 | } 180 | public int TxListLoad(TableLayoutPanel table1, TableLayoutPanel table2) 181 | { 182 | OpenFileDialog TxListFileInfo = new OpenFileDialog(); 183 | if(TxListPath == @".\TxList.ini") 184 | TxListFileInfo.InitialDirectory = Directory.GetCurrentDirectory(); 185 | else 186 | TxListFileInfo.InitialDirectory = Path.GetDirectoryName(TxListPath); 187 | TxListFileInfo.Filter = "ini|*.ini"; 188 | if (TxListFileInfo.ShowDialog() == DialogResult.OK) 189 | { 190 | TxListPath = TxListFileInfo.FileName; 191 | TxList_GetNum(TxListPath); 192 | TableTxCreate(table1, table2); 193 | return TxListFirstLoad(); 194 | } 195 | return 0; 196 | } 197 | public void TxListSave(string num) 198 | { 199 | IniWrite("基本配置", "TableTxNum", num, TxListPath); 200 | for(int i = 0; i < TxListNum; i++) 201 | { 202 | string txmsg = TextboxTX[i].Text; 203 | txmsg = txmsg.Replace("\r\n", "\\n"); 204 | txmsg = txmsg.Replace("$", "\\\\&"); 205 | string str = Checkbox[i].Checked.ToString() + "$" + TextboxTimer[i].Text + "$" + 206 | txmsg + "$" + Button[i].Text; 207 | IniWrite("发送区", "TableTx" + (i + 1).ToString(), str, TxListPath); 208 | } 209 | } 210 | public void TxListOtherSave(string num) 211 | { 212 | SaveFileDialog TxListFileInfo = new SaveFileDialog(); 213 | if (TxListPath == @".\TxList.ini") 214 | TxListFileInfo.InitialDirectory = Directory.GetCurrentDirectory(); 215 | else 216 | TxListFileInfo.InitialDirectory = Path.GetDirectoryName(TxListPath); 217 | TxListFileInfo.Filter = "ini|*.ini"; 218 | TxListFileInfo.FileName = "TxList"; 219 | if (TxListFileInfo.ShowDialog() == DialogResult.OK) 220 | { 221 | TxListPath = TxListFileInfo.FileName; 222 | TxListSave(num); 223 | } 224 | } 225 | public bool TxListNewCreate(TableLayoutPanel table1, TableLayoutPanel table2, string num) 226 | { 227 | SaveFileDialog TxListFileInfo = new SaveFileDialog(); 228 | if (TxListPath == @".\TxList.ini") 229 | TxListFileInfo.InitialDirectory = Directory.GetCurrentDirectory(); 230 | else 231 | TxListFileInfo.InitialDirectory = Path.GetDirectoryName(TxListPath); 232 | TxListFileInfo.Filter = "ini|*.ini"; 233 | TxListFileInfo.FileName = "TxList"; 234 | if (TxListFileInfo.ShowDialog() == DialogResult.OK) 235 | { 236 | TxListPath = TxListFileInfo.FileName; 237 | IniWrite("基本配置", "TableTxNum", num, TxListPath); 238 | TableTxCreate(table1, table2); 239 | return true; 240 | } 241 | return false; 242 | } 243 | 244 | 245 | private void TextboxTX_MouseDoubleClick(object sender, MouseEventArgs e) 246 | { 247 | if (TextboxTXClickBypass) 248 | return; 249 | int i = 0; 250 | TextBox yltb = sender as TextBox; 251 | for (; i < TxListNum; i++) 252 | { 253 | if (yltb == TextboxTX[i]) 254 | break; 255 | } 256 | Button[i].Text = TextboxTX[i].Text; 257 | TextboxTX[i].Text = ""; 258 | } 259 | 260 | public void TextboxTXClickBypassCfg(bool status) 261 | { 262 | TextboxTXClickBypass = status; 263 | } 264 | 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /串口助手/ContextMenu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace 串口助手 12 | { 13 | class ContextMenu 14 | { 15 | public ContextMenuStrip TxListMenu = new ContextMenuStrip(); 16 | public ContextMenuStrip RxShowMenu = new ContextMenuStrip(); 17 | public ContextMenuStrip CreateSuperMsgMenu = new ContextMenuStrip(); 18 | public ContextMenuStrip TxListSimpleMenu = new ContextMenuStrip(); 19 | 20 | 21 | public delegate void CreateSuperMsgHandler(int rx_textbox, int tx_textbox); 22 | CreateSuperMsgHandler createSuperMsgHandler; 23 | 24 | ToolStripComboBox 字体大小 = new ToolStripComboBox(); 25 | 26 | ToolStripTextBox 接收文本框 = new ToolStripTextBox(); 27 | ToolStripTextBox 发送文本框 = new ToolStripTextBox(); 28 | 29 | public void ContextMenuTxListInit() 30 | { 31 | TxListMenu.Name = "发送列表的右键菜单"; 32 | ToolStripTextBox 发送按钮文本输入框 = new ToolStripTextBox(); 33 | 发送按钮文本输入框.BackColor = System.Drawing.Color.Coral; 34 | 发送按钮文本输入框.Size = new System.Drawing.Size(150, 25); 35 | 发送按钮文本输入框.ToolTipText = "给按钮命名"; 36 | 发送按钮文本输入框.LostFocus += new EventHandler(发送按钮文本输入框_LostFocusClick); 37 | TxListMenu.Items.AddRange(new ToolStripItem[] 38 | { 39 | 发送按钮文本输入框, 40 | }); 41 | 42 | TxListSimpleMenu.Name = "发送列表简洁模式的右键菜单"; 43 | 44 | RxShowMenu.Name = "接收显示区的右键菜单"; 45 | ToolStripSeparator 分割线 = new ToolStripSeparator(); 46 | ToolStripMenuItem 复制 = new ToolStripMenuItem(); 47 | ToolStripMenuItem 粘贴 = new ToolStripMenuItem(); 48 | ToolStripMenuItem 全选 = new ToolStripMenuItem(); 49 | ToolStripMenuItem 清空 = new ToolStripMenuItem(); 50 | ToolStripMenuItem 接收区解锁 = new ToolStripMenuItem(); 51 | 复制.Text = "复制"; 52 | 粘贴.Text = "粘贴"; 53 | 全选.Text = "全选"; 54 | 清空.Text = "清空"; 55 | 接收区解锁.Text = "接收区解锁"; 56 | 粘贴.BackColor = System.Drawing.Color.Gainsboro; 57 | 清空.BackColor = System.Drawing.Color.Gainsboro; 58 | 字体大小.MaxLength = 4; 59 | 字体大小.Size = new System.Drawing.Size(60, 25); 60 | 字体大小.ToolTipText = "接收显示区的字体大小"; 61 | 字体大小.DropDownStyle = ComboBoxStyle.DropDown; 62 | 字体大小.Items.AddRange(new object[] 63 | { 64 | "9", 65 | "10.5", 66 | "12", 67 | "14", 68 | "16", 69 | "18", 70 | "21", 71 | "28", 72 | }); 73 | RxShowMenu.Items.AddRange(new ToolStripItem[] 74 | { 75 | 复制, 76 | 粘贴, 77 | 全选, 78 | 清空, 79 | 分割线, 80 | 接收区解锁, 81 | 字体大小, 82 | }); 83 | 84 | TxListMenu.Opening += new CancelEventHandler(发送列表右键菜单_Opening); 85 | RxShowMenu.Opening += new CancelEventHandler(接收显示区右键菜单_Opening); 86 | 复制.Click += new EventHandler(复制ToolStripMenuItem_Click); 87 | 粘贴.Click += new EventHandler(粘贴ToolStripMenuItem_Click); 88 | 全选.Click += new EventHandler(全选ToolStripMenuItem_Click); 89 | 清空.Click += new EventHandler(清空ToolStripMenuItem_Click); 90 | 接收区解锁.Click += new EventHandler(接收区解锁_Click); 91 | 字体大小.TextUpdate += new EventHandler(接收显示区字体大小_Click); 92 | 字体大小.SelectedIndexChanged += new EventHandler(接收显示区字体大小_Click); 93 | 94 | ContextMenu_CreateSuperMsgInit(); 95 | } 96 | private void ContextMenu_CreateSuperMsgInit() 97 | { 98 | CreateSuperMsgMenu.Name = "新增超级报文"; 99 | ToolStripSeparator 分割线 = new ToolStripSeparator(); 100 | ToolStripMenuItem 超级报文创建按钮 = new ToolStripMenuItem(); 101 | 发送文本框.Size = new Size(120, 27); 102 | 发送文本框.Text = "发送文本框个数:"; 103 | 发送文本框.ToolTipText = "发送文本框的个数"; 104 | 接收文本框.Size = new Size(120, 27); 105 | 接收文本框.Text = "接收文本框个数:"; 106 | 接收文本框.ToolTipText = "接收文本框的个数"; 107 | 超级报文创建按钮.Text = "创建"; 108 | 超级报文创建按钮.BackColor = Color.Coral; 109 | 超级报文创建按钮.Click += new EventHandler(超级报文创建按钮ToolStripMenuItem_Click); 110 | CreateSuperMsgMenu.Items.AddRange(new ToolStripItem[] 111 | { 112 | 接收文本框, 113 | 发送文本框, 114 | 分割线, 115 | 超级报文创建按钮, 116 | }); 117 | } 118 | public void ContextMenu_CreateSuperMsgClickCfg(CreateSuperMsgHandler eventHandler) 119 | { 120 | createSuperMsgHandler = eventHandler; 121 | } 122 | 123 | 124 | private void 超级报文创建按钮ToolStripMenuItem_Click(object sender, EventArgs e) 125 | { 126 | try 127 | { 128 | DataTypeConversion dataType = new DataTypeConversion(); 129 | createSuperMsgHandler(dataType.GetStringNumber(接收文本框.Text), 130 | dataType.GetStringNumber(发送文本框.Text)); 131 | } 132 | catch { } 133 | } 134 | 135 | private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) 136 | { 137 | Control c = RxShowMenu.SourceControl; 138 | if (c.GetType().Name == "RichTextBox") 139 | { 140 | RichTextBox r = (RichTextBox)c; 141 | r.SelectAll(); 142 | } 143 | } 144 | 145 | private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) 146 | { 147 | Control c = RxShowMenu.SourceControl; 148 | if (c.GetType().Name == "RichTextBox") 149 | { 150 | RichTextBox r = (RichTextBox)c; 151 | r.Copy(); 152 | } 153 | } 154 | 155 | private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) 156 | { 157 | Control c = RxShowMenu.SourceControl; 158 | if (c.GetType().Name == "RichTextBox") 159 | { 160 | RichTextBox r = (RichTextBox)c; 161 | r.Paste(); 162 | } 163 | } 164 | 165 | private void 清空ToolStripMenuItem_Click(object sender, EventArgs e) 166 | { 167 | Control c = RxShowMenu.SourceControl; 168 | if (c.GetType().Name == "RichTextBox") 169 | { 170 | RichTextBox r = (RichTextBox)c; 171 | r.Clear(); 172 | } 173 | } 174 | private void 发送按钮文本输入框_LostFocusClick(object sender, EventArgs e) 175 | { 176 | Control c = TxListMenu.SourceControl; 177 | if (c.GetType().Name == "Button") 178 | { 179 | ((Button)c).Text = TxListMenu.Items[0].Text; 180 | } 181 | } 182 | private void 发送列表右键菜单_Opening(object sender, CancelEventArgs e) 183 | { 184 | Control c = TxListMenu.SourceControl; 185 | if (c.GetType().Name == "Button") 186 | { 187 | Button r = (Button)c; 188 | TxListMenu.Items[0].Text = r.Text; 189 | } 190 | } 191 | 192 | private void 接收显示区右键菜单_Opening(object sender, CancelEventArgs e) 193 | { 194 | Control c = RxShowMenu.SourceControl; 195 | if (c.GetType().Name == "RichTextBox") 196 | { 197 | RichTextBox r = (RichTextBox)c; 198 | 字体大小.Text = r.Font.Size.ToString(); 199 | } 200 | } 201 | private void 接收显示区字体大小_Click(object sender, EventArgs e) 202 | { 203 | Control c = RxShowMenu.SourceControl; 204 | if (c.GetType().Name == "RichTextBox") 205 | { 206 | RichTextBox r = (RichTextBox)c; 207 | try 208 | { 209 | r.Font = new Font(r.Font.FontFamily, 210 | Convert.ToSingle(((ToolStripComboBox)sender).Text), 211 | r.Font.Style); 212 | } 213 | catch 214 | { 215 | ((ToolStripComboBox)sender).Text = ""; 216 | } 217 | } 218 | } 219 | 220 | private void 接收区解锁_Click(object sender, EventArgs e) 221 | { 222 | ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; 223 | Control c = RxShowMenu.SourceControl; 224 | if (c.GetType().Name == "RichTextBox") 225 | { 226 | RichTextBox r = (RichTextBox)c; 227 | if (menuItem.Text == "接收区解锁") 228 | { 229 | r.ReadOnly = false; 230 | menuItem.Text = "接收区上锁"; 231 | } 232 | else 233 | { 234 | r.ReadOnly = true; 235 | menuItem.Text = "接收区解锁"; 236 | } 237 | } 238 | } 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /串口助手/DataTypeConversion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace 串口助手 9 | { 10 | class DataTypeConversion 11 | { 12 | public int GetStringNumber(string str) 13 | { 14 | try 15 | { 16 | string pattern = @"[^0-9]+"; 17 | Regex rgx = new Regex(pattern); 18 | return Convert.ToInt32(rgx.Replace(str, "")); 19 | } 20 | catch { } 21 | return 0; 22 | } 23 | public bool GetStringSingle(string str, ref float value) 24 | { 25 | //str = Regex.Replace(str, @"[^\d.\d]", " "); 26 | Regex r = new Regex(@"\d*\.\d*|0\.\d*[1-9]\d*$"); 27 | string[] s = new string[] { r.Match(str).Value, r.Replace(str, "") }; 28 | if(s[0] != "" && s[0] != ".") 29 | { 30 | value = Convert.ToSingle(s[0]); 31 | return true; 32 | } 33 | else if(s.Length > 1 && s[1] != "") 34 | { 35 | Regex regex = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2)); 36 | MatchCollection mc = regex.Matches(s[1]); 37 | if(mc.Count > 0) 38 | { 39 | value = Convert.ToSingle(mc[0].Groups[0].Value); 40 | return true; 41 | } 42 | } 43 | return false; 44 | } 45 | 46 | public byte GetByteCheckSum(byte[] data, int length) 47 | { 48 | byte cs = 0; 49 | for (int i = 0; i < length; i++) 50 | { 51 | cs += data[i]; 52 | } 53 | return (byte)(~cs); 54 | } 55 | 56 | public UInt16 GetModBusCRC16(byte[] data, int length) 57 | { 58 | int temp; 59 | UInt16 pos, bit; 60 | UInt16 crc = 0xFFFF; 61 | for(pos = 0; pos < length; pos++) 62 | { 63 | crc = (UInt16)(data[pos] ^ crc); 64 | for(bit = 0; bit < 8; bit++) 65 | { 66 | temp = crc & 0x1; 67 | crc >>= 1; 68 | if (temp == 1) 69 | crc ^= 0xA001; 70 | } 71 | } 72 | return crc; 73 | } 74 | 75 | 76 | 77 | public int ByteAddMsgTail(string MsgTailType, ref byte[] msg) 78 | { 79 | byte[] check; 80 | switch (MsgTailType) 81 | { 82 | case "无": 83 | check = null; 84 | break; 85 | case "CS": 86 | check = new byte[1]; 87 | check[0] = GetByteCheckSum(msg, msg.Length); 88 | break; 89 | case "ModBus": 90 | UInt16 crc; 91 | crc = GetModBusCRC16(msg, msg.Length); 92 | check = new byte[2]; 93 | check[0] = (byte)(crc); 94 | check[1] = (byte)(crc >> 8); 95 | break; 96 | default: 97 | check = StringToByte("HEX", MsgTailType); 98 | break; 99 | } 100 | if (check != null) 101 | { 102 | int TxBufLen = msg.Length; 103 | Array.Resize(ref msg, TxBufLen + check.Length); 104 | Array.Copy(check, 0, msg, TxBufLen, check.Length); 105 | } 106 | return msg.Length; 107 | } 108 | 109 | /// 110 | /// 字符串转字节数组 111 | /// 112 | /// ASCII、HEX 113 | /// 114 | /// 115 | public byte[] StringToByte(string data_type, string data) 116 | { 117 | try 118 | { 119 | byte[] buf; 120 | if (data_type == "ASCII") 121 | { 122 | buf = Encoding.Default.GetBytes(data); 123 | } 124 | else 125 | { 126 | int i = 0, length, len; 127 | //string pattern = @"\s"; 128 | string replacement = ""; 129 | Regex rgx = new Regex(@"\s"); 130 | string str = rgx.Replace(data, replacement); 131 | 132 | length = (str.Length - str.Length % 2) / 2; 133 | len = length; 134 | if (str.Length % 2 != 0) 135 | len++; 136 | buf = new byte[len]; 137 | //逐个字符变为16进制字节数据 138 | for (i = 0; i < length; i++) 139 | { 140 | buf[i] = Convert.ToByte(str.Substring(i * 2, 2), 16); 141 | } 142 | if (str.Length % 2 != 0) 143 | { 144 | buf[i] = Convert.ToByte(str.Substring(i * 2, 1), 16); 145 | length++; 146 | } 147 | } 148 | return buf; 149 | } 150 | catch { } 151 | return null; 152 | } 153 | 154 | /// 155 | /// 字节数组转字符串 156 | /// 157 | /// ASCII、HEX 158 | /// 159 | /// 160 | /// 161 | public string ByteToString(string data_type, byte[] data, int length) 162 | { 163 | try 164 | { 165 | string s = ""; 166 | if (data_type == "ASCII") 167 | { 168 | s = Encoding.Default.GetString(data, 0, length); 169 | } 170 | else 171 | { 172 | s = BitConverter.ToString(data.Skip(0).Take(length).ToArray()).Replace("-", " "); 173 | } 174 | return s; 175 | } 176 | catch 177 | { 178 | 179 | } 180 | return ""; 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /串口助手/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace 串口助手 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /串口助手/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("串口助手V2.0")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("串口助手")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("448aef62-d3a8-4cd4-9f10-1b326548dc33")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("2.0.0.0")] 37 | -------------------------------------------------------------------------------- /串口助手/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace 串口助手.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("串口助手.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Bitmap help { 67 | get { 68 | object obj = ResourceManager.GetObject("help", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 75 | /// 76 | internal static System.Drawing.Bitmap hex { 77 | get { 78 | object obj = ResourceManager.GetObject("hex", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 85 | /// 86 | internal static System.Drawing.Bitmap log { 87 | get { 88 | object obj = ResourceManager.GetObject("log", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 95 | /// 96 | internal static System.Drawing.Bitmap MSB { 97 | get { 98 | object obj = ResourceManager.GetObject("MSB", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 105 | /// 106 | internal static System.Drawing.Bitmap 保存 { 107 | get { 108 | object obj = ResourceManager.GetObject("保存", resourceCulture); 109 | return ((System.Drawing.Bitmap)(obj)); 110 | } 111 | } 112 | 113 | /// 114 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 115 | /// 116 | internal static System.Drawing.Bitmap 公众号 { 117 | get { 118 | object obj = ResourceManager.GetObject("公众号", resourceCulture); 119 | return ((System.Drawing.Bitmap)(obj)); 120 | } 121 | } 122 | 123 | /// 124 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 125 | /// 126 | internal static System.Drawing.Bitmap 关闭 { 127 | get { 128 | object obj = ResourceManager.GetObject("关闭", resourceCulture); 129 | return ((System.Drawing.Bitmap)(obj)); 130 | } 131 | } 132 | 133 | /// 134 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 135 | /// 136 | internal static System.Drawing.Bitmap 删除 { 137 | get { 138 | object obj = ResourceManager.GetObject("删除", resourceCulture); 139 | return ((System.Drawing.Bitmap)(obj)); 140 | } 141 | } 142 | 143 | /// 144 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 145 | /// 146 | internal static System.Drawing.Bitmap 多级发送 { 147 | get { 148 | object obj = ResourceManager.GetObject("多级发送", resourceCulture); 149 | return ((System.Drawing.Bitmap)(obj)); 150 | } 151 | } 152 | 153 | /// 154 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 155 | /// 156 | internal static System.Drawing.Bitmap 开启 { 157 | get { 158 | object obj = ResourceManager.GetObject("开启", resourceCulture); 159 | return ((System.Drawing.Bitmap)(obj)); 160 | } 161 | } 162 | 163 | /// 164 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 165 | /// 166 | internal static System.Drawing.Bitmap 换行 { 167 | get { 168 | object obj = ResourceManager.GetObject("换行", resourceCulture); 169 | return ((System.Drawing.Bitmap)(obj)); 170 | } 171 | } 172 | 173 | /// 174 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 175 | /// 176 | internal static System.Drawing.Bitmap 新建 { 177 | get { 178 | object obj = ResourceManager.GetObject("新建", resourceCulture); 179 | return ((System.Drawing.Bitmap)(obj)); 180 | } 181 | } 182 | 183 | /// 184 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 185 | /// 186 | internal static System.Drawing.Bitmap 时间戳 { 187 | get { 188 | object obj = ResourceManager.GetObject("时间戳", resourceCulture); 189 | return ((System.Drawing.Bitmap)(obj)); 190 | } 191 | } 192 | 193 | /// 194 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 195 | /// 196 | internal static System.Drawing.Bitmap 清除 { 197 | get { 198 | object obj = ResourceManager.GetObject("清除", resourceCulture); 199 | return ((System.Drawing.Bitmap)(obj)); 200 | } 201 | } 202 | 203 | /// 204 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 205 | /// 206 | internal static System.Drawing.Bitmap 置顶 { 207 | get { 208 | object obj = ResourceManager.GetObject("置顶", resourceCulture); 209 | return ((System.Drawing.Bitmap)(obj)); 210 | } 211 | } 212 | 213 | /// 214 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 215 | /// 216 | internal static System.Drawing.Bitmap 设置 { 217 | get { 218 | object obj = ResourceManager.GetObject("设置", resourceCulture); 219 | return ((System.Drawing.Bitmap)(obj)); 220 | } 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /串口助手/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\image\log.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\image\关闭.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\image\置顶.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\image\开启.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ..\image\多级发送.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 135 | 136 | 137 | ..\image\新建.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 138 | 139 | 140 | ..\image\MSB.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 141 | 142 | 143 | ..\image\删除.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 144 | 145 | 146 | ..\image\保存.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 147 | 148 | 149 | ..\image\hex.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 150 | 151 | 152 | ..\image\时间戳.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 153 | 154 | 155 | ..\image\清除.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 156 | 157 | 158 | ..\image\换行.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 159 | 160 | 161 | ..\image\设置.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 162 | 163 | 164 | ..\image\help.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 165 | 166 | 167 | ..\image\公众号.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 168 | 169 | -------------------------------------------------------------------------------- /串口助手/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | namespace 串口助手.Properties 13 | { 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 17 | { 18 | 19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 20 | 21 | public static Settings Default 22 | { 23 | get 24 | { 25 | return defaultInstance; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /串口助手/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /串口助手/RealTimeCurve.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace 串口助手 3 | { 4 | partial class RealTimeCurve 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.components = new System.ComponentModel.Container(); 33 | System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 34 | System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 35 | this.toolStrip1 = new System.Windows.Forms.ToolStrip(); 36 | this.toolStripButton_新建 = new System.Windows.Forms.ToolStripButton(); 37 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); 38 | this.toolStripButton_RT_Curve_Cmd = new System.Windows.Forms.ToolStripButton(); 39 | this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); 40 | this.toolStripButton_设置 = new System.Windows.Forms.ToolStripButton(); 41 | this.contextMenuStrip_创建 = new System.Windows.Forms.ContextMenuStrip(this.components); 42 | this.toolStripTextBox_CurveName = new System.Windows.Forms.ToolStripTextBox(); 43 | this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); 44 | this.toolStrip1.SuspendLayout(); 45 | ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); 46 | this.contextMenuStrip_创建.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // toolStrip1 50 | // 51 | this.toolStrip1.AllowItemReorder = true; 52 | this.toolStrip1.AutoSize = false; 53 | this.toolStrip1.BackColor = System.Drawing.Color.Transparent; 54 | this.toolStrip1.Dock = System.Windows.Forms.DockStyle.Right; 55 | this.toolStrip1.ImageScalingSize = new System.Drawing.Size(21, 21); 56 | this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 57 | this.toolStripButton_新建, 58 | this.toolStripSeparator1, 59 | this.toolStripButton_RT_Curve_Cmd, 60 | this.toolStripButton_设置}); 61 | this.toolStrip1.Location = new System.Drawing.Point(428, 0); 62 | this.toolStrip1.Name = "toolStrip1"; 63 | this.toolStrip1.Size = new System.Drawing.Size(28, 290); 64 | this.toolStrip1.TabIndex = 0; 65 | this.toolStrip1.Text = "toolStrip1"; 66 | // 67 | // toolStripButton_新建 68 | // 69 | this.toolStripButton_新建.AutoSize = false; 70 | this.toolStripButton_新建.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 71 | this.toolStripButton_新建.Image = global::串口助手.Properties.Resources.新建; 72 | this.toolStripButton_新建.ImageTransparentColor = System.Drawing.Color.Magenta; 73 | this.toolStripButton_新建.Margin = new System.Windows.Forms.Padding(0, 0, 0, 2); 74 | this.toolStripButton_新建.Name = "toolStripButton_新建"; 75 | this.toolStripButton_新建.Size = new System.Drawing.Size(25, 25); 76 | this.toolStripButton_新建.Text = "toolStripButton1"; 77 | this.toolStripButton_新建.ToolTipText = "新建一条曲线"; 78 | this.toolStripButton_新建.Click += new System.EventHandler(this.toolStripButton_新建_Click); 79 | // 80 | // toolStripSeparator1 81 | // 82 | this.toolStripSeparator1.Name = "toolStripSeparator1"; 83 | this.toolStripSeparator1.Size = new System.Drawing.Size(26, 6); 84 | // 85 | // toolStripButton_RT_Curve_Cmd 86 | // 87 | this.toolStripButton_RT_Curve_Cmd.AutoSize = false; 88 | this.toolStripButton_RT_Curve_Cmd.BackColor = System.Drawing.Color.LimeGreen; 89 | this.toolStripButton_RT_Curve_Cmd.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 90 | this.toolStripButton_RT_Curve_Cmd.Image = global::串口助手.Properties.Resources.开启; 91 | this.toolStripButton_RT_Curve_Cmd.ImageTransparentColor = System.Drawing.Color.Magenta; 92 | this.toolStripButton_RT_Curve_Cmd.Margin = new System.Windows.Forms.Padding(0, 0, 0, 2); 93 | this.toolStripButton_RT_Curve_Cmd.Name = "toolStripButton_RT_Curve_Cmd"; 94 | this.toolStripButton_RT_Curve_Cmd.Size = new System.Drawing.Size(25, 25); 95 | this.toolStripButton_RT_Curve_Cmd.Text = "启动"; 96 | this.toolStripButton_RT_Curve_Cmd.Click += new System.EventHandler(this.toolStripButton_RT_Curve_Cmd_Click); 97 | // 98 | // chart1 99 | // 100 | chartArea1.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; 101 | chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; 102 | chartArea1.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; 103 | chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; 104 | chartArea1.CursorX.IsUserEnabled = true; 105 | chartArea1.CursorX.IsUserSelectionEnabled = true; 106 | chartArea1.CursorY.IsUserEnabled = true; 107 | chartArea1.CursorY.IsUserSelectionEnabled = true; 108 | chartArea1.Name = "ChartArea1"; 109 | this.chart1.ChartAreas.Add(chartArea1); 110 | this.chart1.Dock = System.Windows.Forms.DockStyle.Fill; 111 | legend1.Name = "Legend1"; 112 | this.chart1.Legends.Add(legend1); 113 | this.chart1.Location = new System.Drawing.Point(0, 0); 114 | this.chart1.Margin = new System.Windows.Forms.Padding(0); 115 | this.chart1.Name = "chart1"; 116 | this.chart1.Size = new System.Drawing.Size(428, 290); 117 | this.chart1.TabIndex = 1; 118 | this.chart1.Text = "chart1"; 119 | // 120 | // toolStripButton_设置 121 | // 122 | this.toolStripButton_设置.AutoSize = false; 123 | this.toolStripButton_设置.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 124 | this.toolStripButton_设置.Image = global::串口助手.Properties.Resources.设置; 125 | this.toolStripButton_设置.ImageTransparentColor = System.Drawing.Color.Magenta; 126 | this.toolStripButton_设置.Margin = new System.Windows.Forms.Padding(0, 0, 0, 2); 127 | this.toolStripButton_设置.Name = "toolStripButton_设置"; 128 | this.toolStripButton_设置.Size = new System.Drawing.Size(25, 25); 129 | this.toolStripButton_设置.Text = "toolStripButton1"; 130 | this.toolStripButton_设置.Click += new System.EventHandler(this.toolStripButton_设置_Click); 131 | // 132 | // contextMenuStrip_创建 133 | // 134 | this.contextMenuStrip_创建.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 135 | this.toolStripTextBox_CurveName, 136 | this.toolStripMenuItem1}); 137 | this.contextMenuStrip_创建.Name = "contextMenuStrip_创建"; 138 | this.contextMenuStrip_创建.Size = new System.Drawing.Size(181, 73); 139 | // 140 | // toolStripTextBox_CurveName 141 | // 142 | this.toolStripTextBox_CurveName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 143 | this.toolStripTextBox_CurveName.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 144 | this.toolStripTextBox_CurveName.MaxLength = 10; 145 | this.toolStripTextBox_CurveName.Name = "toolStripTextBox_CurveName"; 146 | this.toolStripTextBox_CurveName.Size = new System.Drawing.Size(80, 23); 147 | this.toolStripTextBox_CurveName.ToolTipText = "请输入曲线名称"; 148 | // 149 | // toolStripMenuItem1 150 | // 151 | this.toolStripMenuItem1.Name = "toolStripMenuItem1"; 152 | this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22); 153 | this.toolStripMenuItem1.Text = "创建新曲线"; 154 | this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); 155 | // 156 | // RealTimeCurve 157 | // 158 | this.AllowDrop = true; 159 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 160 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 161 | this.AutoSize = true; 162 | this.ClientSize = new System.Drawing.Size(456, 290); 163 | this.Controls.Add(this.chart1); 164 | this.Controls.Add(this.toolStrip1); 165 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 166 | this.Name = "RealTimeCurve"; 167 | this.Text = "RealTimeCurve"; 168 | this.toolStrip1.ResumeLayout(false); 169 | this.toolStrip1.PerformLayout(); 170 | ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); 171 | this.contextMenuStrip_创建.ResumeLayout(false); 172 | this.contextMenuStrip_创建.PerformLayout(); 173 | this.ResumeLayout(false); 174 | 175 | } 176 | 177 | #endregion 178 | 179 | private System.Windows.Forms.ToolStrip toolStrip1; 180 | private System.Windows.Forms.DataVisualization.Charting.Chart chart1; 181 | private System.Windows.Forms.ToolStripButton toolStripButton_RT_Curve_Cmd; 182 | private System.Windows.Forms.ToolStripButton toolStripButton_新建; 183 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; 184 | private System.Windows.Forms.ToolStripButton toolStripButton_设置; 185 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip_创建; 186 | private System.Windows.Forms.ToolStripTextBox toolStripTextBox_CurveName; 187 | private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; 188 | } 189 | } -------------------------------------------------------------------------------- /串口助手/RealTimeCurve.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | using System.Windows.Forms.DataVisualization.Charting; 12 | 13 | namespace 串口助手 14 | { 15 | public partial class RealTimeCurve : Form 16 | { 17 | 18 | private bool rtCurve_Enable = false; 19 | 20 | RealTimeCurveEditor EditorForm = new RealTimeCurveEditor(); 21 | 22 | RealTimeCurve_Channel rtCurve_Channel = new RealTimeCurve_Channel(); 23 | 24 | public RealTimeCurve() 25 | { 26 | InitializeComponent(); 27 | 28 | RealTimeCurve_Channel.Channel rtCurveChannel = new RealTimeCurve_Channel.Channel(); 29 | rtCurveChannel = rtCurve_Channel.Create("电压", new Byte[] { 0x12, 0x25 }); 30 | EditorForm.rtCurveChannels.Add(rtCurveChannel); 31 | chart1.Series.Add(rtCurveChannel.series); 32 | 33 | EditorForm.rtCurveChannelsNameReg("电压"); 34 | EditorForm.rtCurveChannelDelete = rtCurveChannelDelete; 35 | EditorForm.FormClosing += new FormClosingEventHandler(EditorForm_FormClosing); 36 | } 37 | 38 | public void rtCurveChannelDelete(Series series) 39 | { 40 | chart1.Series.Remove(series); 41 | } 42 | 43 | 44 | public void RT_Curve_WriteData(int channel, double yValue) 45 | { 46 | if (!rtCurve_Enable) 47 | return; 48 | if (channel > EditorForm.rtCurveChannels.Count - 1) 49 | return; 50 | rtCurve_Channel.SeriesWriteData(EditorForm.rtCurveChannels[channel], yValue); 51 | } 52 | 53 | public void RT_Curve_WriteData(byte[] data, int length) 54 | { 55 | if (!rtCurve_Enable) 56 | return; 57 | foreach (RealTimeCurve_Channel.Channel ch in EditorForm.rtCurveChannels) 58 | { 59 | if (rtCurve_Channel.SeriesWriteData(ch, data, length)) 60 | return; 61 | } 62 | } 63 | 64 | public void RT_Curve_Off() 65 | { 66 | if (!rtCurve_Enable) 67 | return; 68 | rtCurve_Channel.SeriesThreadRelease(); 69 | if(!EditorForm.IsDisposed) 70 | EditorForm.Close(); 71 | } 72 | 73 | private void toolStripButton_RT_Curve_Cmd_Click(object sender, EventArgs e) 74 | { 75 | if (toolStripButton_RT_Curve_Cmd.Text == "启动") 76 | { 77 | toolStripButton_RT_Curve_Cmd.BackColor = Color.Tomato; 78 | toolStripButton_RT_Curve_Cmd.Image = Properties.Resources.关闭; 79 | toolStripButton_RT_Curve_Cmd.Text = "停止"; 80 | //先清除旧波形 81 | foreach (RealTimeCurve_Channel.Channel ch in EditorForm.rtCurveChannels) 82 | { 83 | rtCurve_Channel.SeriesClear(ch); 84 | } 85 | rtCurve_Channel.SeriesThreadCreate(EditorForm.rtCurveChannels[0]); 86 | rtCurve_Enable = true; 87 | } 88 | else 89 | { 90 | toolStripButton_RT_Curve_Cmd.BackColor = Color.LimeGreen; 91 | toolStripButton_RT_Curve_Cmd.Image = Properties.Resources.开启; 92 | toolStripButton_RT_Curve_Cmd.Text = "启动"; 93 | rtCurve_Channel.SeriesThreadRelease(); 94 | rtCurve_Enable = false; 95 | } 96 | } 97 | 98 | /// 99 | /// 新建曲线,这里通过触发右键菜单,进行创建曲线 100 | /// 101 | /// 102 | /// 103 | private void toolStripButton_新建_Click(object sender, EventArgs e) 104 | { 105 | contextMenuStrip_创建.Show(Control.MousePosition); 106 | } 107 | 108 | /// 109 | /// 关闭编辑器时,把各个参数写入曲线的参数列表中 110 | /// 111 | /// 112 | /// 113 | private void EditorForm_FormClosing(object sender, FormClosingEventArgs e) 114 | { 115 | EditorForm.MsgDecodeCfg(); 116 | EditorForm.Hide(); 117 | e.Cancel = true; 118 | } 119 | 120 | /// 121 | /// 打开曲线的参数编辑器 122 | /// 123 | /// 124 | /// 125 | private void toolStripButton_设置_Click(object sender, EventArgs e) 126 | { 127 | Point point = Control.MousePosition; 128 | point.X -= EditorForm.Width; 129 | EditorForm.Location = point; 130 | EditorForm.Show(); 131 | } 132 | 133 | /// 134 | /// 右键新建一条曲线,连贯打开曲线参数编辑器 135 | /// 136 | /// 137 | /// 138 | private void toolStripMenuItem1_Click(object sender, EventArgs e) 139 | { 140 | string name = toolStripTextBox_CurveName.Text; 141 | if (name == "" || EditorForm.rtCurveChannelCheck(name)) 142 | return; 143 | RealTimeCurve_Channel.Channel rtCurveChannel = new RealTimeCurve_Channel.Channel(); 144 | rtCurveChannel = rtCurve_Channel.Create(name, null); 145 | EditorForm.rtCurveChannels.Add(rtCurveChannel); 146 | chart1.Series.Add(rtCurveChannel.series); 147 | EditorForm.rtCurveChannelsNameReg(name); 148 | toolStripButton_设置_Click(null, null); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /串口助手/RealTimeCurve.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 127, 17 125 | 126 | -------------------------------------------------------------------------------- /串口助手/RealTimeCurveEditor.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace 串口助手 3 | { 4 | partial class RealTimeCurveEditor 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.tabControl1 = new System.Windows.Forms.TabControl(); 33 | this.曲线设置 = new System.Windows.Forms.TabPage(); 34 | this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); 35 | this.toolStrip6 = new System.Windows.Forms.ToolStrip(); 36 | this.toolStripLabel6 = new System.Windows.Forms.ToolStripLabel(); 37 | this.CurveName = new System.Windows.Forms.ToolStripTextBox(); 38 | this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); 39 | this.toolStripLabel7 = new System.Windows.Forms.ToolStripLabel(); 40 | this.CurveGain = new System.Windows.Forms.ToolStripComboBox(); 41 | this.解析规则 = new System.Windows.Forms.TabPage(); 42 | this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 43 | this.toolStrip3 = new System.Windows.Forms.ToolStrip(); 44 | this.toolStripLabel2 = new System.Windows.Forms.ToolStripLabel(); 45 | this.ComboBox_MsgDataType = new System.Windows.Forms.ToolStripComboBox(); 46 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); 47 | this.MsgFlagMSB = new System.Windows.Forms.ToolStripButton(); 48 | this.toolStrip4 = new System.Windows.Forms.ToolStrip(); 49 | this.toolStripLabel3 = new System.Windows.Forms.ToolStripLabel(); 50 | this.MsgParamOffset = new System.Windows.Forms.ToolStripTextBox(); 51 | this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); 52 | this.toolStripLabel4 = new System.Windows.Forms.ToolStripLabel(); 53 | this.MsgParamByteNum = new System.Windows.Forms.ToolStripComboBox(); 54 | this.toolStrip5 = new System.Windows.Forms.ToolStrip(); 55 | this.toolStripLabel5 = new System.Windows.Forms.ToolStripLabel(); 56 | this.MsgHead = new System.Windows.Forms.ToolStripTextBox(); 57 | this.toolStrip1 = new System.Windows.Forms.ToolStrip(); 58 | this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel(); 59 | this.ComboBox_Channel = new System.Windows.Forms.ToolStripComboBox(); 60 | this.toolStripButton_绘制曲线 = new System.Windows.Forms.ToolStripButton(); 61 | this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); 62 | this.toolStripButton_删除曲线 = new System.Windows.Forms.ToolStripButton(); 63 | this.panel1 = new System.Windows.Forms.Panel(); 64 | this.tabControl1.SuspendLayout(); 65 | this.曲线设置.SuspendLayout(); 66 | this.tableLayoutPanel2.SuspendLayout(); 67 | this.toolStrip6.SuspendLayout(); 68 | this.解析规则.SuspendLayout(); 69 | this.tableLayoutPanel1.SuspendLayout(); 70 | this.toolStrip3.SuspendLayout(); 71 | this.toolStrip4.SuspendLayout(); 72 | this.toolStrip5.SuspendLayout(); 73 | this.toolStrip1.SuspendLayout(); 74 | this.panel1.SuspendLayout(); 75 | this.SuspendLayout(); 76 | // 77 | // tabControl1 78 | // 79 | this.tabControl1.Controls.Add(this.曲线设置); 80 | this.tabControl1.Controls.Add(this.解析规则); 81 | this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; 82 | this.tabControl1.Location = new System.Drawing.Point(0, 0); 83 | this.tabControl1.Name = "tabControl1"; 84 | this.tabControl1.SelectedIndex = 0; 85 | this.tabControl1.Size = new System.Drawing.Size(349, 263); 86 | this.tabControl1.TabIndex = 4; 87 | // 88 | // 曲线设置 89 | // 90 | this.曲线设置.Controls.Add(this.tableLayoutPanel2); 91 | this.曲线设置.Location = new System.Drawing.Point(4, 22); 92 | this.曲线设置.Name = "曲线设置"; 93 | this.曲线设置.Padding = new System.Windows.Forms.Padding(3); 94 | this.曲线设置.Size = new System.Drawing.Size(341, 237); 95 | this.曲线设置.TabIndex = 0; 96 | this.曲线设置.Text = "曲线设置"; 97 | this.曲线设置.UseVisualStyleBackColor = true; 98 | // 99 | // tableLayoutPanel2 100 | // 101 | this.tableLayoutPanel2.ColumnCount = 1; 102 | this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 103 | this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); 104 | this.tableLayoutPanel2.Controls.Add(this.toolStrip6, 0, 0); 105 | this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; 106 | this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 3); 107 | this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(0); 108 | this.tableLayoutPanel2.Name = "tableLayoutPanel2"; 109 | this.tableLayoutPanel2.RowCount = 3; 110 | this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 111 | this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 112 | this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 113 | this.tableLayoutPanel2.Size = new System.Drawing.Size(335, 231); 114 | this.tableLayoutPanel2.TabIndex = 0; 115 | // 116 | // toolStrip6 117 | // 118 | this.toolStrip6.Dock = System.Windows.Forms.DockStyle.Bottom; 119 | this.toolStrip6.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 120 | this.toolStrip6.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 121 | this.toolStripLabel6, 122 | this.CurveName, 123 | this.toolStripSeparator4, 124 | this.toolStripLabel7, 125 | this.CurveGain}); 126 | this.toolStrip6.Location = new System.Drawing.Point(0, 52); 127 | this.toolStrip6.Name = "toolStrip6"; 128 | this.toolStrip6.Size = new System.Drawing.Size(335, 25); 129 | this.toolStrip6.TabIndex = 1; 130 | this.toolStrip6.Text = "toolStrip6"; 131 | // 132 | // toolStripLabel6 133 | // 134 | this.toolStripLabel6.Name = "toolStripLabel6"; 135 | this.toolStripLabel6.Size = new System.Drawing.Size(44, 22); 136 | this.toolStripLabel6.Text = "曲线名"; 137 | // 138 | // CurveName 139 | // 140 | this.CurveName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 141 | this.CurveName.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 142 | this.CurveName.MaxLength = 10; 143 | this.CurveName.Name = "CurveName"; 144 | this.CurveName.Size = new System.Drawing.Size(80, 25); 145 | // 146 | // toolStripSeparator4 147 | // 148 | this.toolStripSeparator4.Name = "toolStripSeparator4"; 149 | this.toolStripSeparator4.Size = new System.Drawing.Size(6, 25); 150 | // 151 | // toolStripLabel7 152 | // 153 | this.toolStripLabel7.Name = "toolStripLabel7"; 154 | this.toolStripLabel7.Size = new System.Drawing.Size(56, 22); 155 | this.toolStripLabel7.Text = "放大倍率"; 156 | // 157 | // CurveGain 158 | // 159 | this.CurveGain.AutoSize = false; 160 | this.CurveGain.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 161 | this.CurveGain.FlatStyle = System.Windows.Forms.FlatStyle.Standard; 162 | this.CurveGain.Items.AddRange(new object[] { 163 | "×10", 164 | "×8", 165 | "×4", 166 | "×2", 167 | "×1", 168 | "÷2", 169 | "÷4", 170 | "÷8", 171 | "÷10"}); 172 | this.CurveGain.Name = "CurveGain"; 173 | this.CurveGain.Size = new System.Drawing.Size(50, 25); 174 | this.CurveGain.SelectedIndexChanged += new System.EventHandler(this.CurveGain_SelectedIndexChanged); 175 | // 176 | // 解析规则 177 | // 178 | this.解析规则.Controls.Add(this.tableLayoutPanel1); 179 | this.解析规则.Location = new System.Drawing.Point(4, 22); 180 | this.解析规则.Name = "解析规则"; 181 | this.解析规则.Padding = new System.Windows.Forms.Padding(3); 182 | this.解析规则.Size = new System.Drawing.Size(341, 237); 183 | this.解析规则.TabIndex = 1; 184 | this.解析规则.Text = "解析规则"; 185 | this.解析规则.UseVisualStyleBackColor = true; 186 | // 187 | // tableLayoutPanel1 188 | // 189 | this.tableLayoutPanel1.ColumnCount = 1; 190 | this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 191 | this.tableLayoutPanel1.Controls.Add(this.toolStrip3, 0, 1); 192 | this.tableLayoutPanel1.Controls.Add(this.toolStrip4, 0, 2); 193 | this.tableLayoutPanel1.Controls.Add(this.toolStrip5, 0, 0); 194 | this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; 195 | this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3); 196 | this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 197 | this.tableLayoutPanel1.RowCount = 4; 198 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F)); 199 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F)); 200 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F)); 201 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); 202 | this.tableLayoutPanel1.Size = new System.Drawing.Size(335, 231); 203 | this.tableLayoutPanel1.TabIndex = 2; 204 | // 205 | // toolStrip3 206 | // 207 | this.toolStrip3.Dock = System.Windows.Forms.DockStyle.Bottom; 208 | this.toolStrip3.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 209 | this.toolStrip3.ImageScalingSize = new System.Drawing.Size(27, 27); 210 | this.toolStrip3.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 211 | this.toolStripLabel2, 212 | this.ComboBox_MsgDataType, 213 | this.toolStripSeparator1, 214 | this.MsgFlagMSB}); 215 | this.toolStrip3.Location = new System.Drawing.Point(0, 50); 216 | this.toolStrip3.Name = "toolStrip3"; 217 | this.toolStrip3.Size = new System.Drawing.Size(335, 30); 218 | this.toolStrip3.TabIndex = 0; 219 | this.toolStrip3.Text = "toolStrip3"; 220 | // 221 | // toolStripLabel2 222 | // 223 | this.toolStripLabel2.Name = "toolStripLabel2"; 224 | this.toolStripLabel2.Size = new System.Drawing.Size(56, 27); 225 | this.toolStripLabel2.Text = "数据类型"; 226 | // 227 | // ComboBox_MsgDataType 228 | // 229 | this.ComboBox_MsgDataType.AutoSize = false; 230 | this.ComboBox_MsgDataType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 231 | this.ComboBox_MsgDataType.FlatStyle = System.Windows.Forms.FlatStyle.Standard; 232 | this.ComboBox_MsgDataType.Items.AddRange(new object[] { 233 | "整型", 234 | "浮点数", 235 | "字符串"}); 236 | this.ComboBox_MsgDataType.Name = "ComboBox_MsgDataType"; 237 | this.ComboBox_MsgDataType.Size = new System.Drawing.Size(60, 25); 238 | this.ComboBox_MsgDataType.ToolTipText = "HEX:整型、浮点数。ASCII:字符串"; 239 | // 240 | // toolStripSeparator1 241 | // 242 | this.toolStripSeparator1.Name = "toolStripSeparator1"; 243 | this.toolStripSeparator1.Size = new System.Drawing.Size(6, 30); 244 | // 245 | // MsgFlagMSB 246 | // 247 | this.MsgFlagMSB.AutoSize = false; 248 | this.MsgFlagMSB.BackColor = System.Drawing.Color.Transparent; 249 | this.MsgFlagMSB.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 250 | this.MsgFlagMSB.Image = global::串口助手.Properties.Resources.MSB; 251 | this.MsgFlagMSB.ImageTransparentColor = System.Drawing.Color.Magenta; 252 | this.MsgFlagMSB.Margin = new System.Windows.Forms.Padding(0); 253 | this.MsgFlagMSB.Name = "MsgFlagMSB"; 254 | this.MsgFlagMSB.Size = new System.Drawing.Size(30, 30); 255 | this.MsgFlagMSB.Text = "MSB"; 256 | this.MsgFlagMSB.ToolTipText = "低位在前"; 257 | this.MsgFlagMSB.Click += new System.EventHandler(this.MsgFlagMSB_Click); 258 | // 259 | // toolStrip4 260 | // 261 | this.toolStrip4.Dock = System.Windows.Forms.DockStyle.Bottom; 262 | this.toolStrip4.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 263 | this.toolStrip4.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 264 | this.toolStripLabel3, 265 | this.MsgParamOffset, 266 | this.toolStripSeparator2, 267 | this.toolStripLabel4, 268 | this.MsgParamByteNum}); 269 | this.toolStrip4.Location = new System.Drawing.Point(0, 95); 270 | this.toolStrip4.Name = "toolStrip4"; 271 | this.toolStrip4.Size = new System.Drawing.Size(335, 25); 272 | this.toolStrip4.TabIndex = 1; 273 | this.toolStrip4.Text = "toolStrip4"; 274 | // 275 | // toolStripLabel3 276 | // 277 | this.toolStripLabel3.Name = "toolStripLabel3"; 278 | this.toolStripLabel3.Size = new System.Drawing.Size(56, 22); 279 | this.toolStripLabel3.Text = "报文位置"; 280 | // 281 | // MsgParamOffset 282 | // 283 | this.MsgParamOffset.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 284 | this.MsgParamOffset.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 285 | this.MsgParamOffset.MaxLength = 2; 286 | this.MsgParamOffset.Name = "MsgParamOffset"; 287 | this.MsgParamOffset.Size = new System.Drawing.Size(25, 25); 288 | this.MsgParamOffset.Text = "0"; 289 | // 290 | // toolStripSeparator2 291 | // 292 | this.toolStripSeparator2.Margin = new System.Windows.Forms.Padding(25, 0, 2, 0); 293 | this.toolStripSeparator2.Name = "toolStripSeparator2"; 294 | this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25); 295 | // 296 | // toolStripLabel4 297 | // 298 | this.toolStripLabel4.Name = "toolStripLabel4"; 299 | this.toolStripLabel4.Size = new System.Drawing.Size(44, 22); 300 | this.toolStripLabel4.Text = "字节数"; 301 | // 302 | // MsgParamByteNum 303 | // 304 | this.MsgParamByteNum.AutoSize = false; 305 | this.MsgParamByteNum.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 306 | this.MsgParamByteNum.FlatStyle = System.Windows.Forms.FlatStyle.Standard; 307 | this.MsgParamByteNum.Items.AddRange(new object[] { 308 | "1", 309 | "2", 310 | "3", 311 | "4"}); 312 | this.MsgParamByteNum.Name = "MsgParamByteNum"; 313 | this.MsgParamByteNum.Size = new System.Drawing.Size(40, 25); 314 | this.MsgParamByteNum.ToolTipText = "仅供HEX数据使用"; 315 | // 316 | // toolStrip5 317 | // 318 | this.toolStrip5.Dock = System.Windows.Forms.DockStyle.Bottom; 319 | this.toolStrip5.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 320 | this.toolStrip5.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 321 | this.toolStripLabel5, 322 | this.MsgHead}); 323 | this.toolStrip5.Location = new System.Drawing.Point(0, 15); 324 | this.toolStrip5.Name = "toolStrip5"; 325 | this.toolStrip5.Size = new System.Drawing.Size(335, 25); 326 | this.toolStrip5.TabIndex = 2; 327 | this.toolStrip5.Text = "toolStrip5"; 328 | // 329 | // toolStripLabel5 330 | // 331 | this.toolStripLabel5.Name = "toolStripLabel5"; 332 | this.toolStripLabel5.Size = new System.Drawing.Size(32, 22); 333 | this.toolStripLabel5.Text = "报头"; 334 | // 335 | // MsgHead 336 | // 337 | this.MsgHead.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 338 | this.MsgHead.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F); 339 | this.MsgHead.MaxLength = 20; 340 | this.MsgHead.Name = "MsgHead"; 341 | this.MsgHead.Size = new System.Drawing.Size(100, 25); 342 | // 343 | // toolStrip1 344 | // 345 | this.toolStrip1.ImageScalingSize = new System.Drawing.Size(23, 23); 346 | this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 347 | this.toolStripLabel1, 348 | this.ComboBox_Channel, 349 | this.toolStripButton_绘制曲线, 350 | this.toolStripSeparator3, 351 | this.toolStripButton_删除曲线}); 352 | this.toolStrip1.Location = new System.Drawing.Point(0, 0); 353 | this.toolStrip1.Margin = new System.Windows.Forms.Padding(3); 354 | this.toolStrip1.Name = "toolStrip1"; 355 | this.toolStrip1.Size = new System.Drawing.Size(349, 30); 356 | this.toolStrip1.TabIndex = 5; 357 | this.toolStrip1.Text = "toolStrip1"; 358 | // 359 | // toolStripLabel1 360 | // 361 | this.toolStripLabel1.Name = "toolStripLabel1"; 362 | this.toolStripLabel1.Size = new System.Drawing.Size(32, 27); 363 | this.toolStripLabel1.Text = "曲线"; 364 | // 365 | // ComboBox_Channel 366 | // 367 | this.ComboBox_Channel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 368 | this.ComboBox_Channel.DropDownWidth = 150; 369 | this.ComboBox_Channel.FlatStyle = System.Windows.Forms.FlatStyle.Standard; 370 | this.ComboBox_Channel.Name = "ComboBox_Channel"; 371 | this.ComboBox_Channel.Size = new System.Drawing.Size(80, 30); 372 | this.ComboBox_Channel.SelectedIndexChanged += new System.EventHandler(this.ComboBox_Channel_SelectedIndexChanged); 373 | // 374 | // toolStripButton_绘制曲线 375 | // 376 | this.toolStripButton_绘制曲线.BackColor = System.Drawing.Color.Tomato; 377 | this.toolStripButton_绘制曲线.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 378 | this.toolStripButton_绘制曲线.Image = global::串口助手.Properties.Resources.关闭; 379 | this.toolStripButton_绘制曲线.ImageTransparentColor = System.Drawing.Color.Magenta; 380 | this.toolStripButton_绘制曲线.Name = "toolStripButton_绘制曲线"; 381 | this.toolStripButton_绘制曲线.Size = new System.Drawing.Size(27, 27); 382 | this.toolStripButton_绘制曲线.Text = "toolStripButton2"; 383 | this.toolStripButton_绘制曲线.ToolTipText = "启动/暂停绘制当前曲线"; 384 | this.toolStripButton_绘制曲线.Click += new System.EventHandler(this.toolStripButton_绘制曲线_Click); 385 | // 386 | // toolStripSeparator3 387 | // 388 | this.toolStripSeparator3.Name = "toolStripSeparator3"; 389 | this.toolStripSeparator3.Size = new System.Drawing.Size(6, 30); 390 | // 391 | // toolStripButton_删除曲线 392 | // 393 | this.toolStripButton_删除曲线.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 394 | this.toolStripButton_删除曲线.Image = global::串口助手.Properties.Resources.删除; 395 | this.toolStripButton_删除曲线.ImageTransparentColor = System.Drawing.Color.Magenta; 396 | this.toolStripButton_删除曲线.Name = "toolStripButton_删除曲线"; 397 | this.toolStripButton_删除曲线.Size = new System.Drawing.Size(27, 27); 398 | this.toolStripButton_删除曲线.Text = "toolStripButton3"; 399 | this.toolStripButton_删除曲线.ToolTipText = "删除当前曲线"; 400 | this.toolStripButton_删除曲线.Click += new System.EventHandler(this.toolStripButton_删除曲线_Click); 401 | // 402 | // panel1 403 | // 404 | this.panel1.Controls.Add(this.tabControl1); 405 | this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; 406 | this.panel1.Location = new System.Drawing.Point(0, 30); 407 | this.panel1.Margin = new System.Windows.Forms.Padding(0); 408 | this.panel1.Name = "panel1"; 409 | this.panel1.Size = new System.Drawing.Size(349, 263); 410 | this.panel1.TabIndex = 7; 411 | // 412 | // RealTimeCurveEditor 413 | // 414 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 415 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 416 | this.ClientSize = new System.Drawing.Size(349, 293); 417 | this.Controls.Add(this.panel1); 418 | this.Controls.Add(this.toolStrip1); 419 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 420 | this.Name = "RealTimeCurveEditor"; 421 | this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; 422 | this.Text = "RealTimeCurveEditor"; 423 | this.TopMost = true; 424 | this.tabControl1.ResumeLayout(false); 425 | this.曲线设置.ResumeLayout(false); 426 | this.tableLayoutPanel2.ResumeLayout(false); 427 | this.tableLayoutPanel2.PerformLayout(); 428 | this.toolStrip6.ResumeLayout(false); 429 | this.toolStrip6.PerformLayout(); 430 | this.解析规则.ResumeLayout(false); 431 | this.tableLayoutPanel1.ResumeLayout(false); 432 | this.tableLayoutPanel1.PerformLayout(); 433 | this.toolStrip3.ResumeLayout(false); 434 | this.toolStrip3.PerformLayout(); 435 | this.toolStrip4.ResumeLayout(false); 436 | this.toolStrip4.PerformLayout(); 437 | this.toolStrip5.ResumeLayout(false); 438 | this.toolStrip5.PerformLayout(); 439 | this.toolStrip1.ResumeLayout(false); 440 | this.toolStrip1.PerformLayout(); 441 | this.panel1.ResumeLayout(false); 442 | this.ResumeLayout(false); 443 | this.PerformLayout(); 444 | 445 | } 446 | 447 | #endregion 448 | private System.Windows.Forms.TabControl tabControl1; 449 | private System.Windows.Forms.TabPage 曲线设置; 450 | private System.Windows.Forms.TabPage 解析规则; 451 | private System.Windows.Forms.ToolStrip toolStrip4; 452 | private System.Windows.Forms.ToolStripLabel toolStripLabel3; 453 | private System.Windows.Forms.ToolStripTextBox MsgParamOffset; 454 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; 455 | private System.Windows.Forms.ToolStripLabel toolStripLabel4; 456 | private System.Windows.Forms.ToolStripComboBox MsgParamByteNum; 457 | private System.Windows.Forms.ToolStrip toolStrip3; 458 | private System.Windows.Forms.ToolStripLabel toolStripLabel2; 459 | private System.Windows.Forms.ToolStripComboBox ComboBox_MsgDataType; 460 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; 461 | private System.Windows.Forms.ToolStripButton MsgFlagMSB; 462 | private System.Windows.Forms.ToolStrip toolStrip1; 463 | private System.Windows.Forms.ToolStripLabel toolStripLabel1; 464 | private System.Windows.Forms.ToolStripComboBox ComboBox_Channel; 465 | private System.Windows.Forms.Panel panel1; 466 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; 467 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; 468 | private System.Windows.Forms.ToolStrip toolStrip5; 469 | private System.Windows.Forms.ToolStripLabel toolStripLabel5; 470 | private System.Windows.Forms.ToolStripTextBox MsgHead; 471 | private System.Windows.Forms.ToolStrip toolStrip6; 472 | private System.Windows.Forms.ToolStripLabel toolStripLabel6; 473 | private System.Windows.Forms.ToolStripTextBox CurveName; 474 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; 475 | private System.Windows.Forms.ToolStripLabel toolStripLabel7; 476 | private System.Windows.Forms.ToolStripComboBox CurveGain; 477 | private System.Windows.Forms.ToolStripButton toolStripButton_绘制曲线; 478 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; 479 | private System.Windows.Forms.ToolStripButton toolStripButton_删除曲线; 480 | } 481 | } -------------------------------------------------------------------------------- /串口助手/RealTimeCurveEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using System.Windows.Forms.DataVisualization.Charting; 11 | 12 | namespace 串口助手 13 | { 14 | public partial class RealTimeCurveEditor : Form 15 | { 16 | public delegate void rtCurveCtr(Series series); 17 | public rtCurveCtr rtCurveChannelDelete; 18 | 19 | /// 20 | /// 通道列表 21 | /// 22 | public List rtCurveChannels = new List(); 23 | 24 | public RealTimeCurveEditor() 25 | { 26 | InitializeComponent(); 27 | CurveGain.SelectedIndex = 4; 28 | } 29 | 30 | public bool rtCurveChannelCheck(string channel) 31 | { 32 | if (ComboBox_Channel.Items.IndexOf(channel) != -1) 33 | return true; 34 | return false; 35 | } 36 | public bool rtCurveChannelsNameReg(string channel) 37 | { 38 | if (channel == "") 39 | return false; 40 | foreach(string str in ComboBox_Channel.Items) 41 | { 42 | if (str == channel) 43 | { 44 | return false; 45 | } 46 | } 47 | ComboBox_Channel.Items.Add(channel); 48 | ComboBox_Channel.SelectedIndex = ComboBox_Channel.Items.Count - 1; 49 | return true; 50 | } 51 | 52 | public bool MsgDecodeCfg() 53 | { 54 | foreach(RealTimeCurve_Channel.Channel ch in rtCurveChannels) 55 | { 56 | if(ch.series.Name == ComboBox_Channel.Text) 57 | { 58 | //加载曲线的参数 59 | if (CurveName.Text != ch.series.Name) 60 | { 61 | if (-1 == ComboBox_Channel.Items.IndexOf(CurveName.Text)) 62 | { 63 | ComboBox_Channel.Items[ComboBox_Channel.SelectedIndex] = CurveName.Text; 64 | ch.series.Name = CurveName.Text; 65 | } 66 | else 67 | CurveName.Text = ch.series.Name; 68 | } 69 | 70 | ch.msgDecode.data_type = ComboBox_MsgDataType.SelectedIndex; 71 | if(MsgFlagMSB.Text == "MSB") 72 | ch.msgDecode.flag_msb = true; 73 | else 74 | ch.msgDecode.flag_msb = false; 75 | ch.msgDecode.in_msg_pos = Convert.ToInt32(MsgParamOffset.Text); 76 | ch.msgDecode.byte_num = Convert.ToInt32(MsgParamByteNum.Text); 77 | 78 | if (MsgHead.Text == "") 79 | { 80 | MessageBox.Show("请填写解析规则的报头!", "ERROR"); 81 | return false; 82 | } 83 | DataTypeConversion dataType = new DataTypeConversion(); 84 | string temp = "HEX"; 85 | if (ch.msgDecode.data_type == 2) 86 | temp = "ASCII"; 87 | ch.msgDecode.head = dataType.StringToByte(temp, MsgHead.Text); 88 | if(ch.msgDecode.head == null) 89 | { 90 | MessageBox.Show("解析规则的报头应是HEX格式!", "ERROR"); 91 | return false; 92 | } 93 | return true; 94 | } 95 | } 96 | return true; 97 | } 98 | 99 | 100 | private void ComboBox_Channel_SelectedIndexChanged(object sender, EventArgs e) 101 | { 102 | foreach (RealTimeCurve_Channel.Channel ch in rtCurveChannels) 103 | { 104 | if (ch.series.Name == ComboBox_Channel.Text) 105 | { 106 | float[] gain = { 10, 8, 4, 2, 1, 0.5f, 0.25f, 0.125f, 0.1f }; 107 | //加载曲线的参数 108 | CurveName.Text = ComboBox_Channel.Text; 109 | CurveGain.SelectedIndex = Array.IndexOf(gain, ch.gain); 110 | 111 | //加载解析规则 112 | ComboBox_MsgDataType.SelectedIndex = ch.msgDecode.data_type; 113 | if (ch.msgDecode.flag_msb) 114 | MsgFlagMSB.Text = "LSB"; 115 | else 116 | MsgFlagMSB.Text = "MSB"; 117 | MsgFlagMSB_Click(null, null); 118 | 119 | MsgParamOffset.Text = ch.msgDecode.in_msg_pos.ToString(); 120 | MsgParamByteNum.Text = ch.msgDecode.byte_num.ToString(); 121 | 122 | if (ch.msgDecode.head == null) 123 | { 124 | MsgHead.Text = ""; 125 | return; 126 | } 127 | DataTypeConversion dataType = new DataTypeConversion(); 128 | string temp = "HEX"; 129 | if (ch.msgDecode.data_type == 2) 130 | temp = "ASCII"; 131 | MsgHead.Text = dataType.ByteToString(temp, ch.msgDecode.head, ch.msgDecode.head.Length); 132 | return; 133 | } 134 | } 135 | } 136 | 137 | private void MsgFlagMSB_Click(object sender, EventArgs e) 138 | { 139 | if (MsgFlagMSB.Text == "MSB") 140 | { 141 | MsgFlagMSB.BackColor = Color.Transparent; 142 | MsgFlagMSB.ToolTipText = "低位在前"; 143 | MsgFlagMSB.Text = "LSB"; 144 | } 145 | else 146 | { 147 | MsgFlagMSB.BackColor = Color.LimeGreen; 148 | MsgFlagMSB.ToolTipText = "高位在前"; 149 | MsgFlagMSB.Text = "MSB"; 150 | } 151 | } 152 | 153 | private void toolStripButton_绘制曲线_Click(object sender, EventArgs e) 154 | { 155 | if (ComboBox_Channel.Text == "") 156 | return; 157 | if(rtCurveChannels[ComboBox_Channel.SelectedIndex].enable) 158 | { 159 | rtCurveChannels[ComboBox_Channel.SelectedIndex].enable = false; 160 | toolStripButton_绘制曲线.BackColor = Color.LimeGreen; 161 | toolStripButton_绘制曲线.Image = Properties.Resources.开启; 162 | } 163 | else 164 | { 165 | rtCurveChannels[ComboBox_Channel.SelectedIndex].enable = true; 166 | toolStripButton_绘制曲线.BackColor = Color.Tomato; 167 | toolStripButton_绘制曲线.Image = Properties.Resources.关闭; 168 | } 169 | } 170 | 171 | private void toolStripButton_删除曲线_Click(object sender, EventArgs e) 172 | { 173 | if (rtCurveChannels.Count < 2) 174 | return; 175 | int channel = ComboBox_Channel.SelectedIndex; 176 | rtCurveChannelDelete(rtCurveChannels[channel].series); 177 | rtCurveChannels.RemoveAt(channel); 178 | ComboBox_Channel.Items.RemoveAt(channel); 179 | if (ComboBox_Channel.Items.Count > channel) 180 | ComboBox_Channel.SelectedIndex = channel; 181 | else 182 | ComboBox_Channel.SelectedIndex = channel - 1; 183 | } 184 | 185 | private void CurveGain_SelectedIndexChanged(object sender, EventArgs e) 186 | { 187 | 188 | float[] gain = { 10, 8, 4, 2, 1, 0.5f, 0.25f, 0.125f, 0.1f }; 189 | //加载曲线的参数 190 | foreach (RealTimeCurve_Channel.Channel ch in rtCurveChannels) 191 | { 192 | if (ch.series.Name == ComboBox_Channel.Text) 193 | { 194 | ch.gain = gain[CurveGain.SelectedIndex]; 195 | return; 196 | } 197 | } 198 | 199 | } 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /串口助手/RealTimeCurveEditor.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 567, 17 122 | 123 | 124 | 237, 17 125 | 126 | 127 | 347, 17 128 | 129 | 130 | 457, 17 131 | 132 | 133 | 237, 17 134 | 135 | 136 | 347, 17 137 | 138 | 139 | 457, 17 140 | 141 | 142 | 17, 17 143 | 144 | -------------------------------------------------------------------------------- /串口助手/RealTimeCurve_Channel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using System.Windows.Forms.DataVisualization.Charting; 8 | 9 | namespace 串口助手 10 | { 11 | public class RealTimeCurve_Channel 12 | { 13 | [System.Runtime.InteropServices.DllImport("msvcrt.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] 14 | static extern int memcmp(byte[] b1, byte[] b2, long count); 15 | 16 | 17 | public class MsgDecode 18 | { 19 | /// 20 | /// 0:整型,1:浮点数,2:字符串 21 | /// 22 | public int data_type = 0; 23 | /// 24 | /// 高位在前的标志 25 | /// 26 | public bool flag_msb = false; 27 | /// 28 | /// 数据在报文中的偏移量 29 | /// 30 | public int in_msg_pos = 1; 31 | /// 32 | /// 数据的字节数 33 | /// 34 | public int byte_num = 4; 35 | /// 36 | /// 报头 37 | /// 38 | public byte[] head; 39 | }; 40 | public class Channel 41 | { 42 | /// 43 | /// 报文解析规则 44 | /// 45 | public MsgDecode msgDecode = new MsgDecode(); 46 | /// 47 | /// 曲线使能 48 | /// 49 | public bool enable = true; 50 | /// 51 | /// 曲线幅值的放大倍率 52 | /// 53 | public float gain = 1; 54 | public Series series = new Series(); 55 | }; 56 | 57 | 58 | private double seriesY; 59 | private Series Series1 = new Series(); 60 | private Thread threadSeriesWrite; 61 | private AutoResetEvent threadSeriesWrite_Supend = new AutoResetEvent(false); 62 | 63 | 64 | public Channel Create(string name, byte[] mask) 65 | { 66 | Channel channel = new Channel(); 67 | channel.msgDecode.head = mask; 68 | channel.enable = true; 69 | channel.series.Name = name; 70 | channel.series.MarkerStyle = MarkerStyle.Circle; 71 | channel.series.ChartType = SeriesChartType.Spline; 72 | return channel; 73 | } 74 | 75 | 76 | 77 | private void SeriesWriteData_Thread() 78 | { 79 | while (true) 80 | { 81 | if (Series1.Points.Count > 200) 82 | Series1.Points.RemoveAt(0); 83 | try 84 | { 85 | //过大的数值,会导致窗体崩溃 86 | Series1.Points.AddY(seriesY); 87 | } 88 | catch { } 89 | threadSeriesWrite_Supend.Reset(); 90 | threadSeriesWrite_Supend.WaitOne(); 91 | } 92 | } 93 | 94 | public void SeriesWriteData(Channel ch, double yValue) 95 | { 96 | seriesY = yValue; 97 | Series1 = ch.series; 98 | threadSeriesWrite_Supend.Set(); 99 | } 100 | /// 101 | /// 通过报文绘制曲线 102 | /// 103 | /// 104 | /// 105 | /// 106 | public bool SeriesWriteData(Channel ch, byte[] data, int length) 107 | { 108 | if (ch.msgDecode.head == null) 109 | return false; 110 | if (memcmp(data, ch.msgDecode.head, ch.msgDecode.head.Length) == 0) 111 | { 112 | if (ch.enable) 113 | { 114 | seriesY = ch.gain * MsgDecode_GetPointY(ch.msgDecode, data, length); 115 | Series1 = ch.series; 116 | threadSeriesWrite_Supend.Set(); 117 | } 118 | return true; 119 | } 120 | return false; 121 | } 122 | 123 | private double MsgDecode_GetPointY(MsgDecode decode, byte[] data, int length) 124 | { 125 | byte[] buf; 126 | double yValue = 0; 127 | switch (decode.data_type) 128 | { 129 | //整型 130 | case 0: 131 | if (length <= decode.in_msg_pos + decode.byte_num) 132 | goto MSG_LENGTH_ERR; 133 | buf = data.Skip(decode.in_msg_pos).Take(decode.byte_num).ToArray(); 134 | if (true == decode.flag_msb) 135 | { 136 | for (int i = 0; i < decode.byte_num; i++) 137 | yValue = (yValue * 256) + buf[i]; 138 | } 139 | else 140 | { 141 | for (int i = decode.byte_num - 1; i > 0; i--) 142 | yValue = (yValue * 256) + buf[i]; 143 | } 144 | break; 145 | //浮点数 146 | case 1: 147 | if (length <= decode.in_msg_pos + 4) 148 | goto MSG_LENGTH_ERR; 149 | byte[] single = data.Skip(decode.in_msg_pos).Take(4).ToArray(); 150 | if (decode.flag_msb) 151 | Array.Reverse(single); 152 | yValue = BitConverter.ToSingle(single, 0); 153 | break; 154 | //字符串 155 | case 2: 156 | if (length <= decode.in_msg_pos) 157 | goto MSG_LENGTH_ERR; 158 | string s = Encoding.Default.GetString(data, 0, length); 159 | s = s.Substring(decode.in_msg_pos); 160 | DataTypeConversion dataType = new DataTypeConversion(); 161 | float value = 0; 162 | if(false == dataType.GetStringSingle(s, ref value)) 163 | goto MSG_LENGTH_ERR; 164 | yValue = value; 165 | if (s[0] == '-') 166 | yValue = -yValue; 167 | break; 168 | } 169 | return yValue; 170 | MSG_LENGTH_ERR : 171 | return seriesY; 172 | } 173 | 174 | 175 | public void SeriesThreadCreate(Channel ch) 176 | { 177 | Series1 = ch.series; 178 | threadSeriesWrite_Supend.Reset(); 179 | threadSeriesWrite = new Thread(SeriesWriteData_Thread); 180 | threadSeriesWrite.Start(); 181 | } 182 | 183 | public void SeriesThreadRelease() 184 | { 185 | threadSeriesWrite.Abort(); 186 | } 187 | 188 | 189 | public void SeriesClear(Channel ch) 190 | { 191 | ch.series.Points.Clear(); 192 | } 193 | 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /串口助手/RxShow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace 串口助手 11 | { 12 | public partial class Form1 13 | { 14 | private int rxDataLength; 15 | private byte[] rxData; 16 | private MultiCommunication_t CurrentDevice = new MultiCommunication_t(); 17 | //private Thread threadRxDataHandle; 18 | private AutoResetEvent threadRxDataHandle_Supend = new AutoResetEvent(false); 19 | 20 | 21 | private void SendMsgEcho(string data) 22 | { 23 | richTextBox_Rx.SelectionColor = Color.Gold; 24 | richTextBox_Rx.AppendText(data); 25 | gTimestampFlag = true; 26 | } 27 | private void WriteRxMsg(string data) 28 | { 29 | richTextBox_Rx.SelectionColor = Color.White; 30 | richTextBox_Rx.AppendText(data); 31 | gTimestampFlag = false; 32 | } 33 | 34 | private int 处理中文断帧乱码问题(MultiCommunication_t dev, ref byte[] data, int length) 35 | { 36 | int cnt = 0; 37 | for (int pos = 0; pos < length; pos++) 38 | { 39 | if (data[pos] > 0x80) 40 | cnt++; 41 | } 42 | if (cnt % 2 == 1) 43 | { 44 | try 45 | { 46 | if (dev.type == "uart") 47 | { 48 | if(dev.uart.BytesToRead > 0) 49 | length += dev.uart.Read(data, length, 1); 50 | } 51 | else 52 | { 53 | SocketFlags flags = SocketFlags.None; 54 | length += dev.tcp.Receive(data, length, 1, flags); 55 | } 56 | } 57 | catch { } 58 | } 59 | return length; 60 | } 61 | 62 | /// 63 | /// 通信的接收处理 64 | /// 65 | /// 66 | /// 67 | private bool 数据接收_显示_解析_输出日志(object sender, string type, ref byte[] rx_buf, int length) 68 | { 69 | if (length == 0) 70 | return false; 71 | //找出当前的设备名 72 | try 73 | { 74 | if (type == "uart") 75 | { 76 | System.IO.Ports.SerialPort uart = (System.IO.Ports.SerialPort)sender; 77 | foreach (MultiCommunication_t p in listMultiComm) 78 | { 79 | if (p.uart == uart) 80 | { 81 | CurrentDevice = p; 82 | break; 83 | } 84 | } 85 | } 86 | else 87 | { 88 | Socket tcp = sender as Socket; 89 | foreach (MultiCommunication_t p in listMultiComm) 90 | { 91 | if (p.tcp == tcp) 92 | { 93 | CurrentDevice = p; 94 | break; 95 | } 96 | } 97 | } 98 | if (CurrentDevice.name == "S0") 99 | CurrentDevice.hex = toolStripButton_RxHEX.Text; 100 | } 101 | catch { } 102 | 103 | /* 自动换行开启了,需要先关闭自动换行的定时器 */ 104 | if (toolStripButton_RxAutoNewline.Text == "ON") 105 | { 106 | gTimer_RxAutoNewline.Stop(); 107 | } 108 | 109 | try 110 | { 111 | if (CurrentDevice.hex == "ASCII") 112 | length = 处理中文断帧乱码问题(CurrentDevice, ref rx_buf, length); 113 | rxData = rx_buf; 114 | rxDataLength = length; 115 | RxDataHandle_Thread(null); 116 | //if(threadRxDataHandle == null) 117 | //{ 118 | // threadRxDataHandle = new Thread(RxDataHandle_Thread); 119 | // threadRxDataHandle.Start(CurrentDevice); 120 | //} 121 | //threadRxDataHandle_Supend.Set(); 122 | } 123 | catch { } 124 | return true; 125 | } 126 | 127 | private void RxDataHandle_Thread(object dev) 128 | { 129 | //while(true) 130 | { 131 | byte[] tempRxData = rxData; 132 | int tempLength = rxDataLength; 133 | string tmepType = CurrentDevice.hex; 134 | string tmepName = CurrentDevice.name; 135 | string MsgHead = ""; 136 | string LogMsgHead = ""; 137 | if (CurrentDevice.name != "S0") 138 | LogMsgHead = "[" + CurrentDevice.name + "]"; 139 | try 140 | { 141 | DataTypeConversion dataType = new DataTypeConversion(); 142 | string str = dataType.ByteToString(tmepType, tempRxData, tempLength); 143 | if (tmepType != "ASCII") 144 | str += " "; 145 | /* 处理时间戳 */ 146 | if (toolStripButton_Timestamp.Text == "ON") 147 | { 148 | LogMsgHead += DateTime.Now.ToString("HH:mm:ss.fff") + "<<"; 149 | } 150 | if (gTimestampFlag) 151 | { 152 | MsgHead = System.Environment.NewLine + LogMsgHead; 153 | } 154 | //显示接收的数据 155 | WriteRxMsg(MsgHead + str); 156 | commLog.LogWriteMsg(LogMsgHead + str); 157 | realTimeCurve.RT_Curve_WriteData(rxData, tempLength); 158 | if (tmepType != "ASCII") 159 | { 160 | MsgLookup_16To10(rxData, tempLength, MsgHead); 161 | } 162 | if (SuperMsgCurrent != null && tmepName == "S0") 163 | { 164 | textBox_SuperMsgRxShow.AppendText(MsgHead + str); 165 | SuperMsgCurrent.RxMsg_Handler(rxData); 166 | SuperMsgCurrent = null; 167 | } 168 | } 169 | catch { } 170 | gRxNum += tempLength; 171 | Label_Status.Text = "OPEN TX:" + gTxNum + " RX:" + gRxNum; 172 | 173 | /* 自动换行打开了,此时开启它的定时器 */ 174 | if (toolStripButton_RxAutoNewline.Text == "ON") 175 | { 176 | gTimer_RxAutoNewline.Start(); 177 | } 178 | if (toolStripButton_RecClear.Enabled == false) 179 | { 180 | toolStripButton_RecClear.Enabled = true; 181 | toolStripButton_RecClear.BackColor = Color.Gold; 182 | } 183 | 184 | //匹配下位机的应答,自动下发指令 185 | if(tmepName == "S0") 186 | { 187 | byte[] tx = AutoTx.GetTxMsg(rxData, rxDataLength); 188 | if (tx != null) 189 | { 190 | TxMsg(tx); 191 | } 192 | } 193 | 194 | //threadRxDataHandle_Supend.Reset(); 195 | //threadRxDataHandle_Supend.WaitOne(); 196 | } 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /串口助手/SocketClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace 串口助手 11 | { 12 | class SocketClient 13 | { 14 | private ManualResetEvent timeoutObject = new ManualResetEvent(false); 15 | 16 | public bool Connect(Socket Client, IPEndPoint iPEndPoint, int timeout) 17 | { 18 | timeoutObject.Reset(); 19 | //Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 20 | Client.BeginConnect(iPEndPoint, new AsyncCallback(CallBackMethod), Client); 21 | if (timeoutObject.WaitOne(timeout, false)) 22 | return true; 23 | Client.Close(); 24 | return false; 25 | } 26 | 27 | private void CallBackMethod(IAsyncResult asyncResult) 28 | { 29 | Socket Client = (Socket)asyncResult.AsyncState; 30 | try 31 | { 32 | Client.EndConnect(asyncResult); 33 | timeoutObject.Set(); 34 | } 35 | catch { } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /串口助手/TxListHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace 串口助手 11 | { 12 | public partial class Form1 13 | { 14 | List txListSimple_List = new List(); 15 | List