Make an ARC Skill

Example: Saving/Loading Configuration

In all plugins, there is a _cf variable which is provided by the inherited class which defines the Form. The _cf (configuration file) contains the data saved with your project. The _cf.STORAGE[key] is where your plugin configuration is kept. However, due to ARC providing the UCServoSelection user control, there is also a _cf.SERVOS[key] to store servo configuration.

The UCServoSelection user control is the common displayed control across all configuration screens in EZ-Builder. This user control allows configuration of servo ports, min and max distances. As well as multi servo support, etc.. So, if your plugin is to use the UCServoSelection, we highly recommend doing so. To move servos with UCServoSelection configuration data, the example source code in the above mentioned project should be reviewed. In short, it's easy to pass UCServoSelection.Config() data to the ARC.EZBManager.SetServoPosition(), which will take care of the magic - including relationship scaling between multiple servos, min, max and inverted options from UCServoSelection.

Configuration settings must be initialized with default values in the SetConfiguration override. This will ensure that when your plugin is loaded, there is some default configuration data assigned to the keys. Because the data is initialized using the _cf.STORAGE.AddIfNotExist(), the default data will only be added if the key doesn't exist. If the key does exist, following the user loading a project with saved configuration data, the default configuration will not be applied to the key. As demonstrated...


    public override void SetConfiguration(EZ_Builder.Config.Sub.PluginV1 cf) {

      cf.SERVOS.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });
      cf.SERVOS.AddIfNotExist(ConfigurationDictionary._VERTICAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });

      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_DEGREES, 0.14m);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._VERTICAL_DEGREES, 0.14m);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_ENABLED, true);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_SIZE, 10);

      base.SetConfiguration(cf);
    }

The base.SetConfiguration in the above example is necessary to set the configuration with the inherited base. This ensures the initialized configuration is applied.

Also in the above example, the ConfigurationDictionary is a class which contains read-only static strings to reference the resource keys. We use these strings so the configuration data can be referenced without worrying about spelling mistakes where ever the data is to be accessed. Here is a look at the above example ConfigurationDictionary...


  public class ConfigurationDictionary {

    public static readonly string _HORIZONTAL_SERVOS = "horizontal servos";
    public static readonly string _VERTICAL_SERVOS = "vertical servos";

    public static readonly string _HORIZONTAL_DEGREES = "horizontal degrees";
    public static readonly string _VERTICAL_DEGREES = "vertical degrees";

    public static readonly string _EDGE_SIZE = "edge size";
    public static readonly string _EDGE_ENABLED = "edge enabled";
  }

Now to use the configuration data from the _cf in your project, simply cast the object from the _cf.STORAGE to the correct type. For _cf.SERVOS, pass the key result directly into the ARC.EZBManager helper methods. Like so...


      if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._EDGE_ENABLED])) {

        int edgeSize = Convert.ToInt16(_cf.STORAGE[ConfigurationDictionary._EDGE_SIZE]);
        var servosX = _cf.SERVOS[ConfigurationDictionary._HORIZONTAL_SERVOS];
        var servosY = _cf.SERVOS[ConfigurationDictionary._VERTICAL_SERVOS];

        if (_mousePoint.X  _cameraControl.Camera.CaptureWidth - 10)
          ARC.EZBManager.SetServoIncrement(servosX, 1);

        if (_mousePoint.Y  _cameraControl.Camera.CaptureHeight - 10)
          ARC.EZBManager.SetServoIncrement(servosY, 1);
      }

Any data in the _cf.STORAGE and _cf.SERVOS will be automatically saved with the users project. And when that project is loaded again in the future, the _cf data will be reloaded as well. This allows your plugin to save the custom configuration applied by the user.


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

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.