• 1

How to write a better script?


Hi everyone,

I need to write a script to control the UART Protocol so that I can simulate a serial conversation. So far, I've got just this code:

var MyString = "@T00.";

function Serial_Send(){
    print("Automated Serial Writer");
      	// Loop at 0.1 sec rate

if(!('Protocol' in this)) {
    throw("Please open Protocol instrument");


The configuration of my serial is attached

Of course, the endless loop didn't allow me to stop the Script or even abort it. But, it was sending data correctly. To stop the script I had to kill waveforms IDE (v3.7.9).

How can I improve it so that I can stop the program anytime I want? Will I have to set a trigger for that using a StaticIO button?


João Paulo

waveforms config serial.png

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @jpnbino

The wait function is intended to handle execution to the main application processes and to notify the script execution to stop.
This will return false after the Stop button in the Script tool is pressed or returns true after the specified time.

while(wait(1.5)){ // enter loop every 1.5 seconds while not stopped

for ...
	if(!wait()) break // quit loop when stopped
function ...
	if(!wait()) return // return when stopped

if(!wait()) throw "stopped" // abort execution when stopped


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now