053 RS485 Termination Pins
053-rs485-termination-pins.mc applies the same conditional-pin pattern to an RS485 endpoint. U_NODE exposes A, B, and GND. The "RS485_TERM120" variant U_END also exposes TERM0 and TERM1. Both variants connect to BUS_A, BUS_B, and GND. The terminated variant adds this path:
text
BUS_A -> U_END.TERM0 -> R_TERM -> U_END.TERM1 -> BUS_BThe member accesses prove that the conditional names are usable after pins +=, while R_TERM creates the actual 120 Ω termination between the two bus nodes.
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 05-dynamic-pins-and-conditions/053-rs485-termination-pins.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 05-dynamic-pins-and-conditions/053-rs485-termination-pins.mc --lib mcode --viz -o 05-dynamic-pins-and-conditions/053-rs485-termination-pins.htmlSource
text
// Example: RS485 Termination Pins
// Goal: Add optional termination connection pins for a bus endpoint variant.
// Language focus: default parameter, if, pins +=.
component RS485_ENDPOINT(partno::STRING = "RS485_NODE")
{
name = "RS485 Endpoint"
pins = [
io 1 = A
io 2 = B
3 = GND
]
if (partno == "RS485_TERM120")
{
pins += [
io [4:5] = TERM[0:1]
]
}
}
module main
{
io BUS_A
io BUS_B
io GND
RS485_ENDPOINT U_NODE
RS485_ENDPOINT("RS485_TERM120") U_END
RES R_TERM(120R, 50V)
BUS_A -> U_NODE.A
BUS_B -> U_NODE.B
U_NODE.GND -> GND
BUS_A -> U_END.A
BUS_B -> U_END.B
// The termination path uses pins that exist only on the terminated variant.
BUS_A -> U_END.TERM0 -> R_TERM -> U_END.TERM1 -> BUS_B
U_END.GND -> GND
}