|
| View previous topic :: View next topic |
| Author |
Message |
mferreira
Joined: 04 Apr 2012 Posts: 9 Location: Coimbra, Portugal
|
Posted: Wed Apr 04, 2012 6:15 am Post subject: Get data from all active channels |
|
|
Hello,
I'm beginning with X3-10M and to understand how it works I took a look at the Snap Example.
To get the data I've added the following code in the ApplicationIo::HandleDataAvailable() function in the ApplicationIo.cpp file:
| Code: |
void ApplicationIo::HandleDataAvailable(PacketStreamDataEvent & Event)
{
if (Stopped)
return;
Buffer Packet;
//
// Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
IntegerDG Packet_DG(Packet);
if (Settings.RTPlotEnable)
Plot.Update(Packet);
////////////////////////////////////////////////
/// Adicionado por mferreira @ 03-04-2012
fstream fich; // declaração de ficheiro
fich.open("dadosTexto.txt", fstream::app); // abrir ficheiro
for (IntegerDG::iterator it = Packet_DG.begin(); it < Packet_DG.end(); ++it) {
fich << *it << endl;
}
fich.close();
/// Fim de Adição
////////////////////////////////////////
//
// Process the data packet
PacketBufferHeader PktBufferHdr(Packet);
// If enabled, log the data stream
if (Settings.LoggerEnable || Settings.PlotEnable)
if (FBlockCount < BlocksToLog)
Logger.LogWithHeader(Packet);
TallyBlock(Packet_DG.size()*sizeof(int));
}
|
I've managed to get some data, but only from half of the active channels. If two channels are active (ch 0 and 1), only get in file the data from channel 1. If 4 channels are active (ch 0, 1, 2 and 3), only get data from channels 1 and 3. And the same appends with 6 and 8 active channels.
Can you help to get the data from all channels?
Thank you. _________________ Miguel Ferreira |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2248 Location: So. Cal. USA
|
Posted: Wed Apr 04, 2012 11:25 am Post subject: |
|
|
It is not appropriate to open a file and perform I/O within the HandleDataAvailable event callback. This event is called in real-time, as buffers of data flow from the module to the host, so the act of opening the file would be repeated as each buffer flows to the host. This will corrupt the data written to your file, and will make it impossible to sustain rate.
The example already incorporates a DataLogger object to store the raw binary data received from the card into a disk file in real-time (within the capabilities of your disk subsystem). The format of the data received is discussed in the forum post http://www.innovative-dsp.com/forum/viewtopic.php?t=411&highlight=format.
Alternately, you could access the data within the packet delivered in the handler in real-time, using the Datagrams, as detailed in the Malibu User Guide. |
|
| Back to top |
|
 |
mferreira
Joined: 04 Apr 2012 Posts: 9 Location: Coimbra, Portugal
|
Posted: Thu Apr 05, 2012 8:47 am Post subject: |
|
|
Hello,
I followed your advice and put the write to file function out of HandleDataAvailable(). In this function create the following code:
| Code: |
...
if (Settings.RTPlotEnable)
Plot.Update(Packet);
////////////////////////////////////////
/// Added by mferreira @ 05-04-2012
int samples = Packet_DG.size()/Canais;
vector <float> temp;
for(int i = 0; i < Canais; i++)
ChannelData.push_back(temp);
// Extract data from buffer to vector
for(int i = 0; i < Canais; i++){
for(int j = 0; j < samples; j++){
ChannelData[i].push_back(Packet_DG[j*Canais + i]);
}
}
////////////////////////
//
// Process the data packet
PacketBufferHeader PktBufferHdr(Packet);
...
|
Where Canais is a class variable that get the number of channels from ActiveChannels, and ChannelData is a dynamic matrix where the data from the board will be stored.
To write the data stored in this matrix to a file, I've put the following code in HandleAfterStreamStop():
| Code: |
...
UI->AfterStreamAutoStop();
Log(std::string("Analog I/O Stopped"));
/////////////////////////////////////
// Added by mferreira @ 5-4-2012
fstream fich;
float scalefactor = 2.0 / (1 << 15); // Factor de escala para 2V máx
fich.open("dadosTexto.txt", fstream::out);
for(int i = 0; i < Canais; i++){
fich << "Canal " << i << endl;
for(int j = 0; j < ChannelData[i].size(); j++){
fich << ChannelData[i][j] << " -> " << ChannelData[i][j] * scalefactor << endl;
}
fich << endl;
}
fich.close();
///////////////////////////////////
|
Despite this, I was unable to get data from all channels. The previous problem was still happening. So I studied the .bin file that the Snap Example generates and found that each channel sends a 16-bit word per sample and not a 32-bit word per sample. Changing the buffer type from IntegerDG to ShortDG solved the problem.
Can you please tell me if my new approach is correct, or if there is a better one?
Thank you for your advice. _________________ Miguel Ferreira |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2248 Location: So. Cal. USA
|
Posted: Thu Apr 05, 2012 9:28 am Post subject: |
|
|
| This is a reasonable approach. As with all software, it is always possible to optimize further, but if this meets your rate requirements, it is fine. |
|
| Back to top |
|
 |
|
|
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
|
|
|