Start your 30-day complete trial →
Serial Flux Applications

Applications, Automation & Python Examples

Practical starting points for device communication, automated testing, data collection, production diagnostics, and Python-driven workflows.

Python is built in. Serial Flux Python Scripting does not require a separate Python installation and includes an integrated debugger. Examples can be opened, modified, stepped through, and adapted to your device or protocol.

What can you build?

Device Test Automation

Combine Send/Receive Sequences with Python to create repeatable functional and production tests.

Automatic Responses

Use Receive Sequence matching and automatic replies for device simulation, protocol testing, and command/response workflows.

Data Acquisition

Collect serial measurements, process values in Python, and write custom CSV or report files.

Multi-Device Testing

Work with multiple serial connections at the same time and independently start or stop connected devices.

Long-Running Diagnostics

Combine Serial Flux logging with Python test logic for soak tests, intermittent-fault investigation, and unattended captures.

Protocol Development

Exercise command sets, parameter ranges, timing behavior, wildcards, CR/LF terminated messages, and automatic replies.

Downloadable Examples

Python Examples

These starter scripts focus on useful automation patterns. Where an example says integration point, insert the Serial Flux Send/Receive API call appropriate for the project. This avoids presenting an API name that is not part of the current Serial Flux scripting API.

Python Example

Automated Test Template

Structure a repeatable device test with initialization, test, cleanup, PASS/FAIL reporting, and automatic logging.

# Serial Flux Python example: Automated test template
#
# This example shows a clean structure for a production test script.
# Add Serial Flux API calls for your project's Send/Receive Sequences where marked.

import time

def initialize_device():
    print("Initializing device...")
    # Example integration point:
    # Send your project's initialization Send Sequence here.
    time.sleep(0.25)

def run_test():
    print("Running test...")
    # Example integration point:
    # Send a command, wait for the expected Receive Sequence,
    # then evaluate the returned data.
    time.sleep(0.5)
    return True

def cleanup():
    print("Test complete.")

SF.startLogging()
try:
    initialize_device()

    if run_test():
        print("RESULT: PASS")
    else:
        print("RESULT: FAIL")
finally:
    cleanup()
    SF.stopLogging()
Python Example

Logging Control

Start and stop Serial Flux logging directly from an integrated Python script.

# Serial Flux Python example: Logging control
# Uses the Serial Flux logging API.

import time

print("Starting Serial Flux log...")
SF.startLogging()

# Run the test or communicate with the target here.
for second in range(10):
    print(f"Logging... {second + 1}/10")
    time.sleep(1)

SF.stopLogging()
print("Logging stopped.")
Python Example

Custom CSV Data Logger

Record measurements or parsed device data into a CSV file for Excel, reports, or later analysis.

# Serial Flux Python example: Custom CSV data logger
#
# Demonstrates writing measurements or parsed communication data
# to a CSV file using Python's built-in csv module.

import csv
import datetime
import time

filename = "serial_flux_measurements.csv"

with open(filename, "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["Timestamp", "Sample", "Value"])

    for sample in range(20):
        # Replace this demonstration value with data obtained from
        # your Serial Flux communication/test logic.
        value = sample * 0.125
        timestamp = datetime.datetime.now().isoformat(timespec="milliseconds")
        writer.writerow([timestamp, sample, value])
        print(timestamp, value)
        time.sleep(0.1)

print(f"Saved {filename}")
Python Example

Command / Parameter Sweep

Build automated test sweeps that exercise a device across a range of settings while recording communication.

# Serial Flux Python example: Command / parameter sweep template
#
# Useful for exercising a device over a range of settings.
# Insert the appropriate Serial Flux Send Sequence/API call for your project.

import time

values = [0, 10, 25, 50, 75, 100]

SF.startLogging()
try:
    for value in values:
        print(f"Testing setting: {value}")

        # Integration point:
        # Send the command or Send Sequence containing `value`.

        # Allow the target to respond before advancing.
        time.sleep(0.5)
finally:
    SF.stopLogging()

print("Sweep complete.")
Python Example

Exception-Safe Test

Use try/except/finally so a failed test is reported cleanly and logging is always stopped.

# Serial Flux Python example: Exception-safe automated test
#
# Shows a recommended pattern that always stops logging even when
# a test step raises an exception.

import time

def test_step(name, delay=0.25):
    print(f"STEP: {name}")
    time.sleep(delay)

SF.startLogging()

try:
    test_step("Reset target")
    test_step("Read version")
    test_step("Configure target")
    test_step("Run functional test")
    print("RESULT: PASS")

except Exception as exc:
    print(f"RESULT: ERROR - {exc}")
    raise

finally:
    SF.stopLogging()
    print("Logging closed.")