Skip to content

Commit d15e64d

Browse files
authored
Merge pull request #173 from Open-STEM/FranksDev
Fixes for Run and Stop
2 parents 5c7c153 + c82d3d5 commit d15e64d

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/components/navbar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ function NavBar({ layoutref }: NavBarProps) {
864864
} catch (err) {
865865
console.log(err);
866866
}
867+
// When returning from the execute switch back to RUN mode. This happens when the program ends
868+
// naturaly.
869+
setRunning(false);
870+
broadcastRunningState(false);
867871
}
868872

869873
const handlePowerSwitchOK = async () => {

src/connections/connection.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ abstract class Connection {
238238
}
239239
}
240240
await new Promise((resolve) => setTimeout(resolve, 85));
241-
if (waitTime != -1) {
241+
242+
if (waitTime === -2 && this.isRunBusy === false) {
243+
return tempLines;
244+
}
245+
246+
if (waitTime != -1 && waitTime != -2 ) {
242247
numTimes--;
243248
}
244249
}
@@ -359,7 +364,7 @@ abstract class Connection {
359364
this.specialForceOutputFlag = true; //you see the OK, but also get any fast output
360365
this.catchOk = true;
361366
//await this.waitUntilOK();
362-
const result = await this.haltUntilRead(1);
367+
const result = await this.haltUntilRead(1, -2);
363368

364369
/*
365370
This is where errors can be checked for that were returned incase we want to give a better explanation
@@ -488,6 +493,18 @@ abstract class Connection {
488493
}
489494
return gotToPrompt;
490495
}
496+
async prepareForStop() {
497+
498+
if(this.isBusy() && this.isRunBusy === false){ //don't try and STOP if the code is BUSY but not from Running a user program.
499+
return;
500+
}
501+
if(this.isRunBusy){ //if the program is running do ctrl-c until we know it has stopped
502+
this.STOP = true; //let the executeLines code know when it stops, it stopped because the STOP button was pushed
503+
this.specialForceOutputFlag = false; //turn off showing output so they don't see the keyboardInterrupt and stack trace.
504+
this.isRunBusy = false;
505+
return
506+
}
507+
}
491508

492509
}
493510

src/managers/commandstoxrpmgr.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -920,21 +920,21 @@ export class CommandToXRPMgr {
920920
" file.seek(0)\n" +
921921
" file.write(b'\\x00')\n" +
922922
" doNothing = True\n" +
923-
" else:\n" +
924-
" file.seek(0)\n" +
925-
" file.write(b'\\x01')\n" +
923+
//" else:\n" +
924+
//" file.seek(0)\n" +
925+
//" file.write(b'\\x01')\n" +
926926
" if(not doNothing):\n" +
927927
" with open('" + fileToEx + "', mode='r') as exfile:\n" +
928928
" code = exfile.read()\n" +
929929
" execCode = compile(code, '" + fileToEx2 + "', 'exec')\n" +
930930
" exec(execCode)\n" +
931-
" with open(FILE_PATH, 'r+b') as file:\n" +
932-
" file.write(b'\\x00')\n" +
931+
//" with open(FILE_PATH, 'r+b') as file:\n" +
932+
//" file.write(b'\\x00')\n" +
933933
"except Exception as e:\n" +
934934
" import sys\n" +
935935
" sys.print_exception(e)\n" +
936-
" with open(FILE_PATH, 'r+b') as file:\n" +
937-
" file.write(b'\\x00')\n" +
936+
// " with open(FILE_PATH, 'r+b') as file:\n" +
937+
// " file.write(b'\\x00')\n" +
938938
"finally:\n" +
939939
" import gc\n" +
940940
" gc.collect()\n" +
@@ -988,11 +988,13 @@ export class CommandToXRPMgr {
988988
}
989989

990990
/**
991-
* stopProgram - stop program execution on the XRP
991+
* stopProgram - stop program execution on the XRP because they pushed the STOP button
992992
*/
993993
stopProgram() {
994994
if (this.connection) {
995+
this.connection.prepareForStop();
995996
this.connection.getToREPL();
997+
this.BUSY = false;
996998
}
997999
}
9981000

0 commit comments

Comments
 (0)