addmabm.frm

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

FRM
608
字号
VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "Analog Input with bus master DMA"
   ClientHeight    =   4560
   ClientLeft      =   3000
   ClientTop       =   2655
   ClientWidth     =   5985
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4560
   ScaleWidth      =   5985
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      Caption         =   "Event Information"
      Height          =   2520
      Left            =   2520
      TabIndex        =   8
      Top             =   1100
      Width           =   3255
      Begin VB.Label lbReadyBuf 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         Height          =   315
         Left            =   360
         TabIndex        =   15
         Top             =   480
         Width           =   2535
      End
      Begin VB.Label lbOverrunCnt 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         Height          =   315
         Left            =   1680
         TabIndex        =   14
         Top             =   2040
         Width           =   855
      End
      Begin VB.Label lbInterruptCnt 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         Height          =   315
         Left            =   1680
         TabIndex        =   13
         Top             =   1620
         Width           =   855
      End
      Begin VB.Label lbBufChangeCnt 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         Height          =   315
         Left            =   1680
         TabIndex        =   12
         Top             =   1200
         Width           =   855
      End
      Begin VB.Label Label6 
         Caption         =   "Interrupt  Count"
         Height          =   255
         Left            =   120
         TabIndex        =   11
         Top             =   1620
         Width           =   1575
      End
      Begin VB.Label Label5 
         Caption         =   "Overrun  Count"
         Height          =   255
         Left            =   120
         TabIndex        =   10
         Top             =   2040
         Width           =   1695
      End
      Begin VB.Label Label4 
         Caption         =   "Buffer Change  Count"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   1200
         Width           =   1695
      End
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Left            =   5400
      Top             =   0
   End
   Begin VB.CommandButton btExit 
      Caption         =   "Exit"
      Height          =   375
      Left            =   4920
      TabIndex        =   7
      Top             =   3840
      Width           =   855
   End
   Begin VB.CommandButton btStop 
      Caption         =   "Stop"
      Height          =   375
      Left            =   3720
      TabIndex        =   6
      Top             =   3840
      Width           =   855
   End
   Begin VB.CommandButton btRun 
      Caption         =   "Run"
      Height          =   375
      Left            =   2640
      TabIndex        =   5
      Top             =   3840
      Width           =   855
   End
   Begin VB.CommandButton btSetting 
      Caption         =   "Setting"
      Height          =   435
      Left            =   4320
      TabIndex        =   4
      Top             =   360
      Width           =   1455
   End
   Begin VB.ListBox LstStatus 
      Height          =   3180
      Left            =   240
      TabIndex        =   3
      Top             =   1200
      Width           =   2175
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   240
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   480
      Width           =   3735
   End
   Begin VB.Label Label2 
      Caption         =   "Data:"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   960
      Width           =   2535
   End
   Begin VB.Label Label1 
      Caption         =   "Select a device from list:"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   1815
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub btExit_Click()
End
End Sub

Private Sub btRun_Click()
    Dim LogChan As Long
    
    SetState (STATE_Run)
    LstStatus.Clear
    lbReadyBuf.Caption = ""
     UserBuf = GlobalAlloc(GPTR, 4 * Conv)
     If (UserBuf = 0) Then
         ErrMsg = "Not enough memory for buffer"
         DRV_DeviceClose (DriverHandle)
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
     End If
     
    hUserBuf = GlobalLock(UserBuf)
     If (hUserBuf = 0) Then
         ErrMsg = "Not enough memory for buffer"
         DRV_DeviceClose (DriverHandle)
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
     End If
     
    
    DispNum = ChannelNum
    
    If (DataType = 1) Then
      ReDim DisplayBuf(0 To DispNum) As Single
    Else
      ReDim DisplayRawBuf(0 To DispNum) As Integer
    End If
   
    
    If (DataType = 1) Then
        For i = 0 To DispNum - 1
            DisplayBuf(i) = 0
        Next i
    Else
        For i = 0 To DispNum - 1
            DisplayRawBuf(i) = 0
        Next i
    End If
 
    
   If (DataType = 1) Then
      hDisplayBuf = GlobalLock(DRV_GetAddress(DisplayBuf(0)))
    Else
      hDisplayBuf = GlobalLock(DRV_GetAddress(DisplayRawBuf(0)))
    End If
    

    ' Step 1: Device open
    ErrCde = DRV_DeviceOpen(DeviceNum, DriverHandle)
    If ErrCde <> SUCCESS Then
        GlobalUnlock (hUserBuf)
        GlobalUnlock (hDisplayBuf)
        GlobalFree (UserBuf)

        DRV_GetErrorMessage ErrCde, ErrMsg
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
        SetState (STATE_Ready)
        Exit Sub
    End If
    
    ' Step 2: Get device features
    ptDevFeatures.buffer = DRV_GetAddress(DevFeat)
    ptDevFeatures.size = Len(DevFeat)
    ErrCde = DRV_DeviceGetFeatures(DriverHandle, ptDevFeatures)
    If ErrCde <> SUCCESS Then
        GlobalUnlock (hUserBuf)
        GlobalUnlock (hDisplayBuf)
        GlobalFree (UserBuf)
        DRV_GetErrorMessage ErrCde, ErrMsg
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
        DRV_DeviceClose DriverHandle
        SetState (STATE_Ready)
        Exit Sub
    End If

    ' Step 3: Allocate memory for Voltage data or Raw data
    ptFAITransfer.DataBuffer = hDisplayBuf

    
    ' Step 4: Enable event feature
    ' ADS_EVT_INTERRUPT is not used at VB example because of speed issue.
    ptEnableEvent.EventType = ADS_EVT_INTERRUPT Or ADS_EVT_BUFCHANGE Or ADS_EVT_TERMINATED Or ADS_EVT_OVERRUN
    ptEnableEvent.Enabled = EventMode
    ptEnableEvent.Count = 2048         'at lease should be 2048
    ErrCde = DRV_EnableEvent(DriverHandle, ptEnableEvent)
    If ErrCde <> 0 Then
        GlobalUnlock (hUserBuf)
        GlobalUnlock (hDisplayBuf)
        GlobalFree (UserBuf)
        DRV_GetErrorMessage ErrCde, ErrMsg
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
        DRV_DeviceClose DriverHandle
        SetState (STATE_Ready)
        Exit Sub
    End If

    ptAIGetConfig.buffer = DRV_GetAddress(DevCfg_AI)
    ptAIGetConfig.size = Len(DevCfg_AI)
    ErrCde = DRV_AIGetConfig(DriverHandle, ptAIGetConfig)
    If ErrCde <> SUCCESS Then
        DRV_GetErrorMessage ErrCde, ErrMsg
        MsgBox ErrMsg, vbOKOnly, "Driver Message"
        DRV_DeviceClose DriverHandle
        Exit Sub
    End If
    
    For i = 0 To DevFeat.usMaxAISiglChl - 1
        If GainOption = MODE_OverallGain Then
            GainCde(i) = DevFeat.glGainList(InputRange).usGainCde ' no gain list
        Else
            temp = gain(i)
            GainCde(i) = DevFeat.glGainList(temp).usGainCde
        End If
    Next i
    
    gwMaxLogChanNum = GetMaxLogChanNum(DevCfg_AI, DevFeat)
    LogChan = PhyChanToLogChan(DevCfg_AI, StartChannel)
   
    For i = 0 To Min(ChannelNum - 1, gwMaxLogChanNum - 1)
        ReorderGainCode(i) = GainCde(LogChan Mod gwMaxLogChanNum)
        LogChan = LogChan + 1
    Next i
    
    ' Step 5: Start DMA transfer
    ptFAIDmaExStart.TrigSrc = TriggerSource
    ptFAIDmaExStart.TrigMode = TriggerMode
    ptFAIDmaExStart.ClockSrc = ClockSource
    ptFAIDmaExStart.TrigEdge = TriggerEdge
    ptFAIDmaExStart.SRCType = TriggerType
    ptFAIDmaExStart.CyclicMode = CyclicMode
    ptFAIDmaExStart.TrigVol = TriggerVoltage
    ptFAIDmaExStart.StartChan = StartChannel
    ptFAIDmaExStart.NumChans = Min(ChannelNum, gwMaxLogChanNum - 1)
    ptFAIDmaExStart.ulDelayCnt = DelayCount
    ptFAIDmaExStart.SampleRate = PacerRate
    ptFAIDmaExStart.GainList = DRV_GetAddress(ReorderGainCode(0))
    ptFAIDmaExStart.Count = Conv
    ptFAIDmaExStart.buffer0 = hUserBuf
    

⌨️ 快捷键说明

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