breaking while(1) like infinite loop from keyboard asynchronously

Home Forums Matlab breaking while(1) like infinite loop from keyboard asynchronously

This topic contains 4 replies, has 2 voices, and was last updated by  cK 10 years, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #465

    vikas.jain
    Participant

    am continuously acquiring data from serial port. For that I am using a for loop to open the port read data and close the port . now I want to break this infinite loop by using keyboard without waiting for input. means if the for loop is running and some one hits a particular keys asynchronously then the loop shoul break.

    Attachments:
    You must be logged in to view attached files.
    #467

    cK
    Keymaster

    To end (a loop or execution) abruptly, hit Ctrl+C.
    You really don’t need to loop fclose and fopen. Once opened the data will flow in continuously. From your buffer size it looks like you don’t need continuous acquisition and its okay to be losing data. If thats the case a small buffer (like you have now) will achieve that, which is preferable to looped closing and opening. When you need to interrupt then give the fclose() from cmd window. Consider GUIs to make start/stop acquisition more user friendlier.

    #468

    vikas.jain
    Participant

    Sir,

    Actually the data is coming continuously from serial port in a period of 1 second. For that I am using infinite loop. Now, I want user to break that loop by hitting any key from keyboard. I tried for input(), keyboard() etc. but the program wait for that key. But the requirement is like interrupt type. The code is running and the button is in user’s hold. pressing CTRL+C or break will result in loss of variable and data

    Attachments:
    You must be logged in to view attached files.
    #470

    cK
    Keymaster

    Ok, so you have two options – (1) get rid of loops at all as I mentioned earlier for continuous acquisition. (2) Remove the function to make it a script so that variables are in user workspace (the function anyways isn’t much functional in accepting inputs or throwing outputs and you are using global vars).

    #471

    cK
    Keymaster

    To get out of a loop, only ways are to break execution by ctrl+c or use a break statement conditionally.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.