Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

write async

Hi all!
I am using Measurement studio 8.0 with Visual Studio 2003 (C++) and a DAQmx PCI 6733.
 
I am trying to edit my code that sends a continuous sine wave to use the asynchronous analog output mode called "WriteMultiSampleAsync" rather than the synchronous mode. The synchronous output mode works fine (see source code attached), but I am getting random errors for the asynchronous mode (see attached source and images of the errors).
 
I need to use the asynchronous mode to keep in memory the last phase of the previous buffer and send immediately afterwards a new buffer starting with this phase. I have already been using successfully the asynchronous functions to read a signal, and everything worked ok.
 
I can't see what is wrong with that async signal writing code. Can somebody help me?
0 Kudos
Message 1 of 8
(6,485 Views)
Hi,
  judging by the error message, the matrix you're making is in the wrong direction, and you're trying to make 1.9GB of data.
Window's won't allow that size of data - you're getting the size of the data to generate from the
unsigned int size = signal.positiveSignal.GetSize();
how big is "size"?
Also if you sort out the matrix, you'll have to work in columns instead I think.
 
I know the working one - where the only real difference is the Aynch write - works OK with the matrix in that orientation, but could you give it a try anyway?
 
If not, can you post your entire project, so I can view the member variables as it runs though.
 
Does that help?
 
Thanks
 
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
Message 2 of 8
(6,464 Views)
Hi SachaE,
First thanks for your interest and trying to help me!
To answer your question, unsigned int size = signal.positiveSignal.GetSize(); is 2048 points ! That explain the reason why it works with my Synchronous project. It still doesn't explain the message I get in the Asynchronous project. I suspect it is because I am misusing the Asynchronous mode.
 
I already successfully used the following modes in my project:
  • Synchronous reading (ReadSingleSample() et ReadMultiSample())
  • Synchronous writing (WriteSingleSample() et WriteSingleSampleAsync())
  • Asynchronous reading (ReadSingleSampleAsync()) et ReadMultiSampleAsync())
However the last possible mode (Asynchronous writing) is not in the National Instrument help files. I have tried to make my own version of it, by copying the techniques used in the Asynchronous reading, but I am convinced my mistake comes from that.
 
What i am after would be the simplest example of how to use the Asynchronous writing mode with a DAQmx card. Does somebody have that?
 
Thanks a lot again! NI support is one of the best I have ever used!
Rad
0 Kudos
Message 3 of 8
(6,437 Views)

I got back to a very simple project 🙂

Here is the way I tried to convert a ReadMultiSampleAsync project into a WriteMultiSampleAsync project, using my own function generator library.

If I use WriteMultiSampleAsync, I get a "Unhandled exception at 0x6daf0c34 in ContAcqVoltageSamples_IntClk.exe: 0xC0000005: Access violation reading location 0x01f340a8." If I replace WriteMultiSampleAsync by WriteMultiSample, I have no such error.

Does somebody know what I am doing wrong? Or does somebody has a WriteMultiSampleAsync example?

0 Kudos
Message 4 of 8
(6,431 Views)

Hi,

  apologies for the delay.

In the startup section, you're using the asynchronous write, which given the speed of code execution, might not have finished writing the matrix to the buffer before you're actually starting it and it might not have established the full buffer area, so the next write is looking for memory that doesn't necessarily belong to the application at that point.

You always need to make sure that your initial write for a timed output has put all the buffer information written before you start.

You need to do one of two things around line 257

// Begin reading data
m_writer = std::auto_ptr<CNiDAQmxAnalogMultiChannelWriter>
(
new CNiDAQmxAnalogMultiChannelWriter(m_task->Stream));
m_writer->InstallEventHandler(*
this, OnEvent);
// NI Mod
//m_writer->WriteMultiSampleAsync(true, matrix, NULL);
// make sure the buffer is ready to start with.
m_writer->WriteMultiSample(false,matrix);
// End NI Mod

or you can do the WriteMultiSampleAsync, just wait using the return object from that function to see if it's finished writing first.

// Begin reading data
m_writer = std::auto_ptr<CNiDAQmxAnalogMultiChannelWriter>
(
new CNiDAQmxAnalogMultiChannelWriter(m_task->Stream));
m_writer->InstallEventHandler(*
this, OnEvent);
// NI Mod
//m_writer->WriteMultiSampleAsync(true, matrix, NULL);
CNiDAQmxAsyncOperation m_checkme;
// make sure the buffer is ready to start with.
m_checkme = m_writer->WriteMultiSampleAsync(false,matrix, 0);
m_checkme.WaitUntilDone(10000);
// End NI Mod

 The upshot of the second method is you need to be careful about when the second write occurs, and how much data you write the second time (make sure you're writing half the buffer or less comapred to the amount initially written around line 257.

Hope that helps

Thanks

Sacha Emery
National Instruments (UK) 

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 5 of 8
(6,413 Views)

Hi,

  here's another starting point to track through - hope that helps

Thanks

Sacha Emery
National Instruments (UK)

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 6 of 8
(6,410 Views)

Hi SachaE,
I am sorry for the delay coming back to you. I really appreciate what you're doing for me! I have tried you solution and it works fine! I would never have though about that by myself to be honnest! I have been trying to use your solution as a new starting point but i have to say I am still struggling about a particular point.

My aim is to get my card send a signal continuously with a start and stop button.
I have tried two different things to do that, but none of them is working. I must be misusing the provided API again! Smiley Indifferent

  • I have tried to install an even driven method in your thread based project included in your last post
  • I have tried to use the "CNiDAQmxAsyncOperation checkme" + "waitUntilDone" mecanism in my non-threaded project

I include source code of both projects in this message. I defenetly must be doing something clumsy. Can you point me towards a new idea? Smiley Wink

Thanks again !

0 Kudos
Message 7 of 8
(6,371 Views)

Hi SachaE,

Do you have any idea about the previous post I have written?

Thank a lot for you help so far!

Rad

0 Kudos
Message 8 of 8
(6,324 Views)