Innovative Integration
 
Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
get my data to buffer

 
Post new topic   Reply to topic    II Support Forum Index -> X3-10M
View previous topic :: View next topic  
Author Message
cnrs-insu



Joined: 05 May 2009
Posts: 19

PostPosted: Tue Jul 07, 2009 1:01 pm    Post subject: get my data to buffer Reply with quote

Hello,
I am still working on X3-10M.
I develop from the snap example and adapt the source to a multithread console program.
When a packet is received, I need to extract the data from the packet to put it in a local buffer and add some other information.
For this purpose, I didn't find an example or something in the documentation.
The other thing that I need is the organisation of data as I am acquiring 4 channel of 2500 samples (xMHz) at each external trigger (20 Hz).
If you can help me on this point, it should be great.
Best regards
Back to top
View user's profile Send private message
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Tue Jul 07, 2009 2:36 pm    Post subject: Reply with quote

The data received from the board is formatted similar to that shown at forum post http://www.iidsp.com/forum/viewtopic.php?t=411&highlight=format. However, since you are using an X3-10M module with four channels enabled, the payload (which follows the header in each packet) will contain four interleaved channels of 16-bit, twos-complement binary data.

To process each channel within each packet, use code similar to the following within the HandleDataAvailable event handler method (as illustrated in the X3-10M Snap, ApplicationIo.cpp file:

Code:
//
//  Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
ShortDG Packet_DG(Packet);

int channels = Module.Input().Info().Channels().ActiveChannels();
unsigned int samples = Packet_DG.SizeInElements()/channels;
Buffer data(Holding<float>(Packet_DG.SizeInElements()));
FloatDG Data(data);
for (int ch = 0; ch < channels; ++ch)
   {
   for (unsigned int sample = 0; sample < samples; ++sample)
      Data[sample] = Packet_DG[sample*channels+ch];

   //Analyze Data buffer here - Application-specific
   }
Back to top
View user's profile Send private message Visit poster's website
cnrs-insu



Joined: 05 May 2009
Posts: 19

PostPosted: Wed Jul 08, 2009 4:15 am    Post subject: Reply with quote

Very Happy
Thanks for your help.
Back to top
View user's profile Send private message
ballard



Joined: 29 Apr 2011
Posts: 65

PostPosted: Fri Nov 18, 2011 7:12 am    Post subject: Reply with quote

if i want to put 2 channels in 2 separate arrays can i use following code?

Code:
   //----------------------------------Extract the packet from the Incoming Queue...
   Event.Sender->Recv(Packet);
   ShortDG Packet_DG(Packet);

   int channels = Module.Input().Info().Channels().ActiveChannels();
   unsigned int samples = (int)Packet_DG.SizeInElements()/channels;
   Buffer data(Holding<float>(Packet_DG.SizeInElements()));
   Buffer data2(Holding<float>(Packet_DG.SizeInElements()));
   FloatDG Data(data);
   FloatDG Data2(data);
   //---------------------------------set the scale of data
   float scalefactor = 2.0 / (1 << 15);

   //---------------------------------parsing the packet
   for (int ch = 0; ch < channels; ++ch)
   {
      for (unsigned int sample = 0; sample < samples; ++sample)   {
         if (ch==0)
            Data[sample] = Packet_DG[sample*channels+ch]*scalefactor;
         if (ch==1)
            Data2[sample] = Packet_DG[sample*channels+ch]*scalefactor;
      }
         
      
      //--------------------------------Analyze Data buffer here - Application-specific
   }
Back to top
View user's profile Send private message
ballard



Joined: 29 Apr 2011
Posts: 65

PostPosted: Fri Nov 18, 2011 7:24 am    Post subject: Reply with quote

sorry:

Code:
   FloatDG Data(data);
   FloatDG Data2(data2);
Back to top
View user's profile Send private message
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Fri Nov 18, 2011 8:10 am    Post subject: Reply with quote

I think you code is close, but you neglected to compensate for the size of each sample, which is 16-bits on the 10M.
Back to top
View user's profile Send private message Visit poster's website
ballard



Joined: 29 Apr 2011
Posts: 65

PostPosted: Thu Mar 01, 2012 2:34 am    Post subject: Reply with quote

Quote:
I think you code is close, but you neglected to compensate for the size of each sample, which is 16-bits on the 10M.


Thanks for an answer, but how i can do this, can you explain and show?
Back to top
View user's profile Send private message
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Thu Mar 01, 2012 6:05 am    Post subject: Reply with quote

Try something like the following. Note, code below is untested.


Code:
//----------------------------------Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
ShortDG Packet_DG(Packet);

int channels = Module.Input().Info().Channels().ActiveChannels();
size_t samples = Packet_DG.SizeInElements()/channels;
std::vector< std::vector<float> > Data(channels, std::vector<float>(samples));

//---------------------------------set the scale of data
float scalefactor = 2.0 / (1 << 15);

//---------------------------------parsing the packet
short * p = &Packet_DG[0];
for (size_t sample = 0; sample < samples; ++sample)   
   for (int ch = 0; ch < channels; ++ch)
      Data[ch][sample] = (*p++) * scalefactor;

//--------------------------------Analyze Data buffer here - Application-specific
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    II Support Forum Index -> X3-10M (GMT - 8 Hours)
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

© Copyright 2006-2012 Innovative Integration
Powered by phpBB © 2001, 2002 phpBB Group
Based on iCGstation v1.0 Template By Ray © 2003, 2004 iOptional