comment 0

SIMPL# Pro Primer: Part 3 (continued)

We didn’t get very far in the last tutorial, but we did get all of our devices added successfully to the program. We’re going to continue using the same project and finish it by creating a user interface and adding some program logic.

Open up VT-Pro and create the following layout (this file is also available in my GitHub repository):

Touchpanel layout for this program

You might notice, our display controls are all within the 20s and Blu-ray controls are all within 30s and 40s. This will make handling our button logic easier. When buttons are pressed on the touchpanel, they generate SigChange events in our program. These are handled by the _tp_SigChange event handler. Lets add some code to detect which button was pressed:

void _tp_SigChange(BasicTriList currentDevice, SigEventArgs args)
{
    if (args.Sig.Type == eSigType.Bool)
    {
        // Display controls
        if (args.Sig.Number > 20 && args.Sig.Number < 30)
        {
        }

        // Blu-ray controls
        if (args.Sig.Number > 30 && args.Sig.Number < 50)
        {
        }
    }
}

We check to see if the signal type is Bool (a Digital in SIMPL terms), then we check the range of the signal number to see which button it might be. In SIMPL, we would just give a name to each signal we want to handle, but in SIMPL# we can operate on the actual number to try and make our programming more general. Lets add this:

void _tp_SigChange(BasicTriList currentDevice, SigEventArgs args)
{
    if (args.Sig.Type == eSigType.Bool)
    {
        // Display controls
        if (args.Sig.Number > 20 && args.Sig.Number < 30)
        {
            _tp_DisplayControl(currentDevice, args.Sig.Number - 20, args.Sig.BoolValue);
        }

        // Blu-ray controls
        if (args.Sig.Number > 30 && args.Sig.Number < 50)
        {
            _tp_BluRayControl(currentDevice, args.Sig.Number - 30, args.Sig.BoolValue);
        }
    }
}

Notice that we shift the signal number down when we call our individual handlers. Define these two new methods just below the _tp_SigChange event handler:

void _tp_DisplayControl(BasicTriList device, uint number, bool value)
{
    if (value)
    {
        switch (number)
        {
            case 1: // Power On
                _rx.ComPorts[1].Send("");
                break;
            case 2: // Power Off
                _rx.ComPorts[1].Send("");
                break;
            case 3: // HDMI
                _rx.ComPorts[1].Send("");
                break;
        }
    }
}

void _tp_BluRayControl(BasicTriList device, uint number, bool value)
{
}

Lets handle the IR control first. Since we need to handle Press and Release, lets write our _tp_BluRayControl method to handle both events by checking value:

void _tp_BluRayControl(BasicTriList device, uint number, bool value)
{
    string[] commands = {
            "",
            "PLAY", "STOP", "PAUSE",
            "RSCAN", "FSCAN", "TRACK-", "TRACK+",
            "UP_ARROW", "DN_ARROW", "LEFT_ARROW", "RIGHT_ARROW", "ENTER/SELECT"
    };

    if (value)
        _tx.IROutputPorts[1].Press(commands[number]);
    else
        _tx.IROutputPorts[1].Release();
}

When a user presses one of the Blu-ray transport controls on our touchpanel, an event is generated that eventually runs this bit of code. We send the name of the command to the Press method on our IR output port. I grabbed the command names by looking in the driver file using Device Learner in Toolbox. These will likely change depending on the file you’re using. Then, when the user releases the button, another event is generated and runs this code again, but calls Release on our IR output port.

Now we can revisit the display power commands, add the following code to _tp_DisplayControl:

void _tp_DisplayControl(BasicTriList device, uint number, bool value)
{
    if (value)
    {
        switch (number)
        {
            case 1: // Power On
                _rx.ComPorts[1].Send("\xAA\x11\x01\x01\x01\x14");
                break;
            case 2: // Power Off
                _rx.ComPorts[1].Send("\xAA\x11\x01\x01\x00\x13");
                break;
            case 3: // HDMI
                _rx.ComPorts[1].Send("\xAA\x14\x01\x01\x21\x37");
                break;
        }
    }
}

Build this code and upload it to your processor. When you connect your touchpanel, pressing buttons should either trigger IR pulses on the DM-TX-4K-100-C-1G or serial control on the DM-RMC-4KZ-100-C.

Summary

In this part we covered:

  • Adding DM switchers and endpoints to our program
  • Adding IR files to our project and making sure they get copied to the controller
  • Loading an IR driver to an output port
  • Setting serial port communication specs
  • Handling ranges of joins in our SigChange event handler
  • Pulsing IR commands
  • Sending serial strings to devices

All code is available from my GitHub here: https://github.com/kielthecoder/SimplSharpPrimer

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