<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TCM System Functions :: Emtron Resource Centre</title><link>https://docs.emtronaustralia.com.au/transmission-control/scripting/tcm-system-functions/index.html</link><description>This is a reference for every native function callable from a MecScript script running on the TCM including:
General-purpose functions under System:: for debugging and time management. TCM-specific functions under Runtime::, Device::, CAN:: and Output:: for reading live device state, talking to the CAN bus and driving script-controlled outputs. Quick Reference Strings &amp; Debugging (System::) Function Signature Purpose System::Print void Print(string str) Debug-print a string, no newline System::PrintLine void PrintLine(string str) Debug-print a string plus newline System::PrintInt void PrintInt(int i) Debug-print an integer System::PrintFloat void PrintFloat(float f) Debug-print a float System::PrintFormat void PrintFormat(string str, float f) Debug-print a format string with one float System::PrintBuffer void PrintBuffer(byte buf[], int capacity) Debug-print a byte buffer’s null-terminated content System::StrLength int StrLength(byte buf[], int capacity) Length of a buffer’s content up to its null terminator System::StrCopy void StrCopy(byte dest[], int destCapacity, string src) Copy a string constant into a buffer, truncating to fit System::StrAppend void StrAppend(byte dest[], int destCapacity, string src) Append a string constant onto a buffer’s content, truncating to fit System::IntToStr void IntToStr(byte dest[], int destCapacity, int value) Format an integer as decimal text into a buffer System::StrEquals bool StrEquals(byte a[], int capacityA, byte b[], int capacityB) Compare two buffers’ null-terminated contents Time Function Signature Purpose System::NowMs uint NowMs() Device uptime in milliseconds (wraps every ~49.7 days) System::NowUs uint NowUs() Device uptime in microseconds (wraps every ~71.58 min) Script Yielding Function Signature Purpose System::Yield void Yield(uint t) Pause the script for t milliseconds System::YieldUntil uint YieldUntil(uint lastTime, uint delay) Fixed-period pause that returns the updated lastTime for the next call Runtime Channels (Runtime::) Function Signature Purpose Runtime::Read int Read(uint id) Read a live channel value as an integer with the decimal point removed (123.4 reads as 1234) Runtime::ReadReal float ReadReal(uint id) Read a live channel value as a float in real units Runtime::Write bool Write(uint id, int value) Write a writeable channel value as an integer with the decimal point removed Runtime::WriteReal bool WriteReal(uint id, float value) Write a writeable channel value as a float in real units CAN Bus (CAN::) Function Signature Purpose CAN::SetupNode bool SetupNode(uint node, bool enable, uint bitrateSelect, bool termination, bool listenOnly) Enable/disable a CAN node and set its bitrate, termination and listen-only mode CAN::Send void Send(uint node, uint id, byte buffer[], int length) Send a raw frame on CAN 1 or CAN 2 CAN::Read int Read(uint node, uint id, byte buffer[], int length) Poll the latest received frame for a node/id pair CAN::Subscribe void Subscribe(uint node, uint idMatch, uint idMask, func(uint id, byte data[], int length) handler) Register a callback for received frames matching an id/mask CAN::Unsubscribe void Unsubscribe(uint node, uint idMatch, uint idMask) Cancel a subscription registered with the same node/match/mask CAN::Poll int Poll() Fire the handlers for any frames received since the last call Output Control (Output::) Function Signature Purpose Output::SetActiveLevel void SetActiveLevel(byte outputId, int level) Set a script output’s active polarity (0 = active-low, 1 = active-high) Output::SetEffectiveResistance void SetEffectiveResistance(byte outputId, float ohms) Tell current control the load’s resistance Output::SetFreq void SetFreq(byte outputId, float frequency) Set a script output’s PWM/current-chop frequency in Hz Output::SetDuty void SetDuty(byte outputId, float dutyCycle) Drive a script output in PWM mode at a fixed duty (0-100) Output::SetCurrent void SetCurrent(byte outputId, float milliAmps) Drive a script output in closed-loop current control Device Information (Device::) Function Signature Purpose Device::ReadSerialNumber uint ReadSerialNumber() Read the device’s serial number Device::ReadVendorKey uint ReadVendorKey(int keyId) Read one of two vendor keys (keyId 1 or 2), typically used to lock a script to a specific device Calling Convention Every native function is called through its namespace.</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://docs.emtronaustralia.com.au/transmission-control/scripting/tcm-system-functions/index.xml" rel="self" type="application/rss+xml"/></channel></rss>