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

📄 frminit.frm

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 FRM
📖 第 1 页 / 共 2 页
字号:
    Next i
    frmConditions.EnableItems iStart, iStop, True   'Enable selection
    
    'Start the selection
    frmConditions.Show 1
    
End Sub


Private Sub butConvert_Click()
Dim lErrCde As Long
Dim lIntBufPtr As Long
Dim ptIntStart As PT_FAIIntWatchdogStart
Dim iGainCode(0 To 15) As Integer
Dim iCondition(0 To 15) As Integer
Dim ptTrigLevel(0 To 15) As TRIGLEVEL
Dim i, j As Integer
    
    'Open device
    lErrCde = DRV_DeviceOpen(devicelist(lstDevices.ListIndex).dwDeviceNum, ghDev)
    If DoesErr(lErrCde) Then Exit Sub
    
    'Allocate global locked bnuffer for INT transfering
    giConvCount = Val(editDataCounts.Text)
    ReDim giIntBuf(giConvCount)
    lIntBufPtr = DRV_GetAddress(giIntBuf(0))
    If lIntBufPtr = 0 Then
        lErrCde = MsgBox("Allocate memory for INT transfering failure.", "Error!!", 0)
        DRV_DeviceClose (ghDev)
        Exit Sub
    End If
    
    'Get Gain, Condition & Level setting
    j = cmbStartChl.ListIndex
    For i = 0 To cmbChlCount.ListIndex
        'Make Gain code list
        iGainCode(i) = gDevFeature.glGainList(giGainCode(j)).usGainCde

        'Make Condition list
        iCondition(i) = giCondition(j)

        'Make Level list
        ptTrigLevel(i).fLow = gTrigLevel(j).fLow
        ptTrigLevel(i).fHigh = gTrigLevel(j).fHigh
        
        'Next one
        j = j + 1
    Next i

    'Configure for watchdog INT transfering
    gWatchdogCfg.TrigMode = cmbAcqType.ListIndex + 1
    gWatchdogCfg.NumChans = cmbChlCount.ListIndex + 1
    gWatchdogCfg.StartChan = cmbStartChl.ListIndex
    gWatchdogCfg.GainList = DRV_GetAddress(iGainCode(0))
    gWatchdogCfg.CondList = DRV_GetAddress(iCondition(0))
    gWatchdogCfg.LevelList = DRV_GetAddress(ptTrigLevel(0))
    
    lErrCde = DRV_FAIWatchdogConfig(ghDev, gWatchdogCfg)
    If DoesErr(lErrCde) = 1 Then
        ReDim glIntBuf(0)
        DRV_DeviceClose (ghDev)
        Exit Sub
    End If

    'Start Watch Dog INT transfer
    ptIntStart.TrigSrc = radExtTrig.value       'Ext trig mode
    ptIntStart.SampleRate = Val(editSpeed.Text)
    ptIntStart.Count = giConvCount
    ptIntStart.cyclic = chkCyclic.value
    ptIntStart.IntrCount = Val(editCountEvent.Text)
    ptIntStart.buffer = lIntBufPtr
    
    lErrCde = DRV_FAIIntWatchdogStart(ghDev, ptIntStart)
    If (DoesErr(lErrCde)) Then
        ReDim giIntBuf(0)
        lErrCde = DRV_DeviceClose(ghDev)
        Exit Sub
    End If
    
    'Enter another form to get message
    frmInit.Enabled = False
    
    frmRun.prgsConvCount.Max = giConvCount
    frmRun.Show
    frmRun.tmrChkStatus.Enabled = True
End Sub

Private Sub butExit_Click()
    End
End Sub


Private Sub butGainList_Click()
Dim i, ii As Integer
Dim iStart As Integer
Dim iStop As Integer
    
    ' Clear every Condition list box
    frmGainCodes.EnableItems 0, 15, False   'disable all selection
    frmGainCodes.ClearItems 0, 15
    
    'Make invidual chanel's gain code selection item
    iStart = cmbStartChl.ListIndex
    iStop = cmbStartChl.ListIndex + cmbChlCount.ListIndex
    
    For i = iStart To iStop
        For ii = 0 To (gDevFeature.usNumGain - 1)
            frmGainCodes.cmbGain(i).AddItem lstOverallGain.List(ii)
        Next ii
        frmGainCodes.cmbGain(i).ListIndex = giGainCode(i)
        frmGainCodes.cmbGain(i).Enabled = True
    Next i
    frmGainCodes.EnableItems iStart, iStop, True   'Enable all selection
    
    'Start the selection
    frmGainCodes.Show 1
    
    
End Sub

Private Sub butLevels_Click()
Dim i As Integer
Dim iStart As Integer
Dim iStop As Integer

    frmLevels.EnableItems 0, 15, False  'Disable all sub-controls
    
    'Make individual chanel's Level editor
    iStart = cmbStartChl.ListIndex
    iStop = cmbStartChl.ListIndex + cmbChlCount.ListIndex
    
    For i = iStart To iStop
        frmLevels.editHigh(i).Text = Format(gTrigLevel(i).fHigh, "###0.0####")
        frmLevels.editLow(i).Text = Format(gTrigLevel(i).fLow, "###0.0####")
        frmLevels.editHigh(i).Enabled = True
        frmLevels.editLow(i).Enabled = True
    Next i
    frmLevels.Show 1
End Sub

Private Sub chkOverallCond_Click()

    If chkOverallCond.value = 1 Then
        butConditions.Enabled = False
        lstOverallCond.Enabled = True
        lstOverallCond_Click    'Restore overall condition list
    Else
        butConditions.Enabled = True
        lstOverallCond.Enabled = False
    End If
End Sub

Private Sub chkOverallGain_Click()

    If chkOverallGain.value = 1 Then
        butGainList.Enabled = False
        lstOverallGain.Enabled = True
        lstOverallGain_Click
    Else
        butGainList.Enabled = True
        lstOverallGain.Enabled = False
    End If
        
End Sub


Private Sub chkOverallLevel_Click()

    If chkOverallLevel.value = 1 Then
        butLevels.Enabled = False
        editOverallLevelH.Enabled = True
        editOverallLevelL.Enabled = True
        editOverallLevelH_Change
        editOverallLevelL_Change
    Else
        butLevels.Enabled = True
        editOverallLevelH.Enabled = False
        editOverallLevelL.Enabled = False
    End If
End Sub



Private Sub cmbStartChl_Click()
Dim i, j As Integer
    
    'Add analog input channel item
    j = cmbChlCount.ListIndex
    cmbChlCount.Clear
     
    'Add channel count selection
    For i = 1 To giMaxChl - cmbStartChl.ListIndex
        cmbChlCount.AddItem Str(i)
    Next i
    If j = -1 Then j = 0
    If j > i - 3 Then j = i - 2
    cmbChlCount.ListIndex = j
End Sub


Private Sub editOverallLevelH_Change()
Dim i As Integer
Dim fValue As Single

    fValue = Val(editOverallLevelH.Text)
    For i = 0 To giMaxChl
        gTrigLevel(i).fHigh = fValue
    Next i
    
End Sub

Private Sub editOverallLevelH_KeyPress(KeyAscii As Integer)

    If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then Exit Sub
    If KeyAscii = Asc(".") Then Exit Sub
    If KeyAscii = Asc("+") Then Exit Sub
    If KeyAscii = Asc("-") Then Exit Sub
    If KeyAscii = 8 Then Exit Sub       'Baekspace
    
    KeyAscii = 0                        'take off this key
End Sub


Private Sub editOverallLevelL_Change()
Dim i As Integer
Dim fValue As Single

    fValue = Val(editOverallLevelL.Text)
    For i = 0 To giMaxChl
        gTrigLevel(i).fLow = fValue
    Next i
    
End Sub

Private Sub editOverallLevelL_KeyPress(KeyAscii As Integer)
    If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then Exit Sub
    If KeyAscii = Asc(".") Then Exit Sub
    If KeyAscii = Asc("+") Then Exit Sub
    If KeyAscii = Asc("-") Then Exit Sub
    If KeyAscii = 8 Then Exit Sub       'Baekspace
    
    KeyAscii = 0                        'take off this key

End Sub


Private Sub Form_Load()
Dim lList, lErrCde As Long
Dim i, ii, iCounts As Integer
Dim sTmp As String

    ' Read total installed  Advantech device
    lList = DRV_GetAddress(devicelist(0))
    lErrCde = DRV_DeviceGetList(lList, 99, iCounts)
    If DoesErr(lErrCde) <> 0 Then
        Exit Sub
    End If
    
    'Make selection list
    For i = 0 To (iCounts - 1)
        sTmp = ""
        For ii = 0 To MaxDevNameLen
            sTmp = sTmp + Chr(devicelist(i).szDeviceName(ii))
        Next ii
        lstDevices.AddItem sTmp
    Next i
    lstDevices.ListIndex = 0    'Make default selection
    
    'Make default condition selection as GREATER
    lstOverallCond.ListIndex = 3
    
    'Make default Level value
    editOverallLevelH_Change
    editOverallLevelL_Change

    'Default trigger type
    cmbAcqType.ListIndex = 0
End Sub

Private Sub lstDevices_Click()
Dim lErrCde As Long
Dim lDevNum As Long
Dim ptDevGetFeatures As PT_DeviceGetFeatures
Dim ptAIGetConfig As PT_AIGetConfig
Dim i, j As Integer
Dim sTmp As String
    
    'Open device for getting device informations
    'These information contained in features & configurations
    lDevNum = devicelist(lstDevices.ListIndex).dwDeviceNum
    lErrCde = DRV_DeviceOpen(lDevNum, ghDev)
    If (DoesErr(lErrCde)) Then Exit Sub
    
    'Get device features
    ptDevGetFeatures.buffer = DRV_GetAddress(gDevFeature)
    lErrCde = DRV_DeviceGetFeatures(ghDev, ptDevGetFeatures)
    If (DoesErr(lErrCde)) Then Exit Sub

    'Get device configurations
    ptAIGetConfig.buffer = DRV_GetAddress(gDevCfgAi)
    lErrCde = DRV_AIGetConfig(ghDev, ptAIGetConfig)
    If (DoesErr(lErrCde)) Then Exit Sub
      
    If (gDevCfgAi.ulChanConfig = 0) Then
        giMaxChl = gDevFeature.usMaxAISiglChl
    Else
        giMaxChl = gDevFeature.usMaxAIDiffChl
    End If
    If giMaxChl > 15 Then giMaxChl = 15
    
    'Make overall Gain code selection items
    lstOverallGain.Clear
    If (gDevFeature.usNumGain > 0) Then
        For i = 0 To (gDevFeature.usNumGain - 1)
            sTmp = ""
            For j = 0 To 15
                sTmp = sTmp + Chr(gDevFeature.glGainList(i).szGainStr(j))
            Next j
            lstOverallGain.AddItem sTmp
        Next i
    End If
    lstOverallGain.ListIndex = 0    'default gain code
    
    'Make analog input channel selection items
    j = cmbStartChl.ListIndex
    cmbStartChl.Clear
    For i = 0 To (giMaxChl - 1)
        sTmp = Str(i)
        cmbStartChl.AddItem sTmp
    Next i
    If j = -1 Then j = 0
    cmbStartChl.ListIndex = j
    
    'Close Device
    DRV_DeviceClose ghDev

End Sub

Private Sub lstOverallCond_Click()
Dim i As Integer
  
    For i = 0 To giMaxChl - 1
        giCondition(i) = lstOverallCond.ListIndex
    Next i

End Sub

Private Sub lstOverallGain_Click()
Dim i As Integer
  
    For i = 0 To giMaxChl - 1
        giGainCode(i) = lstOverallGain.ListIndex
    Next i
    
End Sub

Private Sub radExtTrig_Click()
    editSpeed.Enabled = False
End Sub


Private Sub radInterTrig_Click()
    editSpeed.Enabled = True
End Sub


⌨️ 快捷键说明

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