ABV Labs
HomeProductsResourcesSupport & CommunityResellersContact

Tutorial

Digital Input and Output

Configure bank directions, use optional write masks, read snapshots and status, and run finite input, output and duplex streams.

SignalDAQ 2421

Documentation edition: SignalDAQ SDK 0.13.0 — Current

Choose another edition

Configure bank directions, use optional write masks, read snapshots and status, and run finite input, output and duplex streams.

ExampleTask
1write masked bank values and read a snapshot
2acquire 17 finite input samples
3generate a finite bank pattern
4run four-bit input and output together

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.

Use a suitable signal source, meter or scope and the correct reference for the selected digital terminals. Verify electrical levels, loading and protection limits in the product manual before wiring; these tutorials do not infer them from analog voltage ranges. Disconnect competing output drivers. Pulse examples should first use an input-only load, not an actuator.

The complete programs take ownership of their named banks and return those entire banks to GPIO Input before work and during cleanup. This also releases specialty timer ownership. Do not adapt this cleanup to a shared bank without deciding which application owns it.

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.

EnumNamed values
DIOBankA=0, B=1
DIODirectionInput=0, Output=1
DIOWidthFourBit=4, SevenBit=7

Select one or two unique banks for static operations. Direction arrays match the bank array. SevenBit stream values use bits 0..6; FourBit values use bits 0..3. Current streaming supports one bank per direction, not two simultaneous input banks or two output banks.

Configure banks A and B as outputs. Set A to 85 and B to 3, then clear only bit 0 of A with mask 1. Read both banks in reverse order.

Omitted masks mean every valid bit, not zero bits. Explicit mask 0 changes nothing. Supplied masks, values and directions must match the bank selection length.

The simulator snapshot is [3, 84] for [B, A]. On hardware, Single Read samples pin levels; Status reports the output latch and configured direction. Neither is a waveform recorder. Static writes are sequential, not atomic.

This example owns bank A/B and resets that entire selection to GPIO Input before the example and during cleanup. Run separately; do not use it on a bank owned by another task.

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.configure_dio_direction(handle, [s.DIOBank.A, s.DIOBank.B], [s.DIODirection.Input] * 2)
    if status != 0: return report(status)
    banks = [s.DIOBank.A, s.DIOBank.B]
    status = s.configure_dio_direction(handle, banks, [s.DIODirection.Output]*2)
    if status != 0: return report(status)
    status = s.write_single_dio(handle, banks, [85, 3])
    if status != 0: return report(status)
    status = s.write_single_dio(handle, [s.DIOBank.A], [0], write_masks=[1])
    if status != 0: return report(status)
    status, pins = s.read_single_dio(handle, [s.DIOBank.B, s.DIOBank.A])
    if status != 0: return report(status)
    print("Pin snapshot B, A:", pins)
    status, state = s.get_dio_status(handle, banks)
    if status != 0: return report(status)
    print("Bank state:", state)
    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 = [
            ("Return owned banks to Input", s.configure_dio_direction(handle, [s.DIOBank.A, s.DIOBank.B], [s.DIODirection.Input] * 2)),
            ("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())

Configure bank B for SevenBit input at a requested 1000 samples/s. Start, read all 17 samples, and verify the next read returns +1 with zero count.

Every U32 sample holds one bank bit pattern in bits 0..6. Python/C# allocate internally; the C buffer capacity is 17 samples. Preserve the returned count and data before handling a read error.

Simulator input samples are zero, not a measured external voltage or loopback. Actual input values depend on wiring. The returned rate is nominal board timing; CPU-paced firmware and transfers can affect observed throughput.

This example owns bank B and resets that entire selection to GPIO Input before the example and during cleanup. Run separately; do not use it on a bank owned by another task.

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.configure_dio_direction(handle, [s.DIOBank.B], [s.DIODirection.Input] * 1)
    if status != 0: return report(status)
    status, actual = s.configure_dio(handle, [s.DIOBank.B], [s.DIODirection.Input],
        s.DIOWidth.SevenBit, 1000, s.AcquisitionMode.Finite, 17)
    if status != 0: return report(status)
    status = s.start_dio(handle)
    if status != 0: return report(status)
    status, values, count = s.read_dio(handle, -1)
    print("Nominal rate:", actual, "S/s; samples including partial data:", count, values)
    if status not in (0, 1): return report(status)
    status, tail, count = s.read_dio(handle, 1)
    print("End status:", status, "count:", count)
    if status != 1 or count != 0: return report(status if status != 0 else -10)
    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 DIO", s.stop_dio(handle)),
            ("Return owned banks to Input", s.configure_dio_direction(handle, [s.DIOBank.B], [s.DIODirection.Input] * 1)),
            ("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 17 SevenBit bank A samples, alternating 0 and 127. Start and poll bank Status until generation is no longer running, with a five-second application deadline.

Write success means host acceptance. Start is asynchronous: do not Stop immediately after upload. The finite total is smaller than 8000, so queue the entire 17-sample total before Start.

Finite completion retains the last output pattern until Stop. Stop returns the stream bank to Input; the runner also resets its owned bank. Status running=false is not an electrical waveform-integrity measurement.

This example owns bank A and resets that entire selection to GPIO Input before the example and during cleanup. Run separately; do not use it on a bank owned by another task.

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.configure_dio_direction(handle, [s.DIOBank.A], [s.DIODirection.Input] * 1)
    if status != 0: return report(status)
    status, actual = s.configure_dio(handle, [s.DIOBank.A], [s.DIODirection.Output],
        s.DIOWidth.SevenBit, 1000, s.AcquisitionMode.Finite, 17)
    if status != 0: return report(status)
    status = s.write_dio(handle, [127 if i%2 else 0 for i in range(17)])
    if status != 0: return report(status)
    status = s.start_dio(handle)
    if status != 0: return report(status)
    deadline = time.monotonic()+5
    while True:
        status, state = s.get_dio_status(handle, [s.DIOBank.A])
        if status != 0: return report(status)
        if not state['stream_running'][0]: break
        if time.monotonic() >= deadline: return report(-3)
        time.sleep(0.002)
    print("Generation stopped; nominal rate:", actual)
    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 DIO", s.stop_dio(handle)),
            ("Return owned banks to Input", s.configure_dio_direction(handle, [s.DIOBank.A], [s.DIODirection.Input] * 1)),
            ("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())

Configure A Output and B Input in FourBit mode, prefill 17 output values 0..15, then Start and read 17 input samples.

Current FourBit streaming fixes A as output and B as input. SevenBit streaming allows the supported alternative bank mappings. There is one bank per direction today; two input or two output banks are not supported by the streaming engine.

The simulator returns zero input samples and does not connect A to B. For physical loopback, wire only permitted digital outputs to inputs according to the product manual. DIO sample values are not packet bytes; there are no public DIO raw transfer calls.

This example owns bank A/B and resets that entire selection to GPIO Input before the example and during cleanup. Run separately; do not use it on a bank owned by another task.

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.configure_dio_direction(handle, [s.DIOBank.A, s.DIOBank.B], [s.DIODirection.Input] * 2)
    if status != 0: return report(status)
    status, actual = s.configure_dio(handle, [s.DIOBank.A, s.DIOBank.B],
        [s.DIODirection.Output, s.DIODirection.Input], s.DIOWidth.FourBit,
        1000, s.AcquisitionMode.Finite, 17)
    if status != 0: return report(status)
    status = s.write_dio(handle, [i%16 for i in range(17)])
    if status != 0: return report(status)
    status = s.start_dio(handle)
    if status != 0: return report(status)
    status, inputs, count = s.read_dio(handle, -1)
    print("Input samples including partial data:", count, inputs)
    if status not in (0,1): return report(status)
    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 DIO", s.stop_dio(handle)),
            ("Return owned banks to Input", s.configure_dio_direction(handle, [s.DIOBank.A, s.DIOBank.B], [s.DIODirection.Input] * 2)),
            ("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.

Static DIO selects one or two unique banks; values, directions and supplied masks match that selection. Omission is NULL/None/null and writes all valid bank bits. Explicit zero masks are no-ops. Single Read samples pin levels; Status returns output latches, directions and per-bank streaming flags, without measuring PWM waveforms.

Managed DIO Configure saves the bank selection. Subsequent sample Read/Write take handle and sample arrays/counts, not another bank selection. Today streaming supports one bank per direction. FourBit fixes A Output/B Input; SevenBit supports the permitted alternative mappings. Both directions share nominal firmware rate and finite total. Raw DIO Read/Write have been removed; SDK workers handle packet encoding and decoding.

DIO Read requestBehavior
Positive NWait for N samples per input bank or the finite tail. Preserve returned partial samples on error.
-1 in FiniteRead all remaining finite samples; bounded by the wrapper single-call allocation limit.
-1 in ContinuousReturn currently buffered samples without waiting.
After finite data drainsReturn status +1, empty array and count 0.

C DIO Read capacity bounds caller memory; Python/C# infer allocation. Output prefill is min(8000, finite total) samples for finite generation; longer output requires continued refills. Write accepts host data, not confirmation of generation. Read/write overflow, timeout or uncertain acceptance require recovery; never blindly retry blocks. Stop/Configure before restarting. Stop retains completed finite input but returns stream output banks to Input.

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