MATLAB Can I add a force stop condition in a loop

AI Thread Summary
The discussion revolves around controlling a Keithley current source with MATLAB, specifically addressing the challenge of turning off the current output when the loop is forcefully stopped using Ctrl+C. The user seeks a method to implement a condition that detects this interruption and automatically sends a command to turn off the device. Suggestions include using the MATLAB function onCleanup, which can help manage cleanup tasks when a function exits, including when interrupted. However, there is uncertainty about whether a direct condition for detecting a force stop can be implemented within the endless loop of the user's temperature control project.
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!
 
Back
Top