初始化项目

This commit is contained in:
2025-12-11 11:54:05 +08:00
commit 6fb36792ed
64 changed files with 100079 additions and 0 deletions

Binary file not shown.

18
App.config Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MultiSerialPortCommu.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<userSettings>
<MultiSerialPortCommu.My.MySettings>
<setting name="SerialPortSettings" serializeAs="String">
<value />
</setting>
</MultiSerialPortCommu.My.MySettings>
</userSettings>
</configuration>

155
CommuniNode.vb Normal file
View File

@@ -0,0 +1,155 @@
Imports System.IO.Ports
Imports System.Threading
Public Class CommuniNode
Public G_SerialPort As SerialPort
Public G_TXTcolor As Color
Public G_msgqueue As Queue(Of (String, Color, String))
Public G_aliasname As String
Public G_ShowHex As Boolean = False
Public G_SendHex As Boolean = False
Public G_ReadFlag As Boolean = True
Public Sub New(serialname As String, baudrate As Integer, aliasname As String, TXTcolor As Color, msgqueue As Queue(Of (String, Color, String)))
'创建串口(serialname, baudrate)
G_SerialPort = New SerialPort(serialname, baudrate)
'设置串口颜色
G_aliasname = aliasname
G_TXTcolor = TXTcolor
G_msgqueue = msgqueue
recvBufferli = New List(Of Byte)()
'关联接收事件()
AddHandler G_SerialPort.DataReceived, AddressOf SerialPort_DataReceived
End Sub
'设置别名和颜色
Public Sub SetAliasAndColor(aliasname As String, TXTcolor As Color)
G_aliasname = aliasname
G_TXTcolor = TXTcolor
End Sub
'设置串口开关
Public Sub SetSerialPortOpen(isOpen As Boolean)
If IsNothing(G_SerialPort) Then Return
If isOpen Then
If Not G_SerialPort.IsOpen Then
G_SerialPort.Open()
End If
Else
G_SerialPort.Close()
End If
recvBufferli.Clear()
End Sub
'设置G_ShowHex
Public Sub SetShowHex(isShowHex As Boolean)
G_ShowHex = isShowHex
End Sub
'设置G_SendHex
Public Sub SetSendHex(isSendHex As Boolean)
G_SendHex = isSendHex
End Sub
Private _recvBuffer(4095) As Byte
Public recvBufferli As List(Of Byte)
Public recvBufferliindex As Integer = 0
Private Sub SerialPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
Static bytes As Integer = 0
Dim sp As SerialPort = DirectCast(sender, SerialPort)
Dim dstr As String
Do
bytes = sp.BytesToRead
'If bytes <= 0 Then
' isListen = False
' Exit Sub
'End If
'If bytes + _recvOffset >= 4096 Then
' 'ShowPortReceData(_recvBuffer)
' sp.Read(_recvBuffer, _recvOffset, 4096 - _recvOffset)
' _recvOffset = 0
'Else
' sp.Read(_recvBuffer, _recvOffset, bytes)
' _recvOffset += bytes
'End If
Dim buf(bytes - 1) As Byte
sp.Read(buf, 0, bytes)
recvBufferli.AddRange(buf)
Thread.Sleep(5)
Loop While sp.BytesToRead > 0
If recvBufferli.Count > 0 Then
If G_ReadFlag Then
If G_ShowHex Then
dstr = publicMode.ByteToHex(recvBufferli.ToArray)
Else
dstr = publicMode.ByteToString(recvBufferli.ToArray)
End If
'发送要不要添加到表格、时间差怎么算
SyncLock G_msgqueue
G_msgqueue.Enqueue((G_aliasname, G_TXTcolor, $"{Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}_{dstr}"))
End SyncLock
End If
recvBufferli.Clear()
'RuningLog.OutputLogsToTheControl(m_Control, New RuningLogConfig($"RX:{DataProcessing.ByteToString2(recvBufferli.ToArray)}", Color.Black), 1)
End If
End Sub
'设置接受标志
Public Sub SetReadFlag(isRead As Boolean)
G_ReadFlag = isRead
End Sub
Public Sub SendData(datastr As String)
'判断串口是否打开
If Not G_SerialPort.IsOpen Then
MsgBox("串口未打开")
Return
End If
If String.IsNullOrEmpty(datastr) Then
MsgBox("发送的数据为空")
Return
End If
Dim Data As Byte()
If G_SendHex Then
Data = publicMode.HexStringToByte(datastr)
If IsNothing(Data) Then
MsgBox("发送的数据异常")
Return
End If
datastr = publicMode.ByteToHexString(Data)
'SyncLock G_msgqueue
' G_msgqueue.Enqueue((G_aliasname, G_TXTcolor, $"{Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}_TX:{datastr}"))
'End SyncLock
'Data = publicMode.HexToByte(datastr)
Else
'SyncLock G_msgqueue
' G_msgqueue.Enqueue((G_aliasname, G_TXTcolor, $"{Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}_TX:{datastr}"))
'End SyncLock
Data = publicMode.StringToByte(datastr)
End If
If IsNothing(Data) Then
MsgBox("发送的数据异常")
Return
End If
G_SerialPort.Write(Data, 0, Data.Length)
End Sub
End Class

423
Form1.Designer.vb generated Normal file
View File

@@ -0,0 +1,423 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form 重写 Dispose以清理组件列表。
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.SplitContainer1 = New System.Windows.Forms.SplitContainer()
Me.SplitContainer2 = New System.Windows.Forms.SplitContainer()
Me.Grid1 = New FlexCell.Grid()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.CheckBox2 = New System.Windows.Forms.CheckBox()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.ToolStrip1 = New System.Windows.Forms.ToolStrip()
Me.ToolStripButton2 = New System.Windows.Forms.ToolStripButton()
Me.ToolStripButton1 = New System.Windows.Forms.ToolStripButton()
Me.ToolStripButton3 = New System.Windows.Forms.ToolStripButton()
Me.SplitContainer3 = New System.Windows.Forms.SplitContainer()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.CheckBox9 = New System.Windows.Forms.CheckBox()
Me.CheckBox8 = New System.Windows.Forms.CheckBox()
Me.CheckBox7 = New System.Windows.Forms.CheckBox()
Me.CheckBox6 = New System.Windows.Forms.CheckBox()
Me.CheckBox5 = New System.Windows.Forms.CheckBox()
Me.CheckBox4 = New System.Windows.Forms.CheckBox()
Me.CheckBox3 = New System.Windows.Forms.CheckBox()
Me.Xlabel = New System.Windows.Forms.Label()
Me.Ylabel = New System.Windows.Forms.Label()
Me.TextBox2 = New System.Windows.Forms.TextBox()
CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SplitContainer1.Panel1.SuspendLayout()
Me.SplitContainer1.Panel2.SuspendLayout()
Me.SplitContainer1.SuspendLayout()
CType(Me.SplitContainer2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SplitContainer2.Panel1.SuspendLayout()
Me.SplitContainer2.Panel2.SuspendLayout()
Me.SplitContainer2.SuspendLayout()
Me.ToolStrip1.SuspendLayout()
CType(Me.SplitContainer3, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SplitContainer3.Panel1.SuspendLayout()
Me.SplitContainer3.Panel2.SuspendLayout()
Me.SplitContainer3.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'SplitContainer1
'
Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
Me.SplitContainer1.Location = New System.Drawing.Point(0, 0)
Me.SplitContainer1.Name = "SplitContainer1"
'
'SplitContainer1.Panel1
'
Me.SplitContainer1.Panel1.Controls.Add(Me.SplitContainer2)
Me.SplitContainer1.Panel1.Controls.Add(Me.ToolStrip1)
'
'SplitContainer1.Panel2
'
Me.SplitContainer1.Panel2.Controls.Add(Me.SplitContainer3)
Me.SplitContainer1.Size = New System.Drawing.Size(1296, 780)
Me.SplitContainer1.SplitterDistance = 734
Me.SplitContainer1.TabIndex = 1
'
'SplitContainer2
'
Me.SplitContainer2.Dock = System.Windows.Forms.DockStyle.Fill
Me.SplitContainer2.Location = New System.Drawing.Point(0, 25)
Me.SplitContainer2.Name = "SplitContainer2"
Me.SplitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal
'
'SplitContainer2.Panel1
'
Me.SplitContainer2.Panel1.Controls.Add(Me.Grid1)
'
'SplitContainer2.Panel2
'
Me.SplitContainer2.Panel2.Controls.Add(Me.Button2)
Me.SplitContainer2.Panel2.Controls.Add(Me.Label1)
Me.SplitContainer2.Panel2.Controls.Add(Me.ComboBox1)
Me.SplitContainer2.Panel2.Controls.Add(Me.CheckBox2)
Me.SplitContainer2.Panel2.Controls.Add(Me.CheckBox1)
Me.SplitContainer2.Panel2.Controls.Add(Me.Button1)
Me.SplitContainer2.Panel2.Controls.Add(Me.TextBox1)
Me.SplitContainer2.Size = New System.Drawing.Size(734, 755)
Me.SplitContainer2.SplitterDistance = 610
Me.SplitContainer2.TabIndex = 2
'
'Grid1
'
Me.Grid1.DefaultFont = New System.Drawing.Font("宋体", 9.0!)
Me.Grid1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Grid1.Location = New System.Drawing.Point(0, 0)
Me.Grid1.MouseWheelSpeed = CType(3, Short)
Me.Grid1.Name = "Grid1"
Me.Grid1.Size = New System.Drawing.Size(734, 610)
Me.Grid1.TabIndex = 0
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.Green
Me.Button2.Font = New System.Drawing.Font("宋体", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.Location = New System.Drawing.Point(577, 4)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(154, 51)
Me.Button2.TabIndex = 2
Me.Button2.Text = "开始接收数据"
Me.Button2.UseVisualStyleBackColor = False
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(218, 19)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(123, 19)
Me.Label1.TabIndex = 5
Me.Label1.Text = "选择发送串口"
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(347, 15)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(210, 27)
Me.ComboBox1.TabIndex = 4
'
'CheckBox2
'
Me.CheckBox2.AutoSize = True
Me.CheckBox2.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.CheckBox2.Location = New System.Drawing.Point(106, 17)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(96, 23)
Me.CheckBox2.TabIndex = 3
Me.CheckBox2.Text = "HEX发送"
Me.CheckBox2.UseVisualStyleBackColor = True
'
'CheckBox1
'
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.CheckBox1.Location = New System.Drawing.Point(4, 17)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(96, 23)
Me.CheckBox1.TabIndex = 2
Me.CheckBox1.Text = "HEX显示"
Me.CheckBox1.UseVisualStyleBackColor = True
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("宋体", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Location = New System.Drawing.Point(611, 61)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(123, 68)
Me.Button1.TabIndex = 1
Me.Button1.Text = "发送"
Me.Button1.UseVisualStyleBackColor = True
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(12, 61)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(593, 68)
Me.TextBox1.TabIndex = 0
'
'ToolStrip1
'
Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripButton2, Me.ToolStripButton1, Me.ToolStripButton3})
Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
Me.ToolStrip1.Name = "ToolStrip1"
Me.ToolStrip1.Size = New System.Drawing.Size(734, 25)
Me.ToolStrip1.TabIndex = 1
Me.ToolStrip1.Text = "ToolStrip1"
'
'ToolStripButton2
'
Me.ToolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
Me.ToolStripButton2.Image = CType(resources.GetObject("ToolStripButton2.Image"), System.Drawing.Image)
Me.ToolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta
Me.ToolStripButton2.Name = "ToolStripButton2"
Me.ToolStripButton2.Size = New System.Drawing.Size(60, 22)
Me.ToolStripButton2.Text = "设置串口"
'
'ToolStripButton1
'
Me.ToolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
Me.ToolStripButton1.Image = CType(resources.GetObject("ToolStripButton1.Image"), System.Drawing.Image)
Me.ToolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta
Me.ToolStripButton1.Name = "ToolStripButton1"
Me.ToolStripButton1.Size = New System.Drawing.Size(36, 22)
Me.ToolStripButton1.Text = "打开"
'
'ToolStripButton3
'
Me.ToolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
Me.ToolStripButton3.Image = CType(resources.GetObject("ToolStripButton3.Image"), System.Drawing.Image)
Me.ToolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta
Me.ToolStripButton3.Name = "ToolStripButton3"
Me.ToolStripButton3.Size = New System.Drawing.Size(48, 22)
Me.ToolStripButton3.Text = "清空表"
'
'SplitContainer3
'
Me.SplitContainer3.Dock = System.Windows.Forms.DockStyle.Fill
Me.SplitContainer3.Location = New System.Drawing.Point(0, 0)
Me.SplitContainer3.Name = "SplitContainer3"
Me.SplitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal
'
'SplitContainer3.Panel1
'
Me.SplitContainer3.Panel1.Controls.Add(Me.GroupBox1)
'
'SplitContainer3.Panel2
'
Me.SplitContainer3.Panel2.Controls.Add(Me.TextBox2)
Me.SplitContainer3.Panel2.Controls.Add(Me.Ylabel)
Me.SplitContainer3.Panel2.Controls.Add(Me.Xlabel)
Me.SplitContainer3.Size = New System.Drawing.Size(558, 780)
Me.SplitContainer3.SplitterDistance = 43
Me.SplitContainer3.TabIndex = 0
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.CheckBox9)
Me.GroupBox1.Controls.Add(Me.CheckBox8)
Me.GroupBox1.Controls.Add(Me.CheckBox7)
Me.GroupBox1.Controls.Add(Me.CheckBox6)
Me.GroupBox1.Controls.Add(Me.CheckBox5)
Me.GroupBox1.Controls.Add(Me.CheckBox4)
Me.GroupBox1.Controls.Add(Me.CheckBox3)
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(558, 43)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "隐藏显示列"
'
'CheckBox9
'
Me.CheckBox9.AutoSize = True
Me.CheckBox9.Location = New System.Drawing.Point(468, 19)
Me.CheckBox9.Name = "CheckBox9"
Me.CheckBox9.Size = New System.Drawing.Size(42, 16)
Me.CheckBox9.TabIndex = 6
Me.CheckBox9.Tag = "8"
Me.CheckBox9.Text = "HEX"
Me.CheckBox9.UseVisualStyleBackColor = True
'
'CheckBox8
'
Me.CheckBox8.AutoSize = True
Me.CheckBox8.Location = New System.Drawing.Point(405, 19)
Me.CheckBox8.Name = "CheckBox8"
Me.CheckBox8.Size = New System.Drawing.Size(48, 16)
Me.CheckBox8.TabIndex = 5
Me.CheckBox8.Tag = "7"
Me.CheckBox8.Text = "TEXT"
Me.CheckBox8.UseVisualStyleBackColor = True
'
'CheckBox7
'
Me.CheckBox7.AutoSize = True
Me.CheckBox7.Location = New System.Drawing.Point(342, 19)
Me.CheckBox7.Name = "CheckBox7"
Me.CheckBox7.Size = New System.Drawing.Size(48, 16)
Me.CheckBox7.TabIndex = 4
Me.CheckBox7.Tag = "6"
Me.CheckBox7.Text = "包长"
Me.CheckBox7.UseVisualStyleBackColor = True
'
'CheckBox6
'
Me.CheckBox6.AutoSize = True
Me.CheckBox6.Location = New System.Drawing.Point(255, 19)
Me.CheckBox6.Name = "CheckBox6"
Me.CheckBox6.Size = New System.Drawing.Size(72, 16)
Me.CheckBox6.TabIndex = 3
Me.CheckBox6.Tag = "5"
Me.CheckBox6.Text = "串口名称"
Me.CheckBox6.UseVisualStyleBackColor = True
'
'CheckBox5
'
Me.CheckBox5.AutoSize = True
Me.CheckBox5.Location = New System.Drawing.Point(180, 19)
Me.CheckBox5.Name = "CheckBox5"
Me.CheckBox5.Size = New System.Drawing.Size(60, 16)
Me.CheckBox5.TabIndex = 2
Me.CheckBox5.Tag = "4"
Me.CheckBox5.Text = "时间差"
Me.CheckBox5.UseVisualStyleBackColor = True
'
'CheckBox4
'
Me.CheckBox4.AutoSize = True
Me.CheckBox4.Location = New System.Drawing.Point(69, 19)
Me.CheckBox4.Name = "CheckBox4"
Me.CheckBox4.Size = New System.Drawing.Size(96, 16)
Me.CheckBox4.TabIndex = 1
Me.CheckBox4.Tag = "3"
Me.CheckBox4.Text = "同串口时间差"
Me.CheckBox4.UseVisualStyleBackColor = True
'
'CheckBox3
'
Me.CheckBox3.AutoSize = True
Me.CheckBox3.Location = New System.Drawing.Point(6, 19)
Me.CheckBox3.Name = "CheckBox3"
Me.CheckBox3.Size = New System.Drawing.Size(48, 16)
Me.CheckBox3.TabIndex = 0
Me.CheckBox3.Tag = "2"
Me.CheckBox3.Text = "时间"
Me.CheckBox3.UseVisualStyleBackColor = True
'
'Xlabel
'
Me.Xlabel.AutoSize = True
Me.Xlabel.Location = New System.Drawing.Point(13, 10)
Me.Xlabel.Name = "Xlabel"
Me.Xlabel.Size = New System.Drawing.Size(41, 12)
Me.Xlabel.TabIndex = 0
Me.Xlabel.Text = "RowID:"
'
'Ylabel
'
Me.Ylabel.AutoSize = True
Me.Ylabel.Location = New System.Drawing.Point(124, 10)
Me.Ylabel.Name = "Ylabel"
Me.Ylabel.Size = New System.Drawing.Size(71, 12)
Me.Ylabel.TabIndex = 1
Me.Ylabel.Text = "ColumnName:"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(6, 25)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(549, 128)
Me.TextBox2.TabIndex = 2
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(1296, 780)
Me.Controls.Add(Me.SplitContainer1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.SplitContainer1.Panel1.ResumeLayout(False)
Me.SplitContainer1.Panel1.PerformLayout()
Me.SplitContainer1.Panel2.ResumeLayout(False)
CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.SplitContainer1.ResumeLayout(False)
Me.SplitContainer2.Panel1.ResumeLayout(False)
Me.SplitContainer2.Panel2.ResumeLayout(False)
Me.SplitContainer2.Panel2.PerformLayout()
CType(Me.SplitContainer2, System.ComponentModel.ISupportInitialize).EndInit()
Me.SplitContainer2.ResumeLayout(False)
Me.ToolStrip1.ResumeLayout(False)
Me.ToolStrip1.PerformLayout()
Me.SplitContainer3.Panel1.ResumeLayout(False)
Me.SplitContainer3.Panel2.ResumeLayout(False)
Me.SplitContainer3.Panel2.PerformLayout()
CType(Me.SplitContainer3, System.ComponentModel.ISupportInitialize).EndInit()
Me.SplitContainer3.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents SplitContainer1 As SplitContainer
Friend WithEvents SplitContainer2 As SplitContainer
Friend WithEvents Grid1 As FlexCell.Grid
Friend WithEvents ToolStrip1 As ToolStrip
Friend WithEvents ToolStripButton2 As ToolStripButton
Friend WithEvents ToolStripButton1 As ToolStripButton
Friend WithEvents CheckBox2 As CheckBox
Friend WithEvents CheckBox1 As CheckBox
Friend WithEvents Button1 As Button
Friend WithEvents TextBox1 As TextBox
Friend WithEvents Label1 As Label
Friend WithEvents ComboBox1 As ComboBox
Friend WithEvents ToolStripButton3 As ToolStripButton
Friend WithEvents SplitContainer3 As SplitContainer
Friend WithEvents Button2 As Button
Friend WithEvents GroupBox1 As GroupBox
Friend WithEvents CheckBox9 As CheckBox
Friend WithEvents CheckBox8 As CheckBox
Friend WithEvents CheckBox7 As CheckBox
Friend WithEvents CheckBox6 As CheckBox
Friend WithEvents CheckBox5 As CheckBox
Friend WithEvents CheckBox4 As CheckBox
Friend WithEvents CheckBox3 As CheckBox
Friend WithEvents Ylabel As Label
Friend WithEvents Xlabel As Label
Friend WithEvents TextBox2 As TextBox
End Class

169
Form1.resx Normal file
View File

@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ToolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="ToolStripButton2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<data name="ToolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<data name="ToolStripButton3.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
</root>

317
Form1.vb Normal file
View File

@@ -0,0 +1,317 @@
Imports System.Threading
Imports Newtonsoft.Json
Public Class Form1
Public G_Dictionary As Dictionary(Of String, (Boolean, String, Integer, String, Color)
Public G_SerialPortli As Dictionary(Of String, CommuniNode)
Public G_msgqueue As Queue(Of (String, Color, String))
Public G_thread As Thread
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'设置页面标题为项目名称+版本号
Me.Text = Application.ProductName & " " & Application.ProductVersion
G_SerialPortli = New Dictionary(Of String, CommuniNode)()
G_msgqueue = New Queue(Of (String, Color, String))
loadSeting()
Initgrid()
G_thread = New Thread(AddressOf ThreadFun)
G_thread.Start()
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
saveSeting()
If Not IsNothing(G_thread) AndAlso G_thread.IsAlive Then
G_thread.Abort()
End If
End Sub
'加载Seting
Public Sub loadSeting()
'刷新内存
My.Settings.Reload()
If String.IsNullOrEmpty(My.Settings.SerialPortSettings) Then
G_Dictionary = New Dictionary(Of String, (Boolean, String, Integer, String, Color)
Else
G_Dictionary = JsonConvert.DeserializeObject(Of Dictionary(Of String, (Boolean, String, Integer, String, Color))(My.Settings.SerialPortSettings)
End If
End Sub
Public Sub saveSeting()
My.Settings.SerialPortSettings = JsonConvert.SerializeObject(G_Dictionary)
End Sub
Delegate Sub Deleg_ThreadFun(msg As (String, Color, String))
Private Sub ThreadFun()
Dim msg As (String, Color, String)
While True
If G_msgqueue.Count > 0 Then
msg = G_msgqueue.Dequeue()
AddMsgToGrid(msg)
End If
Thread.Sleep(10)
End While
End Sub
Public Sub AddMsgToGrid(msg As (String, Color, String))
Dim ts1, ts2, ts3 As String
Dim t1, t2, t3 As DateTime
Dim tc1, tc2 As Integer
Dim buf() As String
If Grid1.InvokeRequired Then
Dim d As New Deleg_ThreadFun(AddressOf AddMsgToGrid)
Grid1.Invoke(d, msg)
Else
'从表格末尾开始遍历但是不遍历第0行
For i As Integer = Grid1.Rows - 1 To 1 Step -1
If i = Grid1.Rows - 1 Then
ts2 = Grid1.Cell(i, 2).Text
't2 = DateTime.Parse(ts2)
DateTime.TryParseExact(ts2, "yyyy-MM-dd HH:mm:ss:fff",
System.Globalization.CultureInfo.InvariantCulture,
Globalization.DateTimeStyles.None, t2)
End If
If msg.Item1.Equals(Grid1.Cell(i, 5).Text) Then
ts1 = Grid1.Cell(i, 2).Text
't1 = DateTime.Parse(ts1)
DateTime.TryParseExact(ts1, "yyyy-MM-dd HH:mm:ss:fff",
System.Globalization.CultureInfo.InvariantCulture,
Globalization.DateTimeStyles.None, t1)
Exit For
End If
Next
buf = msg.Item3.Split("_")
ts3 = buf(0)
DateTime.TryParseExact(ts3, "yyyy-MM-dd HH:mm:ss:fff",
System.Globalization.CultureInfo.InvariantCulture,
Globalization.DateTimeStyles.None, t3)
If IsNothing(t1) Then
tc1 = 0
Else
Try
tc1 = (t3 - t1).TotalMilliseconds
Catch ex As Exception
tc1 = 65535
End Try
End If
If IsNothing(t2) Then
tc2 = 0
Else
Try
tc2 = (t3 - t2).TotalMilliseconds
Catch ex As Exception
tc2 = 65535
End Try
End If
Grid1.AddItem("")
Grid1.Cell(Grid1.Rows - 1, 0).Text = Grid1.Rows - 1
'Grid1.Cell(Grid1.Rows - 1, 1).Text = ts3
Grid1.Cell(Grid1.Rows - 1, 2).Text = ts3
Grid1.Cell(Grid1.Rows - 1, 3).Text = tc1
Grid1.Cell(Grid1.Rows - 1, 4).Text = tc2
Grid1.Cell(Grid1.Rows - 1, 5).Text = msg.Item1
Grid1.Cell(Grid1.Rows - 1, 6).Text = msg.Item3.Replace(ts3 & "_", "").Length
Grid1.Cell(Grid1.Rows - 1, 7).Text = msg.Item3.Replace(ts3 & "_", "")
Grid1.Cell(Grid1.Rows - 1, 8).Text = publicMode.StringToHexString(msg.Item3.Replace(ts3 & "_", ""))
Grid1.Range(Grid1.Rows - 1, 0, Grid1.Rows - 1, 8).WrapText = True
Grid1.Range(Grid1.Rows - 1, 0, Grid1.Rows - 1, 8).ForeColor = msg.Item2
Grid1.Cell(Grid1.Rows - 1, 0).SetFocus()
End If
End Sub
Public Sub Initgrid()
With Grid1
.NewFile()
.Cols = 9
.Rows = 1
.ExtendLastCol = True
.DisplayRowNumber = True
.Cell(0, 0).Text = "序号"
.Cell(0, 1).Text = "选择"
.Cell(0, 2).Text = "时间"
.Cell(0, 3).Text = "同串口时间差"
.Cell(0, 4).Text = "时间差"
.Cell(0, 5).Text = "串口名称"
.Cell(0, 6).Text = "包长"
.Cell(0, 7).Text = "TEXT"
.Cell(0, 8).Text = "HEX"
.Column(0).Width = 50
.Column(1).Width = 20
.Column(1).CellType = FlexCell.CellTypeEnum.CheckBox
.Column(2).Width = 150
.Column(3).Width = 50
.Column(4).Width = 50
.Column(5).Width = 100
.Column(6).Width = 50
.Column(7).Width = 300
.Column(8).Width = 300
.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(7).Alignment = FlexCell.AlignmentEnum.CenterCenter
.Column(8).Alignment = FlexCell.AlignmentEnum.CenterCenter
.HighLightMode = FlexCell.HighLightModeEnum.Both
End With
End Sub
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
'创建设串口页面
Dim form2 As New SetingSerialPort
form2.G_Dictionary = G_Dictionary
form2.ShowDialog()
'判断是否确定关闭
If form2.DialogResult = DialogResult.OK Then
G_Dictionary = form2.G_Dictionary
End If
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
If ToolStripButton1.Text.Equals("打开") Then
ToolStripButton1.Text = "关闭"
ToolStripButton2.Enabled = False
Dim nCommuniNode As CommuniNode
'遍历G_Dictionary
For Each item In G_Dictionary
If item.Value.Item1 Then
nCommuniNode = New CommuniNode(item.Value.Item2, item.Value.Item3, item.Value.Item4, item.Value.Item5, G_msgqueue)
G_SerialPortli.Add(item.Value.Item4, nCommuniNode)
nCommuniNode.SetSerialPortOpen(True)
End If
Next
Button2.Text = "停止接收"
Button2.BackColor = Color.Red
SetReadFlag(True)
Else
ToolStripButton1.Text = "打开"
ToolStripButton2.Enabled = True
For Each item In G_SerialPortli
item.Value.SetSerialPortOpen(False)
Next
Button2.Text = "开始接收"
Button2.BackColor = Color.Green
SetReadFlag(False)
G_SerialPortli.Clear()
ComboBox1.Items.Clear()
ComboBox1.Text = ""
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If IsNothing(G_SerialPortli) OrElse G_SerialPortli.Count = 0 Then Return
For Each item In G_SerialPortli
item.Value.SetShowHex(CheckBox1.Checked)
Next
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
If IsNothing(G_SerialPortli) OrElse G_SerialPortli.Count = 0 Then Return
For Each item In G_SerialPortli
item.Value.SetSendHex(CheckBox2.Checked)
Next
End Sub
Private Sub ComboBox1_DropDown(sender As Object, e As EventArgs) Handles ComboBox1.DropDown
ComboBox1.Items.Clear()
If IsNothing(G_SerialPortli) OrElse G_SerialPortli.Count = 0 Then Return
For Each item In G_SerialPortli
ComboBox1.Items.Add(item.Value.G_aliasname)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If IsNothing(G_SerialPortli) OrElse G_SerialPortli.Count = 0 Then Return
For Each item In G_SerialPortli
If ComboBox1.Text.Equals(item.Value.G_aliasname) Then
item.Value.SendData(TextBox1.Text.Trim)
Return
End If
Next
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Grid1.Rows = 1
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Button2.Text.Equals("停止接收") Then
Button2.Text = "开始接收"
Button2.BackColor = Color.Green
SetReadFlag(False)
Else
Button2.Text = "停止接收"
Button2.BackColor = Color.Red
SetReadFlag(True)
End If
End Sub
Public Sub SetReadFlag(ByVal flag As Boolean)
If IsNothing(G_SerialPortli) OrElse G_SerialPortli.Count = 0 Then Return
For Each item In G_SerialPortli
item.Value.SetReadFlag(flag)
Next
End Sub
Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged, CheckBox9.CheckedChanged, CheckBox8.CheckedChanged, CheckBox7.CheckedChanged, CheckBox6.CheckedChanged, CheckBox5.CheckedChanged, CheckBox4.CheckedChanged
Dim chBox As CheckBox = sender
'判断是否选中
'取到tag
Dim tag As Integer = CIntchBox.Tag)
If chBox.Checked Then
Grid1.Column(tag).Visible = False
Else
Grid1.Column(tag).Visible = True
End If
End Sub
Private Sub Grid1_Click(Sender As Object, e As EventArgs) Handles Grid1.Click
'获取选中单元格
Dim C_x, C_y As Integer
C_x = Grid1.ActiveCell.Row
C_y = Grid1.ActiveCell.Col
'判断行》0
If C_x > 0 Then
'获取行号设置到Xlabel
Xlabel.Text = "RowID:" & Grid1.Cell(C_x, 0).Text
Ylabel.Text = "ColumnName:" & Grid1.Cell(0, C_y).Text
TextBox2.Text = Grid1.Cell(C_x, C_y).Text
End If
End Sub
End Class

25
MultiSerialPortCommu.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32602.291
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MultiSerialPortCommu", "MultiSerialPortCommu.vbproj", "{6088C9C6-2CBB-40B9-90B7-298F497CB641}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6088C9C6-2CBB-40B9-90B7-298F497CB641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6088C9C6-2CBB-40B9-90B7-298F497CB641}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6088C9C6-2CBB-40B9-90B7-298F497CB641}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6088C9C6-2CBB-40B9-90B7-298F497CB641}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {53F8DE75-F78E-478A-A41E-8D428839C71A}
EndGlobalSection
EndGlobal

140
MultiSerialPortCommu.vbproj Normal file
View File

@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6088C9C6-2CBB-40B9-90B7-298F497CB641}</ProjectGuid>
<OutputType>WinExe</OutputType>
<StartupObject>MultiSerialPortCommu.My.MyApplication</StartupObject>
<RootNamespace>MultiSerialPortCommu</RootNamespace>
<AssemblyName>MultiSerialPortCommu</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>MultiSerialPortCommu.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>MultiSerialPortCommu.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="FlexCell, Version=4.7.0.0, Culture=neutral, PublicKeyToken=6f86587eb70ee309, processorArchitecture=MSIL" />
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Drawing" />
<Import Include="System.Diagnostics" />
<Import Include="System.Windows.Forms" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommuniNode.vb" />
<Compile Include="Form1.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.vb">
<DependentUpon>Form1.vb</DependentUpon>
<SubType>Form</SubType>
</Compile>
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="publicMode.vb" />
<Compile Include="RuningLog.vb" />
<Compile Include="SetingSerialPort.Designer.vb">
<DependentUpon>SetingSerialPort.vb</DependentUpon>
</Compile>
<Compile Include="SetingSerialPort.vb">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="SetingSerialPort.resx">
<DependentUpon>SetingSerialPort.vb</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

38
My Project/Application.Designer.vb generated Normal file
View File

@@ -0,0 +1,38 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.MultiSerialPortCommu.Form1
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>0</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View File

@@ -0,0 +1,35 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' 有关程序集的一般信息由以下
' 控制。更改这些特性值可修改
' 与程序集关联的信息。
'查看程序集特性的值
<Assembly: AssemblyTitle("MultiSerialPortCommu")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("MultiSerialPortCommu")>
<Assembly: AssemblyCopyright("Copyright © 2025")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
<Assembly: Guid("62369784-5840-4463-a2d6-2e88cd0af018")>
' 程序集的版本信息由下列四个值组成:
'
' 主版本
' 次版本
' 生成号
' 修订号
'
'可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
'通过使用 "*",如下所示:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

62
My Project/Resources.Designer.vb generated Normal file
View File

@@ -0,0 +1,62 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("MultiSerialPortCommu.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set(ByVal value As Global.System.Globalization.CultureInfo)
resourceCulture = value
End Set
End Property
End Module
End Namespace

117
My Project/Resources.resx Normal file
View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

85
My Project/Settings.Designer.vb generated Normal file
View File

@@ -0,0 +1,85 @@
'------------------------------------------------------------------------------
' <auto-generated>
' 此代码由工具生成。
' 运行时版本:4.0.30319.42000
'
' 对此文件的更改可能会导致不正确的行为,并且如果
' 重新生成代码,这些更改将会丢失。
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
#Region "My.Settings 自动保存功能"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("")> _
Public Property SerialPortSettings() As String
Get
Return CType(Me("SerialPortSettings"),String)
End Get
Set
Me("SerialPortSettings") = value
End Set
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.MultiSerialPortCommu.My.MySettings
Get
Return Global.MultiSerialPortCommu.My.MySettings.Default
End Get
End Property
End Module
End Namespace

View File

@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="My" GeneratedClassName="MySettings" UseMySettingsClassName="true">
<Profiles />
<Settings>
<Setting Name="SerialPortSettings" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

123
RuningLog.vb Normal file
View File

@@ -0,0 +1,123 @@
Public Class RuningLog
Public Shared level As Integer = 1 '日志级别 0不输出日志 1输出日志2输出基础日志和错误信息
Delegate Function Deleg_OutputLogsToTheControl(c As Control config As RuningLogConfig, Controltype As Integer) As Boolean
'输出日志到控件
''' <summary>
''' ''输出日志到控件
''' </summary>
''' <param name="c">控件 </param>
''' <param name="config">日志</param>
''' <returns></returns>
Public Shared Function OutputLogsToTheControl(c As Control config As RuningLogConfig, Controltype As Integer) As Boolean
Try
If c.InvokeRequired Then
Dim dev As New Deleg_OutputLogsToTheControl(AddressOf OutputLogsToTheControl)
c.Invoke(dev, New Object() {c, config, Controltype})
Else
If Controltype >= level Then
Dim nc As RichTextBox = c
'获取富文本字符串末端位置
Dim index As Integer = nc.TextLength
'If (Not IsNothing(config.strdata)) AndAlso config.strdata.Length > 0 Then
' config.logstr = config.logstr & DataProcessing.ByteToString2(config.strdata)
'End If
Dim strtxt = config.logstr & vbCrLf
'设置光标位置
nc.SelectionStart = index
'添加文本
nc.AppendText(strtxt)
'设置选择区域
nc.Select(index, strtxt.Length)
'设置选择区域颜色
nc.SelectionColor = config.logstrColor
'设置选择区域字体
nc.SelectionFont = config.logstrFont
'取消选中区域
nc.DeselectAll()
End If
End If
Catch ex As Exception
End Try
End Function
'字符串附加时间戳
Public Shared Function AddTimeStamps(str As String) As String
Return Now.ToString("yyyy-MM-dd HH:mm:ss:fff") & " " & str
End Function
End Class
Public Class RuningLogConfig
'日志信息
Public logstr As String
'日志信息颜色
Public logstrColor As Color
'日志信息字体
Public logstrFont As Font
'日志信息字体大小
'Public logstrFontSize As Integer
''日志信息字体粗细
'Public logstrFontBold As Boolean
''日志信息字体斜体
'Public logstrFontItalic As Boolean
''日志信息字体下划线
'Public logstrFontUnderline As Boolean
''日志信息字体删除线
'Public logstrFontStrikeout As Boolean
''日志信息字体对齐方式
'Public logstrFontAlign As StringAlignment
'日志信息字体背景色
Public logstrFontBackColor As Color
Public strdata As Byte()
''' <summary>
''' 文本、颜色、Font
''' </summary>
''' <param name="args"></param>
'Sub New(ParamArray args() As Object)
' If args.Length > 0 Then
' logstr = RuningLog.AddTimeStamps(args(0).ToString)
' If args.Length > 1 Then
' logstrColor = args(1)
' If args.Length > 2 Then
' logstrFont = args(2)
' Else
' logstrFont = New Font("宋体", 8)
' End If
' If args.Length > 3 Then
' strdata = args(3)
' Else
' strdata = Nothing
' End If
' Else
' logstrColor = Color.Black
' End If
' Else
' logstr = "输空文本"
' logstrColor = Color.Black
' logstrFont = New Font("宋体", 12)
' End If
'End Sub
Sub New(ParamArray args() As Object)
logstr = RuningLog.AddTimeStamps(args(0).ToString)
logstrColor = args(1)
logstrFont = New Font("宋体", CInt(args(2)))
End Sub
End Class

376
SetingSerialPort.Designer.vb generated Normal file
View File

@@ -0,0 +1,376 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class SetingSerialPort
Inherits System.Windows.Forms.Form
'Form 重写 Dispose以清理组件列表。
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.port1 = New System.Windows.Forms.ComboBox()
Me.boot1 = New System.Windows.Forms.ComboBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.CheckBox2 = New System.Windows.Forms.CheckBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.boot2 = New System.Windows.Forms.ComboBox()
Me.port2 = New System.Windows.Forms.ComboBox()
Me.CheckBox3 = New System.Windows.Forms.CheckBox()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.Button3 = New System.Windows.Forms.Button()
Me.boot3 = New System.Windows.Forms.ComboBox()
Me.port3 = New System.Windows.Forms.ComboBox()
Me.CheckBox4 = New System.Windows.Forms.CheckBox()
Me.TextBox4 = New System.Windows.Forms.TextBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.boot4 = New System.Windows.Forms.ComboBox()
Me.port4 = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.Button5 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'port1
'
Me.port1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.port1.FormattingEnabled = True
Me.port1.Location = New System.Drawing.Point(89, 23)
Me.port1.Name = "port1"
Me.port1.Size = New System.Drawing.Size(121, 20)
Me.port1.TabIndex = 0
Me.port1.Tag = "1"
'
'boot1
'
Me.boot1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.boot1.FormattingEnabled = True
Me.boot1.Items.AddRange(New Object() {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "256000", "512000", "9216000", "1000000"})
Me.boot1.Location = New System.Drawing.Point(233, 23)
Me.boot1.Name = "boot1"
Me.boot1.Size = New System.Drawing.Size(121, 20)
Me.boot1.TabIndex = 1
Me.boot1.Tag = "1"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(537, 22)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(51, 23)
Me.Button1.TabIndex = 2
Me.Button1.Tag = "1"
Me.Button1.Text = "..."
Me.Button1.UseVisualStyleBackColor = True
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(364, 23)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(158, 21)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Tag = "1"
Me.TextBox1.Text = "串口一"
Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'CheckBox1
'
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Location = New System.Drawing.Point(41, 25)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(15, 14)
Me.CheckBox1.TabIndex = 4
Me.CheckBox1.Tag = "1"
Me.CheckBox1.UseVisualStyleBackColor = True
'
'CheckBox2
'
Me.CheckBox2.AutoSize = True
Me.CheckBox2.Location = New System.Drawing.Point(41, 67)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(15, 14)
Me.CheckBox2.TabIndex = 9
Me.CheckBox2.Tag = "2"
Me.CheckBox2.UseVisualStyleBackColor = True
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(364, 65)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(158, 21)
Me.TextBox2.TabIndex = 8
Me.TextBox2.Tag = "2"
Me.TextBox2.Text = "串口二"
Me.TextBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(537, 64)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(51, 23)
Me.Button2.TabIndex = 7
Me.Button2.Tag = "2"
Me.Button2.Text = "..."
Me.Button2.UseVisualStyleBackColor = True
'
'boot2
'
Me.boot2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.boot2.FormattingEnabled = True
Me.boot2.Items.AddRange(New Object() {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "256000", "512000", "9216000", "1000000"})
Me.boot2.Location = New System.Drawing.Point(233, 65)
Me.boot2.Name = "boot2"
Me.boot2.Size = New System.Drawing.Size(121, 20)
Me.boot2.TabIndex = 6
Me.boot2.Tag = "2"
'
'port2
'
Me.port2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.port2.FormattingEnabled = True
Me.port2.Location = New System.Drawing.Point(89, 65)
Me.port2.Name = "port2"
Me.port2.Size = New System.Drawing.Size(121, 20)
Me.port2.TabIndex = 5
Me.port2.Tag = "2"
'
'CheckBox3
'
Me.CheckBox3.AutoSize = True
Me.CheckBox3.Location = New System.Drawing.Point(41, 109)
Me.CheckBox3.Name = "CheckBox3"
Me.CheckBox3.Size = New System.Drawing.Size(15, 14)
Me.CheckBox3.TabIndex = 14
Me.CheckBox3.Tag = "3"
Me.CheckBox3.UseVisualStyleBackColor = True
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(364, 107)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(158, 21)
Me.TextBox3.TabIndex = 13
Me.TextBox3.Tag = "3"
Me.TextBox3.Text = "串口三"
Me.TextBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(537, 106)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(51, 23)
Me.Button3.TabIndex = 12
Me.Button3.Tag = "3"
Me.Button3.Text = "..."
Me.Button3.UseVisualStyleBackColor = True
'
'boot3
'
Me.boot3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.boot3.FormattingEnabled = True
Me.boot3.Items.AddRange(New Object() {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "256000", "512000", "9216000", "1000000"})
Me.boot3.Location = New System.Drawing.Point(233, 107)
Me.boot3.Name = "boot3"
Me.boot3.Size = New System.Drawing.Size(121, 20)
Me.boot3.TabIndex = 11
Me.boot3.Tag = "3"
'
'port3
'
Me.port3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.port3.FormattingEnabled = True
Me.port3.Location = New System.Drawing.Point(89, 107)
Me.port3.Name = "port3"
Me.port3.Size = New System.Drawing.Size(121, 20)
Me.port3.TabIndex = 10
Me.port3.Tag = "3"
'
'CheckBox4
'
Me.CheckBox4.AutoSize = True
Me.CheckBox4.Location = New System.Drawing.Point(41, 151)
Me.CheckBox4.Name = "CheckBox4"
Me.CheckBox4.Size = New System.Drawing.Size(15, 14)
Me.CheckBox4.TabIndex = 19
Me.CheckBox4.Tag = "4"
Me.CheckBox4.UseVisualStyleBackColor = True
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(364, 149)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(158, 21)
Me.TextBox4.TabIndex = 18
Me.TextBox4.Tag = "4"
Me.TextBox4.Text = "串口四"
Me.TextBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(537, 148)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(51, 23)
Me.Button4.TabIndex = 17
Me.Button4.Tag = "4"
Me.Button4.Text = "..."
Me.Button4.UseVisualStyleBackColor = True
'
'boot4
'
Me.boot4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.boot4.FormattingEnabled = True
Me.boot4.Items.AddRange(New Object() {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "256000", "512000", "9216000", "1000000"})
Me.boot4.Location = New System.Drawing.Point(233, 149)
Me.boot4.Name = "boot4"
Me.boot4.Size = New System.Drawing.Size(121, 20)
Me.boot4.TabIndex = 16
Me.boot4.Tag = "4"
'
'port4
'
Me.port4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.port4.FormattingEnabled = True
Me.port4.Location = New System.Drawing.Point(89, 149)
Me.port4.Name = "port4"
Me.port4.Size = New System.Drawing.Size(121, 20)
Me.port4.TabIndex = 15
Me.port4.Tag = "4"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(10, 7)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(77, 12)
Me.Label1.TabIndex = 20
Me.Label1.Text = "选择通信串口"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(123, 7)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(53, 12)
Me.Label2.TabIndex = 21
Me.Label2.Text = "通信串口"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(249, 8)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(89, 12)
Me.Label3.TabIndex = 22
Me.Label3.Text = "通信串口波特率"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(405, 7)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(77, 12)
Me.Label4.TabIndex = 23
Me.Label4.Text = "通信串口别名"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(535, 7)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(53, 12)
Me.Label5.TabIndex = 24
Me.Label5.Text = "设置颜色"
'
'Button5
'
Me.Button5.Font = New System.Drawing.Font("宋体", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button5.Location = New System.Drawing.Point(467, 177)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(120, 52)
Me.Button5.TabIndex = 25
Me.Button5.Text = "保存"
Me.Button5.UseVisualStyleBackColor = True
'
'SetingSerialPort
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(593, 232)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.CheckBox4)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.boot4)
Me.Controls.Add(Me.port4)
Me.Controls.Add(Me.CheckBox3)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.boot3)
Me.Controls.Add(Me.port3)
Me.Controls.Add(Me.CheckBox2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.boot2)
Me.Controls.Add(Me.port2)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.boot1)
Me.Controls.Add(Me.port1)
Me.Name = "SetingSerialPort"
Me.Text = "设置串口"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents port1 As ComboBox
Friend WithEvents boot1 As ComboBox
Friend WithEvents Button1 As Button
Friend WithEvents TextBox1 As TextBox
Friend WithEvents CheckBox1 As CheckBox
Friend WithEvents CheckBox2 As CheckBox
Friend WithEvents TextBox2 As TextBox
Friend WithEvents Button2 As Button
Friend WithEvents boot2 As ComboBox
Friend WithEvents port2 As ComboBox
Friend WithEvents CheckBox3 As CheckBox
Friend WithEvents TextBox3 As TextBox
Friend WithEvents Button3 As Button
Friend WithEvents boot3 As ComboBox
Friend WithEvents port3 As ComboBox
Friend WithEvents CheckBox4 As CheckBox
Friend WithEvents TextBox4 As TextBox
Friend WithEvents Button4 As Button
Friend WithEvents boot4 As ComboBox
Friend WithEvents port4 As ComboBox
Friend WithEvents Label1 As Label
Friend WithEvents Label2 As Label
Friend WithEvents Label3 As Label
Friend WithEvents Label4 As Label
Friend WithEvents Label5 As Label
Friend WithEvents Button5 As Button
End Class

120
SetingSerialPort.resx Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

184
SetingSerialPort.vb Normal file
View File

@@ -0,0 +1,184 @@
Imports System.IO.Ports
Public Class SetingSerialPort
Public G_Dictionary As Dictionary(Of String, (Boolean, String, Integer, String, Color)
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click, Button3.Click, Button2.Click, Button1.Click
Dim bt As Button = CType(sender, Button)
'‘打开选色面板
Dim ColorDialog1 As New ColorDialog
ColorDialog1.ShowDialog()
'‘将选中的颜色赋值给文本的字体色
Select Case bt.Tag
Case "1"
TextBox1.ForeColor = ColorDialog1.Color
Case "2"
TextBox2.ForeColor = ColorDialog1.Color
Case "3"
TextBox3.ForeColor = ColorDialog1.Color
Case "4"
TextBox4.ForeColor = ColorDialog1.Color
End Select
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
G_Dictionary.Clear()
Dim boot As Integer
'判断勾选框是否选中
'判断串口名称是否为空 port1
If String.IsNullOrEmptyport1.Text Then
MsgBox("请选择串口1名称")
Return
End If
'判断波特率是否为空
If String.IsNullOrEmptyboot1.Text Then
MsgBox("请选择串口1波特率")
Return
End If
'判断别名是否为空
If String.IsNullOrEmptyTextBox1.Text Then
MsgBox("择串口1别名为空")
Return
End If
'添加到列表中
G_Dictionary.Add("1", (CheckBox1.Checked, port1.Text, Convert.ToInt32(boot1.Text), TextBox1.Text, TextBox1.ForeColor))
If String.IsNullOrEmptyport2.Text Then
MsgBox("请选择串口2名称")
Return
End If
If String.IsNullOrEmptyboot2.Text Then
MsgBox("请选择串口2波特率")
Return
End If
If String.IsNullOrEmptyTextBox2.Text Then
MsgBox("择串口2别名为空")
Return
End If
G_Dictionary.Add("2", (CheckBox2.Checked, port2.Text, Convert.ToInt32(boot2.Text), TextBox2.Text, TextBox2.ForeColor))
If String.IsNullOrEmptyport3.Text Then
MsgBox("请选择串口3名称")
Return
End If
If String.IsNullOrEmptyboot3.Text Then
MsgBox("请选择串口3波特率")
Return
End If
If String.IsNullOrEmptyTextBox3.Text Then
MsgBox("择串口3别名为空")
Return
End If
G_Dictionary.Add("3", (CheckBox3.Checked, port3.Text, Convert.ToInt32(boot3.Text), TextBox3.Text, TextBox3.ForeColor))
If String.IsNullOrEmptyport4.Text Then
MsgBox("请选择串口4名称")
Return
End If
If String.IsNullOrEmptyboot4.Text Then
MsgBox("请选择串口4波特率")
Return
End If
If String.IsNullOrEmptyTextBox4.Text Then
MsgBox("择串口4别名为空")
Return
End If
G_Dictionary.Add("4", (CheckBox4.Checked, port4.Text, Convert.ToInt32(boot4.Text), TextBox4.Text, TextBox4.ForeColor))
'关闭窗体并返回ok
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
Private Sub SetingSerialPort_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'获取串口列表
Dim portNames As String() = SerialPort.GetPortNames()
'将串口列表添加到下拉框中
port1.Items.Clear()
port2.Items.Clear()
port3.Items.Clear()
port4.Items.Clear()
port1.Items.AddRange(portNames)
port2.Items.AddRange(portNames)
port3.Items.AddRange(portNames)
port4.Items.AddRange(portNames)
If IsNothing(G_Dictionary) OrElse G_Dictionary.Count = 0 Then
G_Dictionary = New Dictionary(Of String, (Boolean, String, Integer, String, Color)
port1.SelectedIndex = 0
port2.SelectedIndex = 0
port3.SelectedIndex = 0
port4.SelectedIndex = 0
boot1.SelectedIndex = 0
boot2.SelectedIndex = 0
boot3.SelectedIndex = 0
boot4.SelectedIndex = 0
Else
For Each item In G_Dictionary
Select Case item.Key
Case "1"
CheckBox1.Checked = item.Value.Item1
If port1.Items.Contains(item.Value.Item2) Then
port1.Text = item.Value.Item2
Else
port1.SelectedIndex = 0
End If
boot1.Text = item.Value.Item3
TextBox1.Text = item.Value.Item4
TextBox1.ForeColor = item.Value.Item5
Case "2"
CheckBox2.Checked = item.Value.Item1
If port2.Items.Contains(item.Value.Item2) Then
port2.Text = item.Value.Item2
Else
port2.SelectedIndex = 0
End If
boot2.Text = item.Value.Item3
TextBox2.Text = item.Value.Item4
TextBox2.ForeColor = item.Value.Item5
Case "3"
CheckBox3.Checked = item.Value.Item1
If port3.Items.Contains(item.Value.Item2) Then
port3.Text = item.Value.Item2
Else
port3.SelectedIndex = 0
End If
boot3.Text = item.Value.Item3
TextBox3.Text = item.Value.Item4
TextBox3.ForeColor = item.Value.Item5
Case "4"
CheckBox4.Checked = item.Value.Item1
If port4.Items.Contains(item.Value.Item2) Then
port4.Text = item.Value.Item2
Else
port4.SelectedIndex = 0
End If
boot4.Text = item.Value.Item3
TextBox4.Text = item.Value.Item4
TextBox4.ForeColor = item.Value.Item5
End Select
Next
End If
End Sub
End Class

BIN
bin/Debug/FlexCell.dll Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MultiSerialPortCommu.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<userSettings>
<MultiSerialPortCommu.My.MySettings>
<setting name="SerialPortSettings" serializeAs="String">
<value />
</setting>
</MultiSerialPortCommu.My.MySettings>
</userSettings>
</configuration>

Binary file not shown.

View File

@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>
MultiSerialPortCommu
</name>
</assembly>
<members>
<member name="T:MultiSerialPortCommu.My.Resources.Resources">
<summary>
A strongly-typed resource class, for looking up localized strings, etc.
</summary>
</member>
<member name="P:MultiSerialPortCommu.My.Resources.Resources.ResourceManager">
<summary>
Returns the cached ResourceManager instance used by this class.
</summary>
</member>
<member name="P:MultiSerialPortCommu.My.Resources.Resources.Culture">
<summary>
Overrides the current thread's CurrentUICulture property for all
resource lookups using this strongly typed resource class.
</summary>
</member>
<member name="M:MultiSerialPortCommu.publicMode.IntToByteHB(System.Int32)">
<summary>
Int转2个字节Byte
高字节在前,低字节在后
</summary>
<param name="i"></param>
<returns></returns>
</member>
<member name="M:MultiSerialPortCommu.publicMode.IntToByteLB(System.Int32)">
<summary>
Int转2个字节Byte
高字节在前,低字节在后
</summary>
<param name="i"></param>
<returns></returns>
</member>
<member name="M:MultiSerialPortCommu.RuningLog.OutputLogsToTheControl(System.Windows.Forms.Control,MultiSerialPortCommu.RuningLogConfig,System.Int32)">
<summary>
''输出日志到控件
</summary>
<param name="c">控件 </param>
<param name="config">日志</param>
<returns></returns>
</member>
</members>
</doc>

Binary file not shown.

11363
bin/Debug/Newtonsoft.Json.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
' <autogenerated/>
Option Strict Off
Option Explicit On
Imports System
Imports System.Reflection
<Assembly: Global.System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName:=".NET Framework 4.8")>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
ecf9c7361932863da722ac7ccde4545660928653

View File

@@ -0,0 +1,17 @@
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.vbproj.AssemblyReference.cache
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.Form1.resources
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.Resources.resources
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.SetingSerialPort.resources
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.vbproj.GenerateResource.cache
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.vbproj.CoreCompileInputs.cache
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\MultiSerialPortCommu.exe.config
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\MultiSerialPortCommu.exe
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\MultiSerialPortCommu.pdb
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\MultiSerialPortCommu.xml
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\FlexCell.dll
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\Newtonsoft.Json.dll
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\bin\Debug\Newtonsoft.Json.xml
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.vbproj.CopyComplete
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.exe
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.xml
E:\Sync\MultiSerialPortCommu\MultiSerialPortCommu\obj\Debug\MultiSerialPortCommu.pdb

View File

@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>
MultiSerialPortCommu
</name>
</assembly>
<members>
<member name="T:MultiSerialPortCommu.My.Resources.Resources">
<summary>
A strongly-typed resource class, for looking up localized strings, etc.
</summary>
</member>
<member name="P:MultiSerialPortCommu.My.Resources.Resources.ResourceManager">
<summary>
Returns the cached ResourceManager instance used by this class.
</summary>
</member>
<member name="P:MultiSerialPortCommu.My.Resources.Resources.Culture">
<summary>
Overrides the current thread's CurrentUICulture property for all
resource lookups using this strongly typed resource class.
</summary>
</member>
<member name="M:MultiSerialPortCommu.publicMode.IntToByteHB(System.Int32)">
<summary>
Int转2个字节Byte
高字节在前,低字节在后
</summary>
<param name="i"></param>
<returns></returns>
</member>
<member name="M:MultiSerialPortCommu.publicMode.IntToByteLB(System.Int32)">
<summary>
Int转2个字节Byte
高字节在前,低字节在后
</summary>
<param name="i"></param>
<returns></returns>
</member>
<member name="M:MultiSerialPortCommu.RuningLog.OutputLogsToTheControl(System.Windows.Forms.Control,MultiSerialPortCommu.RuningLogConfig,System.Int32)">
<summary>
''输出日志到控件
</summary>
<param name="c">控件 </param>
<param name="config">日志</param>
<returns></returns>
</member>
</members>
</doc>

Binary file not shown.

4
packages.config Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
</packages>

Binary file not shown.

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2007 James Newton-King
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Binary file not shown.

View File

@@ -0,0 +1,71 @@
# ![Logo](https://raw.githubusercontent.com/JamesNK/Newtonsoft.Json/master/Doc/icons/logo.jpg) Json.NET
[![NuGet version (Newtonsoft.Json)](https://img.shields.io/nuget/v/Newtonsoft.Json.svg?style=flat-square)](https://www.nuget.org/packages/Newtonsoft.Json/)
[![Build status](https://dev.azure.com/jamesnk/Public/_apis/build/status/JamesNK.Newtonsoft.Json?branchName=master)](https://dev.azure.com/jamesnk/Public/_build/latest?definitionId=8)
Json.NET is a popular high-performance JSON framework for .NET
## Serialize JSON
```csharp
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
string json = JsonConvert.SerializeObject(product);
// {
// "Name": "Apple",
// "Expiry": "2008-12-28T00:00:00",
// "Sizes": [
// "Small"
// ]
// }
```
## Deserialize JSON
```csharp
string json = @"{
'Name': 'Bad Boys',
'ReleaseDate': '1995-4-7T00:00:00',
'Genres': [
'Action',
'Comedy'
]
}";
Movie m = JsonConvert.DeserializeObject<Movie>(json);
string name = m.Name;
// Bad Boys
```
## LINQ to JSON
```csharp
JArray array = new JArray();
array.Add("Manual text");
array.Add(new DateTime(2000, 5, 23));
JObject o = new JObject();
o["MyArray"] = array;
string json = o.ToString();
// {
// "MyArray": [
// "Manual text",
// "2000-05-23T00:00:00"
// ]
// }
```
## Links
- [Homepage](https://www.newtonsoft.com/json)
- [Documentation](https://www.newtonsoft.com/json/help)
- [NuGet Package](https://www.nuget.org/packages/Newtonsoft.Json)
- [Release Notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Contributing Guidelines](https://github.com/JamesNK/Newtonsoft.Json/blob/master/CONTRIBUTING.md)
- [License](https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md)
- [Stack Overflow](https://stackoverflow.com/questions/tagged/json.net)

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

146
publicMode.vb Normal file
View File

@@ -0,0 +1,146 @@
Public Class publicMode
'字符串转byte数组
Public Shared Function StringToByte(ByVal str As String) As Byte()
Return System.Text.Encoding.Default.GetBytes(str)
End Function
Public Shared Function StringToHexString(ByVal b As String) As String
Dim sbuff = StringToByte(b)
Return ByteToHex(sbuff)
End Function
'byte数组转字符串
Public Shared Function ByteToString(ByVal b As Byte()) As String
Return System.Text.Encoding.Default.GetString(b)
End Function
'byte数组转十六进制字符串
Public Shared Function ByteToHex(ByVal b As Byte()) As String
Dim s As String = ""
For Each c As Byte In b
s += c.ToString("X2")
Next
Return s
End Function
'字符串转十六进制字符串不足两位补0
Public Shared Function StringToHex(ByVal str As String) As String
Dim s As String = ""
For Each c As Char In str
s += Convert.ToString(Asc(c), 16).PadLeft(2, "0")
Next
Return s
End Function
'字符串每两个字节转十六进制字符串 不足两位补0
Public Shared Function StringToHex2(ByVal str As String) As String
Dim s As String = ""
Dim nv As String = ""
For i As Integer = 0 To str.Length - 1 Step 2
nv = str.Substring(i, 1)
If nv.Length = 1 Then
nv = "0" & nv
End If
s += nv
Next
Return s
End Function
Public Shared Function StringToHex3(ByVal str As String) As String
Dim result As String = ""
For Each c As Char In str
Dim bytes As Byte() = System.Text.Encoding.Unicode.GetBytes(c)
For Each b As Byte In bytes
result += b.ToString("X2")
Next
Next
Return result
End Function
'十六进制字符串转byte数组
Public Shared Function HexToByte(ByVal hex As String) As Byte()
Dim b As Byte() = New Byte(hex.Length / 2 - 1) {}
Try
For i As Integer = 0 To hex.Length - 1 Step 2
b(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
Next
Catch ex As Exception
Return Nothing
End Try
Return b
End Function
'十六进制字符串转字符串
Public Shared Function ByteToHexString(databuff() As Byte) As String
Dim strData As String = String.Empty
For i = 0 To databuff.Length - 1
strData &= $" {Hex(databuff(i)).PadLeft(2, "0"c)}"
Next
Return strData
End Function
'十六进制字符串转字符串
Public Shared Function HexStringToByte(hexstr As String) As Byte()
Dim result As Byte() = Nothing
'判断字符串是否为空或 者为空字符串
If String.IsNullOrEmpty(hexstr) Then Return Nothing
'替换字符中的分隔符号
hexstr = hexstr.Trim().Replace(" ", "").Replace("-", "").Replace(",", "").Replace(":", "").Replace(";", "").Replace(".", "")
'判断字符串的长度是否为偶数
If hexstr.Length Mod 2 <> 0 Then
'不为偶数往最后一个字节前面补0
hexstr = hexstr.Insert(hexstr.Length - 1, "0")
End If
'以2为步长将字符串转换为字节数组 不足2位前面补0
Try
result = Enumerable.Range(0, hexstr.Length).Where(Function(x) x Mod 2 = 0).Select(Function(x) Convert.ToByte(hexstr.Substring(x, 2), 16)).ToArray()
Catch ex As Exception
result = Nothing
End Try
Return result
End Function
'Public Shared Function HexStringToByte(hexstr As String) As String
' '判断字符串是否为空或 者为空字符串
' If String.IsNullOrEmpty(hexstr) Then Return Nothing
' '替换字符中的分隔符号
' hexstr = hexstr.Trim().Replace(" ", "").Replace("-", "").Replace(",", "").Replace(":", "").Replace(";", "").Replace(".", "")
' '判断字符串的长度是否为偶数
' If hexstr.Length Mod 2 <> 0 Then
' '不为偶数往最后一个字节前面补0
' hexstr = hexstr.Insert(hexstr.Length - 1, "0")
' End If
' '以2为步长将字符串转换为字节数组 不足2位前面补0
' Return hexstr 'Enumerable.Range(0, hexstr.Length).Where(Function(x) x Mod 2 = 0).Select(Function(x) Convert.ToByte(hexstr.Substring(x, 2), 16)).ToArray()
'End Function
''' <summary>
''' Int转2个字节Byte
''' 高字节在前,低字节在后
''' </summary>
''' <param name="i"></param>
''' <returns></returns>
Public Shared Function IntToByteHB(ByVal i As Integer) As Byte()
Dim btemp() As Byte = {0, 0}
Dim b() As Byte = BitConverter.GetBytes(i)
btemp(0) = b(0)
btemp(1) = b(1)
Return btemp
End Function
''' <summary>
''' Int转2个字节Byte
''' 高字节在前,低字节在后
''' </summary>
''' <param name="i"></param>
''' <returns></returns>
Public Shared Function IntToByteLB(ByVal i As Integer) As Byte()
Dim btemp() As Byte = {0, 0}
Dim b() As Byte = BitConverter.GetBytes(i)
btemp(0) = b(1)
btemp(1) = b(0)
Return btemp
End Function
End Class