2

I have a script where I launch a shell command. The problem is that the script doesn't wait until the command is finished and continues right away. I have tried WAIT but it doesn't work as the shell command turns the source off and on (ignition off/on) and I get the error that WAIT cannot be executed because power is off.

Is there any command I can use for program to wait until the command is executed?

My script looks like this:

    OS.COMMAND echo OUTP OFF > COM1
    
    OS.COMMAND echo OUTP ON > COM1
    
    System.up
Holger
  • 3,920
  • 1
  • 13
  • 35
sandra
  • 65
  • 4

1 Answers1

1

If I would want to execute a shell command without redirecting I would use OS.Area instead of OS.Command, because OS.Area is blocking and will wait until the shell command has finished. However OS.Area does not support redirecting I think.

If I would want to execute a shell command and redirect the output to a file I would first delete the file and then wait until it gets accessible. Like this:

IF OS.FILE.EXIST("myfile.txt")
    RM "myfile.txt"
OS.Command ECHO "Hello World" > "myfile.txt"
WAIT OS.FILE.readable("myfile.txt") 

However it looks like you want to write via a shell command to a COM port on Windows. But I don't think it is possible to wait in TRACE32 until this write to the COM port has been done when using OS.Command...

So I suggest to do this task with the TERM commands instead:

TERM.METHOD #1 COM COM1 115200. 8 NONE 1STOP NONE
TERM.view #1
TERM.Out  #1 "OUTP OFF" 0x0A
TERM.Out  #1 "OUTP ON"  0x0A

Of course you have to set the correct baud rate, bits, parity and stop bits. The 0x0A after each TERM.Out is simply the line-feed character.

Does you terminal show any output as a reaction to OUTP ON? If yes you can also wait for this output with e.g. SCREEN.WAIT TERM.LINE(#1,-1)=="OUTP is now ON" 5.s

Otherwise I assume that a simple WAIT 50.ms before SYStem.Up will probably do the trick too.

Holger
  • 3,920
  • 1
  • 13
  • 35
  • Thank you for your support. Unfortunately, it does not apply to what I'm trying to do, maybe I didn't explain it well. My OS command is controlling the power supply for the microcontroller and when the program is running and I am performing the command, when going to the next statement which is System.up or Wait I get the error the program can't perform it because the power is down. However, the command turns off the power and then turns it on again but the script does not wait until the power is on again. I tried OS.Area but the script stops after performing the command. – sandra Jan 11 '22 at 08:43
  • So you target is running and TRACE32 is in state UP (bottom right corner of the status line). Then you switch of the power with the script and you get an error message and the script stops at that point. Is this correct? – Holger Jan 11 '22 at 09:52
  • Yes, Trace32 is in state UP and program is running. After I switch off the power with the script, it informs me that power is off and cannot perform the System.up command. If Trace32 is UP and the program is not running (if I write a "break" before writing the os command, it works but this changes the outcome of my test so I cannot use it) – sandra Jan 11 '22 at 10:04
  • 1
    Put `ON ERROR CONTinue` in you script before executing the command, which causes the power-loss. That will ensure that the script keeps running in case of an error. Later you should probably use `ON ERROR inherit` to restore the normal error handling. – Holger Jan 11 '22 at 11:23