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

📄 仪器通信测试系统.vb

📁 一个小巧的通信检测软件
💻 VB
字号:
Option Strict Off
Option Explicit On
Friend Class FormMain
    Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
    Public Sub New()
        MyBase.New()
        If m_vb6FormDefInstance Is Nothing Then
            If m_InitializingDefInstance Then
                m_vb6FormDefInstance = Me
            Else
                Try
                    '对于启动窗体,所创建的第一个实例为默认实例。
                    If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
                        m_vb6FormDefInstance = Me
                    End If
                Catch
                End Try
            End If
        End If
        '此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
    End Sub
    '窗体重写处置,以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器来修改它。
    '不要使用代码编辑器修改它。
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Prob1 As System.Windows.Forms.ProgressBar
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents ButtonImport As System.Windows.Forms.Button
    Friend WithEvents ButtonSave As System.Windows.Forms.Button
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents LabelTest As System.Windows.Forms.Label
    Friend WithEvents ButtonTest As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Public WithEvents MSCommMain As AxMSCommLib.AxMSComm
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FormMain))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.MSCommMain = New AxMSCommLib.AxMSComm
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.Prob1 = New System.Windows.Forms.ProgressBar
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.ButtonImport = New System.Windows.Forms.Button
        Me.ButtonSave = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.LabelTest = New System.Windows.Forms.Label
        Me.ButtonTest = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        CType(Me.MSCommMain, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'MSCommMain
        '
        Me.MSCommMain.Enabled = True
        Me.MSCommMain.Location = New System.Drawing.Point(456, 136)
        Me.MSCommMain.Name = "MSCommMain"
        Me.MSCommMain.OcxState = CType(resources.GetObject("MSCommMain.OcxState"), System.Windows.Forms.AxHost.State)
        Me.MSCommMain.Size = New System.Drawing.Size(38, 38)
        Me.MSCommMain.TabIndex = 0
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.Prob1)
        Me.GroupBox2.Controls.Add(Me.Label2)
        Me.GroupBox2.Controls.Add(Me.Label3)
        Me.GroupBox2.Controls.Add(Me.ButtonImport)
        Me.GroupBox2.Controls.Add(Me.ButtonSave)
        Me.GroupBox2.Location = New System.Drawing.Point(200, 16)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(288, 152)
        Me.GroupBox2.TabIndex = 47
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "GroupBox2"
        '
        'Prob1
        '
        Me.Prob1.Location = New System.Drawing.Point(16, 80)
        Me.Prob1.Name = "Prob1"
        Me.Prob1.Size = New System.Drawing.Size(264, 16)
        Me.Prob1.TabIndex = 41
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.InactiveCaptionText
        Me.Label2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label2.Location = New System.Drawing.Point(16, 32)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 32)
        Me.Label2.TabIndex = 43
        Me.Label2.Text = "记录总数:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.InactiveCaptionText
        Me.Label3.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label3.Location = New System.Drawing.Point(120, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(56, 32)
        Me.Label3.TabIndex = 43
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'ButtonImport
        '
        Me.ButtonImport.Location = New System.Drawing.Point(200, 32)
        Me.ButtonImport.Name = "ButtonImport"
        Me.ButtonImport.Size = New System.Drawing.Size(72, 32)
        Me.ButtonImport.TabIndex = 0
        Me.ButtonImport.Text = "数据导入"
        '
        'ButtonSave
        '
        Me.ButtonSave.Location = New System.Drawing.Point(96, 112)
        Me.ButtonSave.Name = "ButtonSave"
        Me.ButtonSave.Size = New System.Drawing.Size(96, 32)
        Me.ButtonSave.TabIndex = 0
        Me.ButtonSave.Text = "保存数据"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.LabelTest)
        Me.GroupBox1.Controls.Add(Me.ButtonTest)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(176, 152)
        Me.GroupBox1.TabIndex = 46
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "GroupBox1"
        '
        'LabelTest
        '
        Me.LabelTest.BackColor = System.Drawing.SystemColors.InactiveCaptionText
        Me.LabelTest.Font = New System.Drawing.Font("幼圆", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.LabelTest.ForeColor = System.Drawing.Color.Green
        Me.LabelTest.Location = New System.Drawing.Point(24, 32)
        Me.LabelTest.Name = "LabelTest"
        Me.LabelTest.Size = New System.Drawing.Size(128, 56)
        Me.LabelTest.TabIndex = 42
        Me.LabelTest.Text = "Label1"
        Me.LabelTest.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'ButtonTest
        '
        Me.ButtonTest.Location = New System.Drawing.Point(40, 112)
        Me.ButtonTest.Name = "ButtonTest"
        Me.ButtonTest.Size = New System.Drawing.Size(100, 32)
        Me.ButtonTest.TabIndex = 0
        Me.ButtonTest.Text = "通信测试"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Highlight
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(144, 72)
        Me.Label1.TabIndex = 42
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'FormMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(504, 182)
        Me.Controls.Add(Me.MSCommMain)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Location = New System.Drawing.Point(4, 30)
        Me.Name = "FormMain"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "仪器通信测试系统"
        CType(Me.MSCommMain, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
#End Region
#Region "升级支持"
    Private Shared m_vb6FormDefInstance As FormMain
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As FormMain
        Get
            If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
                m_InitializingDefInstance = True
                m_vb6FormDefInstance = New FormMain
                m_InitializingDefInstance = False
            End If
            DefInstance = m_vb6FormDefInstance
        End Get
        Set(ByVal Value As FormMain)
            m_vb6FormDefInstance = Value
        End Set
    End Property
#End Region

    Dim tmpstr As String
    Dim sendbuf As String
    Dim MSC As AxMSCommLib.AxMSComm
    Dim revbuf As String
    Dim j As Integer
    Dim i As Integer
    Dim tf As Boolean
    Dim jq1ok As Boolean
    Private Sub Comm(ByVal MSC As AxMSCommLib.AxMSComm, ByVal strMachineName As String)

        Dim j As Integer
        Dim revbuf As String
        Dim i As Integer
        Dim tf As Boolean
        Dim sendbuf As String
        Dim jq1ok As Boolean

        tf = False
        i = 0
        sendbuf = "R"
        MSC.Output = sendbuf

        'If MSC.InBufferCount Then MsgBox("OK")

        Do While Not tf
            'DoEvents()
            If MSC.InBufferCount > 0 Then
                If MSC.InBufferCount <= MSC.InBufferSize Then
                    revbuf = MSC.Input
                Else
                    MsgBox("数据溢出")
                End If

                tf = True
                MSC.InBufferCount = 0
            Else
                i = i + 1
                If i >= 3 Then
                    LabelTest.ForeColor = System.Drawing.Color.Red
                    LabelTest.Text = strMachineName & "通信未能建立!!!"
                    Me.Refresh()
                    jq1ok = False
                    j = 0
                    Exit Sub
                End If
            End If
        Loop

        tmpstr = revbuf

        'S57.51$62.69$00000$62.41$1.684$E
        'If Mid(tmpstr, 1, 1) <> "S" Or Microsoft.VisualBasic.Right(tmpstr, 1) <> "E" Or Mid(tmpstr, 1, 1) <> "O" Then
        'labeltest.ForeColor = System.Drawing.Color.Red
        'labeltest.Text = strMachineName & "通信未能建立!!!"
        'Me.Refresh()
        'jq1ok = False
        'j = 0
        'Else
        ' If Mid(tmpstr, 10, 1) <> "$" Or Mid(tmpstr, 16, 1) <> "$" Or Mid(tmpstr, 22, 1) <> "$" Or Mid(tmpstr, 28, 1) <> "$" Or Mid(tmpstr, 34, 1) <> "$" Then
        '  labeltest.ForeColor = System.Drawing.Color.Red
        '  labeltest.Text = strMachineName & "通信未能建立!!!"
        ' Me.Refresh()
        'jq1ok = False
        'j = 0
        'Else
        ' startdata1(0) = Mid(tmpstr, 2, 5)
        'startdata1(1) = Mid(tmpstr, 8, 5)
        'startdata1(2) = Mid(tmpstr, 14, 5)
        'startdata1(3) = Mid(tmpstr, 20, 5)
        'startdata1(4) = Mid(tmpstr, 26, 5)
        'labeltest.ForeColor = System.Drawing.Color.Blue
        'labeltest.Text = strMachineName & "通信正常!!!"
        'jq1ok = True
        'j = 1
        'jqnum = jqnum + 1
        ' End If
        'End If
        'Me.Refresh()

    End Sub

    Private Sub FormLogin_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        MSCommMain.Dispose()
    End Sub


    Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTest.Click
        tf = False
        i = 0
        sendbuf = "R"

        Do While Not tf
            'DoEvents()
            If MSC.InBufferCount > 0 Then
                If MSC.InBufferCount <= MSC.InBufferSize Then
                    revbuf = MSC.Input
                Else
                    MsgBox("数据溢出")
                End If

                tf = True
                MSC.InBufferCount = 0
            Else
                i = i + 1
                If i >= 3 Then
                    LabelTest.ForeColor = System.Drawing.Color.Red
                    LabelTest.Text = "通信未能建立!!!"
                    Me.Refresh()
                    jq1ok = False
                    j = 0
                    Exit Sub
                End If
            End If
        Loop
        If Mid(tmpstr, 1, 2) = "OK" Then
            LabelTest.ForeColor = System.Drawing.Color.Blue
            LabelTest.Text = "通信成功!!!"
        Else
            LabelTest.ForeColor = System.Drawing.Color.Red
            LabelTest.Text = "很遗憾,通信未能建立!!!"
        End If
        Me.Refresh()
    End Sub
End Class

⌨️ 快捷键说明

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