Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

loop in combination with Analog output

Hi
 
I have modified the script thats translate a value in to a static analog output voltage. The value comes from another online running application. The analog output value must remain static until a new value arise. I'm using VB6 and DAQmx 8.5 on a XP computer. The DA converter is NI USB-6211. I have tried to play around with the Start/Stop and clear commands but my script still makes the program highly unstabile.
So am I using the commands correctly?. And have I setup the write commands correctly too. Can anyone allso explain how to use the command Doevent correctly
 
  Dim taskHandle As Long
    Dim clockEdge As Long
    Dim sampsPerCycle As Double
    Dim desiredSampleClockRate As Double
    Dim resultingFrequency As Double
    Dim amplitude As Double
    Dim numSampsPerChannel As Long
    Dim numChannels As Long
    Dim errorCode As Long
    Dim errorString As String
    Dim sampsPerChanWritten As Long
    Dim XICVolt As Double
   
 '  Create the DAQmx task.
    Call DAQmxCreateTask("", taskHandle)
    '  Add an analog output channel to the task and check to see whether there is only ONE task.
    Call DAQmxCreateAOVoltageChan(taskHandle, "Dev2/ao0", "aoChannel", "-10", "10", DAQmx_Val_VoltageUnits2_Volts, "")
    Call DAQmxGetTaskNumChans(taskHandle, numChannels)
   
    If numChannels > 1 Then
        errorCode = -1
        errorString = "Please specify only one channel."
        Err.Raise errorCode, , errorString
    End If

Data_is_recorded:

    If Actualcycles = expectedcycles Then
    GoTo end_script
    Else
    If Actualcycles > lastcycles Then
    DoEvents

     Call DataPoint.GetDataPoint(thenumberOfDataPoint, theXvalue, theYvalue)
    
    
         
        XICVolt = (theYvalue / 10000000#)
       
       
       
    '  Write to the desired channel(s).
    Call DAQmxWriteAnalogF64(taskHandle, 1, True, 10#, _
        DAQmx_Val_GroupByScanNumber, XICVolt, sampsPerChanWritten, ByVal 0&
               
   
    Else
     lastcycles = theWF.GetActualNumberOfCycles(sampleIndex, 0)
     End If
    GoTo Data_is_recorded
  
   
end_script:
End If
 
call DAQmx.stopTask(Taskhandle)
call DAQmx.clearTask(taskhandle)
Best regards
 
Peter
0 Kudos
Message 1 of 1
(6,362 Views)