ABV Labs
HomeProductsResourcesSupport & CommunityResellersContact

Tutorial

Analog Output

Write voltages or DAC codes, inspect output state, and generate finite or onboard-repeat waveforms with explicit handles and status.

SignalDAQ 2421

Documentation edition: SignalDAQ SDK 0.13.0 — Current

Choose another edition

Write voltages or DAC codes, inspect output state, and generate finite or onboard-repeat waveforms with explicit handles and status.

ExampleTask
1generate one voltage
2set two outputs and inspect status
3generate a finite waveform
4repeat an onboard waveform
5write DAC codes

Connect a meter or scope to the selected AO and appropriate signal ground. Disconnect competing output sources. Verify the product manual and load limits before hardware use. Current voltage writes accept 0 to 5 V. Only the two-output example owns and zeros both channels; other examples own and zero AO0 only.

Use SDK 0.13.0 and firmware 1.1.36, the development pairing documented by this SDK. This is a breaking wrapper/read API update; rebuild callers and use the matching DLL. Use Windows 10 or later, the SignalDAQ WinUSB driver for hardware, and an x64 or x86 DLL matching the calling process. Close other SignalDAQ applications before opening hardware.

All complete examples open the simulator by default. It opens no USB device and generates no physical voltage. Simulation checks API usage and software state, not analog accuracy, electrical timing, throughput, or waveform integrity.

Device operations take an explicit handle and return signed status: 0 is success; AI/DIO stream reads also return +1 at normal finite EOF. Python returns status first when data is returned; C# uses out parameters; C uses output pointers. Check status before using outputs, and preserve partial stream-read data/counts on errors. These APIs do not automatically throw status errors. Loader/runtime failures and some utility helpers can still raise exceptions.

AI Single Read and Read return voltage values only. Single Read Codes and Read Codes return decoded signed I32 samples without host voltage conversion. Code reads and voltage reads consume the same acquisition queue. Raw AI Read returns packet bytes and is not a decoded-code read. AO likewise has separate voltage and decoded-code writes, plus a packet-byte Raw Write.

Use Python 3.9 or later. Install the wrapper from the SDK folder with python -m pip install ./wrappers/python. The worked programs import signaldaq as s; they use module functions, not Device analog methods. Keep the same environment for installation and execution.

Use a .NET 8 console project with a project reference to wrappers/csharp/SignalDAQ/SignalDAQ.csproj. The examples use SignalDAQ.Analog static methods and C# top-level statements. Set SIGNALDAQ_DLL to the absolute path of bin/x64/signaldaq.dll for an x64 process, or the x86 DLL for an x86 process. Read the examples before following the run commands below.

Use a Windows C compiler, include/signaldaq.h, the matching lib/x64/signaldaq.lib or lib/x86/signaldaq.lib, and the matching DLL beside the executable. Examples use C11 and the Windows timing API. The full header includes every handle, count and output parameter.

Run each complete program separately. The examples use explicit handles and status checks, including returned partial read counts and cleanup status.

Command AO0 to 2.5 V briefly. A voltage write uses the stored output calibration and needs no waveform Configure or Start.

Stop and Close do not reset static outputs. This complete program explicitly returns AO0 to 0 V during cleanup. A meter reading depends on hardware accuracy and loading; simulator state is not a physical measurement.

Code example

import math
import sys
import time
import signaldaq as s

def report(status):
    print(f"SDK status {status}: {s.status_message(status)}", file=sys.stderr)
    return status

def run_example(handle):
    status = s.write_single_ao(handle, [s.AOChannel.AO0], [2.5])
    if status != 0:
        return report(status)
    print("AO0 commanded to 2.5 V")
    time.sleep(0.25)
    return 0

def main():
    status, handle = s.open_simulated()
    if status != 0:
        report(status)
        return 1
    result = 0
    try:
        result = run_example(handle)
    finally:
        # Attempt every cleanup operation, even when an earlier one fails.
        cleanup = [
            ("Stop AO", s.stop_ao(handle)),
            ("Zero owned outputs", s.write_single_ao(handle, [s.AOChannel.AO0], [0.0])),
            ("Close", s.close_device(handle)),
        ]
        for label, status in cleanup:
            if status != 0:
                print(label, file=sys.stderr)
                report(status)
                if result == 0:
                    result = status
    return 0 if result == 0 else 1

if __name__ == "__main__":
    raise SystemExit(main())

Select AO0 and AO1, command 1 V and 3 V respectively, and request their output state in the same order. This program owns and zeros both outputs during cleanup.

The function return is SDK status; the separate output object contains cached DAC codes, estimated voltages, enabled flags and waveform-running flags. It is not a voltage measurement or physical DAC-register readback.

Single writes are sequential; a later channel failure may leave an earlier channel changed.

Code example

import math
import sys
import time
import signaldaq as s

def report(status):
    print(f"SDK status {status}: {s.status_message(status)}", file=sys.stderr)
    return status

def run_example(handle):
    channels = [s.AOChannel.AO0, s.AOChannel.AO1]
    status = s.write_single_ao(handle, channels, [1.0, 3.0])
    if status != 0:
        return report(status)
    status, output_state = s.get_ao_status(handle, channels)
    if status != 0:
        return report(status)
    print("Estimated volts:", output_state['estimated_volts'])
    print("Enabled:", output_state['output_enabled'])
    return 0

def main():
    status, handle = s.open_simulated()
    if status != 0:
        report(status)
        return 1
    result = 0
    try:
        result = run_example(handle)
    finally:
        # Attempt every cleanup operation, even when an earlier one fails.
        cleanup = [
            ("Stop AO", s.stop_ao(handle)),
            ("Zero owned outputs", s.write_single_ao(handle, [s.AOChannel.AO0, s.AOChannel.AO1], [0.0, 0.0])),
            ("Close", s.close_device(handle)),
        ]
        for label, status in cleanup:
            if status != 0:
                print(label, file=sys.stderr)
                report(status)
                if result == 0:
                    result = status
    return 0 if result == 0 else 1

if __name__ == "__main__":
    raise SystemExit(main())

Queue 1024 samples on AO0, alternating 1 V and 3 V every 64 samples, at a requested 10000 S/s/channel.

Configure returns the actual configured rate. Start is asynchronous; wait for generation to stop before cleanup. The status poll has a five-second application deadline.

At a returned 10000 S/s the nominal duration is 0.1024 seconds. An early Stop truncates output even if every sample was uploaded. A stopped flag alone is not a waveform-integrity measurement.

Code example

import math
import sys
import time
import signaldaq as s

def report(status):
    print(f"SDK status {status}: {s.status_message(status)}", file=sys.stderr)
    return status

def run_example(handle):
    waveform = [1.0 if (i // 64) % 2 == 0 else 3.0 for i in range(1024)]
    status, actual_rate = s.configure_ao(handle, [s.AOChannel.AO0], 10000,
        s.GenerationMode.Finite, finite_samples_per_channel=len(waveform))
    if status != 0:
        return report(status)
    print(f"Configured rate: {actual_rate:g} S/s/channel")
    status = s.write_ao(handle, waveform)
    if status != 0:
        return report(status)
    status = s.start_ao(handle)
    if status != 0:
        return report(status)

    deadline = time.monotonic() + 5.0
    while True:
        status, output_state = s.get_ao_status(handle, [s.AOChannel.AO0])
        if status != 0:
            return report(status)
        if not output_state['waveform_running'][0]:
            break
        if time.monotonic() >= deadline:
            return report(-3)
        time.sleep(0.01)
    print("Finite waveform stopped")
    return 0

def main():
    status, handle = s.open_simulated()
    if status != 0:
        report(status)
        return 1
    result = 0
    try:
        result = run_example(handle)
    finally:
        # Attempt every cleanup operation, even when an earlier one fails.
        cleanup = [
            ("Stop AO", s.stop_ao(handle)),
            ("Zero owned outputs", s.write_single_ao(handle, [s.AOChannel.AO0], [0.0])),
            ("Close", s.close_device(handle)),
        ]
        for label, status in cleanup:
            if status != 0:
                print(label, file=sys.stderr)
                report(status)
                if result == 0:
                    result = status
    return 0 if result == 0 else 1

if __name__ == "__main__":
    raise SystemExit(main())

Upload a 256-sample sine cycle once, then repeat it onboard for a short demonstration. The requested waveform spans 0.5 to 4.5 V.

Configure Onboard does not upload or start. Write the complete cycle before Start. The entire waveform must fit the reported onboard capacity; no PC refill is needed during repeat.

Use the returned rate to calculate frequency: actual rate / 256. At 10000 S/s that is 39.0625 Hz. Increase the hold time when observing hardware.

Code example

import math
import sys
import time
import signaldaq as s

def report(status):
    print(f"SDK status {status}: {s.status_message(status)}", file=sys.stderr)
    return status

def run_example(handle):
    samples_per_cycle = 256
    waveform = [2.5 + 2.0 * math.sin(2 * math.pi * i / samples_per_cycle) for i in range(samples_per_cycle)]
    status, actual_rate = s.configure_ao_onboard(handle, [s.AOChannel.AO0], 10000, samples_per_cycle)
    if status != 0:
        return report(status)
    print(f"Cycle frequency: {actual_rate / samples_per_cycle:g} Hz")
    status = s.write_ao(handle, waveform)
    if status != 0:
        return report(status)
    status = s.start_ao(handle)
    if status != 0:
        return report(status)
    time.sleep(0.25)
    return 0

def main():
    status, handle = s.open_simulated()
    if status != 0:
        report(status)
        return 1
    result = 0
    try:
        result = run_example(handle)
    finally:
        # Attempt every cleanup operation, even when an earlier one fails.
        cleanup = [
            ("Stop AO", s.stop_ao(handle)),
            ("Zero owned outputs", s.write_single_ao(handle, [s.AOChannel.AO0], [0.0])),
            ("Close", s.close_device(handle)),
        ]
        for label, status in cleanup:
            if status != 0:
                print(label, file=sys.stderr)
                report(status)
                if result == 0:
                    result = status
    return 0 if result == 0 else 1

if __name__ == "__main__":
    raise SystemExit(main())

Use Single Write Codes for one integer value and Write Codes for a finite waveform. Current DAC codes are unsigned integers from 0 to 65535.

These calls bypass host voltage calibration. A code is not a calibrated voltage request. Raw Write is different: it accepts firmware packet bytes, not an array of decoded DAC values.

The finite waveform alternates codes 13107 and 39321; do not infer measured voltages from these example codes. The program stops and commands AO0 to 0 V during cleanup.

Code example

import math
import sys
import time
import signaldaq as s

def report(status):
    print(f"SDK status {status}: {s.status_message(status)}", file=sys.stderr)
    return status

def run_example(handle):
    status = s.write_single_ao_codes(handle, [s.AOChannel.AO0], [32768])
    if status != 0:
        return report(status)
    waveform = [13107 if (i // 64) % 2 == 0 else 39321 for i in range(1024)]
    status, actual_rate = s.configure_ao(handle, [s.AOChannel.AO0], 10000, s.GenerationMode.Finite, len(waveform))
    if status != 0:
        return report(status)
    status = s.write_ao_codes(handle, waveform)
    if status != 0:
        return report(status)
    status = s.start_ao(handle)
    if status != 0:
        return report(status)

    deadline = time.monotonic() + 5.0
    while True:
        status, output_state = s.get_ao_status(handle, [s.AOChannel.AO0])
        if status != 0:
            return report(status)
        if not output_state['waveform_running'][0]:
            break
        if time.monotonic() >= deadline:
            return report(-3)
        time.sleep(0.01)
    print("Finite waveform stopped")
    return 0

def main():
    status, handle = s.open_simulated()
    if status != 0:
        report(status)
        return 1
    result = 0
    try:
        result = run_example(handle)
    finally:
        # Attempt every cleanup operation, even when an earlier one fails.
        cleanup = [
            ("Stop AO", s.stop_ao(handle)),
            ("Zero owned outputs", s.write_single_ao(handle, [s.AOChannel.AO0], [0.0])),
            ("Close", s.close_device(handle)),
        ]
        for label, status in cleanup:
            if status != 0:
                print(label, file=sys.stderr)
                report(status)
                if result == 0:
                    result = status
    return 0 if result == 0 else 1

if __name__ == "__main__":
    raise SystemExit(main())

Each worked listing is a complete independent program. Copy one language tab into a file; do not combine several listings or paste API reference declarations into a program. Run the simulator first. Cleanup checks Stop, output reset where applicable, and Close even after an earlier operation fails.

python -m pip install ./wrappers/python
python example.py

For hardware, replace s.open_simulated() with s.open_device() or s.open_device("YOUR_SERIAL"). Both return (status, handle); leave explicit handle arguments and status checks in place.

# PowerShell from the SDK folder; use an x64 process.
dotnet new console -n SdkExample -f net8.0
dotnet add ./SdkExample/SdkExample.csproj reference ./wrappers/csharp/SignalDAQ/SignalDAQ.csproj
# Replace SdkExample/Program.cs with one complete C# listing.
$env:SIGNALDAQ_DLL = (Resolve-Path ./bin/x64/signaldaq.dll).Path
dotnet run --project ./SdkExample/SdkExample.csproj

For hardware, replace Analog.OpenSimulated(out uint handle) with Analog.Open(null, out uint handle), or supply a serial string instead of null. Every analog method returns status explicitly. The listing uses application-level Report helpers; the SDK does not throw analog status errors automatically.

cl /nologo /W4 /std:c11 /I include example.c /link lib/x64/signaldaq.lib
copy bin\x64\signaldaq.dll .
example.exe

Run the C commands in an x64 Visual Studio Developer Command Prompt from the SDK folder. For hardware, replace sdaq_open_simulated(&handle) with sdaq_open(NULL, &handle), or pass a serial string. Match the compiler target, import library and DLL architecture.

SDK 0.13.0: include/signaldaq.h; wrappers/python/signaldaq/init.py; wrappers/csharp/SignalDAQ/Analog.cs, Digital.cs, Specialty.cs, Native.cs; ANALOG_API_0_9_0.md; DIO_API.md; DIGITAL_SPECIALTY_API.md; TIMEOUT_POLICY.md. Firmware 1.1.36: SignalDAQ 2421/Software/Core/Inc/daq_protocol.h and Core/Src/daq_app.c, dio.c, dac80502_sai.c. Existing analog API documentation version names are historical; current public signatures come from this SDK source.

Worked listings are validated with the SDK simulator, not physical hardware. LabVIEW import headers and DLLs are current; binary VI regeneration and execution remain pending. No LabVIEW diagram or fabricated textual diagram is included.

Related resources