Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for counter output #15

Open
glopesdev opened this issue May 11, 2023 · 1 comment
Open

Add support for counter output #15

glopesdev opened this issue May 11, 2023 · 1 comment
Labels
proposal Request for a new feature

Comments

@glopesdev
Copy link
Member

The DAQmx counter output API is very useful for generating digital trains for experimental control. It is essentially a self-contained task which requires no input buffer to be provided, so it can be implemented as an observable source returning Unit.

@glopesdev glopesdev added the proposal Request for a new feature label May 11, 2023
@bruno-f-cruz
Copy link

Draft of possible implementation:

public override IObservable<Unit> Generate()
        {
            return Observable.Using(
                () => new Task(),
                task => Observable.Create<Unit>(observer =>
                {
                    task.COChannels.CreatePulseChannelFrequency(
                        counterChannel,
                        "",
                        COPulseFrequencyUnits.Hertz,
                        COPulseIdleState.Low,
                        0, frequency, dutyCycle);
                    if (numberOfSamples.HasValue)
                    {
                        task.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, numberOfSamples.Value);
                    }
                    else
                    {
                        task.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples);
                    }
                    task.Control(TaskAction.Verify);
                    task.Control(TaskAction.Commit);
                    task.Start();

                    task.Done += (sender, e) =>
                    {
                        if (e.Error != null) observer.OnError(e.Error);
                        else observer.OnCompleted();
                    };
                    return Disposable.Create(task.Stop);
                }
            )
            );
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants