User`s manual

Writing Custom Applications
//---------------------------------------------------------------------------
// ApplicationIo::HandleDataRequired()
//---------------------------------------------------------------------------
void ApplicationIo::HandleDataRequired(PacketStreamDataEvent & Event)
{
SendOneBlock(Event.Sender);
}
//------------------------------------------------------------------------------
// ApplicationIo::SendOneBlock()
//------------------------------------------------------------------------------
const int HeaderTagValuePostPacketizer = 0x00000000;
const int HeaderTagValueOriginal = HeaderTagValuePostPacketizer;
void ApplicationIo::SendOneBlock(PacketStream * PS)
{
static Buffer Packet;
ShortDG Packet_DG(Packet);
if (!FBlockCount)
{
Packet_DG.Resize(Settings.StreamPacketSize);
PacketBufferHeader PktBufferHdr(Packet);
PktBufferHdr.PacketSize(Settings.StreamPacketSize);
PktBufferHdr.PeripheralId(Module.Output().PacketId());
PktBufferHdr[1] = HeaderTagValueOriginal;
//
// Builds a one or 2 channel buffer
BuildWave(Packet, Settings.WaveType);
}
For speed, the packet is created on the first call only. After that, the same data wave is sent to all channels. Note that it is
allowed to send more than one output packet per notification. If no packets are sent, however, it is possible that further
notifications may stop until the application starts sending data again. This decoupling of notification from sending allows
different models of data generation to exist in Malibu. An application may send packets asynchronously and not handle
notifications at all.
// Calculate transfer rate in kB/s
double Period = Time.Differential();
if (Period)
FBlockRate = Packet_DG.SizeInBytes() / (Period*1.0e6);
//
// No matter what channels are enabled, we have one packet type
// to send here
PS->Send(Packet);
++FBlockCount;
}
X5-GSPS User's Manual 64