Make an ARC Skill

Example: EZ-Script/Blockly Edit Control

Throughout ARC controls, you will notice an edit usercontrol which allows single-line, multi-line and Blockly editing for EZ-Script. The usercontrol looks like this...

User-inserted image

When holding a single line of Script, it looks like this...

User-inserted image

Multi-line script is generated by either syntax editor or Blockly editor, both of which are accessible by pressing the edit button on the control. When holding multi-lines of script, generated from either Blockly or Syntax editing UI, it looks like this...

User-inserted image

This control can be found as a component within the ARC.exe, and it is called "UCScriptEditInput"

User-inserted image

When the edit button of the UCScriptEditInput is pressed, it will display a new window containing both script syntax editor and Blockly code creator. The default view (blockly/syntax) is based on 1) the user's preferred editor from preferences menu, 2) the last saved edit mode. ARC will decide which view to display to the user.

Blockly Tab Of Editor

User-inserted image

Script Syntax Tab Of Editor

User-inserted image

Loading Saved Code Into UCScriptEditInput Your plugin should be saving code that was created by the user to the project file via the cf.STORAGE option demonstrated in an earlier step of this tutorial. The UCScriptEditInputrequires the loaded data in two formats, the VALUE and XML. The VALUE property contains the raw EZ-Script that was edited using the Syntax Editor. The XML is the Blockly configuration. In the code example below, the UCScriptEditInput is populated by the cf.STORAGE.


public void SetConfiguration(PluginV1 cf) {

      ucScriptEdit1.Value = cf.STORAGE["MyCodeValue"].ToString();
      ucScriptEdit1.XML = cf.STORAGE["MyCodeXML"].ToString();
    }

Saving Code from UCScriptEditInput As you saw from the earlier step, the user code is loaded in two parts, the XML and script. Both of those properties contain the data which will be saved to the cf.STORAGE as well.


    public PluginV1 SaveCode() {

      PluginV1 cf = new PluginV1();

      cf.STORAGE["MyCodeValue"] = ucScriptEdit1.Value;
      cf.STORAGE["MyCodeXML"] = ucScriptEdit1.XML;

      return cf;
    }

Script Editing in DataGridView Having multiple saved scripts in a DataGridView is possible as well. This allows users to create multiple scripts that could be triggered based on an input, for example. Reference of this behavior is the Speech Recognition or Twitter Recognition controls. They each allow the user to add custom scripts that are triggered on an input (Phrase) value.

User-inserted image

When defining an EZ-Script column for the DataGridView, select the UCScriptEditColumn for the type.

User-inserted image

Populating Saved Code Loading user saved code from the project configuration file to UCScriptEditColumn is a little different than loading to a single UCScriptEditInput. The difference is that a UCScriptEditColumn accepts the CODE and XML to be provided in a single class (UCForms.UC.FormScriptEdit.ConfigurationCls) and passed to the VALUE property. In this example below, the saved data is stored as a CustomObjectv2 in the project configuration. As you learned in an earlier step of this tutorial, the CustomObjectv2 will save your custom class using reflection into the project file.

The code below will foreach loop through each item of the saved code class, which contains the Phrase, Code and XML of each user added item in the DataGridView. Notice how the Code and XML are populated to the UCScriptEditColumn within the UCForms.UC.FormScriptEdit.ConfigurationCls class.


using System.Windows.Forms;

namespace EZ_Builder {

  public partial class Testform : Form {

    public class SavedCodeCls {

      public SavedCodeItemCls [] UserCodes = new SavedCodeItemCls[] { };

      public class SavedCodeItemCls {

        public string Phrase = string.Empty;
        public string Code = string.Empty;
        public string XML = string.Empty;
      }
    }

    public Testform() {

      InitializeComponent();
    }

    public void LoadSavedData(Config.Sub.PluginV1 cf) {

      SavedCodeCls savedCode = (SavedCodeCls)cf.GetCustomObjectV2(typeof(SavedCodeCls));

      foreach (var codeItem in savedCode.UserCodes) {

        // Add a new row and get the index of it
        int rowIndex = dataGridView1.Rows.Add();

        // Assign the saved Phrase to column 0
        dataGridView1.Rows[rowIndex].Cells[0].Value = codeItem.Phrase;

        // Assign the saved Code and XML to column 1
        dataGridView1.Rows[rowIndex].Cells[1].Value = new UCForms.UC.FormScriptEdit.ConfigurationCls(codeItem.Code, codeItem.XML);
      }
    }
  }
}

Saving Code We will now expand on the above code example to include a function for saving the user defined rows and code from the DataGridView to the project file.


using System.Windows.Forms;
using System.Collections.Generic;

namespace EZ_Builder {

  public partial class Testform : Form {

    public class SavedCodeCls {

      public SavedCodeItemCls [] UserCodes = new SavedCodeItemCls[] { };

      public class SavedCodeItemCls {

        public string Phrase = string.Empty;
        public string Code = string.Empty;
        public string XML = string.Empty;
      }
    }

    public Testform() {

      InitializeComponent();
    }

    public void LoadSavedData(Config.Sub.PluginV1 cf) {

      SavedCodeCls savedCode = (SavedCodeCls)cf.GetCustomObjectV2(typeof(SavedCodeCls));

      foreach (var codeItem in savedCode.UserCodes) {

        // Add a new row and get the index of it
        int rowIndex = dataGridView1.Rows.Add();

        // Assign the saved Phrase to column 0
        dataGridView1.Rows[rowIndex].Cells[0].Value = codeItem.Phrase;

        // Assign the saved Code and XML to column 1
        dataGridView1.Rows[rowIndex].Cells[1].Value = new UCForms.UC.FormScriptEdit.ConfigurationCls(codeItem.Code, codeItem.XML);
      }
    }

    public Config.Sub.PluginV1 GetSavedData() {

      var cf = new Config.Sub.PluginV1();

      List items = new List();

      foreach (DataGridViewRow dgvr in dataGridView1.Rows) {

        // Check if this row is valid by seeing if any necessary columsn are null
        if (dgvr.Cells[0].Value == null)
          continue;
        else if (dgvr.Cells[1].Value == null)
          continue;

        // Get the values of each column
        var phrase = dgvr.Cells[0].Value.ToString();
        var code = (UCForms.UC.FormScriptEdit.ConfigurationCls)dgvr.Cells[1].Value;

        // Assign the values (code, xml and phrase) to the item
        var codeItem = new SavedCodeCls.SavedCodeItemCls();
        codeItem.Code = code.Code;
        codeItem.XML = code.XML;
        codeItem.Phrase = phrase;

        // Add the item to the list
        items.Add(codeItem);
      }

      // Assign the list of code items to the array within the master clas
      SavedCodeCls savedCode = new SavedCodeCls();
      savedCode.UserCodes = items.ToArray();

      // Add the master config class to the project configuration as a custom object
      cf.SetCustomObjectV2(savedCode);

      return cf;
    }
  }
}


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

United Kingdom
#1  

Is this out of date? There doesn't seem to be a GetConfiguration function within EZ_Builder.Config.Sub.PluginV1

PRO
Synthiam
#2  

Look at the tutorial step titled [color=#ce3991][size=3][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]Code: Saving/Loading Configuration

[color=#ce3991][size=3][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]The get and set configuration methods are overrides of the form. There’s a great video on the first step of this tutorial that demonstrates the step by step of building a plugin. I recommend watching that because it helps fill in any steps that were missed. [/font][/size][/color]

[color=#ce3991][size=3][font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]When you’ve done it once, it makes sense and voila, you can rinse and repeat:)[/font][/size][/color][/font][/size][/color]

United Kingdom
#3  

Excellent, thanks - I will do. I really must learn not to just jump ahead in the process:)

PRO
Synthiam
#4  

Hey no problem - I do it all the time, and end up frustrated because I dont know what it was that I missed. Excitement gets the best of me

United Kingdom
#5  

Trying to follow the tutorials but can't find where the plugin page has gone. How do I add a new plugin to the ez-robot / Synthiam site to get the XML?

United Kingdom
#6  

Never mind. Just found the "Create skill control" link:)

#7  

I am trying to follow the instructions for adding my own plugin but I cannot seem to find the place to register the plugin based on the instructions.

Any help is appreciated.

Thanks

PRO
Synthiam
#8   — Edited

The new button to create a plugin skill control is less than an inch below the button you pressed to create this question. :)

User-inserted image

#9  

Thanks for the quick response.

This what happens when you are working on robotics when its way past your bed time.

You miss the obvious

PRO
Synthiam
#10  

No problem - i get it:D

#11  

User-inserted image

User-inserted image

User-inserted image

User-inserted image

Sorry but can I ask you something why I didn't see the ARC library when I added visual studio even though I set up the C ++. DLL library and there's another way to execute it and send / receive console in out but I don't know how to do it with EZ_builder?

PRO
Synthiam
#12   — Edited

Please follow the tutorial. It’s impossible to know why you’re plug-in isn’t showing up without asking you if you followed each step of the tutorial:). Reviewing your screenshots, it doesn’t appear as if any of the tutorial steps have been followed.

#13   — Edited

Hi i fixed it. thanks

Hello, I am trying the tutorial to get the robot to speak. I am using Visual studio. Currently, the sound is output from the pc instead of the robot. Is there a code I can attach so that the sound comes from the robot speakers instead of the pc?

PRO
Synthiam
#14   — Edited

Look in this tutorial for the step labeled "output audio from ezb". It’s lower down in the list. There’s instruction examples for either playing audio (ie mp3) or text to speech.

#15  

Error: the referenced component" EZ_builder,EZ_B" could not be found, DJ Sure i hope you can help me !

PRO
Synthiam
#16   — Edited

User-inserted image

Joinny, you have to add the referencing by following the instructions in this tutorial. They are outlined with step by step to easily follow. Click add references, and browse to the appropriate files as directed in the tutorial. I can’t write anything clearer in response. The step to add references is incredibly clear but you’re skipping it.

#17  

The error cannot read the COM file, I downloaded it and when I follow the instructions, I get an error, while other files read normally. .

User-inserted image

#18   — Edited

sorry for me but i tried many different ways but still show the error,I couldn't find EZ_B.dll file even though I downloaded it

PRO
Synthiam
#19  

None of the required references are in your list. Please follow the tutorial. It explains exactly how to click the browse button and navigate to the folder and select the files.

#20  

Sorry, but the reason I can't reference is because there is no file in the EZ_B folder and there is an error : this folder is empty , I am trying to solve it. I would like to thank DJ sure for answering my superfluous questions and I'm sorry for bothering you

Australia
#21   — Edited

I need to playback 5 Serial Bus servos in sequence.

PRO
Synthiam
#22   — Edited

What protocol is it? A "serial bus" is a generic term for anything using a UART that's chained together sharing the same RX line. Also, why did you add a photo with the question text added in your response?

Are you planning on making a skill control to do this? You wrote the question in the skill control thread in a comment - I'd like to make sure your question is in the right place to help you out.

To begin, I would recommend starting with servo Script control so you can make the serial bus protocol work - then consider making a skill control only if you're planning on distributing the effort to others: https://synthiam.com/Products/Controls/Scripting/Servo-Script-19068

#23  

He seems rather demanding as well.  I guess he needs the benefit of the doubt as English may not be his native language....

#24   — Edited

I have installed all the software dependencies and still ARC does not detect that I have Visual Studio installed. OS is Windows 10, .NET 4.8 or newer, Visual Studio Community 2019.

PRO
Synthiam
#25  

When the popup says it doesn’t detect visual studio, you can still skip and continue. I wonder why it’s not detecting it? We had a hard time trying to find a proper way of detecting - even Microsoft’s suggestion didn’t actually work eye roll

ill look into it a bit further and see if we can find a better way of detecting

PRO
USA
#26  

@DJ: It's easy to find the Visual Studio 2017 and up: Microsoft: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild

Some quick c# code to use with .NET: https://github.com/ppedro74/Utils/blob/master/FindVisualStudio/Program.cs

using System;
using System.Diagnostics;
using System.IO;

namespace FindVisualStudio
{
    internal class Program
    {
        static string ProcessStart(string fileName, string args)
        {
            var processStartInfo = new ProcessStartInfo
            {
                Arguments = args,
                CreateNoWindow = true,
                FileName = fileName,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetDirectoryName(fileName),
            };

            using (var process = Process.Start(processStartInfo))
            {
                process.WaitForExit();
                return process.StandardOutput.ReadToEnd().Trim();
            }
        }

        private static string GetInstallationPath(string vsWhere)
        {
            var installationPath = ProcessStart(vsWhere, "-latest -products * -requires Microsoft.Component.MSBuild -property installationPath");
            return installationPath;
        }

        private static string GetProductLineVersion(string vsWhere)
        {
            var version = ProcessStart(vsWhere, "-latest -property catalog_productLineVersion");
            return version;
        }


        private static void Main(string[] args)
        {
            var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            var vsWhere = Path.Combine(programFiles, "Microsoft Visual Studio", "Installer", "vswhere.exe");
            if (!File.Exists(vsWhere))
            {
                throw new FileNotFoundException("Cannot find Microsoft Visual Studio's vswhere.exe utility.", vsWhere);
            }

            var version = GetProductLineVersion(vsWhere);
            Console.WriteLine($"Visual Studio Version: {version}");

            var installationPath = GetInstallationPath(vsWhere);
            if (!Directory.Exists(installationPath))
            {
                throw new DirectoryNotFoundException(installationPath);
            }

            Console.WriteLine($"Visual Studio installation Path: {installationPath}");

        }
    }
}
PRO
USA
#27   — Edited

Quote:

With Visual Studio 2017 Update 2 or newer installed, you can find vswhere at %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe, or to make sure it's always available in your repo see Installing for an option using NuGet.
Because is only available with "Visual Studio 2017 Update 2", you can add the vswhere package to your ARC project, and use your version (nuget) to detect older 2017 or legacy Visual Studio Versions (although does not make sense for ARC). https://devblogs.microsoft.com/setup/vswhere-now-searches-older-versions-of-visual-studio/

PRO
Synthiam
#28   — Edited

We went this route and it didn’t work on my computer - because I had a preview of visual studio installed which isn’t in that directory path. Microsoft had numerous suggestions of detecting visual studio. The one which worked for our various installations was a registry check.

apparently with the above individual, the registry didn’t work either. I’ll have to combine a few methods.

everything looks simple from the outside - until you have a hundred thousand+ installations of your software. That’s when you run into things like this lol

PRO
USA
#29   — Edited

@DJ: I agree sometimes the things go out of script easily.

I avoid going through the registry keys, unless is recommended by the vendor. A lot of people blame the changes (keys,  entries are renamed etc), but, that is normal if I own my product is my business and is part of the software evolution. Some products you can break the support contract agreement if you query directly the database, or if you look elsewhere outside of the public API.

Is true story some years ago a "rogue" developer on my team released a Sharepoint integration using a mix of APIs and database queries, everything worked well with multiple clients, until one day the Microsoft Black suits visit one of the customers to follow up on an unrelated support ticket, and they basically used "unsupported" card and left the client hanging, and we had problems too, unfortunately the Rogue developer went to another galaxy ... and the team suffered the consequences.

That does not mean I'm not tempted to do it...:)

I used the vswhere before and I would say is almost 99% bulletproof, is used with Xamarin, NVIDIA, Intel setups. If you add vswhere.exe to your project (nuget package) you cover scenarios where the tool is not present or have been deleted (broken uninstalls).

The other fallback could be ask the user the visual studio version.

The other reason to avoid registry is due to Visual Studio uses a private exclusive registry keys to store more stuff:  http://www.visualstudioextensibility.com/2017/07/15/about-the-new-privateregistry-bin-file-of-visual-studio-2017/

So the things are getting more complex.

The above post is only part of the "Full solution" for example I have one setup with visual studio 2017 c# installed and Visual studio 2019 with Python and C++, vswhere will return 2019 version,  but my c# is done with VS2017.

If you are generating customized vs version project files, maybe a fallback (ask the VS version) will cover more bases.

PRO
Synthiam
#30  

Yes - Microsoft has a few pages on how to identify visual studio and we tried them all during testing - the one we went with was with registry. I'm going to combine the two as using only one method apparently doesn't work for all cases.