采集卡采集程序如下,要实现5分钟自动采集,和单点采集程序该怎么加啊。自动采集我打算在VB界面上添加个定时器控件,单点采集的意思就是点击采集按钮就马上采集。
Option ExplicitDim InputRange As Integer
Dim ADBuffer(0 To 4095, 0 To 31) As Long  ' Receive AD data buffer
Dim SegmentID As Long
Dim hDevice As Long
Dim DeviceLgcID As IntegerDim dwErrorCode As Integer
Dim strDwError As String
Dim strErrorMsg As StringDim ADPara As PCI8602_PARA_AD            ' Initialization AD parameter structure
Dim DMAStatus As PCI8602_STATUS_DMA      ' DMA Stats parameter
Dim Index As Integer
Dim nADChannel As Integer
Dim ADData As Integer
Dim fVolt As Double
Dim strTemp As String
Private Sub Command1_Start_Click()
    DeviceLgcID = 0
    hDevice = PCI8602_CreateDevice(DeviceLgcID)         ' create device object
    If hDevice = INVALID_HANDLE_VALUE Then
        dwErrorCode = PCI8602_GetLastErrorEx("PCI8602_CreateDevice", strErrorMsg)
        strDwError = dwErrorCode
        MsgBox "dwErrorCode =" + strDwError + strErrorMsg
        Exit Sub
    End If    InputRange = Me.Combo1_InputRange.ListIndex           ' ask users to select the input range through the keyboard    ' 预置硬件参数
    ADPara.ADMode = PCI8602_ADMODE_SEQUENCE             ' continuous sampling
    ADPara.FirstChannel = 0                             ' first channel
    ADPara.LastChannel = 2                              ' last channel
    ADPara.Frequency = 25000                            ' sampling frequency(Hz)
    ADPara.GroupInterval = 50                          ' group interval(uS)
    ADPara.LoopsOfGroup = 1                             ' loops of group
    ADPara.InputRange = InputRange                      ' Analog Input Range range    ADPara.TriggerMode = PCI8602_TRIGMODE_SOFT          ' software trigge
    ADPara.TriggerSource = PCI8602_TRIGSRC_ATR          ' select ATR as a trigger source
    ADPara.TriggerType = PCI8602_TRIGTYPE_EDGE          ' edge trigger
    ADPara.TriggerDir = PCI8602_TRIGDIR_NEGATIVE        ' negative trigger    ADPara.ClockSource = PCI8602_CLOCKSRC_IN            ' internal clock
    ADPara.bClockOutput = False     '
    
    Dim hDmaEvent As Long
    hDmaEvent = PCI8602_CreateSystemEvent()
    If PCI8602_InitDeviceDmaAD(hDevice, hDmaEvent, ADBuffer(0, 0), 4096, 32, 4096, ADPara) = False Then  ' Initial AD
        dwErrorCode = PCI8602_GetLastErrorEx("PCI8602_InitDeviceDmaAD", strErrorMsg)
        strDwError = dwErrorCode
        MsgBox "dwErrorCode =" + strDwError + strErrorMsg
        GoTo ExitRead1
    End IfSleep 10
    If PCI8602_StartDeviceDmaAD(hDevice) = False Then           ' Start AD
        MsgBox "PCI8602_StartDeviceDmaAD Error..."
    End If
  
    While True ' Check whether the current data on the physical buffer is ready
        If WaitForSingleObject(hDmaEvent, 100) = 0 Then     ' Wait DMA event
            GoTo Read
        End If
        Wend
    
Read:
    If PCI8602_GetDevStatusDmaAD(hDevice, DMAStatus) = False Then
        MsgBox "Get Device Status Error..."
        GoTo ExitRead0
    End If    If DMAStatus.bBufferOverflow = 1 Then
        MsgBox "DMA Overflow..."
    End If
    
    If DMAStatus.bSegmentSts(SegmentID) = 1 Then
        For Index = 0 To 2 Step 1
            ' The AD data is converted to voltage value(mV)
           Select Case InputRange
           Case PCI8602_INPUT_0_P5000mV      ' 0V - +5V
           Case fVolt = (5000# / 65536) * (ADBuffer(Index, SegmentID) And 65535)
            Case Else:
                MsgBox "Select Range errer...."
            End Select
            strTemp = fVolt
            Sleep 200
            Me.TextVolt(Index).Text = Format(strTemp, "00.00")
        Next Index
    End If
    
    If PCI8602_SetDevStatusDmaAD(hDevice, SegmentID) = False Then
        MsgBox "SetDevStatusDmaAD Error..."
        GoTo ExitRead0
    End IfExitRead0:
    If PCI8602_ReleaseDeviceDmaAD(hDevice) = False Then          ' Release AD,stop AD data conversion
        MsgBox "PCI8602_ReleaseDeviceDmaAD Error.."
    End If
    
    If PCI8602_ReleaseSystemEvent(hDmaEvent) = False Then
        MsgBox "PCI8602_ReleaseSystemEvent Error..."
    End If
    
ExitRead1:
    If PCI8602_ReleaseDevice(hDevice) = False Then       ' Release device object
        MsgBox "PCI8602_ReleaseDevice Error.."
    End If
    End Sub
Private Sub Form_Load()
    Me.Combo1_InputRange.ListIndex = 0
End Sub
Private Sub End_Click()
End
End Sub

解决方案 »

  1.   

    把你的定时器控件中 timer 事件中的代码复制到 command1.click 中不就OK了么.
      

  2.   

    Option Explicit
    Dim TimeNum As BytePrivate Sub Command1_Click()
        '此处为采集代码
    End SubPrivate Sub Timer1_Timer()
    'Timer1.Interval = 60000
    TimeNum = TimeNum + 1
    If TimeNum = 5 Then
        Call Command1_Click
        TimeNum = 0
    End If
    End Sub大概就是这个样子吧。
      

  3.   

    Option Explicit 
    Dim TimeNum As Byte 
    Private Sub Command1_Click() 
    '此处为采集代码 
    End Sub 
    Private Sub Timer1_Timer() 'Timer1.Interval = 60000 
    TimeNum = TimeNum + 1 
    If TimeNum = 5 Then 
    timer1.enabled=false
    Call Command1_Click 
    timer1.enabled=true
    TimeNum = 0
     End If
     End Sub
      

  4.   

    这个是阿尔泰的,如果我想把这3个通道采集到的数据实时储存到数据库怎么解决啊?数据库是Access的就三个字段,依次为 CH0温度  CH1温度 CH2温度,并且数据列表显示,列表显示的话是用ADO控件和DataGrid控件一起用的。