frmrun.frm

来自「16 relay output channels and 16 isolated」· FRM 代码 · 共 728 行 · 第 1/2 页

FRM
728
字号
      Caption         =   "Sampling Rate"
      ForeColor       =   &H80000008&
      Height          =   855
      Left            =   240
      TabIndex        =   6
      Top             =   2880
      Width           =   5295
      Begin VB.TextBox txtSample 
         Height          =   285
         Left            =   2280
         Locked          =   -1  'True
         TabIndex        =   8
         Text            =   "txtSample"
         Top             =   600
         Width           =   615
      End
      Begin VB.HScrollBar hscrlFreq 
         Height          =   255
         LargeChange     =   10
         Left            =   120
         Max             =   100
         TabIndex        =   7
         Top             =   240
         Value           =   10
         Width           =   5055
      End
      Begin VB.Label labFreqHigh 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "10 Hz"
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   4560
         TabIndex        =   1
         Top             =   480
         Width           =   615
      End
      Begin VB.Label labFrequencyLow 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "0 (Stop)"
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   120
         TabIndex        =   2
         Top             =   480
         Width           =   855
      End
   End
   Begin VB.Timer tmrRead 
      Left            =   120
      Top             =   960
   End
   Begin VB.CommandButton cmdRead 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "&Read one data"
      Height          =   495
      Left            =   840
      TabIndex        =   5
      Top             =   3960
      Width           =   1455
   End
   Begin VB.TextBox txtVoltRead 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   14.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   450
      Index           =   0
      Left            =   600
      Locked          =   -1  'True
      TabIndex        =   3
      Text            =   "0.00"
      Top             =   840
      Width           =   975
   End
   Begin VB.CommandButton cmdExit 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "E&xit"
      Height          =   495
      Left            =   3240
      TabIndex        =   0
      Top             =   3960
      Width           =   1455
   End
   Begin VB.Label labChan 
      Alignment       =   2  'Center
      BackColor       =   &H00C0C0C0&
      Caption         =   "12 - 15"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   3
      Left            =   4200
      TabIndex        =   27
      Top             =   480
      Width           =   975
   End
   Begin VB.Label labChan 
      Alignment       =   2  'Center
      BackColor       =   &H00C0C0C0&
      Caption         =   "8 - 11"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   2
      Left            =   3000
      TabIndex        =   26
      Top             =   480
      Width           =   975
   End
   Begin VB.Label labChan 
      Alignment       =   2  'Center
      BackColor       =   &H00C0C0C0&
      Caption         =   "4 - 7"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   1
      Left            =   1800
      TabIndex        =   25
      Top             =   480
      Width           =   975
   End
   Begin VB.Label labChan 
      Alignment       =   2  'Center
      BackColor       =   &H00C0C0C0&
      Caption         =   "0 - 3"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   0
      Left            =   600
      TabIndex        =   24
      Top             =   480
      Width           =   975
   End
   Begin VB.Shape shapLed 
      BorderColor     =   &H000000FF&
      BorderStyle     =   0  'Transparent
      FillColor       =   &H00808080&
      FillStyle       =   0  'Solid
      Height          =   255
      Left            =   240
      Shape           =   3  'Circle
      Top             =   120
      Width           =   255
   End
   Begin VB.Label labVolt 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Voltage read"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   600
      TabIndex        =   4
      Top             =   120
      Width           =   1215
   End
End
Attribute VB_Name = "frmRun"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim Response As Integer
Dim ErrCount As Integer
Dim fVoltage(0 To MaxChannels) As Single
Dim iStart, iStop, iCur As Integer

Private Sub cmdExit_Click()
    frmRun.Hide
    Unload Me
    frmDevSel.Show
    frmDevSel.cmdExit.SetFocus
End Sub

Private Sub cmdPost_Click()
    iCur = iCur + 1
    UpDateTitle
    If (iCur + 1) > iStop Then
        cmdPost.Enabled = False
    End If
    cmdPre.Enabled = True
End Sub

Private Sub cmdPre_Click()
    iCur = iCur - 1
    UpDateTitle
    If (iCur - 1) < iStart Then
        cmdPre.Enabled = False
    End If
    cmdPost.Enabled = True
End Sub

Private Sub cmdRead_Click()
  tmrRead.Enabled = False

  shapLed.FillColor = QBColor(12)
  
  ptMAIVoltageIn.NumChan = ptMAIConfig.NumChan
  ptMAIVoltageIn.StartChan = ptMAIConfig.StartChan
  ptMAIVoltageIn.GainArray = DRV_GetAddress(usGainCode(ptMAIConfig.StartChan))
  ptMAIVoltageIn.TrigMode = AiCtrMode
  
  ' if MAIVoltageIn.Voltage doesn't point to a array, then it would be nil.
  ptMAIVoltageIn.VoltageArray = DRV_GetAddress(fVoltage(ptMAIConfig.StartChan))

  ErrCde = DRV_MAIVoltageIn(DeviceHandle, ptMAIVoltageIn)
  If (ErrCde <> 0) Then
       ErrCount = ErrCount + 1
       If (ErrCount > 2) Then
          Unload frmRun
          frmDevSel.cmdExit.SetFocus
       Else
          DRV_GetErrorMessage ErrCde, szErrMsg
          Response = MsgBox(szErrMsg, vbOKOnly, "Error!!")
          Exit Sub
       End If
  End If

  UpDateValue
End Sub

Private Sub cmdRead_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    shapLed.FillColor = QBColor(12)
End Sub

Private Sub Form_Load()
Dim i As Integer
  ErrCount = 0
  hscrlFreq_Change
  
  iStart = usStartChan \ 16
  iStop = (usStartChan + usNumChan - 1) \ 16
  iCur = iStart
  
  If (iCur + 1) > iStop Then
    cmdPost.Enabled = False
  End If
  If (iCur - 1) < iStart Then
    cmdPre.Enabled = False
  End If
  
  For i = 0 To MaxChannels
    fVoltage(i) = 0
  Next
  UpDateTitle
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Unload Me
    frmDevSel.Show
End Sub

Private Sub hscrlFreq_Change()
    If hscrlFreq.value = 0 Then
        tmrRead.Interval = 0
    Else
        tmrRead.Interval = 10000 / hscrlFreq.value
    End If
    
    txtSample.Text = Format((hscrlFreq.value / 10), "###0.00")
    ' "Read One Shot" would disable the "trmREAD" Timer,
    ' so it need to enable here.
    tmrRead.Enabled = True
    tmrLed.Enabled = True
End Sub

Private Sub tmrLed_Timer()
    shapLed.FillColor = QBColor(8)
End Sub

Private Sub tmrRead_Timer()
  shapLed.FillColor = QBColor(12)
  
  
  ptMAIVoltageIn.NumChan = ptMAIConfig.NumChan
  ptMAIVoltageIn.StartChan = ptMAIConfig.StartChan

  ptMAIVoltageIn.GainArray = DRV_GetAddress(usGainCode(ptMAIConfig.StartChan))
  ptMAIVoltageIn.TrigMode = AiCtrMode
  
  ' if MAIVoltageIn.Voltage doesn't point to a array, then it would be nil.
  ptMAIVoltageIn.VoltageArray = DRV_GetAddress(fVoltage(ptMAIConfig.StartChan))

  ErrCde = DRV_MAIVoltageIn(DeviceHandle, ptMAIVoltageIn)
  If (ErrCde <> 0) Then
       ErrCount = ErrCount + 1
       If (ErrCount > 2) Then
          Unload frmRun
          frmDevSel.cmdExit.SetFocus
       Else
          DRV_GetErrorMessage ErrCde, szErrMsg
          Response = MsgBox(szErrMsg, vbOKOnly, "Error!!")
          Exit Sub
       End If
  End If
 
  UpDateValue
End Sub

Private Sub UpDateValue()
    Dim i, iPos As Integer
    
    ' Since the output box is too small to display all the digits
    ' of the input voltage, so it must use to format to get better
    ' display.
    iPos = iCur * 16
    For i = iPos To iPos + 15
        txtVoltRead(i - iPos).Text = Format(fVoltage(i), "###0.000")
    Next i
End Sub

Private Sub UpDateTitle()
    Dim iPos As Integer
    
    iPos = iCur * 16
    labChan(0).Caption = Format(iPos, "0") & " - " & Format(iPos + 3, "0")
    labChan(1).Caption = Format(iPos + 4, "0") & " - " & Format(iPos + 7, "0")
    labChan(2).Caption = Format(iPos + 8, "0") & " - " & Format(iPos + 11, "0")
    labChan(3).Caption = Format(iPos + 12, "0") & " - " & Format(iPos + 15, "0")
End Sub

⌨️ 快捷键说明

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