Skip to content

C# and shell commands

Hi Martin,

 

I have a question similar to https://www.plcnext-community.net/index.php?option=com_easydiscuss&view=post&id=1512&Itemid=224&lang=en

I recently started my project over but using C# instead of C++ since we need the function block functionality.

The problem is, this block needs to run (5 small) linux programs upon user command but as i understand this from the thread it can only be done from C++.

FYI instead of calling external progs this was actually going to be done using a .NET library but it's not compatible with eCLR since not every .NET function is implemented it turned out so this leaves us only that option.

Of course I can't go back to C++ but my question:

is it much work to have the necessary classes implemented in the Phoenix framework? That way i can create a class for instance as described here: https://loune.net/2017/06/running-shell-bash-commands-in-net-core/

If i try this way now, I get:

Connector.cs(78,35,78,39): error CS1110: Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll?

 

I understand the concerns with execution time but I mean, what does phoenix care if a developer writes code that doesn't work. It's his/her responsibility, no?

For my project i need to be able to:

1. execute 2 small linux binaries with params that have to be executed on command, they return immediately with just a statuscode. In worst case I could start them in a thread and asynchronously update the values in the ports using the returned values read from inside the thread. 12ms < 100ms so shouldnt be a prob:

real 0m0.012s
user 0m0.006s
sys 0m0.001s

2. execute a program with params that immediately daemonizes (instant return):

real 0m0.011s
user 0m0.001s
sys 0m0.008s

3. execute a program with params that starts a listener and from which the stdout should be mildly parsed in the C# block that called it. This ofcourse requires a thread so it doesn't block the Esm. (Ofcourse, time the command doesnt make sense here). An other way is to change these programs so they serve on a local socket which i can then connect to from C# instead of starting a prog and catching the stdout but this is really not preferred and will cost too much time.

So my point being, i really don't see any problem here to launch shell commands from eCLR framework. Is there a way this can be easily implemented?

Maybe by sending me some .dll/.so you use at Phoenix for internal use which is able to do all this so i can reference them from Visual Studio?

Comments

  • Hello Thomas,

    we will have a look at this posibility and give an update as soon as possible.


    What IS possible :

    Use a C++ Program to start the LinuxServices and exchange Parameters from IEC to C++ via Ports.


    Keep in mind the USER that executes your Services will be the FW user. so there might be more work involved modifying the System to run your system commands.

    kind regards,
    Oliver

  • "Keep in mind the USER that executes your Services will be the FW user. so there might be more work involved modifying the System to run your system commands."

    like changing user/group ownership and permissions on the bins? :-) or is there more?

     

    I understand the C++ method but i'm not really keen on adding another software link in the chain of the process.

     

    Thank you, Martin! I am looking forward to the answer, hope it's feasible

  • Hi Thomas,

    Just adding to Oliver's earlier answer, with some more answers to your questions: 

    is it much work to have the necessary classes implemented in the Phoenix framework?

    Yes, it is. There may be more classes from .NET standard added to the eCLR in future, but the development effort will probably be prioritised to include classes that are most relevant to "PLC" type applications, that are suitable for running in a real-time task.

    I understand the concerns with execution time but I mean, what does phoenix care if a developer writes code that doesn't work. It's his/her responsibility, no?

    You're right, but it's not a matter of excluding classes that could cause the task watchdog time to be exceeded (there are already some of those in the eCLR), but its about prioritising the inclusion of classes that are more likely to be useful in "PLC"-type applications.

    Maybe by sending me some .dll/.so you use at Phoenix for internal use which is able to do all this so i can reference them from Visual Studio?

    In future it will be easier to launch shell commands from programs running on ESM tasks - using features of the Visual Studio add-in that are currently under development - but I don't have a timeframe for those features yet.

    - Martin.

Sign In or Register to comment.