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

📄 frmmain.frm

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 FRM
📖 第 1 页 / 共 2 页
字号:
    nDevice = cmbSelectDevice.ListIndex
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub cmdStart_Click()
    Static nFlag As Integer
    nFlag = Abs(nFlag - 1)
    If (nFlag = 1) Then
        bRun = True
        cmdExit.Enabled = False
        cmdStart.Caption = "&Stop"
        cmbSelectDevice.Enabled = False
        If (Not uRun) Then
            cmdExit.Enabled = True
            cmdStart.Caption = "&Start"
            cmbSelectDevice.Enabled = True
            bRun = False
            nFlag = 0
        End If
    Else
        bRun = False
        cmdExit.Enabled = True
        cmdStart.Caption = "&Start"
        cmbSelectDevice.Enabled = True
        Timer1.Enabled = False
        txtCounterStatus.Text = ""
        ErrCde = DRV_DeviceClose(DeviceHandle)
        If (ErrCde <> 0) Then
            uShowErrMsg
        End If
    End If
End Sub

Private Sub Form_Load()
    Dim nOutEntries As Integer
    Dim i, ii As Integer
    Dim tt As Long
    Dim tempStr As String
    
    bRun = False
    DeviceHandle = vbNull
    Timer1.Enabled = False
    nDevice = 0
    nGain = 0
    nBoardID = 0
    nExpChan = 0
    nChannel = 0
    'set scan time
    Timer1.Enabled = False
    
    'Add type of PC Card
    tt = DRV_GetAddress(devicelist(0))
    ErrCde = DRV_DeviceGetList(tt, MaxEntries, nOutEntries)
    If (ErrCde <> 0) Then
        uShowErrMsg
        Exit Sub
    End If
    
    ' Return the number of devices which you install in the system using
    ' Device Installation
    ErrCde = DRV_DeviceGetNumOfList(gnNumOfDevices)
    If (ErrCde <> 0) Then
        uShowErrMsg
        Exit Sub
    End If
    If (gnNumOfDevices > MAX_DEVICES) Then gnNumOfDevices = MAX_DEVICES
    For i = 0 To (gnNumOfDevices - 1)
        tempStr = ""
        For ii = 0 To MaxDevNameLen
            tempStr = tempStr + Chr(devicelist(i).szDeviceName(ii))
        Next ii
        cmbSelectDevice.AddItem tempStr
    Next i
    If (gnNumOfDevices > 0) Then cmbSelectDevice.ListIndex = 0
    'sub device
    If (Not uHandleSubDevice()) Then Exit Sub
    'Initialize Input Range
    If (Not uHandleRange()) Then Exit Sub
End Sub

Private Function uHandleSubDevice() As Boolean
    Dim tt As Long, nOutEntries As Integer
    Dim i As Integer, ii As Integer, tempStr As String * 80
    
    uHandleSubDevice = True
    gnNumOfSubDevices = devicelist(nDevice).nNumOfSubdevices
    If (gnNumOfSubDevices > MAX_DEVICES) Then gnNumOfSubDevices = MAX_DEVICES
    If (gnNumOfSubDevices > 0) Then
        tt = DRV_GetAddress(SubDevicelist(0))
        ErrCde = DRV_DeviceGetSubList(devicelist(nDevice).dwDeviceNum, tt, gnNumOfSubDevices, nOutEntries)
        If (ErrCde <> 0) Then
            uShowErrMsg
            uHandleSubDevice = False
            Exit Function
        End If
        cmbModule.Enabled = True
        For i = 0 To gnNumOfSubDevices - 1
            tempStr = ""
            For ii = 0 To MaxDevNameLen
                tempStr = tempStr + Chr(SubDevicelist(i).szDeviceName(ii))
            Next ii
            cmbModule.AddItem tempStr
        Next i
        cmbModule.ListIndex = 0
    End If
End Function

Private Function uHandleRange() As Boolean
    Dim MaxChan As Integer, i As Integer, ii As Integer
    Dim tmpstr As String, szExpName As String * 80
    uHandleRange = True
    If (gnNumOfSubDevices = 0) Then
        ErrCde = DRV_DeviceOpen(devicelist(nDevice).dwDeviceNum, DeviceHandle)
    Else
        ErrCde = DRV_DeviceOpen(SubDevicelist(nDevice).dwDeviceNum, DeviceHandle)
    End If
    If (ErrCde <> 0) Then
        uShowErrMsg
        uHandleRange = False
        Exit Function
    End If
    'get device feature
    ptDevGetFeatures.buffer = DRV_GetAddress(lpDevFeatures)
    ErrCde = DRV_DeviceGetFeatures(DeviceHandle, ptDevGetFeatures)
    If (ErrCde <> 0) Then
        uShowErrMsg
        uHandleRange = False
        DRV_DeviceClose DeviceHandle
        Exit Function
    End If
    'check feature
    If (lpDevFeatures.usMaxAIDiffChl = 0 And lpDevFeatures.usMaxAISiglChl = 0) Then
        MsgBox "AI function not supported.", vbOKOnly Or vbInformation, "Error"
        uHandleRange = False
        DRV_DeviceClose DeviceHandle
        Exit Function
    End If
    'get AI config
    ptAIGetConfig.buffer = DRV_GetAddress(DevConfig)
    ErrCde = DRV_AIGetConfig(DeviceHandle, ptAIGetConfig)
    If (ErrCde <> 0) Then
        uShowErrMsg
        uHandleRange = False
        DRV_DeviceClose DeviceHandle
        Exit Function
    End If
    'set channel
    MaxChan = lpDevFeatures.usMaxAISiglChl
    
    cmbChannel.Enabled = True
    For i = 0 To MaxChan - 1
        tmpstr = CStr(i)
        If (i = DevConfig.usCjcChannel) Then
            tmpstr = tmpstr & " (CJC Channel)"
        Else
            If (DevConfig.Daughter(i And &HF).dwBoardID <> 0) Then
            DRV_BoardTypeMapBoardName DevConfig.Daughter(i And &HF).dwBoardID, szExpName
            tmpstr = tmpstr & " " & szExpName
            End If
        End If
        cmbChannel.AddItem tmpstr
    Next i
    cmbChannel.ListIndex = 0
    'end, close deive
    DRV_DeviceClose DeviceHandle
End Function

Private Function uRun() As Boolean
    uRun = True
    'get timer interval
    If (Not IsNumeric(txtScan.Text)) Then
        MsgBox "Please input numeric for Scan time.", vbOKOnly Or vbInformation, "Error"
        uRun = False
        Exit Function
    End If
    Timer1.Interval = CInt(txtScan.Text)
    'open device
    If (gnNumOfSubDevices = 0) Then
        ErrCde = DRV_DeviceOpen(devicelist(nDevice).dwDeviceNum, DeviceHandle)
    Else
        ErrCde = DRV_DeviceOpen(SubDevicelist(nDevice).dwDeviceNum, DeviceHandle)
    End If
    If (ErrCde <> 0) Then
        uShowErrMsg
        uRun = False
        Exit Function
    End If
    'get number of counter channel
    ptDevGetFeatures.buffer = DRV_GetAddress(lpDevFeatures)
    ErrCde = DRV_DeviceGetFeatures(DeviceHandle, ptDevGetFeatures)
    If (ErrCde <> 0) Then
        uShowErrMsg
        uRun = False
        DRV_DeviceClose DeviceHandle
        Exit Function
    End If
    'config gain for specical AI channel
    If (DevConfig.Daughter(nChannel And &HF).dwBoardID = 0) Then
        lpAIConfig.DasGain = lpDevFeatures.glGainList(nGain).usGainCde
        lpAIConfig.DasChan = nChannel
        ErrCde = DRV_AIConfig(DeviceHandle, lpAIConfig)
        If (ErrCde <> 0) Then
            uShowErrMsg
            uRun = False
            DRV_DeviceClose DeviceHandle
            Exit Function
        End If
    End If
    'enable timer
    Timer1.Enabled = True
End Function

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If (bRun) Then
        MsgBox "Can't terminate now!", vbOKOnly Or vbInformation, "Error"
        Cancel = 1
    End If
End Sub

Private Sub Timer1_Timer()
    Dim dbVoltage As Single       'input voltage

    If (DevConfig.Daughter(nChannel And &HF).dwBoardID = 0) Then
        AiVolIn.chan = nChannel
        AiVolIn.gain = lpAIConfig.DasGain
        AiVolIn.TrigMode = 0            'internal trigger
        AiVolIn.voltage = DRV_GetAddress(dbVoltage)
        ErrCde = DRV_AIVoltageIn(DeviceHandle, AiVolIn)
        If (ErrCde <> 0) Then
            uShowErrMsg
            Timer1.Enabled = False
            Exit Sub
        End If
    Else
        AiVolInExp.DasChan = nChannel
        AiVolInExp.DasGain = nGain
        AiVolInExp.ExpChan = nExpChan
        AiVolInExp.voltage = DRV_GetAddress(dbVoltage)
        If (DevConfig.Daughter(nChannel And &HF).dwBoardID = BD_PCLD788) Then
            AiVolInExp.ExpChan = nBoardID * 32 + nExpChan
        End If
        ErrCde = DRV_AIVoltageInExp(DeviceHandle, AiVolInExp)
        If (ErrCde <> 0) Then
            uShowErrMsg
            Timer1.Enabled = False
            Exit Sub
        End If
    End If
    'show result
    txtCounterStatus.Text = "data =" & Format(dbVoltage, "###0.000000")
End Sub

⌨️ 快捷键说明

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