.Net CLR
Accessing the .NET CLR from ARC JavaScript
For advanced users, the .NET Common Language Runtime (CLR) is available to the ARC JavaScript engine. This lets you access the underlying ARC platform and operating system directly from JavaScript, including .NET classes, namespaces, and system services.
Use this capability when you need functionality beyond the built-in ARC APIs, but be mindful of permissions, resource management, and thread/latency considerations.
What is the CLR?
The Common Language Runtime (CLR) is the run-time environment provided by the .NET Framework. It executes code and provides services that simplify application development and execution. Code compiled to target the CLR is called managed code and benefits from runtime services that improve reliability, security, and interoperability.
Key benefits of managed code
- Cross-language integration and consistent exception handling across languages.
- Enhanced security and access control enforced by the runtime.
- Versioning and simplified deployment support.
- Component interaction model that reduces integration complexity.
- Built-in debugging, profiling, and memory management services.
.NET Framework Example
The example below demonstrates using the System.IO.StreamWriter class to write text to a log file on C:\. ARC's JavaScript engine already provides file-writing helpers; this example shows direct access to raw CLR classes and namespaces.
// Create an instance of the StreamWriter
var file = new System.IO.StreamWriter('c:\\log.txt');
// Write some text to the file
file.WriteLine('Hello World !');
// Close the file and dispose the object
file.Dispose();
Tips: Always dispose or close file and resource objects to release handles. Ensure ARC has permission to write to the target path, and consider using application-specific paths instead of root-level directories.
EZ_B Driver Example
The ARC JavaScript engine exposes the raw EZ_B driver for each connected EZ-B controller. In robot skills this collection is available as ARC.EZBManager.EZBs; in many contexts you can access it simply as EZBs. The example below moves a servo on port D2 of EZB #0 to position 20.
// Move the servo on port D2 to position 20 on EZB #0
EZBs[0].Servo.SetServoPosition(2, 20);
Note: Verify the correct EZB index and servo port for your configuration before issuing commands. Use safety checks to avoid unexpected motion.
Best practices
- Dispose CLR objects (Dispose or using patterns) to free resources promptly.
- Check file and system permissions before performing I/O operations.
- Avoid long-running or blocking calls on the main thread; use asynchronous patterns if available.
- Test CLR interactions thoroughly to ensure stability and compatibility with ARC.