1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. Fanuc Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

Wierd USB issues in KAREL

  • ChrisFS
  • April 13, 2023 at 2:03 PM
  • Thread is Resolved
  • ChrisFS
    Reactions Received
    1
    Trophies
    3
    Posts
    8
    • April 13, 2023 at 2:03 PM
    • #1

    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 April 13, 2023 at 2:09 PM

    Approved the thread.
  • PnsStarter
    Reactions Received
    90
    Trophies
    6
    Posts
    325
    • April 13, 2023 at 3:32 PM
    • #2

    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

    Backdate/TP-Tools: A small collection of tools that simplify the commissioning and programming of Fanuc robots. (github.com)

  • ChrisFS
    Reactions Received
    1
    Trophies
    3
    Posts
    8
    • April 18, 2023 at 1:56 PM
    • #3

    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

  • rf103
    Reactions Received
    17
    Trophies
    4
    Posts
    264
    • April 19, 2023 at 8:53 AM
    • #4

    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.

  • evanc18
    Trophies
    1
    Posts
    2
    • April 10, 2025 at 9:23 PM
    • #5

    I know this an old thread but wanted to share my solution to this. This function first attempts to open a file in RW mode, creating it if it doesn't exist. Note, this will fail if there is no USB inserted but the IO status will stay at 0, which doesn't tell me anything. After that, I open the file in update mode (UD). If there is no USB inserted IO_STATUS will catch this and be non-zero. This sequence is also needed because it removes the need to have a permanent file on the USB just for checking if it exists or not. At the end, I get a register value I can error handle with to the PLC

    Code
    PROGRAM CHECK_USB
    %COMMENT = 'Version 1.0'
    %NOBUSYLAMP
    %NOLOCKGROUP
    %NOABORT = ERROR + TPENABLE + COMMAND
    %NOPAUSE = ERROR + TPENABLE + COMMAND
    
    
    VAR
        result : INTEGER
        status: INTEGER
        activeFileName: STRING[128]
        logfile: FILE
    
    BEGIN
        -- Checks if the USB is connected and returns the status to register 103
        -- 1 = USB not connected
        -- 0 = USB connected and writeable
        status = 0
        result = 1
        activeFileName = 'UD1:LOG-checkusb.txt' 
    
        -- Attempt to open the file for writing, create if it doesn't exist
        -- This is required because IO_STATUS only works in UD (update) mode
        -- The only way to check if the USB is connected is to try to open a file in UD mode
        OPEN FILE logfile ('RW', activeFileName)
        CLOSE FILE logfile
        CLR_IO_STAT(logfile)
    
        OPEN FILE logfile ('UD', activeFileName)
        status = IO_STATUS(logfile)
        CLR_IO_STAT(logfile)
        IF (status = 0) THEN
            WRITE logfile ('USB enabled for write', CR)
            CLOSE FILE logfile
            status = IO_STATUS(logfile)
            IF (status = 0) THEN
                result = 0
            ELSE
                result = 1
            ENDIF
            CLR_IO_STAT(logfile)
        ELSE
            result = 1
        ENDIF
    
        SET_INT_REG(103, result, status)
    
    END CHECK_USB
    Display More

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download