comments 6

SIMPL# Pro Primer: Part 1

In Part 1 of this primer, we’re going to look at how to create a new SIMPL# Pro project. This series assumes you have a copy of Visual Studio 2008 SP1 installed as well as the Crestron SIMPL# Plug-In. If you need to install the plug-in, it can be downloaded from Crestron. The current version is 2.000.0058.01.

First, we want to create a new Project. Go to File > New > Project in the menus and you’ll see the following dialog window:

Creating a new SIMPL# Pro project in Visual Studio 2008

Make sure to pick Crestron for the type, select SIMPL# Pro as the template, and choose a location to save the project. We’re going to name this first one Part1. Press OK and your new project will be created.

Your new project will open with the ControlSystem.cs file opened automatically. You can scan through this file if you like, but we’re not changing any parts of it just yet.

We need to tell Visual Studio how to connect to our controller to test out this program. In the Solution Explorer window, open the ControlSystem.cfg file by double-clicking on it.

Accessing ControlSystem.cfg from the Solution Explorer

In the configuration settings, click the Address Book icon to select a control system. This is the same Address Book used by Toolbox. If you already have Toolbox open, you may run into problems with Visual Studio trying to use the same COM server.

Changing our connection settings

Once you’ve selected a controller, make sure to select a Program Slot. We’ll load to Slot 1 in this example.

Connect to PRO3_CS from my Address Book, showing a previously loaded SIMPL program

The Upload Project button is grayed out still because we need to build our project first. Go to the Build > Build Solution menu item or press F6. If you watch the status bar at the bottom you should see “Build succeeded” once it’s done compiling. Much faster than SIMPL Windows, right?!

Now we can press the Upload Project button on the ControlSystem.cfg page. Press the Upload button to send your program to the control system.

Uploading our program to the controller

Once you see “Program successfully uploaded,” you may close the Upload Project dialog. If you’ve made it this far, great! Unfortunately, we don’t really know what our program is doing yet. Is it even running?

Open ControlSystem.cs and lets change a few things. I want you to remove almost everything until you’re left with only this:

using System;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.CrestronThread;

namespace Part1
{
    public class ControlSystem : CrestronControlSystem
    {
        public ControlSystem()
            : base()
        {
            Thread.MaxNumberOfUserThreads = 10;
        }

        public override void InitializeSystem()
        {
            CrestronConsole.PrintLine("\n Hello world! \n");
        }
    }
}

When the control system starts our program, it creates a new ControlSystem object then calls InitializeSystem to handle the rest. After that, we rely solely on events to trigger things in our program (i.e.: button pushes, serial communication, timers, etc.). Build this program and load it to your controller.

Again, nothing happens? We can’t launch SIMPL Debugger to inspect the program because we’re not running the SIMPL engine anymore. But we can look at the console. The call we’re making to CrestronConsole.PrintLine can be very useful to see what’s going on inside our code. Later, we’ll look into using the debugging features built into Visual Studio to inspect the running program even better. For now, PrintLines will work just fine. Use an SSH client (such as PuTTY) to connect to your control processor and watch what happens.

Connecting to the Text Console on our controller

Still not much going on, right? Because right now, the only thing our program does is print out “Hello world!” when it starts (in InitializeSystem). If we restart the program from Text Console, we can watch the message when it starts up. Use the progreset command to restart our program:

Hello world!

There’s our “Hello world!” Notice that it’s printed out after the program header but before our program has fully initialized. InitializeSystem is one of those special methods that must return quickly otherwise the controller might think our program locked up. Later on when we start reading configuration files, we’ll need to find a way to pass this off to another execution thread. That way we can still let InitializeSystem return quickly.

Summary

In this part we learned:

  • How to create a new SIMPL# Pro project
  • Connect to a control system and push code
  • Open a Text Console to send commands and watch for feedback
  • Use CrestronConsole.PrintLine to debug

6 Comments

  1. Pingback: SIMPL# Pro Primer: Part 2 – Kiel the Coder

  2. Pingback: Huddle Room: Part 1 – Kiel the Coder

  3. Pingback: Contract Editor – Kiel the Coder

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s