📄 frmcomset2.frm
字号:
VERSION 5.00
Begin VB.Form Frmcomset2
BorderStyle = 3 'Fixed Dialog
Caption = "串口设置"
ClientHeight = 4080
ClientLeft = 45
ClientTop = 435
ClientWidth = 4590
Icon = "Frmcomset2.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4080
ScaleWidth = 4590
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.Frame Frame1
Caption = "RS232串口通信参数设置:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 4080
Left = 0
TabIndex = 0
Top = 0
Width = 4605
Begin VB.ComboBox Combo1
DataField = "端口"
Height = 300
Left = 1440
TabIndex = 8
Top = 600
Width = 1935
End
Begin VB.ComboBox Combo2
Height = 300
Left = 1440
TabIndex = 7
Top = 1080
Width = 1935
End
Begin VB.ComboBox Combo3
Height = 300
Left = 1440
TabIndex = 6
Top = 1560
Width = 1935
End
Begin VB.ComboBox Combo4
Height = 300
Left = 1440
TabIndex = 5
Top = 2040
Width = 1935
End
Begin VB.ComboBox Combo5
Height = 300
Left = 1440
TabIndex = 4
Top = 2520
Width = 1935
End
Begin VB.ComboBox Combo6
Height = 300
Left = 1440
TabIndex = 3
Top = 3000
Width = 1935
End
Begin VB.CommandButton cmdok
Caption = "确认"
Height = 330
Left = 585
TabIndex = 2
Top = 3600
Width = 1275
End
Begin VB.CommandButton cmdc
Caption = "取消"
Height = 330
Left = 2520
TabIndex = 1
Top = 3600
Width = 1275
End
Begin VB.Label Label7
Caption = "Label7"
Height = 495
Left = 3555
TabIndex = 16
Top = 1080
Width = 975
End
Begin VB.Label Label1
Caption = "端口状态:"
Height = 255
Left = 3600
TabIndex = 15
Top = 630
Width = 975
End
Begin VB.Label Label8
AutoSize = -1 'True
Caption = "通信端口:"
Height = 180
Left = 360
TabIndex = 14
Top = 600
Width = 900
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "波特率:"
Height = 180
Left = 360
TabIndex = 13
Top = 1200
Width = 720
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "数据位:"
Height = 180
Left = 360
TabIndex = 12
Top = 1680
Width = 720
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "校验位:"
Height = 180
Left = 360
TabIndex = 11
Top = 2160
Width = 720
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "停止位:"
Height = 180
Left = 360
TabIndex = 10
Top = 2640
Width = 720
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "数据控制流:"
Height = 180
Left = 360
TabIndex = 9
Top = 3120
Width = 1080
End
End
End
Attribute VB_Name = "Frmcomset2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private iFlow1 As Integer, iTempEcho1 As Boolean
Private Sub cmdc_Click()
Unload Me
End Sub
Private Sub cmdok_Click()
Dim OldPort As Integer, ReOpen As Boolean
On Error Resume Next
Echo = iTempEcho1
OldPort = Frmcom.MSComm2.CommPort
NewPort = Combo1.ListIndex + 1
If NewPort <> OldPort Then ' 如果端口号被更改, 关闭原来的端口。
If Frmcom.MSComm2.PortOpen Then
Frmcom.MSComm2.PortOpen = False
ReOpen = True
End If
Frmcom.MSComm2.CommPort = NewPort ' 设置新的端口号。
If Err = 0 Then
If ReOpen Then
Frmcom.MSComm2.PortOpen = True
End If
End If
If Err Then
MsgBox Error$, 48
Frmcom.MSComm2.CommPort = OldPort
Exit Sub
End If
End If
Frmcom.MSComm2.Settings = Trim$(Combo2.Text) & "," & Left$(Combo4.Text, 1) _
& "," & Trim$(Combo3.Text) & "," & Trim$(Combo5.Text)
If Err Then
MsgBox Error$, 48
Exit Sub
End If
Select Case Combo6.Text
Case "无"
Combo6.Text = "无"
iFlow1 = 0
Case "Xon/Xoff"
Combo6.Text = ""
iFlow1 = 1
Case "RTS"
iFlow1 = 2
Case "Xon/RTS"
iFlow1 = 3
End Select
Frmcom.MSComm2.Handshaking = iFlow1
If Err Then
MsgBox Error$, 48
Exit Sub
End If
SaveSetting App.Title, "属性", "设置", Frmcom.MSComm2.Settings
SaveSetting App.Title, "属性", "通信端口", Frmcom.MSComm2.CommPort
SaveSetting App.Title, "属性", "握手", Frmcom.MSComm2.Handshaking
'SaveSetting App.Title, "属性", "回应", Frmcom.MSComm2.PortOpen
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
Frmcom.Show
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim Settings As String
Dim offset As Integer
On Error Resume Next
'If mark = 1 Then
'
'
'ElseIf mark = 2 Then
'
'
'End If
With Frmcom.MSComm2
Label7.Caption = ""
For i = 1 To 16
Combo1.AddItem "Com" & Trim$(Str$(i))
Next i
Combo2.AddItem "110"
Combo2.AddItem "300"
Combo2.AddItem "600"
Combo2.AddItem "1200"
Combo2.AddItem "2400"
Combo2.AddItem "4800"
Combo2.AddItem "9600"
Combo2.AddItem "14400"
Combo2.AddItem "19200"
Combo2.AddItem "38400"
Combo2.AddItem "57600"
Combo2.AddItem "115200"
Combo2.AddItem "230400"
Combo2.AddItem "460800"
Combo2.AddItem "921600"
Combo3.AddItem "4"
Combo3.AddItem "5"
Combo3.AddItem "6"
Combo3.AddItem "7"
Combo3.AddItem "8"
Combo4.AddItem "Even"
Combo4.AddItem "Odd"
Combo4.AddItem "None"
Combo4.AddItem "Mark"
Combo4.AddItem "Space"
Combo5.AddItem "1"
Combo5.AddItem "1.5"
Combo5.AddItem "2"
Combo6.AddItem "无"
Combo6.AddItem "Xon/Xoff"
Combo6.AddItem "RTS"
Combo6.AddItem "Xon/RTS"
' 设置默认的设置
Settings = .Settings
' 在大多数情况下,右边的大部分设置将为一个字符
' 除了可能出现的 1.5 停止位.
If InStr(Settings, ".") > 0 Then
offset = 2
Else
offset = 0
End If
Combo2.Text = Left$(Settings, Len(Settings) - 6 - offset)
Select Case Mid$(Settings, Len(Settings) - 4 - offset, 1)
Case "e"
Combo4.Text = "Even"
Case "m"
Combo4.Text = "Mark"
Case "n"
Combo4.Text = "None"
Case "o"
Combo4.Text = "Odd"
Case "s"
Combo4.Text = "Space"
End Select
Combo3.Text = Mid$(Settings, Len(Settings) - 2 - offset, 1)
Combo5.Text = Right$(Settings, 1 + offset)
Combo1.ListIndex = .CommPort - 1
Select Case .Handshaking
Case "0"
Combo6.Text = "无"
Case "1"
Combo6.Text = "Xon/Xoff"
Case "2"
Combo6.Text = "RTS"
Case "3"
Combo6.Text = "Xon/RTS"
End Select
If .PortOpen = True Then
Label7.Caption = "串口连接中"
Else
Label7.Caption = "串口断开中"
End If
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -