📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
AutoRedraw = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "RS232"
ClientHeight = 4740
ClientLeft = 2340
ClientTop = 1875
ClientWidth = 7485
Icon = "Form1.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 4740
ScaleWidth = 7485
Begin MSComDlg.CommonDialog CommonDialog1
Left = 6300
Top = 1920
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command8
Caption = "RS232设置"
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 12
Top = 4200
Width = 1335
End
Begin VB.CommandButton Command7
Caption = "关于"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 11
Top = 4200
Width = 1335
End
Begin VB.CommandButton Command6
Caption = "保 存"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 10
Top = 3000
Width = 1365
End
Begin VB.CommandButton Command5
Caption = "清 除"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 9
Top = 3540
Width = 1365
End
Begin VB.CommandButton Command4
Caption = "打 开"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 8
Top = 360
Width = 1365
End
Begin VB.CommandButton Command3
Caption = "结 束"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2640
TabIndex = 5
Top = 4200
Width = 2295
End
Begin VB.Timer Timer1
Interval = 1
Left = 5220
Top = 4140
End
Begin VB.CommandButton Command2
Caption = "清 除"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 4
Top = 1440
Width = 1365
End
Begin VB.CommandButton Command1
Caption = "发 送"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5820
TabIndex = 3
Top = 900
Width = 1365
End
Begin VB.TextBox Text2
Height = 1635
Left = 180
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 2
TabStop = 0 'False
Top = 2400
Width = 5295
End
Begin VB.TextBox Text1
Height = 1635
Left = 180
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 360
Width = 5295
End
Begin MSCommLib.MSComm MSComm1
Left = 1800
Top = 4080
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Label Label5
Caption = "RS232 接收"
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 195
Left = 2340
TabIndex = 7
Top = 2100
Width = 1035
End
Begin VB.Label Label2
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Caption = "RS232-USB"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 5880
TabIndex = 6
Top = 2460
Width = 1275
End
Begin VB.Label Label1
Caption = "RS232 发送"
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 195
Left = 2340
TabIndex = 1
Top = 60
Width = 1035
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim SendOk As Boolean
Dim CancelSend As Boolean
Dim SendText As String
Private Sub Command1_Click()
SendText = Text1.Text
CancelSend = False
If (SendOk = True) Then
If (Len(SendText) > 60) Then
MSComm1.Output = Left(SendText, 60)
SendText = Right(SendText, Len(SendText) - 60)
Timer1.Enabled = True
Command1.Enabled = False
Else
MSComm1.Output = SendText
End If
Else
Timer1.Enabled = True
Command1.Enabled = False
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
CancelSend = True
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Command4_Click()
Dim LineOfText As String
Dim FileOfText As String
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Form1.MousePointer = 11
Text1.Text = ""
Open CommonDialog1.FileName For Input As #1
Do Until EOF(1)
Line Input #1, LineOfText
FileOfText = FileOfText & LineOfText & vbCrLf
Loop
Form1.MousePointer = 0
Close #1
Text1.Text = FileOfText
End If
CancelSend = False
End Sub
Private Sub Command5_Click()
Text2.Text = ""
End Sub
Private Sub Command6_Click()
CommonDialog1.Filter = "文本文件(*.txt)|*.txt"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
Form1.MousePointer = 11
Open CommonDialog1.FileName For Output As #1
Print #1, Text2.Text
Form1.MousePointer = 0
Close #1
End If
End Sub
Private Sub Command7_Click()
Form3.Show 1
End Sub
Private Sub Command8_Click()
Form2.Show 1
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.InBufferSize = 1024
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeText
MSComm1.OutBufferSize = 1024
MSComm1.SThreshold = 0
MSComm1.Handshaking = comNone
MSComm1.PortOpen = True
SendOk = True
CancelSend = True
Com1Sel = True
Com1Txt = "default"
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Text2.Text = Text2.Text + MSComm1.Input
Case comEventRxOver
MsgBox "串行口接收缓冲区溢出", 48, "警告"
Case comEvCTS
SendOk = Not SendOk
If SendOk = False Then
Label2.Caption = "USB传输失败"
Else
Label2.Caption = "USB传输成功"
End If
End Select
End Sub
Private Sub Timer1_Timer()
If (SendOk = True) Or (CancelSend = False) Then
If (Len(SendText) > 60) Then
MSComm1.Output = Left(SendText, 60)
SendText = Right(SendText, Len(SendText) - 60)
Else
MSComm1.Output = SendText
Timer1.Enabled = False
Command1.Enabled = True
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -