Storing results in external memory (USB Drive)

2022-05-12
2022-06-08
  • princessdvlk - 2022-05-12

    Hello All,

    I am using a PLC based on raspberry Pi and the Codesys version I am working on is Codesys SP17 Patch 3. I have connected an USB drive to the Rasp Pi and I am given a file patch 'ls -al /media/pi' that I have to type somewhere in Codesys so that I can store results in this path. I am new to both Rasp Pi and Codesys. I am figuring out where to write this command. Can anyone help me?

    Or is there any other way I can access the USB drive connected to Rasp Pi using Codesys?

    Best Regards!

     
  • paulpotat

    paulpotat - 2022-05-13

    Hello,
    You can use the SysProcess library to run commands from CodeSys. You can use the SysProcessExecuteCommand2 to run a command and get its output in a string.
    For example if you wanted to wrap this function in your programm you could do the following :

    FUNCTION Run_Command
    VAR_OUTPUT
        Command_Output : STRING;
    END_VAR
    VAR
        command : STRING := 'ls -al /media/pi';
        res : RTS_IEC_RESULT;
    END_VAR
    
    SysProcessExecuteCommand2(
        pszCommand := command,
        pszStdOut := Command_Output,
        udiStdOutLen := SIZEOF(Command_Output),
        pResult := res
    );
    

    Then You can manage errors with the value returned in the "res" variable as you want.
    Hope this helps,
    BR

     
    • princessdvlk - 2022-06-08

      Hello, Thank you so much. I will check this and get back to you.

       
    • princessdvlk - 2022-06-08

      by the way, could you please helpe through this issue. i am suddenly unable to download the code into my plc. and i have no clue what is going on. i have pasted the link that elaborates the problem here.

      https://forge.codesys.com/forge/talk/Engineering/thread/7053c43207/#7c33

       

Log in to post a comment.