-
Notifications
You must be signed in to change notification settings - Fork 0
CtLab Library Code Examples
Here are some code examples to demonstrate how the CtLab Library is typically used.
These samples show how device-specific interfaces are used. They are related to the FPGA Lab. However, similar interfaces can be easily developed for other devices.
The code below generates an amplitude-modulated signal using two DDS generator channels.
// Configure DDS channel 0 (carrier, modulated by DDS channel 1).
signalGenerator.DdsGenerators[0].Waveform = Waveforms.Sine;
signalGenerator.DdsGenerators[0].Frequency = 1000;
signalGenerator.DdsGenerators[0].Amplitude = (short)(fpgaLab.DdsGenerators[0].MaximumAmplitude * 1 / 2);
signalGenerator.DdsGenerators[0].AmplitudeModulationSource = ModulationAndSynchronizationSources.DdsGenerator1;
// Configure DDS channel 1 (modulator).
signalGenerator.DdsGenerators[1].Waveform = Waveforms.Sine;
signalGenerator.DdsGenerators[1].Frequency = 100;
signalGenerator.DdsGenerators[1].Amplitude = (short)(fpgaLab.DdsGenerators[1].MaximumAmplitude * 1 / 4);
// Flush all modifications, i.e. send all set commands that have modified values.
appliance.SendSetCommandsForModifiedValues();
The following example shows how to configure the universal counter for frequency measurement with a gate time of 100ms. The universal counter is automatically polled for value changes which will raise the ValueChanged event.
// Configure the universal counter.
signalGenerator.UniversalCounter.PrescalerMode = PrescalerModes.GatePeriod_100ms;
// Flush all modifications, i.e. send all set commands that have modified values.
appliance.SendSetCommandsForModifiedValues();
// Listen to counter changes and display them.
signalGenerator.UniversalCounter.ValueChanged +=
(sender, e) => Console.WriteLine("Counter reported a new frequency: {0}", e.Value);
// Send the cached query commands periodically.
appliance.StartSendingQueryCommands(_queryCommandSendPeriod);
These samples show how the low-level interfaces are used. They use commands and messages and are the foundation for the device-specific interfaces.
The code below sends the value of 128 to subchannel 1.
// Send a command.
var setCommandClass = new SetCommandClass(_channel, 1);
setCommandDictionary.Add(setCommandClass);
setCommandClass.SetValue(128);
setCommandDictionary.SendCommandsForModifiedValues();
This example shows how to handle messages, in this case those received from subchannel 255.
// Prepare to receive messages.
var messageContainer = messageCache.Register(_channel, 255);
messageContainer.MessageUpdated +=
(sender, e) => Console.WriteLine("Message received, channel {0}/{1}, raw value {2}",
messageContainer.Message.Channel,
messageContainer.Message.Subchannel,
messageContainer.Message.RawValue);