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

📄 frmai.frm

📁 通过vb与鸿格7000系列模块进行通讯
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Left            =   240
         TabIndex        =   30
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "TimeOut"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         Left            =   270
         TabIndex        =   12
         Top             =   720
         Width           =   990
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Step 5: Read AI"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   990
      Left            =   4320
      TabIndex        =   7
      Top             =   2910
      Width           =   4275
      Begin VB.CommandButton cmdRead 
         Caption         =   "Read"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   420
         Left            =   135
         TabIndex        =   9
         Top             =   330
         Width           =   1545
      End
      Begin VB.TextBox txtRead 
         Enabled         =   0   'False
         Height          =   375
         Left            =   1965
         TabIndex        =   8
         Top             =   330
         Width           =   2085
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Step 1: Open COM Port"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1575
      Left            =   30
      TabIndex        =   1
      Top             =   60
      Width           =   4245
      Begin VB.CommandButton cmdClose 
         Caption         =   "Close COM"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   2280
         TabIndex        =   27
         Top             =   960
         Width           =   1455
      End
      Begin VB.CommandButton cmdOpen 
         Caption         =   "Open COM Port"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   480
         Left            =   240
         TabIndex        =   6
         Top             =   945
         Width           =   1665
      End
      Begin VB.TextBox txtPort 
         Height          =   330
         Left            =   990
         TabIndex        =   3
         Text            =   "1"
         Top             =   450
         Width           =   570
      End
      Begin VB.TextBox txtBaudrate 
         Height          =   390
         Left            =   2805
         TabIndex        =   2
         Text            =   "9600"
         Top             =   420
         Width           =   960
      End
      Begin VB.Label Label1 
         Caption         =   "COM Port"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   90
         TabIndex        =   5
         Top             =   480
         Width           =   810
      End
      Begin VB.Label Label2 
         Caption         =   "BaudRate"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         Left            =   1830
         TabIndex        =   4
         Top             =   510
         Width           =   825
      End
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   450
      Left            =   3660
      TabIndex        =   0
      Top             =   4140
      Width           =   1725
   End
End
Attribute VB_Name = "frmAI"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit
Dim iPort As Integer
Dim iCheckSum As Integer
Dim iTimeOut As Integer
Dim lBaudrate As Long

Private Sub cmdClose_Click()
    Me.Caption = " COM " + Str(iPort) + " Closed !"
    Close_Com (iPort)
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub cmdOpen_Click()
Dim iRet As Integer
    iPort = CInt(txtPort.Text)
    lBaudrate = CLng(txtBaudrate.Text)
    iRet = Open_Com(iPort, lBaudrate, 8, 0, 0)
    If iRet Then
        MsgBox "Open COM Port Error:" + Str(iRet), vbCritical, "Open COM"
    Else
        Me.Caption = " COM " + Str(iPort) + " Opened !"
    End If
    
End Sub

Private Sub cmdRead_Click()
Dim iRet As Integer
Dim iVal As Integer
Dim fVal As Single
Dim iSlot As Integer
Dim iTotal As Integer
Dim iCh As Integer
Dim iAddress As Integer
    iAddress = CInt(txtAddress.Text)
    If optCheck(0).Value = True Then
        iCheckSum = 0
    Else
        iCheckSum = 1
    End If
    iTimeOut = CInt(txtTimeout.Text)
    If optModule(0).Value = True Then
        iSlot = -1
    Else
        iSlot = CInt(txtSlot.Text)
    End If
    iCh = CInt(txtCh.Text)
    iTotal = CInt(txtTotal.Text)
    
    iRet = DCON_Read_AI(iPort, iAddress, iSlot, iCh, iTotal, iCheckSum, iTimeOut, cboDataformat.ListIndex, fVal, iVal)
    If iRet = 0 Then
        txtRead.Text = Str(fVal)
    ElseIf iRet = 19 Then
        txtRead.Text = Str(fVal)
        Me.Caption = "Under Range" & " Error" + Str(iRet)
    ElseIf iRet = 20 Then
        txtRead.Text = Str(fVal)
        Me.Caption = "Exceed Range" & " Error" + Str(iRet)
    Else
        txtRead.Text = "Error" + Str(iRet)
    End If
End Sub

Private Sub Form_Load()
    cboDataformat.List(0) = "Engineering"
    cboDataformat.List(1) = "Percent"
    cboDataformat.List(2) = "Hex"
    cboDataformat.ListIndex = 0
    
    If optModule(0).Value = True Then
        txtSlot.Enabled = False
        txtSlot.Text = "-1"
    Else
        txtSlot.Enabled = True
        txtSlot.Text = "0"
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Close_Com (iPort)
End Sub

Private Sub optModule_Click(Index As Integer)
    If Index = 0 Then
        txtSlot.Enabled = False
        txtSlot.Text = "-1"
    Else
        txtSlot.Enabled = True
        txtSlot.Text = "0"
    End If
End Sub

⌨️ 快捷键说明

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