Reference |
Script Editor |
|
The Script Editor is a utility within the Stardraw Control IDE Integrated Design Environment for building and testing Stardraw Control programs. for creating and editing scripts.
In Stardraw Control, scripts are used within device drivers to define Ports and their functions, and within Script Components to add powerful programming functionality to your forms.
A Port script adds its own unique functionality that provides all of the protocol functions and features supported by the device driver. A Script Component can provide utility functions or other interactivity required by your forms that may be difficult or impossible to achieve using Actions alone.
Scripts are standard Microsoft C# programs that utilize core Microsoft.Net functionality provided by Stardraw Control.
Ports and Script Components are Microsoft.Net classes, which are objects that encapsulate all the functionality required to communicate with your computer's ports, or extend the interactivity of your forms. Classes are a standard way of programming using Microsoft.Net technology. Stardraw Control provides base classes for Ports and Script Components.
You can find many resources on C# programming in print and online.
Read this section and still have a problem you just can't solve or get working? Someone in the Support Forums or a Certified Programmer may be able to help.
The Script Editor utility displays the script from a Port or Script Component, and allows you to edit and verify your changes:
The Script Editor utility
The editing area allows you to create, cut, copy and paste whole scripts and code fragments. Various parts of the code are colored: this is called syntax hi-lighting, and is a simple feature that aids readability.
When you are finished writing or editing a script, click Compile: the Script Editor will compile your script, that is, it will interpret and verify that your code can run as a .Net class.
Any errors that the Script Editor encounters when compiling your code will be displayed below the script editing area: it will display a description of each problem. You can double-click any error and the Script Editor will jump to the line of code that caused the error.
Tip
Sometimes even scripts which compile correctly may still contain bugs that do not give the expected behavior. You can use the Logger object that is built into all Port scripts, or the ScriptHelper object's Logger to output your own test or diagnostic information to the Debug Window to assist in finding and fixing problems with your code.
Click OK to compile the script and close the Script Editor utility or click Cancel to close the Script Editor without saving your changes.
Some scripts require access to functionality that is not part of the core classes that the default scripts have access to.
Such functionality may be provided by additional classes contained in .Net assemblies Binary files, usually DLLs or EXEs, that contain compiled Microsoft.Net classes., which may be supplied with Stardraw Control, or available from third-party software vendors. In this case, you need to add a reference to the assembly file.
Select the References
tab in the Script Editor.
The list of existing assembly references will be displayed:
The Script Editor References list
Click Add
to add an assembly reference:
Browse to the location of the assembly file.
The namespaces A systematic naming convention that hierarchically groups Microsoft.Net classes into logically related units. that encapsulate the classes within the assembly will be added to the list.
In the Script tab, add a using statement to your code for each new namespace; this gives the script access to the classes in the assembly:
// declare the namespace of the referenced assembly
using MyCompany.MyNamespace;
Information on the namespaces and classes within an assembly should be available from the software vendor.
Tips
Most of the core Microsoft.Net 1.1 Framework classes are available within the Script Editor without explicitly referencing the assembly files. Just add the appropriate using statements to the namespaces you require.
Namespaces and classes provided by Stardraw Control for advanced programming are documented in the Class Library section.
You can remove obsolete assembly references by selecting the namespace from the list and clicking Remove.