Can I add a force stop condition in a loop

  • Context: MATLAB 
  • Thread starter Thread starter liran avraham
  • Start date Start date
  • Tags Tags
    Condition Force Loop
Click For Summary

Discussion Overview

The discussion revolves around the implementation of a force stop condition in a MATLAB loop controlling a Keithley current source. Participants explore methods to ensure that the current source is turned off when the loop is forcibly stopped, particularly using keyboard interrupts like Ctrl+C.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant inquires about adding an if condition to turn off the current source when the loop is forcefully stopped.
  • Another participant suggests setting a variable to true if the loop completes normally, which could indicate that the loop was not stopped early.
  • A third participant clarifies that they are specifically looking for a way to detect a force stop (Ctrl+C) and turn off the device in that case.
  • A later reply mentions the MATLAB function onCleanup as a potential solution, directing to the official documentation.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the best method to implement the desired functionality, and multiple approaches are suggested without resolution.

Contextual Notes

The discussion does not clarify whether the proposed solutions are feasible or effective in the specific context of the user's application.

Who May Find This Useful

This discussion may be useful for MATLAB users working with hardware control who are interested in implementing robust error handling and stopping conditions in their code.

liran avraham
Messages
7
Reaction score
0
i have keithley currnet source that i control with matlab, inside a loop, if i force stop the loop the device continue to output the last current.
my question is can i add if condition that turn of the current source?
for example
if force stop
fprintf(device, ':OUTP OFF')
end
 
Physics news on Phys.org
liran avraham said:
my question is can i add if condition that turn of the current source?

I'm not a MATLAB expert, but one thing you could try is to place a statement at the very end of the loop that sets a variable to true if the loop completes. Then you could check right after the loop to see if the variable was set to true. If not, then the loop was stopped early.
 
that not what i meant.
i asked if there is some way to add a condition to my code that identify a force stop (ctr +c) so when i force stop my current supply output is truned off. in a way some
if (force stop\ctr +c)
turn off device
end

my main loop is endless i built some homemaide temperature controler, i am always measuring tne temperature:
while (1)
...
end
 
liran avraham said:
i asked if there is some way to add a condition to my code that identify a force stop (ctr +c)

My mistake. I'm afraid I don't know if that's possible or not, but perhaps someone else here can help you. Good luck!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
6
Views
2K
Replies
1
Views
2K