Wierd USB issues in KAREL

  • Hi all,


    so i'm writing a KAREL program of which part of it logs to a file on USB (UD1) if the user has selected choice to log.

    if the user HAS selected choice to log then the USB MUST be inserted for logging - if not the program must abort it's process


    so...


    OPEN FILE LOG_FILE('AP', fn)fstatus = IO_STATUS(LOG_FILE)


    fstatus is always zero whether USB plugged in or not


    so it was suggested to me to try opening the file read-only as that gives the correct IO status...


    OPEN FILE LOG_FILE('RO',fn)

    fstatus = IO_STATUS(LOG_FILE)


    fstatus is zero if USB in and file already exists

    fstatus is 2014 if USB in and file doeasn't exist yet (FILE-014 File not found)

    fstatus is 2014 is USB is not in (FILE-014 File not found)


    It seems there’s no difference between..

    1. “the file doesn’t exist because usb NOT plugged in” (2014) and
    2. “the usb IS plugged in but the file doesn’t exist on it” (2014)


    another suggestion was to use

    flist : ARRAY[2] OF STRING[40]

    FILE_LIST(fn, 0, 3, flist, n_files, fstatus)


    but similarly, fstatus is always 0 whether USB is in or not. Hmmmm….


    basically all i need is,..


    IF USB connected THEN

    append log file

    ELSE

    ABORT

    ENDIF


    Anyone have any ideas what's going on, or how to solve it?


    Any help would be extremey appreciated


    Chris

  • HawkME

    Approved the thread.
  • Hi ChrisFS,

    I think the behavior, and the error messages are correct.

    Quote

    OPEN FILE LOG_FILE('AP', fn)fstatus = IO_STATUS(LOG_FILE)

    fstatus is always zero whether USB plugged in or not

    That the status is zero is ok, only when writing there is an error.

    We want to append text to the file, in 'AP' mode it doesn't matter if the file exists or not.


    And the second error is also correct.

    as you have written: 2014 -->FILE-014 File not found

    E.g. Windows would tell you in this case also "File not found"... and not "USB stick not inserted" :winking_face:


    ---

    You can evaluate the error when you write to the file and then set a status variable that tells you or the program that no USB drive is present.

    ---

    Alternatively you can use (from Karel manual)

    Code
    DOSFILE_INF('UD1:', DF_MANUFNAME, value, status)


    DF_MANUFNAME' vendor name

    value -->manufacturer name but not of interest here.


    check "status" ...

    ---

    But I strongly advise not to write a background program to monitor if the USB stick is inserted...


    best regards

  • hi PnsStarter,


    that's for the reply.


    OK, it was not working because i was using roboguide. sim gives 2014 for everything - duh!

    on the real robot, the correct status's are set.


    but....


    OPEN FILE LOG_FILE('AP', fn)

    fstatus = IO_STATUS(LOG_FILE)


    fstatus is always zero whether USB plugged in or not on sim and robot.

    No-one at our Fanuc contacts know why.


    OPEN FILE LOG_FILE('RO', fn)

    however, does give the correct status though. so this was used in the end (if anyone's insterested)..


    OPEN FILE LOG_FILE('RO',fn)

    fstatus = IO_STATUS(LOG_FILE)

    IF (fstatus = 0) OR (fstatus = 2014) THEN;

           IF (fstatus = 0) THEN;

                  -- log file exists..

           ENDIF

           IF (fstatus = 2014) THEN;

                  -- log file doesn’t exists..

           ENDIF

           CLOSE FILE LOG_FILE

           OPEN FILE LOG_FILE('AP',fn)

    fstatus = IO_STATUS(LOG_FILE)

           IF fstatus = 0 THEN

                  -- write log file..

           ENDIF

    ELSE

           IF (fstatus = 2068) THEN;

                  -- usb not plugged in..

           ENDIF

    ENDIF

    CLOSE FILE LOG_FILE


    Cheers,


    Chris

  • From experience I know that appending to a file from karel can get very slow, especially when writing to usb.

    The karel interpreter seems to seek the length of the file after opening, to get to the end, and that's slow.

Advertising from our partners