www.pudn.com > VBserial.rar > Form1.frm, change:2010-11-12,size:10486b


VERSION 5.00 
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" 
Begin VB.Form Form1  
   Caption         =   "Form1" 
   ClientHeight    =   6585 
   ClientLeft      =   60 
   ClientTop       =   450 
   ClientWidth     =   11460 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   6585 
   ScaleWidth      =   11460 
   StartUpPosition =   3  '窗口缺省 
   Begin VB.TextBox TextTime  
      Height          =   375 
      Left            =   9360 
      TabIndex        =   19 
      Top             =   5160 
      Width           =   1335 
   End 
   Begin VB.TextBox TextReceive  
      Height          =   3015 
      Left            =   840 
      TabIndex        =   18 
      Top             =   1560 
      Width           =   4575 
   End 
   Begin VB.TextBox TextSend  
      Height          =   735 
      Left            =   6240 
      ScrollBars      =   1  'Horizontal 
      TabIndex        =   17 
      Top             =   3600 
      Width           =   3255 
   End 
   Begin VB.ComboBox Combo5  
      Height          =   300 
      Left            =   6240 
      TabIndex        =   16 
      Text            =   "Combo5" 
      Top             =   3000 
      Width           =   1815 
   End 
   Begin VB.OptionButton Option4  
      Caption         =   "Option4" 
      Height          =   615 
      Left            =   4680 
      TabIndex        =   13 
      Top             =   720 
      Width           =   1095 
   End 
   Begin VB.OptionButton Option3  
      Caption         =   "Option3" 
      Height          =   495 
      Left            =   840 
      TabIndex        =   12 
      Top             =   840 
      Width           =   1215 
   End 
   Begin VB.OptionButton Option2  
      Caption         =   "Option2" 
      Height          =   615 
      Left            =   3480 
      TabIndex        =   11 
      Top             =   720 
      Width           =   1095 
   End 
   Begin VB.OptionButton Option1  
      Caption         =   "Option1" 
      Height          =   375 
      Left            =   2160 
      TabIndex        =   10 
      Top             =   840 
      Width           =   975 
   End 
   Begin VB.Timer Timer2  
      Left            =   10800 
      Top             =   3840 
   End 
   Begin VB.Timer Timer1  
      Left            =   10800 
      Top             =   3360 
   End 
   Begin VB.CommandButton ComClean3  
      Caption         =   "计数清空" 
      Height          =   495 
      Left            =   8280 
      TabIndex        =   9 
      Top             =   720 
      Width           =   1095 
   End 
   Begin VB.CommandButton ComClean2  
      Caption         =   "清空接收区" 
      Height          =   495 
      Left            =   1320 
      TabIndex        =   8 
      Top             =   4920 
      Width           =   1095 
   End 
   Begin VB.CommandButton ComClean1  
      Caption         =   "清空发送区" 
      Height          =   495 
      Left            =   6240 
      TabIndex        =   7 
      Top             =   5040 
      Width           =   1215 
   End 
   Begin VB.CommandButton ComSend1  
      Caption         =   "手动发送" 
      Height          =   495 
      Left            =   7800 
      TabIndex        =   6 
      Top             =   4440 
      Width           =   1335 
   End 
   Begin VB.CommandButton ComSend2  
      Caption         =   "自动发送" 
      Height          =   495 
      Left            =   6600 
      TabIndex        =   5 
      Top             =   4440 
      Width           =   1095 
   End 
   Begin VB.CommandButton ComOpen  
      Caption         =   "打开串口" 
      Height          =   495 
      Left            =   9000 
      TabIndex        =   4 
      Top             =   2880 
      Width           =   1095 
   End 
   Begin MSCommLib.MSComm MSComm1  
      Left            =   10680 
      Top             =   4440 
      _ExtentX        =   1005 
      _ExtentY        =   1005 
      _Version        =   393216 
      DTREnable       =   -1  'True 
   End 
   Begin VB.ComboBox Combo4  
      Height          =   300 
      Left            =   6240 
      TabIndex        =   3 
      Text            =   "Combo4" 
      Top             =   2520 
      Width           =   1815 
   End 
   Begin VB.ComboBox Combo3  
      Height          =   300 
      Left            =   6240 
      TabIndex        =   2 
      Text            =   "Combo3" 
      Top             =   2040 
      Width           =   1815 
   End 
   Begin VB.ComboBox Combo2  
      Height          =   300 
      Left            =   6240 
      TabIndex        =   1 
      Text            =   "Combo2" 
      Top             =   1440 
      Width           =   1815 
   End 
   Begin VB.ComboBox Combo1  
      Height          =   300 
      Left            =   6240 
      TabIndex        =   0 
      Text            =   "Combo1" 
      Top             =   840 
      Width           =   1815 
   End 
   Begin VB.Label Label11  
      Caption         =   "发送:" 
      Height          =   375 
      Left            =   8400 
      TabIndex        =   15 
      Top             =   2040 
      Width           =   855 
   End 
   Begin VB.Label Label10  
      Caption         =   "接收:" 
      Height          =   375 
      Left            =   8400 
      TabIndex        =   14 
      Top             =   1560 
      Width           =   855 
   End 
   Begin VB.Shape Shape1  
      Height          =   495 
      Left            =   8280 
      Top             =   2880 
      Width           =   495 
   End 
End 
Attribute VB_Name = "Form1" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
 
Private Sub Form_Load() 
If MSComm1.PortOpen = True Then 
   MSComm1.PortOpen = False 
Else 
End If 
Combo1.AddItem "COM1" 
Combo1.AddItem "COM2" 
Combo1.AddItem "COM3" 
Combo1.AddItem "COM4" 
Combo1.AddItem "COM5" 
Combo1.AddItem "COM6" 
Combo1.AddItem "COM7" 
Combo1.AddItem "COM8" 
Combo1.AddItem "COM9" 
Combo1.AddItem "COM10" 
Combo1.AddItem "COM11" 
Combo1.AddItem "COM12" 
Combo1.AddItem "COM13" 
Combo1.AddItem "COM14" 
Combo1.AddItem "COM15" 
Combo1.AddItem "COM16" 
Combo1.ListIndex = 2 
Combo2.AddItem "256000" 
Combo2.AddItem "128000" 
Combo2.AddItem "115200" 
Combo2.AddItem "57600" 
Combo2.AddItem "38400" 
Combo2.AddItem "28800" 
Combo2.AddItem "19200" 
Combo2.AddItem "14400" 
Combo2.AddItem "12800" 
Combo2.AddItem "11520" 
Combo2.AddItem "9600" 
Combo2.AddItem "4800" 
Combo2.AddItem "2400" 
Combo2.AddItem "1200" 
Combo2.AddItem "600" 
Combo3.AddItem "无None" 
Combo3.AddItem "奇Odd" 
Combo3.AddItem "偶Even" 
Combo4.AddItem "4" 
Combo4.AddItem "5" 
Combo4.AddItem "6" 
Combo4.AddItem "7" 
Combo4.AddItem "8" 
Combo5.AddItem "1" 
Combo5.AddItem "2" 
MSComm1.CommPort = Combo1.ListIndex + 1 
MSComm1.Settings = "9600,n,8,1" 
ComOpen.Caption = "打开串口" 
Shape1.FillColor = &HFFFFC0 
End Sub 
Private Sub ComOpen_Click() 
On Error GoTo uerror      '发现错误跳转到错误处理 
 If ComOpen.Caption = "关闭串口" Then 
        MSComm1.PortOpen = False 
        ComOpen.Caption = "打开串口"  '按钮文字改变 
        Shape1.FillColor = &HFFFFC0    '灯颜色改变 
 Else 
       MSComm1.PortOpen = True 
       ComOpen.Caption = "关闭串口" 
       Shape1.FillColor = &HFF 
 End If 
 Exit Sub 
uerror: 
    msg$ = "无效端口号"          '错误显示 
    Title$ = "串口调试助手" 
    X = MsgBox(msg$, 48, Title$)  '48标示显示警告图标 
End Sub 
 
Private Sub MSComm1_OnComm() 
    Dim BytReceived() As Byte 
    Dim strBuff As String 
    Dim i As Integer 
    Select Case MSComm1.CommEvent    '事件发生 
        Case 2 
            Cls 
            MSComm1.InputLen = 0     '读入缓冲区全部内容 
            strBuff = MSComm1.Input  '读入到缓冲区 
            Label10.Caption = Label10.Caption + Len(strBuff) '接收计数 
         If MSComm1.InputMode = comInputModeBinary Then 
            BytReceived() = strBuff  '如果是二进制接收模式则进行数据处理,否则直接显示字符串 
            For i = 0 To UBound(BytReceived) 
                If Len(Hex(BytReceived(i))) = 1 Then 
                    strData = strData & "0" & Hex(BytReceived(i)) & " " '如果只有一个字符,则前补0,如F显示0F,最后补空格 
                Else                                                    '方便显示观察如: 00 0F FE 
                    strData = strData & Hex(BytReceived(i)) & " " 
                End If 
            Next 
            TextReceive = TextReceive & strData 
            strData = "" 
        Else 
            TextReceive = TextReceive & strBuff 
        End If 
    End Select 
End Sub 
Private Sub ComSend1_Click()   '手动发送 
Dim Temp(0) As Byte 
Dim strBuff As String 
If Option1.Value = True Then '如果显示16进制发送则进行16进制处理 ,这里只发送一个 
   Temp(0) = "&H" & TextSend 
   MSComm1.Output = Temp  '发送一个16进制 
Else 
     strBuff = TextSend 
End If 
If MSComm1.PortOpen = False Then 
   MsgBox "请打开串口" 
End If 
On Error GoTo uerror 
MSComm1.Output = strBuff 
Label11.Caption = Label11.Caption + Len(strBuff)  '发送计数 
uerror: 
End Sub 
Private Sub ComSend2_Click() 
If ComSend2.Caption = "自动发送" Then 
    ComSend2.Caption = "关闭自动发送" 
    Timer1.Interval = TextTime.Text 
    Timer1.Enabled = True 
Else 
    ComSend2.Caption = "自动发送" 
    Timer1.Enabled = False 
End If 
End Sub 
Private Sub ComClean1_Click() 
TextSend.Text = ""                      '清空发送窗口 
End Sub 
Private Sub Option3_Click() 
MSComm1.InputMode = comInputModeBinary  '选择接收方式 
End Sub 
Private Sub Option4_Click() 
MSComm1.InputMode = comInputModeText   '选择接收方式 
End Sub 
Private Sub Timer1_Timer() 
Call ComSend1_Click      '定时调用手动发送 
End Sub 
Private Sub Timer2_Timer() 
If Combo3 = "无None" Then 
   MSComm1.Settings = Str(Combo2) + "N" + Str(Combo4) + Str(Combo5) 
ElseIf Combo3 = "奇Odd" Then 
   MSComm1.Settings = Str(Combo2) + "O" + Str(Combo4) + Str(Combo5) 
ElseIf Combo3 = "偶Even" Then 
   MSComm1.Settings = Str(Combo2) + "E" + Str(Combo4) + Str(Combo5) 
End If 
End Sub 
Private Sub Combo1_Click() 
If MSComm1.PortOpen = True Then  '如果串口打开先关闭后再进行其他操作 
   MSComm1.PortOpen = False 
 End If 
MSComm1.CommPort = Combo1.ListIndex + 1 '读取com口号 
End Sub 
Private Sub ComClean3_Click() 
Label10.Caption = 0 
Label11.Caption = 0 
End Sub 
Private Sub ComClean2_Click() 
TextReceive.Text = ""   '接收窗口 
End Sub 

2018无需申请注册送58体验金