Skip to content
Version 6.1.0
Contact Us

BACnetStack_LoopMSTP

void BACnetStack_LoopMSTP(const uint32_t networkPortInstance);

Runs the stack-owned MS/TP engine of one port: applies a new configuration, moves queued NPDUs into the engine, reads the octets the receive callback has, advances the receive and master-node state machines over them, sends what they decide to send, and returns.

NEVER BLOCKS, apart from inside the send callback (which blocks until the last stop bit has left the wire). It takes no lock and may run on its own thread, concurrently with BACnetStack_Tick() and every other export except those that add or remove Network Port objects or reset the stack (see “Stack-owned MS/TP” above). It does nothing for a port that is not in byte mode, has no readable MAC_Address, or does not exist.

HOW OFTEN. The engine reads octets and checks its timers only here, so the call period adds to every MS/TP deadline. A node must start sending a Token or a reply to a Poll For Master within Tusage_timeout (35 ms) of the last octet it received, after Tturnaround (40 bit times: 4.17 ms at 9600 baud and 1.04 ms at 38400 baud, which the engine rounds up to whole milliseconds, 5 ms and 2 ms), and must answer a data-expecting-reply frame within Treply_delay (250 ms; the engine sends Reply Postponed at 125 ms). Call it at least once every 20 ms at any supported baud rate (9600 and up), and every 1 to 5 ms where you can. A slower host loses replies and token passes: the node drops out of the ring and rejoins. The receive path also needs the call: a frame’s octets are only taken from the receive callback here, and the host’s UART buffer must hold the octets that arrive between calls. With a clock that is not advancing (BACnetStack_RegisterCallbackMSTPMicroseconds()) the engine sends nothing at all.

Parameter Direction Description
networkPortInstance in The instance of the MS/TP Network Port object (BACnetStack_AddNetworkPortObject()), or BACNET_NETWORK_PORT_DEFAULT for the default port.

Topic: Data link and system callbacks. Declared in CASBACnetStackDLL.h.