02-10-2010 04:19 AM
Hi,
using a NI PCIe-6259 DAQ Card on Windows XP, MS Visual Studio 2005, Visual Basic
I want to
-measure continously (into array) from 2 Analog INs (AI0, AI1) RSE at rates around 1kSamples/s up to what's possible. 200kS/s maybe.
-simultaneously process code like processing, visualisation, counting
-simultaneously switch digital outputs (PFI0, PFI1)
Seperate routines work, but my simultaneous routine stops with error:
An unhandled exception of type 'NationalInstruments.DAQmx.DaqException' occurred in NationalInstruments.DAQmx.dll
Additional information: Measurements: Specified operation cannot be performed when there are no devices in the task. Task Name: _unnamedTask<1> Status Code: -200477
I post here the Sub, could you please tell me how to fulfill that task, or what I do wrong, maybe in Task-management,
Thank you in advance,
Ausflug
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click '=BUTTON: CONTINOUS MEASUREMENT Dim anf, ende, n, senso As Integer anf = CInt(TextBox8.Text) ende = CInt(TextBox9.Text) senso = anf ''Try ' Create a new task myTask = New Task() 'TASK FUER DIE DIE ANALOG EINGAENGE 'Dim digitalWriteTask As Task 'digitalWriteTask = New Task Dim digitalWriteTask As Task = New Task() ' Initialize local variables Dim sampleRate As Double = Convert.ToDouble(TextBox6.Text) Dim samplesPerChan As Int32 = Convert.ToInt32(TextBox7.Text) ' Create an Digital Output channel and name it. ' Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample ' of digital data on demand, so no timeout is necessary. Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream) 'HIER WERDEN DIE INPUTS DEFINIERT UND GESTARTET ' Create a channel myTask.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai1", "", NationalInstruments.DAQmx.AITerminalConfiguration.Rse, ainuv, ainov, AIVoltageUnits.Volts) 'myTask1.AIChannels.CreateVoltageChannel("Dev1/ai1", "", NationalInstruments.DAQmx.AITerminalConfiguration.Rse, ainuv, ainov, AIVoltageUnits.Volts) ' Configure timing specs myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChan) 'myTask1.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChan) ' Verify the task myTask.Control(TaskAction.Verify) 'myTask1.Control(TaskAction.Verify) reader = New AnalogMultiChannelReader(myTask.Stream) 'HIER SCHEINT DIE MESSUNG ZU BEGINNEN 'NUN WIRD VOR DEM SCAN DER SENSOR 1 REGULAER SELEKTIERT TextBox1.Text = "1" Call select_the_sensor() Dim appendtext As String appendtext = "" For n = anf To ende senso = n 'TextBox1.Text = CStr(n) 'Sensornummer 'TextBox1.Text = CStr(CInt(TextBox1.Text) + 1) ' CheckBox3.Checked = True 'DIN 1 CLK 0 digcontrolbyte = 1 writer.WriteSingleSamplePort(True, Decimal.ToUInt32(digcontrolbyte)) ' CheckBox2.Checked = False 'DIN1 CLK1 digcontrolbyte = 0 writer.WriteSingleSamplePort(True, Decimal.ToUInt32(digcontrolbyte)) digcontrolbyte = 2 writer.WriteSingleSamplePort(True, Decimal.ToUInt32(digcontrolbyte)) digcontrolbyte = 3 writer.WriteSingleSamplePort(True, Decimal.ToUInt32(digcontrolbyte)) digcontrolbyte = 1 writer.WriteSingleSamplePort(True, Decimal.ToUInt32(digcontrolbyte)) ' CheckBox3.Checked = True 'DIN1 CLK 0 'digcontrolbyte = 1 ' Call measure_them_quick(n) 'Misst und Schreibt in Ausgabefeld appendtext = appendtext + (Chr(13) + Chr(10) + Format(senso, "0000") + ";" + Format(diffwert(n), "000.00000")) Next n ' Read the data Dim data As Double(,) = reader.ReadMultiSample(samplesPerChan) Call paint_canvas() TextBox4.AppendText(appendtext) ' dataToDataTable(data, dataTable) Dim datalen As Integer Dim kurvy As Double Dim messanz As Integer datalen = data.Length messanz = (data.Length / 2) - 1 'einfach den letzten wert aus der mehrfachmessung nehmen kurvy = (data(0, messanz) - data(1, messanz)) diffwert(senso) = kurvy ' appendtext = appendtext + Format(data(0, i), "00.00000") + ";" + Format(data(1, i), "00.00000") + ";" + Format(kurvy, "00.00000") + ";" 'TextBox4.AppendText(appendtext) ''Catch ex As DaqException '' MessageBox.Show(ex.Message) 'Catch ex As System.Exception 'SO WAR DIE BESPIELROUTINE FUER DEN WRITER (DIG) TEIL 'MessageBox.Show(ex.Message) ''Finally myTask.Dispose() ' digitalWriteTask.Dispose() System.Windows.Forms.Cursor.Current = Cursors.Default ''End Try End Sub
02-15-2010 09:58 AM - edited 02-15-2010 09:59 AM
Hi Ausflug
For your device you installed the DAQmx driver I think.
So there you can find some examples to work with Visual Basic and the the PCIe-6259.
Please look at Windows start -> programs -> National Instruments -> NI-DAQ -> Text-Based Code Support
or C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\Visual Basic 6.0 (-> Vista)
For the error -200477 look here for more informations
Error -200477, What's wrong here?
http://forums.ni.com/ni/board/message?board.id=170&message.id=221076&requireLogin=False
Digital I/O error with PCI-6229
http://forums.ni.com/ni/board/message?board.id=250&message.id=28166&requireLogin=False
Error-code -200477 means:
"Measurements: Specified operation cannot be performed when there are no devices in the task."
You have to add a physical device for your task as Dev1/port0 in the MAX or with DAQmx
Create Channel.
Please have a look at the documentation about using the DAQmx with C or VB
Kind regards
Beat, NI Germany
02-17-2010 08:10 AM
Dear Beat, Dear Pixar,
thank you very much for your helpful reply.
As you suggested I had to create a channel.
Basically I added the following line to the code:
' Create a channel for Analog INs myTask.AIChannels.CreateVoltageChannel("Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3", "", NationalInstruments.DAQmx.AITerminalConfiguration.Rse, ainuv, ainov, AIVoltageUnits.Volts)
now the error message is gone.
But I am sorry, my original goal is still not fulfilled.
The tasks
(1) reading out (ai0,ai1,ai2,ai3) and
(2) digital out
are still executed one after the other. Code execution stops for the whole time while ai-sampling is running.
But I want to be able to execute code while the analog measurement is running.
For timing control reasons I have cable connected ai2 and ai3 to my digitaloutputs Port1/Bit0 and Port1/Bit1.
I am not able to watch these digital outs change in state.
I want to have the analog in measurement running, then do the digital outputs (which are with reaction times of around 50ms still way too slow, but that seems to be a different problem) and then end the analog measurement and read out the data.
I read something in this forum (link below)
http://forums.ni.com/ni/board/message?board.id=232&message.id=6070#M6070
that one way of achieving this is to "tie the digital I/O clock to a analog clock"
Does that mean I have to make a cable connection eg. from PFI7/AI SAMP CLK / Pin 38
to (which pin?, I don't find a digital clock pin) ?
Could you explain me how to do this, ideally with a short code example.
Thank you very much in advance,
Regards,
Ausflug
02-17-2010 08:53 AM
Hi Ausflug
Do you have some parallel thread for the analog input measurement and the digital outputs ?
If you handle this in the same thread it is logical that you have to wait untill the AI measurement is done.
For the other question, I think they mean that you use the AI clock as digital sample clock, but that is
for the synchronization of the AI and D I/O
For examples please have a look here:
http://zone.ni.com/devzone/cda/tut/p/id/6999
http://digital.ni.com/public.nsf/websearch/341C14328D91EDF186256D9800456FC0?OpenDocument
Kind regards
Pixar
NI Germany