Skip to content

Creating Folders with eCLR: Forbidden

I am trying to develop an application using the eCLR library with C#. I program various logic blocks that are then used by a PLC.

 

I see from the help file that the System.IO classes Directory and DirectoryInfo are not supported. This is a major problem for us since the application involves creating, reading, moving, and deleting numerous files.

 

Is there any possible workaround or any assistance whatsoever for somehow gaining the ability to create folders? I don't need to delete them or rename them, only create. I already tried creating my own class and then referencing it in eCLR, that didn't work. Please help!

 

Thanks very much,

Alex Hearn

Armstrong Fluid Technology

Toronto, Canada

Comments

  • Hi Alex,

    One work-around might be as follows:

    • From a shell session on the PLC, create an empty file somewhere (e.g. touch /opt/plcnext/myfile)
    • Download the PlcnextBase library from the PLCnext Store.
    • In your PLCnext Engineer project, import the two libraries PlcnextBaseServices and PlcnextBase.
    • As per the instructions in the documentation for that library, create an instance of the ServiceProvider program.
    • Create an instance of the PBCL_FileCopy_1 function block.
    • Every time your C# FB wants to create a new directory, it can signal this FB instance to copy the empty file to the directory name you want to create (e.g. /opt/plcnext/mynewdir).
    • The "xDone" flag on the FileCopy FB can be passed back to your C# to signal that the new directory is now available.
    • Repeat this every time you want to create a new directory.

    The new directory will be created with the dummy file in it, but this is the only way I could get this FB to work without error.

    Perhaps someone else has a better idea.

    You could also contact the developer of the PlcnextBase library (via the Store) and put in a feature request for a "Create Directory" function.

    Hope this helps.

    ~ Martin.

  • Hi Martin,

    I work with Alex Hearn.

    Thanks for your answer, we tested the PLCNextBase Library and it worked! We were able to create a directory.

    However, we have one more question: The PBCL_FileCopy FB takes as destination path (input strDstPath) a string of type PBCL_STR_500, but my C# FB can't output this type of string. I believe C# only has IecString80. 

    Can you please clarify?

     

    Thanks,

     

    Alex

  • Hi Alex,

    Glad to hear you have something working.

    You are correct, the IEC type "String" has a maximum length of 80 characters. However it is possible to define your own String data types with different maximum lengths (this is described in the PLCnext Help system).

    The PLCnextBase library has defined it own custom String datatype, called PBCL_STR_500 with (I am guessing from the name) a maximum length of 500 characters. You can declare a variable of this data type in your own IEC-61131 POU, and then assign the value of your C# string to that variable before passing it to the PBCL_FileCopy FB.

    Hope this helps.

    ~ Martin.

  • Thanks Martin,

     

    Using the PBCL_FileCopy FB achieved the goal.

     

     

     

    Regards,

     

    Alex

Sign In or Register to comment.