Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial script-run command #101

Merged
merged 2 commits into from
Dec 20, 2018
Merged

Add initial script-run command #101

merged 2 commits into from
Dec 20, 2018

Conversation

shaggygi
Copy link
Contributor

@shaggygi shaggygi commented Dec 15, 2018

This adds a new command section for scripting using the Roslyn Scripting APIs. This enables scenarios for more granular control over target devices and ability to execute routine tasks like integration tests for connected peripherals.

It contains a basic "script-run" command and currently only supports C# (assuming Visual Basic and F# could be added later). There is a required attribute for file path (-f) of script to execute.

Basic Example

  1. Create a MyIotScript.csx file with the following code:
#r "System.Device.Gpio"

using System;
using System.Device.Gpio;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

Console.WriteLine("Started Script File!");

void BlinkPin(int pinNumber, int millisecondsTimeout)
{
    for (int cnt = 0; cnt < 10; cnt++)
    {
        controller.Write(pinNumber, PinValue.Low);
        Thread.Sleep(millisecondsTimeout);
        controller.Write(pinNumber, PinValue.High);
        Thread.Sleep(millisecondsTimeout);
    }
}

Console.WriteLine("Get GPIO Controller...");
GpioController controller = new GpioController();

Console.WriteLine("Set GPIO Pin Mode...");
controller.OpenPin(21, PinMode.Output);

Console.WriteLine("Blink Pin...");
BlinkPin(21, 500);
Console.WriteLine("Blink Pin Faster...");
BlinkPin(21, 100);

Console.WriteLine("Dispose GPIO Controller...");
controller.Dispose();

Console.WriteLine("Exiting Script File!");
  1. Copy script file to target device. In this example, it is stored at the user home (/home/pi).
  2. Run DeviceApiTester CLI with the following: DeviceApiTester script-run -f "/home/pi/MyIotScript.csx"
  3. Notice it will print status to Console as it executes the script.

Notes

  1. This seems to be a nifty command as the script can be modified directly on the target and executed on the fly (assuming there are no syntax errors with script code 😄)
  2. As mentioned, this only supports C# for now.
  3. There is some slowness when starting the script. This is probably limited by the scripting APIs' compilation, but not sure.
  4. Referencing Add scripting commands to DeviceApiTester #102

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty. Of course, there may be some remote execution concerns but given that this is mainly a tool for testing on a device I think this is fine. I'll see if @anphel31 or @jslobodzian have any feedback since they are the ones maintaining this tool.

@joperezr
Copy link
Member

Merging now since I don't expect to get any more feedback here.

@joperezr joperezr merged commit 0bb8059 into dotnet:master Dec 20, 2018
@shaggygi
Copy link
Contributor Author

Thanks @joperezr I have a few more additions to add in DeviceApiTester over the holiday break 🎅

@joperezr
Copy link
Member

I have a few more additions to add in DeviceApiTester over the holiday break

Response from our side might be a bit slower since most people will be out, but I will be monitoring new PRs that come our way 😄

@shaggygi shaggygi deleted the deviceapitester-script branch December 20, 2018 23:35
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants