XScript Manual · Chapter 50
title: "SYS — system globals & utilities" chapter: 50
SYS — system global object
SYS bundles system-level utilities — time, files, HTTP, module execution.
It is the single most-used global and unifies OS access for scripts.
Time / ticks
| Property / Method | Type | Description |
|---|---|---|
SYS.TickCount | int | Elapsed ms since startup |
SYS.GetTickCount() | int | Same, as function |
SYS.GetElasped(int startTick) | int | TickCount - startTick |
SYS.SecondCount | int | Seconds counter |
SYS.Year / Month / Day / Hour | int | Current date/time parts |
SYS.DateString | string | YYYYMMDD |
SYS.TimeString | string | HHMMSS |
SYS.DateTimeString | string | YYYYMMDD_HHMMSS |
SYS.DateTimeFilename | string | File-safe timestamp |
SYS.DateTimeMsecString | string | With milliseconds |
SYS.CurrentDateTimeInISO8601 | string | ISO 8601 |
SYS.GetDateTimeStringFormat(string format) | string | C# format string |
int start = SYS.TickCount;
DoSomething();
int elapsed = SYS.GetElasped(start);
Log($"Elapsed: {elapsed} ms");Files / paths
| Method | Description |
|---|---|
bool ExistsFile(string path) | File exists |
string ReadAllText(string path) | Read whole file |
bool WriteAllText(string path, string data) | Write whole file |
array ReadAllLines(string path) | Read as lines |
bool WriteAllLines(string path, array lines) | Write as lines |
bool AppendLine(string path, string data) | Append line |
bool CreateDirectory(string path) | mkdir -p |
bool DeleteFile(string path) | Delete |
bool CopyFile(string src, string dest, bool overwrite) | Copy |
string Combine(string path1, string path2) | Join path |
string GetFileName(string path) | Base name |
string GetFileNameWithoutExtension(string path) | No extension |
string GetValidFileName(string name) | Sanitize invalid chars |
string ProjectBaseDirectory | Project root |
string DownloadsFolderPath | Downloads folder |
string file = SYS.Combine(SYS.ProjectBaseDirectory, "JSON\\cube_machine.json");
if (SYS.ExistsFile(file) == false)
{
LogError($"Not found: {file}");
return false;
}
string text = SYS.ReadAllText(file);HTTP
| Method | Description |
|---|---|
string SendHttpGet(string url) / with token | GET |
string SendHttpPost(string url, string data) / with token | POST |
string SendHttpDelete(string url, string token) | DELETE |
string SendHttpPatch(string url, string data, string token) | PATCH |
SYS.HTTP_ERROR_STR | Sentinel for error |
SYS.LastHttpError | Last error message |
string url = SS.MachineApiServer + "/machine-status";
string result = SYS.SendHttpPost(url, data, SS.HttpToken);
if (result == SYS.HTTP_ERROR_STR)
{
LogError($"ERROR: {SYS.LastHttpError}");
return false;
}Parameters / module execution
| Method | Description |
|---|---|
bool SaveSetupParam(void) | Persist setup params |
bool LoadJobFileParam(void) | Reload job-file params |
bool GetParamValue(string name, ref string value) | Read parameter |
bool SetModuleVar(string name, value) / bool GetModuleVar(string name, ref value) | Cross-module vars |
bool RunScriptFunction(string module, string func, args...) | Call cross-module |
bool StartModule(string module) | Restart module |
void StopMotorAll(void) | Stop all axes |
bool CheckMotorName(string name) | Axis exists |
if (SYS.RunScriptFunction(moduleName, "ParseJsonToModuleData", data) == false)
{
ShowError(EB_Ok, 107, moduleName);
return false;
}System state / errors
| Property | Type | Description |
|---|---|---|
SYS.IsRunning | bool | Auto-run active |
SYS.ManualThreadExitSignal | bool | Manual thread exit requested |
SYS.LastErrorCode | int | Last error code |
SYS.LastErrorMsg | string | Last error message |
SYS.LastErrorModuleName | string | Origin module |
SYS.ProjectVersion / SYS.QMSVersion | string | Versions |
if (SYS.IsRunning == false)
{
return true;
}
SYS.LastErrorCode = 0;
SYS.LastErrorMsg = "";
SYS.ResetError();Real-world — HTTP with timing & logging
FUNCTION GetServerOrderCount()
{
string url = $"{SS.HttpOrderAddr}/order-queue/machines/{SS.MachineId}/status";
int s = SYS.TickCount;
string data = SYS.SendHttpGet(url, SS.HttpToken);
if (data == SYS.HTTP_ERROR_STR)
{
if (SS.OrderMode == 1)
{
LogError($"GetServerOrderCount Error :[{SYS.TickCount-s}ms] {SYS.LastHttpError}");
}
return -1;
}
int count = Order::GetOrderCount(data);
return count;
}Tips
- Long waits: measure with
SYS.GetElasped(startTick)and checkManualThreadExitSignalbetween sleeps. - File IO: always precede writes with
CreateDirectoryandExistsFilefor reads. - HTTP calls don't throw — compare result with
SYS.HTTP_ERROR_STR. - Cross-module calls: always go through
SetModuleVar/GetModuleVar/RunScriptFunction.