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

📄 通讯.frm

📁 vb全站仪数据通讯
💻 FRM
📖 第 1 页 / 共 3 页
字号:
      BeginProperty Font 
         Name            =   "隶书"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   210
      TabIndex        =   8
      Top             =   1485
      Width           =   3870
      Begin VB.OptionButton Option12 
         Caption         =   "8"
         Height          =   420
         Left            =   300
         TabIndex        =   12
         Top             =   345
         Value           =   -1  'True
         Width           =   615
      End
      Begin VB.OptionButton Option11 
         Caption         =   "7"
         Height          =   375
         Left            =   1185
         TabIndex        =   11
         Top             =   345
         Width           =   615
      End
      Begin VB.OptionButton Option10 
         Caption         =   "6"
         Height          =   375
         Left            =   2145
         TabIndex        =   10
         Top             =   345
         Width           =   615
      End
      Begin VB.OptionButton Option9 
         Caption         =   "5"
         Height          =   375
         Left            =   3030
         TabIndex        =   9
         Top             =   345
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "波特率设定"
      BeginProperty Font 
         Name            =   "隶书"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1215
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   8475
      Begin VB.OptionButton Option7 
         Caption         =   "19200"
         Height          =   255
         Left            =   360
         TabIndex        =   7
         Top             =   480
         Width           =   855
      End
      Begin VB.OptionButton Option6 
         Caption         =   "300"
         Height          =   255
         Left            =   7440
         TabIndex        =   6
         Top             =   480
         Width           =   615
      End
      Begin VB.OptionButton Option5 
         Caption         =   "600"
         Height          =   255
         Left            =   6360
         TabIndex        =   5
         Top             =   480
         Width           =   615
      End
      Begin VB.OptionButton Option4 
         Caption         =   "1200"
         Height          =   255
         Left            =   5280
         TabIndex        =   4
         Top             =   480
         Value           =   -1  'True
         Width           =   735
      End
      Begin VB.OptionButton Option3 
         Caption         =   "2400"
         Height          =   255
         Left            =   4200
         TabIndex        =   3
         Top             =   480
         Width           =   735
      End
      Begin VB.OptionButton Option2 
         Caption         =   "4800"
         Height          =   255
         Left            =   3000
         TabIndex        =   2
         Top             =   480
         Width           =   735
      End
      Begin VB.OptionButton Option1 
         Caption         =   "9600"
         BeginProperty Font 
            Name            =   "隶书"
            Size            =   10.5
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   1680
         TabIndex        =   1
         Top             =   360
         Width           =   735
      End
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   2160
      Top             =   6240
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      InputLen        =   1024
      RThreshold      =   20
      RTSEnable       =   -1  'True
      SThreshold      =   10
      EOFEnable       =   -1  'True
   End
   Begin VB.Label Label1 
      Caption         =   "文件选择"
      BeginProperty Font 
         Name            =   "隶书"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   735
      TabIndex        =   33
      Top             =   6270
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim 波特率 As String
Dim 数据位 As String
Dim 奇偶校验 As String
Dim 停止位 As String
Dim 串行口 As Integer
Dim 串行口1 As Integer
Dim 结束符 As String


Dim 交握协议 As Integer
Dim Ls As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Dim Ls1  As Integer
Option Explicit
Public Sub 通讯参数()




    
    If Option1.Value = True Then
      
      波特率 = "9600"
      
    ElseIf Option2.Value = True Then
    
     波特率 = "4800"
    
    ElseIf Option3.Value = True Then
    
     波特率 = "2400"
     
    ElseIf Option4.Value = True Then
    
     波特率 = "1200"
     
    ElseIf Option5.Value = True Then
    
     波特率 = "600"
     
    ElseIf Option6.Value = True Then
    
     波特率 = "300"
     
    ElseIf Option7.Value = True Then
    
     波特率 = "19200"
     
    End If
    
    
   If Option9.Value = True Then
    
     数据位 = "5"
     
    ElseIf Option10.Value = True Then
    
     数据位 = "6"
     
    ElseIf Option11.Value = True Then
    
     数据位 = "7"
     
    ElseIf Option12.Value = True Then
    
     数据位 = "8"
     
   End If
    
    
     
    If Option8.Value = True Then
    
     奇偶校验 = "E"
     
    ElseIf Option13.Value = True Then
    
     奇偶校验 = "O"
     
    ElseIf Option14.Value = True Then
    
     奇偶校验 = "N"
     
    
   End If
  
    
   If Option15.Value = True Then
    
     停止位 = "1"
     
    ElseIf Option16.Value = True Then
    
     停止位 = "1.5"
     
    ElseIf Option17.Value = True Then
    
     停止位 = "2"
     
    End If
    
    '===
    If Option22.Value = True Then
    
     串行口 = 1
     
    ElseIf Option23.Value = True Then
    
     串行口 = 2
     
    ElseIf Option24.Value = True Then
    
     串行口 = 3
     
    ElseIf 串行口1 > 0 Then
    
     Option22.Value = False

     Option23.Value = False
     
     Option24.Value = False
     
     串行口 = 串行口1
     
    End If
    
    
    
    If Option18.Value = True Then
    
     交握协议 = 0
     
    ElseIf Option19.Value = True Then
    
     交握协议 = 1
     
    ElseIf Option20.Value = True Then
    
     交握协议 = 2
     
    ElseIf Option21.Value = True Then
    
     交握协议 = 3
    
    End If
    
   
   
   
   
   If Option26.Value = True Then
    
     结束符 = Chr(26) '& vbCrLf
     
    ElseIf Option27.Value = True Then
    
     结束符 = "OK" '& vbCrLf
     
    End If

    
   MSComm1.Settings = 波特率 & "," & 奇偶校验 & "," & 数据位 & "," & 停止位
   MSComm1.CommPort = 串行口
   MSComm1.Handshaking = 交握协议

End Sub



Private Sub Command1_Click()

Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Dim Buffer As String

Dim Ls1 As Integer
Dim ls2 As Long
Dim Ls3 As String
'Open "COM1:" For Input As #2

Open Text1.Text For Output As #3


Ls1 = "1"


通讯参数

MSComm1.PortOpen = True

MSComm1.InputLen = 0

Text2.FontSize = 20

Text2.Text = "计算机已准备好,正在等待来自于COM" & 串行口 & "的数据!"

Cls

Do Until Len(MSComm1.Input) > 0

Buffer$ = Buffer$ & MSComm1.Input

Loop
   
Text2.FontSize = 10
   
Text2.Text = "正在接收数据请稍候。。。。。。。。"
Cls
   Do
      'DoEvents
   Buffer$ = Buffer$ & MSComm1.Input
               Ls1 = 999
           Do Until Ls1 = 0
        
                Ls1 = InStr(Buffer$, vbCrLf)
          
                Text2.Text = Mid(Buffer$, 1, Ls1)
                
                'Text2.Text = Trim(Text2.Text)
               ' Cls
                If Ls1 = 0 Then
                  
                  
                Else
                  Cls
                  Text2.Text = Text2.Text
                  Cls
                  Print #3, Text2.Text
                End If
                'Buffer$ = Trim(Buffer$)
                Buffer$ = Mid(Buffer$, Ls1 + 1)
        
        
        Loop

⌨️ 快捷键说明

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