Skip to content

Systems

A collection of devices and harnesses that satisfies a set of functionality requirements for some external purpose.


How system data is stored

A system revision holds these lists. What each one is: Project data.


Building a system

  1. Harnice runs the build instructions if it's found in the system directory.

  2. The system is validated and verified.

  3. The external ICD is compiled from external-interface flags (after build instructions).

  4. The system block diagram SVG is updated from placed-instance symbol files under instance_data/ (so device/subsystem symbol edits are picked up), including derived channel/circuit trace overlays based on the built system.

  5. PDF drawings: call run_macro("pdf_generator", …, page_setup=…) in build instructions after other macros that write masters.

The subsystem_symbol macro runs in build instructions, so it reads the ICD from the previous build and runs device signals-list / symbol-pin verification against it. After ICD changes, build twice. That lag is expected.

The default system build instructions ship with Harnice as harnice/defaults/system_default_build_instructions.py. The first build copies them into build.py.

Default system build instructions
import os

# ===========================================================================
#                HARNESSES DEFINED ON BUSES
# ===========================================================================
# Nominally, draw harnesses in the block diagram as the specific bundles you may
# need, using buses to bundle groups of harnesses into a similar route. However,
# sometimes it is useful to define harnesses themselves with build rules. Route
# buses to your connectors in the block diagram, and add the device mating connectors
# to specific harnesses via code.
#
# Block-diagram-drawn harnesses have their definitions saved in the SVG block diagram.
# Build-instructions-defined harnesses have their definitions saved here. Declare
# them with harnesses.define(). mpn, rev, lib_repo, lib_subpath and design_exists are
# optional; without mpn the build warns and the harness is not on the BOM.
# harnesses.define(
#     "H10",
#     mpn="HRN-0042",
#     rev="1",
#     lib_repo="https://github.com/your-org/your-library",
#     lib_subpath="harnesses",
#     design_exists=True,
# )
#
# End the harness at device connectors on one bus. A drawn harness can also be
# extended onto a bus its run touches.
# harnesses.add_connector([("MIC1", "J1"), ("PRE1", "J3")], "H10")
#
# Every harness has an instance (item_type "harness"). Its appearance colors its
# trace in the Analyze harnesses view: a drawn harness starts with its line
# color, a harness defined here with #3a6ea5. To change one:
# instances.modify("H10", {"appearance": {"base_color": "#E24B4A"}})

# stop the build if a device connector on a bus has no harness
harnesses.verify()

# ===========================================================================
#                CHANNEL AND PASSTHROUGH MAPPING
# ===========================================================================
print("Mapping channels between devices...")

# system.build() already called channel_map.new() - one row per channel endpoint.
#
# A patch is two endpoints. Each key is:
#   (device_refdes, channel_id)                        # one endpoint
#   (device_refdes, channel_id, repeat_channel_id)     # two endpoints (a face)
# 3-tuple on a single-instance channel is an error; omitting the repeat on a
# two-instance channel is an error.
# Both endpoints (and any route() hop) must be in the same group of connected
# harnesses. Unmated terminating connectors are in no group.
#
# channel_map.map(from_key, to_key=None, multi_ch_junction_key="")
#
# endpoint -> endpoint:
# channel_map.map(("MIC1", "out1"), ("PRE1", "in1"))
#
# map onto one passthrough face. That face must have no harness, or the
# last hop must be that harness that your channel is routed through
# channel_map.map(("MIC1", "out1"), ("X1", "ch0", "A"))
#
# dual-map: two map() calls to the two faces of the same passthrough.
# consumes both as patch ends; does not write a passthrough-map row.
# channel_map.map(("MIC1", "out1"), ("X1", "ch0", "A"))
# channel_map.map(("SNK1", "in1"), ("X1", "ch0", "B"))
#
# map a channel endpoint to a shared multi_ch_junction_key
# channel_map.map(("MIC1", "out1"), multi_ch_junction_key="jcn1")

# force a 1:1 patch regardless of channel-type compatibility.
# Same signal names compile by name (pos still meets pos).
# Different signal names stay pending until circuits_list.force()
# pairs every from-side signal and drops every unused to-side signal.
# The circuit keeps the from-side name. A from-side signal cannot be dropped;
# swap the endpoints so the extra name is on the to side, then drop it.
# channel_map.force(("MIC1", "out1"), ("PWR1", "in1"))
# circuits_list.force(
#     ("MIC1", "out1"),
#     {"pos": "live", "neg": "neutral"},
#     drop=["earth"],
# )

# remaining single-endpoint channels in the same group of connected harnesses,
# compatible types, alphabetical. Skips every channel with more than one endpoint.
channel_map.map_unmapped_compatibles_alphabetically()

# this system's channel map, plus the channel map imported with every child
# subsystem (recursive). Unmapped rows are omitted. A passthrough with both
# faces mapped as patch ends becomes one row between the outer devices.
# Inside a subsystem, refdes,
# harness groups, junction ids, and connector/harness chains are prefixed:
# subsystem.name, or subsystem.subsystem.name. Channel ids are not.
channel_map.flatten()

print("Routing mapped channels through passthroughs and harnesses...")

# one row per passthrough channel, plus routing context (availables per
# group / from->to type / directionality). Dual-mapped passthroughs are omitted.
passthrough_map.new()

# add manual hops here (after new, before resolve).
# passthrough_map.route(
#     to_from_channel_device_refdes,  # either end of an already-mapped patch
#     to_from_channel_id,
#     intended_device_refdes,         # the passthrough device
#     intended_channel_id=None,       # omit to pick any available channel
#     repeat_channel_id=None,         # face the from-side arrives on; omit to infer
# )
# passthrough_map.route("MIC1", "out1", "X1")
# passthrough_map.route(
#     "MIC1", "out1", "X1", intended_channel_id="ch0", repeat_channel_id="A"
# )

# shortest remaining path; writes chain_of_connectors / chain_of_harnesses
passthrough_map.resolve()

print("Building circuits and adding them to the instances file...")

# expand every mapped patch (and its passthrough path) into conductor circuits.
# multi-ch junction rows become from_channel.signal -> mcj.signal (first type's signals)
circuits_list.new()

# ===========================================================================
#        SEED THE INSTANCES FILE FROM CIRCUITS THAT EXIST SO FAR
# ===========================================================================
system_utils.create_instances_from_circuits_list()


# ===========================================================================
#                 RUN SYSTEM DESIGN CHECKS
# ===========================================================================
connector_list = fileio.read_tsv("system connector list")
circuits = circuits_list.read()

# check for circuits with no connectors
system_utils.find_connector_with_no_circuit(connector_list, circuits)

# check that each imported harness design has the system's connectors and
# carries every circuit the system requires of it. The post harness instances
# list is normally rebuilt after this script, so rebuild it here first.
post_harness_instances.rebuild()
post_harness_rows = fileio.read_tsv("post harness instances")
for bom_row in fileio.read_tsv("bom"):
    if bom_row.get("harness") == "TRUE" and bom_row.get("design_exists") == "TRUE":
        system_utils.verify_harness_conductors_against_circuits_list(
            bom_row["device_refdes"], post_harness_rows
        )

# A mismatch stops the build with system_utils.HarnessDesignError. To accept
# some kinds of problem and still stop on the rest, catch it and re-raise when
# anything unexpected is left. err.problems lists each problem with a "kind"
# and a "message"; the kinds are listed on system_utils.HarnessDesignError.
# For example, to allow circuits that end on a device connector with no cavity:
#
#     try:
#         system_utils.verify_harness_conductors_against_circuits_list(
#             bom_row["device_refdes"], post_harness_instances
#         )
#     except system_utils.HarnessDesignError as err:
#         unexpected = [
#             problem for problem in err.problems
#             if problem["kind"] != "circuit_end_has_no_cavity"
#         ]
#         if unexpected:
#             raise
#         cli.warn(str(err))  # still show the accepted problems
#
# To report every harness before stopping, collect the errors in the loop and
# raise after it instead of raising on the first one.

# ===========================================================================
#              ADD APPEARANCES TO CHANNEL TYPES AND CIRCUITS
# ===========================================================================
print("Assigning colors and recommended cables to channels and circuits...")

# Channel traces use channel_default_appearance from the channel type's
# channel_types.tsv. Circuit traces use signal_default_appearances for
# signal_of_channel_type. The maps below write an instance appearance, and
# an instance appearance that includes base_color replaces that default.
# color -> channel types that should use that color
channel_type_colors = {
    "#D59A10": [
        (1, "https://github.com/harnice/harnice-general-library"),
        (2, "https://github.com/harnice/harnice-general-library"),
    ],
    "#4039A1": [
        (5, "https://github.com/harnice/harnice-general-library"),
    ],
}

# channel type -> signal -> color
circuit_signal_colors = {
    (1, "https://github.com/harnice/harnice-general-library"): {
        "pos": "#E24B4A",
        "neg": "#2E6B9F",
    },
    (2, "https://github.com/harnice/harnice-general-library"): {
        "pos": "#E24B4A",
        "neg": "#2E6B9F",
    },
    (5, "https://github.com/harnice/harnice-general-library"): {
        "chassis": "#4039A1",
    },
}

# apply the above appearances in the instances file as a simple base-color.
for instance in instances.read():
    color = None
    channel_type = instance.get("this_channel_from_channel_type")
    if instance.get("item_type") == "circuit":
        for mapped_channel_type, signals in circuit_signal_colors.items():
            if channel_type == str(mapped_channel_type):
                color = signals.get(instance.get("signal_of_channel_type"))
                break
    if not color:
        for mapped_color, channel_types in channel_type_colors.items():
            if channel_type in [str(t) for t in channel_types]:
                color = mapped_color
                break
    if color:
        instances.modify(
            instance.get("instance_name"),
            {"appearance": {"base_color": color}},
        )

# If you need more specific appearances, you can assign a full appearance dict to an instance like this:
# {
#     "base_color": "#E24B4A",          # required fill
#     "outline_color": "black",         # optional path outline
#     "parallelstripe": ["white"],      # optional stripes along the path
#     "perpstripe": ["red", "white"],   # optional stripes across the path
#     "twisted": "RH",                  # optional "RH", "LH", or None
# }
# example: twisted red/white pos conductor for channel type 1
# circuit_signal_colors[(1, "https://github.com/harnice/harnice-general-library")]["pos"] = {
#     "base_color": "#E24B4A",
#     "outline_color": "black",
#     "parallelstripe": ["white"],
#     "twisted": "RH",
# }
# instances.modify(
#     instance.get("instance_name"),
#     {"appearance": circuit_signal_colors[(1, "https://github.com/harnice/harnice-general-library")]["pos"]},
# )

# ===========================================================================
#              RECOMMEND CABLES ON CIRCUITS
# ===========================================================================
# Write rules at the system level based on system metrics to suggest information that is later consumed by
# downstream harness projects about what cables to apply onto what conductors.

# this_channel_from_channel_type -> library cable fields for instances.modify
circuit_cable_mpns = {
    (1, "https://github.com/harnice/harnice-general-library"): {
        "mpn": "M27500-22SB2T23",
        "lib_repo": "https://github.com/harnice/harnice-aerospace-library",
        "lib_subpath": "M27500",
    },
    (2, "https://github.com/harnice/harnice-general-library"): {
        "mpn": "M27500-22SB2T23",
        "lib_repo": "https://github.com/harnice/harnice-aerospace-library",
        "lib_subpath": "M27500",
    },
}

# signal_of_channel_type -> cable identifier (must be unique in the cable JSON)
circuit_cable_identifiers = {
    "pos": "black",
    "neg": "white",
    "chassis": "drain_wire",
}

# modify the instances file per the above
cable_counter = 1
channel_to_cable = {}  # keep every channel inside its own sequentially-counted cable
for instance in instances.read():
    if instance.get("item_type") != "circuit":
        continue

    channel_type = chtype.parse(instance.get("this_channel_from_channel_type"))
    if channel_type in circuit_cable_mpns:
        channel_group = instance.get("channel_group")
        if channel_group not in channel_to_cable:
            channel_to_cable[channel_group] = f"cable-{cable_counter}"
            cable_counter += 1
        instances.modify(
            instance.get("instance_name"),
            {
                **circuit_cable_mpns[channel_type],
                "cable_group": channel_to_cable[channel_group],
                "cable_identifier": circuit_cable_identifiers.get(
                    instance.get("signal_of_channel_type")
                ),
            },
        )


# ===========================================================================
#                   ASSIGN BOM LINE NUMBERS
# ===========================================================================
# Placed devices, harnesses, and subsystems go on the system BOM. Circuits also
# carry an MPN (the recommended cable above) but belong to the harness BOMs.
for instance in instances.read():
    if instance.get("item_type") in ["device", "harness", "system"] and instance.get("mpn"):
        instances.modify(instance.get("instance_name"), {"bom_line_number": True})
instances.assign_bom_line_numbers()


# ===========================================================================
#              GENERATE OUTPUTS
# ===========================================================================
# Store the default trace layout styles into a variable to be used later when
# generating the GUI block diagram layouts if desired.
default_trace_overlay_style = dict(svg_utils.trace_overlay_style)

generate_outputs = True  # change to False if you'd like to skip the outputs generation process
if generate_outputs:
    print("Drawing the subsystem symbol, physical view, block diagram, and PDF...")

    # Each run_macro call is one symbol (switch instances in the console to edit it).
    # scale is applied to the system block diagram primitive in the symbol.
    # Each build replaces that primitive's contents with a new copy of the
    # block diagram and leaves its position. Each show_* flag is one layer:
    # True draws it, False sets display="none".
    # Connector pins come from unique ICD connectors. The ICD is written after
    # build instructions, so a second build is required after ICD changes.
    # This macro also runs device signals-list / symbol-pin verification on the ICD.
    scale = 0.1

    build_utils.run_macro(
        "subsystem_symbol",
        "macros/system_artifacts",
        "https://github.com/harnice/harnice-general-library",
        artifact_id="subsystem-symbol-1",
        scale=scale,
        show_boundary=True,
        show_devices=True,
        show_subsystems=True,
        show_harnesses=True,
        show_mating_connectors=True,
        show_external_interface_flags=True,
        show_harness_labels=True,
        show_channel_traces=True,
        show_circuit_traces=True,
    )

    # Orthographic drawing of the physical assembly. One view per call.
    # scale is the drawing scale. lineweight is the sheet stroke in px.
    build_utils.run_macro(
        "physical_model_drawing",
        "macros/system_artifacts",
        "https://github.com/harnice/harnice-general-library",
        artifact_id="physical-1",
        scale=1,
        lineweight=1,
        hidden_instances=[],
        orientation="front",
    )

    # Example of how to edit the trace layouts for various outputs. Copy and paste
    # svg_utils.regenerate_trace_overlays and modify the style dict before a macro
    # to modify that macro's trace layout appearance.
    svg_utils.regenerate_trace_overlays(
        style={
            # 4 pt labels on a sheet at scale=1 (96 units per inch, so 4 pt =
            # 4 / 0.75). Channel, circuit and harness traces all use this size.
            "label_font_size": 4 / 0.75,
            "harness_label_font_size": 4 / 0.75,
            "segment_spacing": 1.5,
            "stroke_width": 0.5 / 96,
            "min_label_segment_length": None,
            "network_segment_stroke_width": 1.8,
            "network_segment_font_size": 11,
            "network_node_radius": 2.2,
            "network_node_font_size": 10,
        },
    )

    # Block diagram sheet. Writes {artifact_id}-master.svg for the PDF generator.
    # scale is the drawing scale. Each show_* flag is one of the old sheet
    # checkboxes: True draws that layer, False hides it. show_harness_traces
    # draws one trace per harness, as in the Analyze harnesses view; for a
    # harness sheet, set it True and the channel and circuit traces False.
    build_utils.run_macro(
        "block-diagram-svg-exporter",
        "macros/system_artifacts",
        "https://github.com/harnice/harnice-general-library",
        artifact_id="block-diagram-1",
        scale=1,
        show_boundary=True,
        show_devices=True,
        show_subsystems=True,
        show_harnesses=True,
        show_mating_connectors=True,
        show_external_interface_flags=True,
        show_harness_labels=True,
        show_channel_traces=True,
        show_circuit_traces=True,
        show_harness_traces=False,
    )

    # Bill of materials. Each BOM line gets a total row. An instance listed
    # in bom_disclosure also gets its own row under it, with one column per key.
    bom_disclosure = {}
    for instance in instances.read():
        bom_disclosure[instance.get("instance_name")] = {
            "IP address": instances.configuration_value(instance, "ip_address"),
        }
    build_utils.run_macro(
        "bom_table_bottom_up",
        "macros/drawing_artifacts",
        "https://github.com/harnice/harnice-general-library",
        artifact_id="bom-1",
        per_instance_disclosure=bom_disclosure,
    )

    # Each run_macro call is one PDF file.
    build_utils.run_macro(
        "pdf_generator",
        "macros/drawing_artifacts",
        "https://github.com/harnice/harnice-general-library",
        artifact_id="pdf_drawing-1",
        page_setup={
            "pages": [
                {
                    "tblock_mpn": "harnice_tblock",
                    "tblock_lib_repo": "https://github.com/harnice/harnice-general-library",
                    "tblock_lib_subpath": "titleblocks/",
                    "page_size_in": [11.0, 8.5],
                    "tblock_anchor": "bottom-right",
                    "tblock_offset_px": [40.0, 40.0],
                    "text_replacements": {
                        "tblock-key-pagedesc": "block_diagram",
                        "tblock-key-desc": rev_history.info(field="desc"),
                        "tblock-key-pn": state.partnumber("pn"),
                        "tblock-key-drawnby": rev_history.info(field="drawnby"),
                        "tblock-key-rev": state.partnumber("R"),
                        "tblock-key-scale": scale,
                        "tblock-key-sheet": "autosheet",
                    },
                },
            ],
        },
    )


# ===========================================================================
#              FEATURES FOR RELATIVES
# ===========================================================================
# Any other harnice project can import and these functions using build_utils.run_instruction_from_relative().
# The following functions are defaults. Adjust, remove, duplicate them as needed. Features for relatives are
# intended to be used as a cohesive set of rules by any child part such that anything derived from this sytem
# follows the same set of rules.


def connector_chooser():
    # if the device-side connector MPN is x, assign mating connector y
    mating_connector_lookup_table = {
        #       x  :   y
        "XLR3M": {
            "mpn": "NC3FXX",  # Neutrik 3-pin female cable
            "lib_repo": "https://github.com/harnice/harnice-av-library",
            "lib_subpath": "neutrik",
            "lib_rev_used_here": None,
        },
        "XLR3F": {
            "mpn": "NC3MXX",  # Neutrik 3-pin male cable
            "lib_repo": "https://github.com/harnice/harnice-av-library",
            "lib_subpath": "neutrik",
            "lib_rev_used_here": None,
        },
        "DB25F": {
            "mpn": "M24308_4-3T",  # MIL-DTL-24308 25-pin crimp plug, nickel fluorocarbon
            "lib_repo": "https://github.com/harnice/harnice-aerospace-library",
            "lib_subpath": "dsub",
            "lib_rev_used_here": None,
        },
        "DB25M": {
            "mpn": "M24308_2-3T",  # MIL-DTL-24308 25-pin crimp receptacle, nickel fluorocarbon
            "lib_repo": "https://github.com/harnice/harnice-aerospace-library",
            "lib_subpath": "dsub",
            "lib_rev_used_here": None,
        },
    }

    # if the harness connector instance is named x, assign mating connector y
    # regardless of the device-side part number. leave empty unless you mean it.
    connector_by_instance_name = {
        #       x  :   y
        # "J1": {
        #     "mpn": "NC3FXX",
        #     "lib_repo": "https://github.com/harnice/harnice-av-library",
        #     "lib_subpath": "",
        #     "lib_rev_used_here": None,
        # },
    }

    for instance in instances.read():
        if instance.get("item_type") != "harness_connector":
            continue

        instance_name = instance.get("instance_name")

        mate = mating_connector_lookup_table.get(
            instance.get("device_side_connector_mpn")
        )
        if mate:
            instances.modify(
                instance_name=instance_name,
                instance_data=mate,
            )
            continue

        mate = connector_by_instance_name.get(instance_name)
        if mate:
            instances.modify(
                instance_name=instance_name,
                instance_data=mate,
            )
            continue

        # per-position rules (state.harness is the child's system position name):
        # if state.harness == "H01" and instance_name == "P1":
        #     instances.modify(
        #         instance_name,
        #         {
        #             "mpn": "NC3FXX",
        #             "lib_repo": "https://github.com/harnice/harnice-av-library",
        #             "lib_subpath": "neutrik",
        #             "lib_rev_used_here": None,
        #         },
        #     )
        #     continue

        # family choosers (D38999, Mighty Mouse, ...) are in the connector-choosing
        # examples ribbon - insert them here, then continue if they assign an mpn.

        # No rule matched. Keep the harness building with a placeholder.
        # Artwork goes in the general library at
        # connectors/example/EXAMPLE_CONNECTOR/rev1/drawing.svg.
        cli.warn(
            f"connector_chooser could not find a solution for {instance_name}; "
            "using EXAMPLE_CONNECTOR"
        )
        instances.modify(
            instance_name=instance_name,
            instance_data={
                "mpn": "EXAMPLE_CONNECTOR",
                "lib_repo": "https://github.com/harnice/harnice-general-library",
                "lib_subpath": "connectors/example",
                "lib_rev_used_here": None,
            },
        )

# Reset the trace overlay style to default saved earlier to set the gui trace
# overlay style.
svg_utils.trace_overlay_style.update(default_trace_overlay_style)

# ===========================================================================
#                  REMOVE UNUSED INSTANCE DATA
# ===========================================================================
# Drop instance_data folders whose refdes is no longer in this project.
build_utils.remove_unused_instance_data()

Channel and passthrough mapping

After Harnice exports a BOM and system connector list from your block diagram SVG, it seeds a channel map—one row per channel endpoint, including both faces of a passthrough. Your build instructions then declare which endpoints carry the same logical signal (map()), and (when a patch must cross a two-face device) which passthrough routes each cross-harness link uses. That process is what turns diagram connectivity into a circuits list and downstream harness instances.

Where mapping runs in a system build

  1. Before build instructions: channel_map.new() runs automatically during system.build(). It reads the system connector list and each device's signals list, and writes one channel-map row per channel endpoint (device_refdes, channel_id[, repeat_channel_id]).

  2. In build instructions (typical order): map channels → channel_map.flatten() → passthrough_map.new() → optional route() hops → passthrough_map.resolve() → build the circuits list.

  3. After mapping: circuits_list.new() expands every mapped channel pair (and its passthrough path) into individual conductor circuits. A multi-channel junction row (no to_* partner) becomes one circuit per signal: from is from_channel.signal, to is mcj.signal. Signal names come from the first channel type seen on that junction id.

The default system build instructions follow this pattern:

# 2-tuple when the channel has one endpoint; 3-tuple when it has two
# channel_map.map(("MIC1", "out1"), ("PRE1", "in1"))
# channel_map.map(("MIC1", "out1"), ("X1", "ch0", "A"))

channel_map.map_unmapped_compatibles_alphabetically()
channel_map.flatten()

passthrough_map.new()

# optional: passthrough_map.route("MIC1", "out1", "X1", intended_channel_id="ch0", repeat_channel_id="A")
passthrough_map.resolve()

circuits_list.new()

Concepts

Channel. A channel is one logical link on a device—audio in, power, differential pair, etc. Its channel type (from the channel-types library) is electrical information only: required signals, direction, limits, and which other types it may mate with. A channel type must not specify a connector type. The connector is connector_id and the part number on the signals list. See channel types documentation for compatibility rules.

Channel endpoint. One complete instance of a channel on one connector (channel_id + channel_type + connector_id, plus repeat_channel_id when that channel has two faces).

Patch. A pair of channel endpoints created by channel_map.map(). Stored in the channel map.

Passthrough. A channel with exactly two channel endpoints on the same device. Identified by (device_refdes, channel_id) plus a repeat_channel_id for each face.

Mapped channel. A mapped channel is a connection from one channel on a device to another. They define the functional requirement of any harness, and form the basis of which circuits are generated and where they go. The channel map is the list of mapped channels (and any still-unmapped channels).

Group of connected harnesses (group_of_connected_harnesses). Harness wires in your block diagram define equivalence classes of harnesses: any harnesses linked through a passthrough share the same group_of_connected_harnesses label on the system connector list, copied onto each channel-map row. Unmated terminating connectors are in no group. An unmated passthrough face still belongs to the group of its other, mated face. Automatic channel mapping only considers pairs within the same group of connected harnesses—channels in different groups are never auto-mapped together. Manual map() and route() also require the same group.

Channel mapping in detail

Seeding: channel_map.new()

For every row in the system connector list where device_refdes is set, Harnice loads that device's signals list. For each channel endpoint on that connector, it appends a row with:

  • group_of_connected_harnesses — copied from the matching system connector list row

  • from_device_refdes, from_device_channel_id, from_repeat_channel_id, from_channel_type — the channel endpoint (from_repeat_channel_id is set when that channel has two faces)

  • to_* columns empty until mapped

It also creates an empty mapped channels set TSV used to prevent double-mapping.

Manual mapping: channel_map.map(from_key, to_key=None, multi_ch_junction_key="")

from_key and to_key are (device_refdes, channel_id) when that channel has one endpoint, or (device_refdes, channel_id, repeat_channel_id) when it has two. A 3-tuple on a single-instance channel is an error. Dual-map is two map() calls to the two repeats of the same passthrough (no passthrough-map row). A patch may end by crossing a device only if that destination face has no harness. Calling map(from_key, to_key):

  1. Finds the row whose from_* columns match from_key and copies to_device_refdes, to_device_channel_id, to_repeat_channel_id, and to_channel_type from the row that matches to_key.

  2. Removes the separate "to-only" row for to_key (each physical endpoint appears once as a from_* row; mapping is directed).

  3. Records both keys in the mapped channels set and writes a manual_map_channel_python_equiv cell you can copy back into build instructions.

To connect several channels to each other on one multi-channel junction, pass multi_ch_junction_key="jcn1" instead of to_key. That consumes from_key and writes jcn1 as multi_ch_junction_id on the same row. Several rows can share that id without pairing to a single partner. A channel may join only if its type is, or is compatible with, every other member already on that junction (chtype.is_or_is_compatible_with, either direction). Automatic mapping never attaches leftover channels to a multi-channel junction. On the block-diagram channel overlay, traces of the same id follow the harness to the T (one arm per member). The circuit overlay does the same per signal (from_channel.signal → mcj.signal), using the first channel type seen on that id for signal names. A junction dot is placed where that net arrives on three or more arms.

Raises ValueError if either key was already mapped, if the endpoints are not in the same group, if a required to_key row is missing, if both to_key and multi_ch_junction_key are passed, or if the joining channel is not compatible with every existing junction member.

Force mapping: channel_map.force(from_key, to_key)

Maps one endpoint to another with the same group and face rules as map(), and does not check channel-type compatibility. map() itself is unchanged. When both channel types list the same signal names, circuits compile by those names. When the names differ, the patch stays pending until circuits_list.force(from_key, signal_pairs, drop=()) pairs every from-side name and explicitly drops every unused to-side name. The circuit keeps the from-side name; the to-side cavity is looked up under the paired name. A from-side signal cannot be dropped. circuits_list.new() raises if any pending patch is still waiting.

Automatic mapping: channel_map.map_unmapped_compatibles_alphabetically()

For each group_of_connected_harnesses, rows are sorted alphabetically by device refdes and channel id. Channels with more than one endpoint (passthroughs) are skipped, even if nothing else is left. For each remaining row whose from_key is not yet mapped, Harnice scans later rows in the same group of connected harnesses and maps to the first candidate whose channel types are mutually compatible: either to_type is in chtype.compatibles(from_type) or from_type is in chtype.compatibles(to_type). This is deterministic but not unique—use manual channel_map.map() first for anything that must not follow alphabetical pairing.

Flattened channel map: channel_map.flatten()

Writes maps/channel_map_flattened.tsv with the same columns as the channel map. The sheet starts with this system's channel map, then appends the channel map imported with each child subsystem, and repeats that walk through every nested subsystem. Those imported channel maps are the source of truth for which endpoints were mapped. This does not re-run channel mapping inside the subsystem.

Before those prefixes are applied, a passthrough channel whose two faces are both mapped patch ends is folded into one row between the outer endpoints. The lexicographically smaller outer endpoint is the from side. chain_of_connectors records the disconnect between them. chain_of_harnesses on that row is left blank. A chain of dual-mapped disconnects folds to the two outer devices. A channel with only one face mapped stays as that one patch. A row that already joins the two faces is left unchanged. Rows with no partner and no multi-channel junction are omitted. A junction row is kept. The flat channel map is not rewritten.

Rows from a subsystem prefix that subsystem's instance name onto group_of_connected_harnesses, from_device_refdes, to_device_refdes, multi_ch_junction_id, chain_of_connectors, and chain_of_harnesses. Each entry in a list is prefixed (AMP.H1+AMP.H2, AMP.MIC3.J1;AMP.X1.A). Nested subsystems accumulate prefixes (AMP.PRE.MIC1). from_repeat_channel_id, to_repeat_channel_id, and manual_map_channel_python_equiv are omitted. from_channel_type_description and to_channel_type_description sit beside the channel type columns and are the description from that type's channel_types.tsv. Channel ids and channel types are copied unchanged. This system's own rows are not prefixed. Call it after map_unmapped_compatibles_alphabetically(). It snapshots the channel map as it stands at the call.

Channel-map columns filled later

| Column | When it is filled |

|--------|-------------------|

| chain_of_connectors, chain_of_harnesses | Via passthrough_map.resolve() from the passthrough path |

| multi_ch_junction_id | When you pass multi_ch_junction_key= to channel_map.map(). Copied onto circuits (from_channel.signal → mcj.signal) |

A row is fully mapped when to_device_refdes and to_device_channel_id are set. Passthrough routing requires fully mapped rows whose endpoints sit on different harnesses.

Passthrough routing in detail

Channel mapping answers which device channels are the same signal. The passthrough map lists every unused passthrough channel; passthrough_map.resolve() chooses which passthroughs carry each mapped signal and writes chain_of_connectors / chain_of_harnesses on the channel map. Dual-map consumes both faces as patch ends and does not write a passthrough-map row.

passthrough_map.new()

Reads the system BOM, loads each device's signals list, and writes one row per unused passthrough channel. Builds the routing context used by route() / resolve(). Passthroughs already consumed as dual-map ends are omitted.

passthrough_map.route()

Pins a mapped channel through a chosen passthrough (optional channel id and repeat_channel_id for the face the patch arrives on). Call after new() and before resolve() for required hops. The passthrough must be in the same group as the mapped channel. Routing a channel whose faces are already map-consumed is an error.

passthrough_map.resolve()

Completes passthrough routing for each mapped channel (optional user route() waypoints first). Writes satisfaction on the passthrough map and fills chain_of_connectors / chain_of_harnesses on the channel map. Connector tokens are refdes.connector (e.g. MIC3.J1;X1.A;X1.B;PREAMP1.J1); harness names are refdes per hop (H1;H2).

Practical tips

  • Map critical channel pairs manually before map_unmapped_compatibles_alphabetically().

  • Use route() for required passthrough hops; let resolve() fill the rest.

  • Both endpoints of a map(), and any route() hop, must be in the same group of connected harnesses.


Physical model

Open physical model on a system to pose every placed device that has a body.step. Poses and fasten mates are physical.json (fileio.path("physical assembly")). The page rewrites assembly.step from that file. How the mates solve, and how a device gets a body, is CAD.

Instructions for child harnesses

A system can define functions such as connector_chooser and m85049_chooser in its build instructions. Child harnesses call them after they import from this revision:

build_utils.run_instruction_from_relative(
    "connector_chooser",
    system_pn,
    system_lib_repo,
    system_lib_subpath,
    system_rev,
)
build_utils.run_instruction_from_relative(
    "m85049_chooser",
    system_pn,
    system_lib_repo,
    system_lib_subpath,
    system_rev,
)

That is how system-level behavior (mating-connector policy, per-position assignments) stays on the parent instead of being copy-pasted into every harness. A missing file or function raises. It runs in the harness working directory. It is not a macro: no instance folder, no library-history row. Only the function (plus any remaining imports and literal data) is loaded from the system file — Harnice list, utility, and channel-type modules are already in the namespace. The system's own channel-mapping and macros are not re-run.

Use state.harness inside the function for one harness position. When the system revision changes, the next harness rebuild picks up the new rules.


How to define a new system

  1. Make a folder for the part number of your system somewhere on your computer. Click Build in Harnice, which will generate an example system that you can then edit.

    Building a project
    1. In Harnice, click New project…. You do not need a rev folder yet.

    2. Fill in part number, revision (1 is fine), project type, and a description, then click OK. Harnice creates the folders and an example you can edit.

    3. Click Build to generate the rest of the project files.

  2. Open that system in Harnice and edit the block diagram. Place devices from your library, draw harness wires between connectors, then save.

  3. Click Build often as you refine the diagram and build instructions.


Designing your block diagram

Device symbols are placed in the system block diagram SVG from the Harnice console (Place device). A two-face passthrough is a device.

Harness wires represent entire harnesses between connectors. The diagram is agnostic to the individual conductors, channels, or signals of a harness—only that certain connectors are connected via a harness.

To join two harnesses through a passthrough, place a two-face device and route harness wires to its faces. Set library pull fields on the placed symbol (same attributes used when placing from the library):

  1. MPN — part number of the device

  2. lib_repo — traceable path to the repo that contains the device

  3. lib_subpath — path between the library root and the part number, if any (for example, if the part lives at {library_root}/devices/audio/tascam-db25/rev1/, use devices/audio/)

  4. rev — revision to use in this system (optional)

An external interface flag (red triangle) marks a connector that appears on the system's external ICD (fileio.path("icd")). Place it on a harness mating connector (yellow dot) or on a device connector that has no harness mated to it. It cannot be placed on a device connector that already has a harness. On build, flags on harness-mated passthrough connectors fill the ICD from circuits; flags on unmated device connectors copy that connector's rows from the device's signals list.

Block diagram symbols

Default system build instructions run the subsystem_symbol macro once (artifact_id="subsystem-symbol-1", scale=0.1). Each additional run_macro call of that MPN is another imported instance; open it from instance data. The editor is the same drawing tools as a device symbol, plus System diagram, which drops the current system block diagram contents as a primitive. scale sets that primitive's scale. Each show_* argument is one layer (show_boundary, show_devices, show_subsystems, show_harnesses, show_mating_connectors, show_external_interface_flags, show_harness_labels, show_channel_traces, show_circuit_traces). True draws it. False sets display="none". Omitted flags are True. A later build keeps each primitive where you put it, updates its scale, and replaces its contents with a new copy of the current block diagram using those flags. The macro seeds a blank SVG if none exists and does not add, move, or delete primitives you placed.

On first seed (and on later builds when pins are still missing), the macro places one connector pin per unique connector_name in the system ICD (fileio.path("icd")). It also runs device signals-list checks against that ICD (the system's signals list). Pin mismatches vs the ICD print a warning and do not fail the build; missing pins are still appended. The ICD is compiled after build instructions, so this macro always reads the ICD from the previous build. After you add, remove, or rename external-interface flags, build twice: the first build writes the ICD, and the second build updates symbol pins and re-checks from it. That one-build lag is expected. If no previous ICD exists yet, verification is skipped.