DAQmx: Numerical indicators go blank intermittently using DAQmx Read

Hello everyone,
I was wondering if anyone else has ever fought this issue and won.  I have a loop (I will attempt to attach an image of the block diagram) which performs a DAQmx Read operation.  The loop employs a 200 millisecond wait.  The loop scales the data, sends all of the values to little indicators in an array, picks out a few critical values to display on duplicate large indicators, and optionally logs the data by streaming it to disk.  The task will usually (99.9% of the time) be run at 100Hz.  So, I was figuring I could do a "Read All", since at 200 ms of wait time due to the millisecond multiple wait function, I should always have around 20 points to read in the buffer the next time around.  This would allow me to have very current readings in my displays.  I could do a partial read, but then I figure I would have a lag between the displayed values and the reality of what's going on in the test.  Having current readings, as current as can be, is highly desirable for this application.
I figured everything was good with what I was doing, especially when I tested it with a simulated device (I know a simulated device behaves much differently than a real device, especially at start up).  Everything seemed to work well.  When I go to the real hardware, though, I intermittently get blank indicators.  Actually, it is more like intermittent numbers in my indicators.  Most of the time, the DAQmx Read operation returns a null, empty array (no data available in the buffer).  I must be missing something, because I figured that a 200 ms wait would allow another 20 samples to be collected.
If someone could please just ease my conscience and let me know that I haven't done something very fundamentally wrong in this code, even if you couldn't help me with a solution, I would very much appreciate it.  I feel that this code should work, keeping data in the indicators at all times, and don't know why it doesn't work.  If you could offer me the solution, even if it is to point out that I did something very wrong, I would much appreciate it.
I am just writing this code, and still have some icons to make, so the sub VI's still have the default icons.  Sorry about that.  Basically all those do is get array subsets, or scale data, or write data to the data files.  If you need to ask questions about the code, I can understand.  I am not the greatest yet at writing self documenting code yet.  And if you need to know what that event structure does, it watches the two boolean button controls to determine what state in the state machine to go to next, and the time out case of the event structure highlights a data value if it goes out of bounds.
Sorry if I am too wordy.  I have been accused of that before.  I just notice a lot of "Help!  DAQ doesn't work.  How do I fix?" posts, and I don't see how I or anyone else could help that person at all.
I am using LV8.2, with DAQmx 8.3.1, on Windows XP, 1GB of RAM, and a fairly healthy Duo core processor.  I have a workaround where I throttle back the read operation, only reading 55% of the available samples, as reported by a DAQmx Read property node (the highest percentage I found that prevents the indicators from going blank).  This introduces a small lag between the real world and the data on display, however.  Also, it seems like a processor dependent solution.  I would have to tweak this percentage for every machine I run this on.
If I have left anything important out, please let me know, and I will do my best to clarify, and thank to anyone who reads this, and a big thank you to anyone who takes the time to reply.  Again, I would be real happy with a "That code looks good to me, and your thinking is correct", if that indeed is the case.
Thanks.
Attachments:
Log Monitor Block.JPG ‏292 KB

Yeah, as you and Erik said, just specifying (Sample Rate / 5) as the '# to read' could do the trick.  Then you can ditch the 'Wait (msec multiple)' function.  I don't think I'd recommend the -1 = infinite timeout though.  I'm pretty leery of stuff that can lead to an infinite wait or an infinite loop.  Even a 1 sec timeout should easily be way more than enough.  Note however that this method depends on all your processing code executing in under 200 msec on average.  Otherwise, your reads will fall behind and you'll eventually get a DAQ buffer overflow error.  My earlier suggestion to first query for # available samples and then read the MAX of (# available, SampleRate/5) will prevent cumulative fall-behind effects.
There's too many unknowns to speculate with any confidence on exactly why the software timing method didn't work.   I can point out some additional things that bear greater scrutiny though.
1. You've got some sort of function dealing with file streaming that takes a path input and produces a path output.  This probably means that every loop iteration you're using the path to open a file, write data, and close the file again.  This actually may consume more than 200 msec, at least some of the time.  Because this runs in parallel with the msec wait function, something like the following could be happening:
A. Iteration 1 proceeds as expected.  The DAQ read collects 20 samples, the file write consumes only 100 msec, and the wait msec function ends after 160 msec in order to end on a 200 msec multiple.  The wait function took longest, so your whole loop ends on a 200 msec multiple.
B. On iteration 2, the wait msec function ends after 200 msec on the next 200 msec multiple.  The DAQ read collects another 20 samples (because it's been pretty much exactly 200 msec since the previous loop iteration started) right away.  However, Windows was busy messing with the file cache so this time your file write consumes 375 msec.  The file function took longest so your whole loop ends 175 msec into the next 200 msec multiple.
C. On iteration 3, the wait msec function ends after 25 msec on the next 200 msec multiple.  The DAQ read collects 37 samples that have come in since the prior call 375 msec ago.  The file function consumes only 50 msec this time, ending the loop 25 msec into the next 200 msec multiple.
D. On iteration 4, the wait msec function ends after 175 msec at the next 200 msec multiple.  The DAQ read collects the 5 samples that have come in since the prior call 50 msec ago.  Uh oh, not enough samples...
One possible fix is to open the file outside the loop and leave it open until after the loop is done.  Opening and closing files has quite a lot of overhead.  Inside the loop, you'd be passing around the file refnum.  Doing this one thing alone might also be a way to fix your timing problem.  Along similar lines, you could write the data to a queue and then do your file writes in an independent loop that reads the data out of the queue.  You can search here for "producer consumer" for more info.
-Kevin P.

Similar Messages

  • How do I use daqmx to get encoder direction/count on E-series board?

    Hardware:
    PCI-6014
    Labview 7.1
    I have a linear actuator and wish to get distance/direction.  The
    motor has a quad encoder with phase A and B only.  I connected the
    lines according the the E-series, PFI-8 and PFI-6, and ground to
    digital ground. I then attempted to design a control with daqmx but
    failed.  I have tried the daqmx examples but none were attempting
    a reverse in direction.  Most examples given for direction change
    are for traditional daq control; i cant make a correlation on what to
    use to substite traditional daq with daqmx vi's. 
    2 questions:
    How do I use daqmx to get encoder direction/count on E-series board?
    Are there low pass filter vi's recommended for each phase connection to stabilize data?
    Thanks,
    Wayne Hilburn

    Hello Wayne,
    Take a look at the Count Digital Events.vi shipping example.  You can find this in LabVIEW by selecting Help >> Find Examples... then browsing to Hardware Input and Output >> DAQmx >> Counter Measurements >> Count Digital Events.
    If you set the "Count Direction" control to "Externally Controlled", you will be able to count up and down depending on which direction you rotate your encoder.  Make sure you wire Phase A to Ctr0 Source and Phase B to P0.6.  P0.6 is the up/down line for counter 0.
    I hope this helps.  Please let me know if you have any further questions.
    Regards,
    Sean C.

  • How to make a good UI for channel selection using DAQmx

    A lot of my Labview programming was with earlier verisons of labview (pre Labview 7), and there are a ton of new features that I'm trying to digest (currently using Labview 8.2).
    My question is (in general terms), how are people programming their UI for selecting channels and such when using DAQmx hardware?  What I have in mind is a compacDAQ system with a number of modules.  The user would be able to pick and choose which channels to monitor.  Using MAX as part of that process seems counter intuative, and somewhat static (yeah I know you can change it there, but it feels more like something you would use for something that really doesn't change much).  I'd like all the UI to be within the VI.
    Are programmers using the create task VIs for that or something else?
    Thanks in advance.
    Solved!
    Go to Solution.

    I wholeheartedly second the motion to keep MAX out of the picture as far as users are concerned.
    Setting up UI's for channel selection is a breeze in DAQmx when you create channels on the block diagram. The control you create off the Channels input will populate itself with the inputs that it knows are capable of performing the desired task...
    <<< My configuration knows that my Module 5 is capable of doing Analog Input.
    So... Just create a panel that waits for the user to select the proper channel. I also run a quick check of the user's selection before creating / starting the task. For example, if they choose ai30 or higher, and I know that the system isn't wired for those inputs, I'll not allow that selection. Also check for using two of the same input, etc.
    Richard

  • How to make a virtual channel in MAX using DAQmx ?

    I want to measure the CJC temperature on the TBX 1328 ( attached to SCXI 1121). I want to create a virtual channel in MAX using DAQmx. I have right clicked on DAQmx but there is no option for virtual channel. Ther is the option of 'Traditional virtual channel' which i dont want.
    I used the VI to make the virtual channel but i want to knowhow to doit inMAX.
    thanks

    Here are 2 ways that you can create a DAQmx channel that appears in MAX.
    1) In MAX, right click on "Data Neighborhood" and select "Create New...". Then click "NI-DAQmx Global Channel" (or "NI-DAQmx Task" -- a task contains the channel(s) and triggering/timing information) and click "Next". This launches the DAQ Assistant that will guide you in creating the channel or task.
    2) In LV, place a NI-DAQmx Global Channel control on your panel or constant on your diagram. Right click on the control/constant and select "New Channel(DAQ Assistant)..." (Note: You can do the same from the NI-DAQmx Task control/constant to create a NI-DAQmx Task.)
    Deborah

  • How can I get properties of global virtual channels using DAQmx?

    I'm using DAQmx with VB6. In my app, I would like to be able to present the user with a list of available predefined channels to select from. I can use DAQmxGetSysGlobalChans to get a list of the channels, but I need a way to sort out which of these channels are defined as inputs, and which are outputs. It would also be nice to be able to query other properties of the virtual channel (for example, the device and physical channel being used). These all seem very simple things, but I haven't found anything like this in the documentation so far.
    Thanks.

    Try using  DAQmxGetChanType(TaskHandle taskHandle, const char channel[ ], int32 *data)DAQmxGetChanType(TaskHandle taskHandle, const char channel[ ], int32 *data).  This will return one of the following types:
    DAQmx_Val_AI
    10100
    Analog input channel.
    DAQmx_Val_AO
    10102
    Analog output channel.
    DAQmx_Val_DI
    10151
    Digital input channel.
    DAQmx_Val_DO
    10153
    Digital output channel.
    DAQmx_Val_CI
    10131
    Counter input channel.
    DAQmx_Val_CO
    10132
    Counter output channel.
    Let me know if this works. 
    Regards,
    L. Allen

  • Multiple inputs and outputs using DAQmx VIs

    Hello,
    I am fairly new with the LabView programming language.  I have a few training books that I have been reading, and I have been following online tutorials and reading the forums.  However, I have come to a problem where I don’t see a clear solution.  I am using LabView 2009 (9.0f3) and DAQmx VIs.
    I am using a NI 9172 chassis PLC, with two 9201 AI cards, 9217 AI RTD card, 9472 DO card, 9263 AO card, and two 9237 AI Bridge cards.
    I am reading eight analog inputs with the 9201 cards, two analog RTD inputs with the 9217 card, three digital outputs with the 9472 card, three analog outputs with the 9263, and eight analog inputs with the 9237 cards.
    I wrote a simple program to test one digital output task, two of the analog output tasks, and a single analog input task.  I put all of them in the same while loop, and it worked perfectly.  However, when I add analog input tasks to the same loop, I get an error 200022.    So I tested each sensor individually by changing the channel before each run.  I searched error 200022 and found that this is because I cannot start another analog input task until the previous one ends.  With this said, I don’t know how to acquire an analog voltage in the same task as an analog RTD voltage.  Both inputs take different constants in the start task DAQmx icon.
    Attached is my test program.  It is titled “Test All”. This is the program I used to test the various sensors.  I tested the input sensors one at a time, and it worked fine.  A few tasks are written just to test functionality, and will be added to later.  The data is only displayed on the screen.  I will add triggers and data write to disk functions later.  This program works now, but if I add more analog inputs, it will generate the 200022 error.
    Can someone show me how to correctly write the code for multiple inputs and outputs using DAQmx?  All training materials and tutorials I can find all show a single input or single output, not multiples of each.  Thanks for looking.
    -Randy
    Attachments:
    TestAll-NI.vi ‏32 KB

    Hi RandyC,
    The Knowledge Base article Using Different Types of DAQmx Global Channels in the Same Task goes into a little more depth of what Bryan is talking about, and it also includes some example code to help show what to do.
    Hope that helps,

  • How do I configure a counter to generate pulses using DAQmx?

    How do I configure a counter to generate pulses using DAQmx?
    Is says in the DAQmx C reference help
    "CtrnInternalOutput—The signal at this internal terminal is where the pulsed or toggled output of the counter appears. The output of a counter pulses or toggles when the counter reaches terminal count. When counting down, the counter reaches terminal count when the count reaches zero. When counting up, the counter reaches terminal count when the counter rolls over. To configure the counter to toggle or generate pulses, use the Export Signal function/VI with Counter Output Event as the signal name."
    I've tried this but can't get it to work, I may have the parameters wrong or something. The DAQmxExportSignal() function is very unintuitive to me. Here is my counter config code...
    int ret = 0;
    ret = DAQmxCreateTask("",&task_);
    errorMsg(ret);
    if (ret != 0)
    throw ret;
    // Configure the counter
    ret = DAQmxCreateCOPulseChanTicks( task_, "Dev1/ctr0", "", "/Dev1/PFI8", DAQmx_Val_Low, 0, divider, divider );
    errorMsg(ret);
    ret = DAQmxCfgImplicitTiming( task_, DAQmx_Val_ContSamps, 1000 );
    errorMsg(ret);
    // Change to pulse mode
    ret = DAQmxExportSignal( task_, DAQmx_Val_CounterOutputEvent, "/Dev1/Ctr0InternalOutput" );
    errorMsg(ret);
    // Start the counter
    ret = DAQmxStartTask(task_);
    errorMsg(ret);
    The above code works fine, in toggle mode, if I just comment out the DAQmxExportSignal() part.
    HELP!!!
    Stefan

    The problem is due to the DAQmxExportSignal call.  By default, when you create a counter output pulse train task, the driver will automatically set the output of the counter to toggle when the count for each high ticks and low ticks expire.  The driver also automatically routes the signal present at Ctr0InternalOutput terminal (the output of the counter internal to the device) to the Ctr0Out terminal (the I/O pin available externally).  Using the line
     ret = DAQmxExportSignal( task_, DAQmx_Val_CounterOutputEvent, "/Dev1/Ctr0InternalOutput" );
    will tell the driver to tristate the Ctr0Out terminal and not output the signal to the external I/O pin.  Using the DAQmxExportSignal function is generally only useful if you want to route the signal to some other terminal internal to the board without having the output show up on the external connector, route the signal to some other external pin other than the default pin, or if you want to have the output show up at multiple locations. 
    If you want to change the output behavior from toggle to pulse, you need to use the DAQmxSetExportedCtrOutEventOutputBehavior function.  However, this is generally only useful if all you care about are edges (not the duty cycle of the pulse train), and you want to generate higher frequency signals.  For example, with a 20 MHz timebase as the source of your counter, you can only generate a 5 MHz pulse train by default.  This is because the minimum value for the low and high ticks parameter is 2 (20 MHz / 4 = 5 MHz).  By changing the output behavior form toggle to pulse, you can generate a pulse train at 10 MHz since the output is now pulsing instead of toggling.  However, the width of each pulse is not programmable so you will no longer have a 50% duty cycle signal.  I don't remember exactly what the width of each pulse is, but I believe it's in the neighborhood of 50 - 100 nanoseconds in width.  I hope this information helps.

  • How do I reset an STC Counter using DAQmx?

    When another digital line goes high I want to reset my counter. How do I reset the counter using DAQmx?

    Hello,
    Thank you for contacting National Instruments.
    Please see this link for information on this issue.
    I have attached an example program which shows how to to do this in software.
    Regards,
    Bill B
    Applications Engineer
    National Instruments
    Attachments:
    Count_Digital_Events_with_Reset_Button.vi ‏68 KB

  • Does the voltage to temperature conversation require in usb 6008 using daqmx 8.5??

    Another question need u all guy help.I currently using K-type thermocoupler for my project using usb 6008.Does the voltage to temperature conversation require in usb 6008 using daqmx 8.5? what is DAQ TEDS function use ? is it help us to convert?

    You will need to factor the voltage per degrees C to get to reading in degrees, this is 10mv per degree V for the device mentioned in the post you previously made
    http://forums.ni.com/ni/board/message?board.id=170&message.id=246200#M246200
    TEDS - Transducer Electronic Data Sheet
    A video about TEDS
    http://digital.ni.com/demo.nsf/websearch/8e55de8fe6b5702686256e7c007a47b4?opendocument

  • How do i pass a daqmx task from labview to matlab using the math interface toolkit?

    I want to use DAQMX functions from Matlab using the Math Interface Toolkit (MIT). How can I have a labview function output (return) the DAQMX task to matlab via the MIT?
    I want to do this so I can start a DAQMX task in Labview from a matlab function and return control to matlab without losing the task.

    Hi Mark,
    (I already posted this answer in your other thread, but let's keep THIS thread alive - it makes more sense here in the LabVIEW forum than in Instrument Control forum.)
    Since the DAQmx Task is not a native data type that can be passed directly to MATLAB from LAbVIEW, try flattening the DAQmx Task to a string before passing to MATLAB. However, I doubt that you can access the task from within MATLAB, but feel free to give it a try.
    Good luck!
    - Philip Courtois, Thinkbot Solutions

  • How do I get a list of configured channel using DAQmx

    I would like to know how to read the channels in a task list or the global channels that are setup in MAX. I use to be able to do it in DAQ using the read channel VI. I can't find any equivalent in DAQmx. My new system works only with DAQmx. My program allows the operator to select from the channels configured in MAX.

    Hi Benegin,
    This can be found under the DAQmx System property node. I have attatched a picture to help you find it.
    -Sal
    Attachments:
    system_property_node.JPG ‏359 KB

  • Do I need to use DAQmx Base for PDA module or DAQmx will work just fine?

    Hi All,
    Does PDA module work only with DAQmx Base or DAQmx as well?
    hellolv

    Hi hellolv,
    The PDA module currently only works with DAQmx Base.  If you've never used DAQmx Base before, it is actually very similar to DAQmx, and there are lots of examples out there to get you started.  I recommend searching through our Example Code Library.
    Thanks,
    Justin M.
    National Instruments

  • Inverted Outputs using DAQMX

    We have been using traditional daq with an SCXI 1163.  We have an interface that uses an inverted digital output on odd channels.  Using traditonal DAQ we could set any of the bits to be inverted in the properties.  Using DAQMX it looks like you can only set them to all inverted or not and not able to set individual bits.

    Sorry for the late response was on vacation and then at NI Week.
    We have custom cards in our test systems that have logic driven by the SCXI 1163.  In the test mode we select two bits one inverted and the other non inverted (ie channel 0 and 1).  This allows us to read voltages and currents from our test systems by using the the test parameters of an SCXI 1102 in test mode using MAX.  The following screen shot is from the Traditional DAQ properties which allows you to set the bits to invert.  In DAQmx there is only one selection that allows you to invert all but not on an individual basis.  This prevents us from converting to DAQmx.  Hope this all makes sense.

  • When does a clock signal appear on a RTSI bus using DAQmx for a PCI NI-4472 DSA?

    Hello,
    I am trying to synchronize several PCI NI-4472 DSA boards over a RTSI cable using MATLAB. I have read that with DAQmx it is not necessary to use DAQmxExportSignal to put the clock signal on a RTSI line provided that the RTSI cable is registered in MAX and that the DSA cards are listed as being connected to the RTSI device. Apparently, the DAQmx drivers are supposed to route the clock signal between the cards as required….
    So I have done the above and see in MAX, in the device routes tab for Dev1, that
    /Dev1/ai/SampleClock uses RTSI6
    /Dev1/ai/SampleClockTimebase uses RTSI8
    Right now I am monitoring the RTSI lines on an oscilloscope in the hopes of detecting a clock signal on one of the three boards in the system while one board (the eventual master) is acquiring data using the Test Panels in MAX. I am getting nothing on the ‘scope (may be monitoring the wrong line – have just posted a request for RTSI pinouts for this DSA) and am wondering under what circumstances is the clock present on the RTSI bus.
    My real problem is that MATLAB R14SP3 does not yet support a master card in a synchronization application but, oddly enough, seems to allow one to setup slave cards. I would like to continue using the MATLAB data acquisition toolbox to manage the DSA cards and the application and would rather avoid using calls the DAQmx dll library. (It's not clear how to integrate the functionality of the data acquisition toolbox with direct calls to the DAQmx library.) So I am looking for a workaround to get the clock signal on the RTSI bus so that I may try out the slaves.
    Thanks,
    Sebulba

    Hi
    Both ports of a two port CAN board are handled by one processor and they use the same memory for alocating the necessary queues.
    But, both ports if connected to different CAN buses have their own handle, own queues and error handling. That means if one Bus enters to BUS OFF, the second bus can still communicate. And you can stop and restart communication independently on both ports. Even the ncaction reset works  on a single port at a time.
    DirkW

  • PXI 4070 use DAQmx Drivers

    I have replaced a PXI 4060 card with a PXI 4070 card in a PXI 1042 chassis that I use for resistance measurements.  I want to use DAQmx drivers instead of the traditional daq drivers.  How can I do this?
    My controlling software is VB6.  I have had issues with traditional daq on Windows XP machines with new NI installations.  Errors indicate there is an issue with the traditional daq drivers.  The sample applications installed with the niDMM 2.7 installation error with message "Error Loading Driver Module".  I have used the palbase utility in the past to work around this issue, however, the palbase utility is not failing to change the base address.  There is an error message associated with the failure, but I figure I may save myself the headache by switching to DAQmx drivers.

    I would recommend upgrading to the niDMM 3.0.4 drivers found here.  This version is still compatible with Visual Basic 6.0 and Windows XP.  niDMM 2.7 would have installed NI-DAQ 8.5.  The name indicates that it is traditional DAQ, but as far as I can tell, version 8.5 was only DAQmx.  3.0.4 will also install a newer version of DAQmx that is compatible with XP, as well as the examples.  It seems that the version you have should have worked, but there may be some corruption, or there may have been a version of traditional DAQ 8.5 at some time (we had some versions of NI-DAQ that included both traditional DAQ and DAQmx).  I hope this helps!
    Thanks,
    Sean
    Applications Engineering Specialist - Semiconductor Test
    National Instruments

Maybe you are looking for