03-13-2013 07:19 AM
Hi,
I'm trying to use PCIe-6343 in Visual Basic 2010 on WinXP and writing codes to measure AI signal,save to text file.
I succeeded single point measurement, so I tried to repeat program using 'For..Next' loop and failed error -50103.
Would you tell me how can I change this sourse code.
I referenced Example file from /Dotnet4.0/Anarog In/Measure Voltage/ContAcqVoltageSamples_IntClk_ToFile
Thanks.
Private Sub StartContButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartContButton.Click
Dim filecount As Integer
For filecount = 0 To 1024
filecount += 1
AcqFileNum.Text = filecount
AcqSinglepoint()
Dim AcqTime As Double = Convert.ToInt32(samplesPerChannelNumeric.Value) / Convert.ToDouble(rateNumeric.Value)
myTask.WaitUntilDone(AcqTime * 1000)
Next
End Sub
Private Sub AcqSinglepoint()
'determine filename and fullfilepath
If runningTask Is Nothing Then
Try
'Create a new file for data
Dim opened As Boolean = CreateDataFile()
If Not opened Then
Return
End If
'Create a new task
myTask = New Task()
'Create a virtual channel
myTask.AIChannels.CreateVoltageChannel("/Dev1/ai0,/Dev1/ai1", "", AITerminalConfiguration.Rse, Convert.ToDouble(minimumValueNumeric.Value), Convert.ToDouble(maximumValueNumeric.Value), AIVoltageUnits.Volts)
'Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value), SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, Convert.ToInt32(samplesPerChannelNumeric.Value))
'Verify the Task
myTask.Control(TaskAction.Verify)
'Prepare the table and file for Data
Dim channelNames(myTask.AIChannels.Count - 1) As String
Dim i As Integer = 0
Dim a As AIChannel
For Each a In myTask.AIChannels
channelNames(i) = a.PhysicalName
i = i + 1
Next a
InitializeDataTable(channelNames, dataTable)
'Add the channel names (and any other information) to the file
Dim samples As Integer = Convert.ToInt32(samplesPerChannelNumeric.Value)
PrepareFileForData()
savedData = New ArrayList
For i = 0 To myTask.AIChannels.Count - 1
savedData.Add(New ArrayList)
Next
runningTask = myTask
analogInReader = New AnalogMultiChannelReader(myTask.Stream)
'Use SynchronizeCallbacks to specify that the object
'marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = True
analogCallback = New AsyncCallback(AddressOf AnalogInCallback)
analogInReader.BeginReadMultiSample(samples, analogCallback, myTask)
Catch exception As DaqException
'DisplayErrors
MessageBox.Show(exception.Message)
runningTask = Nothing
myTask.Dispose()
stopButton.Enabled = False
startButton.Enabled = True
End Try
End If
Dim AcqTime As Double = Convert.ToInt32(samplesPerChannelNumeric.Value) / Convert.ToDouble(rateNumeric.Value)
End Sub
Private Sub AnalogInCallback(ByVal ar As IAsyncResult)
Try
If (Not (runningTask Is Nothing)) AndAlso runningTask Is ar.AsyncState Then
'Read the available data from the channels
data = analogInReader.EndReadMultiSample(ar)
'Plot your data here
LogData(data)
End If
Catch exception As DaqException
'Display Errors
TextBox1.AppendText("Error in AnalogInCallBack" + vbCrLf)
MessageBox.Show(exception.Message)
runningTask = Nothing
myTask.Dispose()
stopButton.Enabled = False
startButton.Enabled = True
End Try
If Not (runningTask Is Nothing) Then
'Dispose of the task
CloseFile()
runningTask = Nothing
myTask.Dispose()
stopButton.Enabled = False
startButton.Enabled = True
End If
End Sub
03-13-2013 09:06 PM
Hi, I replied to your Japanese post, so I'll keep it short here.
You are using FiniteSample in ContinousSample example.
Please see the folloing examples for correct usage of FiniteSample and ContinousSample
Finite: \DotNET4.0\Analog In\Measure Voltage\AcqVoltageSamples_IntClk
Continous: \DotNET4.0\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk