Example: EZ-Script Executor
EZ-Script is the programming language used in EZ-Builder. The scripting language is similar to Basic and has many robot specific commands. The power of EZ-Script also allows controls to interact with each other using the ControlCommand(), which you may have already read about in this tutorial.
This part of the tutorial will demonstrate how to execute EZ-Script code within your plugin. An example of how this is useful is if your plugin provides configuration for the user to configure custom code for a specific action. If you look at DJ's Tic Tac Toe example, you will notice that the configuration dialog allows the user to create custom EZ-Script for Winning, Losing and Tie.
The namespace for all scripting methods is EZ_Builder.Scripting.
Simple Example This code example demonstrates how to run an EZ-Script piece of code that will speak a phrase out of the speaker when the button is pressed. You will need to add a Button to your form and assign the Click event for it to work.
public partial class MainForm : EZ_Builder.UCForms.FormPluginMaster {
EZ_Builder.Scripting.Executor _executor;
public MainForm()
: base() {
InitializeComponent();
_executor = new EZ_Builder.Scripting.Executor();
}
private void button1_Click(object sender, EventArgs e) {
_executor.StartScriptASync("Say(\"Hello, I am ez-script\")");
}
}
Example with Events There are many events that can be associated with the Executor, such as OnDone, OnError, etc.. This allows your program to accommodate behaviors. In this example, the Executor will display a message box when the script has completed executing.
public partial class MainForm : EZ_Builder.UCForms.FormPluginMaster {
EZ_Builder.Scripting.Executor _executor;
public MainForm()
: base() {
InitializeComponent();
_executor = new EZ_Builder.Scripting.Executor();
_executor.OnDone += _executor_OnDone;
}
private void button1_Click(object sender, EventArgs e) {
_executor.StartScriptASync("Say(\"Hello, I am ez-script\")");
}
void _executor_OnDone(string compilerName, TimeSpan timeTook) {
MessageBox.Show(string.Format("Script has completed and took {0} milliseconds", timeTook.TotalMilliseconds));
}
}
Starting A New Script When Another Is Running If the executor is currently running an ASync script in the background while you launch another, the first script will be cancelled and the most recent script will begin executing. Each instance of an Executor can run only one script. To run multiple scripts at the same time, use an Executor per script.
Inside the Executor The executor has many methods and events.
EZ_Builder.Scripting.Executor.ExecuteScriptSingleLine(string line); Executes only one line of EZ-Script and blocks until it has completed. This method returns the result of the single line of code. For example, if the code was a function to return the value of a servo (example GetServo(d0)), the value of the servo d0 will be returned.
EZ_Builder.Scripting.Executor.Resume(); There is an EZ-Script command to "Pause" the current running script. If the command is ever executed in the script, this will resume the execution.
EZ_Builder.Scripting.Executor.StartScriptASync(Command[] compiled); This executes the compiled Command Opcode array in the background. If you precompile the script into an array of Command Opcodes, this method can be used. The advantage to pre-compiling the source into Command Opcodes is that the script will execute faster because it will not need to be compiled each time. There is a compiler cache in the Executor, however. This means that if you run the same script twice that is not compiled, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StartScriptASync(string script); This method compiles the plain text EZ-Script and executes it in the background. There is a compiler cache in the Executor, however. This means that if you run the same script consecutive times, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StartScriptBlocking(Command[] compiled); Executes the compiled Command OpCode array on the current thread.
EZ_Builder.Scripting.Executor.StartScriptBlocking(string script); This method compiles the plain text EZ-Script and executes it on the current thread. There is a compiler cache in the Executor, however. This means that if you run the same script consecutive times, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StopScript(); Stops the current ASync running EZ-Script on this Executor.
Events These events can be assigned to an Executor and will be raised at their appropriate function. The "CompilerName" parameter will include the optional compiler name that can be provided when the Executor class is initiated. In the above examples, the Executor class is created without any parameters. If a parameter was supplied, it would be the name of this compiler. If your program has many Executors that share these events, the CompilerName parameter will come in handy to identify what executor it originated from.
event OnCmdExecHandler(string compilerName, int lineNumber, string execTxt) Event is raised for each line that is executed in the script. This will dramatically slow the execution of the script, but is great for debugging.
event OnDoneHandler(string compilerName, TimeSpan timeTook) Event is raised when the script has completed.
event OnPausedHandler(string compilerName) Event is raised when the EZ-Script calls the Pause method. The Executor.Resume() function is necessary to continue, or StopScript().
event OnResumeHandler(string compilerName) Event is raised when the script is instructed to resume after a Pause.
event OnStartHandler(string compilerName) Event is raised when the script begins to execute.
The error cannot read the COM file, I downloaded it and when I follow the instructions, I get an error, while other files read normally. .
sorry for me but i tried many different ways but still show the error,I couldn't find EZ_B.dll file even though I downloaded it
None of the required references are in your list. Please follow the tutorial. It explains exactly how to click the browse button and navigate to the folder and select the files.
Sorry, but the reason I can't reference is because there is no file in the EZ_B folder and there is an error : this folder is empty , I am trying to solve it. I would like to thank DJ sure for answering my superfluous questions and I'm sorry for bothering you
I need to playback 5 Serial Bus servos in sequence.
What protocol is it? A "serial bus" is a generic term for anything using a UART that's chained together sharing the same RX line. Also, why did you add a photo with the question text added in your response?
Are you planning on making a skill control to do this? You wrote the question in the skill control thread in a comment - I'd like to make sure your question is in the right place to help you out.
To begin, I would recommend starting with servo Script control so you can make the serial bus protocol work - then consider making a skill control only if you're planning on distributing the effort to others: https://synthiam.com/Products/Controls/Scripting/Servo-Script-19068
He seems rather demanding as well. I guess he needs the benefit of the doubt as English may not be his native language....
I have installed all the software dependencies and still ARC does not detect that I have Visual Studio installed. OS is Windows 10, .NET 4.8 or newer, Visual Studio Community 2019.