⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vb的工作平台.txt

📁 一个用VB编写的通信平台
💻 TXT
📖 第 1 页 / 共 2 页
字号:
Private Sub Form_Load()
connectsuccess = False
ordertype = True
n = 1
timebln = True
End Sub

Private Sub sblx_Click()
Call showinformation(3, "设备类型")
End Sub
Private Sub azdd_Click()
Call showinformation(1, "安装地点")
End Sub

Private Sub cjbs_Click()
Call showinformation(2, "厂家标识")
End Sub

Private Sub bbh_Click()
Call showinformation(4, "版本号")
End Sub
Private Sub czbz_Click()
Dim response As Integer '用来显示帮助等操作步骤
response = MsgBox("操作步骤" & Chr(13) & "操作步骤" & Chr(13) & "操作步骤", vbOKOnly, "操作步骤")
End Sub
Sub showinformation(n As Integer, strtitle As String)
Dim response As String
Dim k As Integer

Open "D:\Telnumber.txt" For Input As #1
    For k = 1 To n
       Line Input #1, strinformation
    Next k
Close #1
    response = MsgBox(strinformation, vbOKOnly, strtitle)
End Sub

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
'该段代码用来发送查询命令
Private Sub Cmdquery_Click()
  Dim n As Integer
  Dim i As Integer
  Dim sendmessage As order
  
  ordertype = "order_quary"
  ReDim quary_answer(4)
  timenum = 0
  n = 0
  timebln = True
  
  If ((Not MSComm1.PortOpen) And telnum.Text = "") Then
     warning = MsgBox("请打开串口并输入电话号码", vbOKOnly, "注意")
     Exit Sub
  ElseIf (Not MSComm1.PortOpen) Then
     warning = MsgBox("请打开串口", vbOKOnly, "注意") '如果串口没打开请打开
     Exit Sub
  ElseIf telnum.Text = "" Then
     warning = MsgBox("请输入电话号码", vbOKOnly, "注意")
     Exit Sub
  End If
  
  'If connectsuccess = False Then
  '     warning = MsgBox("连接不成功,请再次连接", vbOKOnly, "注意")
  '    Exit Sub
  'End If
  
  For i = 0 To 4
    If Chekquary(i).Value = 1 Then n = n + 1
  Next i

  For i = 0 To 4
      If Chekquary(i).Value = 1 Then
        Select Case i
           Case 0
               sendmessage.minglingbianhao = &H20
           Case 1
               sendmessage.minglingbianhao = &H10
           Case 2
               sendmessage.minglingbianhao = &H21
           Case 3
               sendmessage.minglingbianhao = &H23
           Case 4
               sendmessage.minglingbianhao = &H24
         End Select
        Call Fnsendmessage(sendmessage, i, n)
      End If
  Next i
End Sub

'该段代码用来发送设置命令
Private Sub Cmdset_Click()
  Dim i As Integer
  Dim sendmessage As order
  
  ordertype = "order_set" '判断命令类型
  ReDim quary_answer(4)
  timenum = 0
  n = 0
  timebln = True
  
  If ((Not MSComm1.PortOpen) And telnum.Text = "") Then
     warning = MsgBox("请打开串口并输入电话号码", vbOKOnly, "注意")
     Exit Sub
  ElseIf (Not MSComm1.PortOpen) Then
     warning = MsgBox("请打开串口", vbOKOnly, "注意") '如果串口没打开请打开
     Exit Sub
  ElseIf telnum.Text = "" Then
     warning = MsgBox("请输入电话号码", vbOKOnly, "注意")
     Exit Sub
  ElseIf telnum.Text = "" Then
  End If
  
  'If connectsuccess = False Then
  '     warning = MsgBox("连接不成功,请再次连接", vbOKOnly, "注意")
  '     Exit Sub
  'End If
  
  For i = 0 To 4
    If Chekset(i).Value = 1 Then n = n + 1
  Next i

  For i = 0 To 4
      If Chekset(i).Value = 1 Then
        Select Case i
           Case 0
               sendmessage.minglingbianhao = &H30 '设置设备系统编号
               sendmessage.minglingchangdu = 10
               If Txtset(0).Text = "" Then
               warning = MsgBox("请输入设备系统编号", vbOKOnly, "注意")
               Exit Sub
               End If
               sendmessage.minglingti = Trim(Txtset(0).Text)
           Case 1
               sendmessage.minglingbianhao = &H31 '设置远程通信参数
               sendmessage.minglingchangdu = 50
               
               If Txtset(1).Text = "" Then
               warning = MsgBox("请输入远程通信参数", vbOKOnly, "注意")
                  Exit Sub
               End If
               
               Dim strchr As String
               Dim m As Integer
                   strchr = Chr(32)
                   For m = 1 To 30
                      strchr = strchr & Chr(32)
                   Next m
               sendmessage.minglingti = strchr & Trim(Txtset(2).Text) & Chr(1) & "0" & "0" & "0" & "0"
               
           Case 2
               sendmessage.minglingbianhao = &H32 '设置设备主动告警使能标志命令回应
               sendmessage.minglingchangdu = 2

               sendmessage.minglingti = CStr(&H94) & CStr(&H22) & "0" & "0"
               
           Case 3
               sendmessage.minglingbianhao = &H33 '设置门限值
               sendmessage.minglingchangdu = 10
               
               If Txtset(3).Text = "" Then
               warning = MsgBox("请输入远程通信参数", vbOKOnly, "注意")
               Exit Sub
               End If
               
               sendmessage.minglingti = Trim(Txtset(3).Text)
           Case 4
               sendmessage.minglingbianhao = &H35 '设置基站ID/直放站ID
               sendmessage.minglingchangdu = 20
               
               If Txtset(4).Text = "" Then
               warning = MsgBox("请输入远程通信参数", vbOKOnly, "注意")
               Exit Sub
               End If
               
               sendmessage.minglingti = Trim(Txtset(4).Text)
               
         End Select
      Call Fnsendmessage(sendmessage, i, n)
      End If
  Next i
   Timer1.Enabled = True
End Sub

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'如果号码有误可以取消请求
Private Sub Cmdquxiao_Click()
  Timer1.Enabled = False
  Cmdconnect.Caption = "建立连接"
End Sub

'用来判断消息返回是否超时
Private Sub Timer1_Timer()
  Dim T_timer As Long
  timenum = timenum + 1
  T_timer = timenum * 100
  If T_timer >= 1800 * n Then
    If ordertype = "order_connect" Then
       Dim response As Integer
       Cmdconnect.Caption = "建立连接"
       Timer1.Enabled = False
       response = MsgBox("连接失败", vbOKOnly, "警告") '超时退出
       timebln = False '判断是否超时,超时设为False
       timenum = 0
       Exit Sub
    Else
       Call showmessage
       Timer1.Enabled = False
       timebln = True '判断是否超时,超时设为False
    End If
  End If
End Sub
'打开和关闭串口
Private Sub Command1_Click()
Dim StringCom As String
StringCom = Combo1.Text
timebln = True
If Command1.Caption = "打开串口" Then
  MSComm1.CommPort = Val(Right(Trim(StringCom), 1))
  MSComm1.Settings = "9600,N,8,1"
  MSComm1.InputLen = 0
  MSComm1.SThreshold = 0
  MSComm1.RThreshold = 1
  MSComm1.PortOpen = True
  Command1.Caption = "关闭串口"
  MSComm1.Output = "AT+CMGD" & "=" & "1,4" & Chr(13)
Else
  MSComm1.PortOpen = False
  Command1.Caption = "打开串口"
End If
End Sub
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'选择串口,关闭前一串口的同时打开选择的串口
Private Sub Combo1_Click()
Dim StringCom As String
StringCom = Combo1.Text
If Command1.Caption = "关闭串口" Then
  MSComm1.PortOpen = False
  MSComm1.CommPort = Val(Right(Trim(StringCom), 1))
  MSComm1.Settings = "9600,N,8,1"
  MSComm1.InputLen = 0
  MSComm1.SThreshold = 0
  MSComm1.RThreshold = 1
  MSComm1.PortOpen = True
  MSComm1.Output = "AT+CMGD" & "=" & "1,4" & Chr(13)
Else
End If
End Sub
'输入电话号码后请求连接
Private Sub Cmdconnect_Click()
Dim n As Integer
Dim telnumber As String
Dim responce As String
Dim warning As Integer

ordertype = "order_connect"

timebln = True
  If ((Not MSComm1.PortOpen) And telnum.Text = "") Then
     warning = MsgBox("请打开串口并输入电话号码", vbOKOnly, "注意")
     Exit Sub
  ElseIf (Not MSComm1.PortOpen) Then
     warning = MsgBox("请打开串口", vbOKOnly, "注意") '如果串口没打开请打开
     Exit Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -