MT-VIKI HDMI Matrix Switch TCP Plugin

Hello! I’m trying to create a TCP connection plugin to my MT-VIKI 16x16 HDMI Matrix Switch. When I run the simulator in the designer, I get this error: “No public methods with the specified arguments were found.” Just to clarify, I’ve only included 2 commands (SW 3 7 and SW 4 7), as I’m testing and simply trying to get it to work. My first time using TCP, as everything else has primarily been IR. Any ideas as to what my issue is?

TCP connection to the switch is raw text, and the switch format is SW Input Output1 Output2 etc.

plugin.Name = "Viki";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 250;
plugin.DefaultSettings = { "Host": "192.168.1.6", "Port": "8080" };

var deviceId = "1";
var socket = new TCPClient();

var commands = {
    "SwitchIn3Out7" : "SW 3 7",
    "SwitchIn4Out7" : "SW 4 7",
}

function onChangeRequest(device, attribute, value) {
    if (attribute != "MediaCommand")
        throw "Invalid attribute";

    var command = commands[value];
    if (!command)
        throw "Invalid command";

    socket.send(command);
}

function onConnect() {
    socket.connect(plugin.Settings["Host"], parseInt(plugin.Settings["Port"]));

    var device = plugin.Devices[deviceId];
    if (device != null) {
        device.SupportedMediaCommands = Object.keys(commands);
    }
}

function onDisconnect() {
    socket.close();
}

function onPoll() {
}

function onSynchronizeDevices() {
    var device = new Device();
    device.Id = deviceId;
    device.DisplayName = "Viki";
    device.Capabilities = ["MediaControl"];
    device.Attributes = [];
    plugin.Devices[deviceId] = device;
}

Thank you for the help!

I didn’t have a great way to test this, but the plugin seemed to do the right thing for me (at least I didn’t get the error you’re getting). Maybe this is the issue you’re having:

The only change I made was to replace the socket.send() call with a console.log() call.

Aside from the problem you’re having, I think your plugin likely has a bug. The socket.send() call should probably append a newline to each command:

    socket.send(command + "\n");

I’m guessing the switch’s protocol is expecting that to end the command, although I didn’t specifically look into it. But I have been bitten with that bug myself and I wondered why the device never responded to anything I sent from THR but it worked fine via telnet :slight_smile:

Sorry I couldn’t be more help, but good luck!

I greatly appreciate your reply!

I ran the home remote designer as administrator and I still have the same error. I also added console logging, but nothing comes back as it only reports back “No public methods with the specified arguments were found.”

I added returns after each line (great idea, btw), and that didn’t change anything.

I use putty and connect raw on port 8080. The commands and connection work fine outside of THR. I send commands followed by enter, and it executes. My assumption is it’s something syntax related or I’m missing something fundamental.

Anything else to try? Thank you!

I’m not really sure. Like I said, when I did it, all I replaced was the socket.send() call with a console.log() call and it seemed to work correctly.

The only other thing I can think of is trying to delete and re-add the plugin. Then, after you do that, save, exit the Designer, restart the Designer, and open the saved HRP file. I have noticed that when you install a new plugin, if you don’t save and exit, then the Designer doesn’t fully pick up the new device entries from the plugin. I have also noticed that if you change certain things about the plugin, such as its Settings, if you don’t delete and re-add it, sometimes things don’t get fully set up correctly. Re-running Synchronize Devices might work also, but I’ve found it easier to just delete and re-add.

Thanks for the replies! HFN: I removed, saved, exited, reinstalled, and that got rid of the error! But, I’m still unable to send the commands. According to the console.log, I am passing the right command in the variable command, but it’s not getting to the switch.

I streamlined the code a bit. This is currently what I’m working with:

plugin.Name = "Viki";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 250;
plugin.DefaultSettings = { "Host": "192.168.1.6", "Port": "8080" };

var deviceId = "1";
var socket = new TCPClient();

var commands = {
    "SwitchIn3Out7" : "SW 3 7",
    "SwitchIn4Out7" : "SW 4 7",
}

function onChangeRequest(device, attribute, value) {
    var command = commands[value];
    console.log("sending=> " + command);
    socket.send(command);
}

function onConnect() {
    socket.connect("192.168.1.6", 8080);
}

function onDisconnect() {
    socket.close();
}

function onPoll() {
}

function onSynchronizeDevices() {
    var device = new Device();
    device.Id = deviceId;
    device.DisplayName = "Viki";
    device.Capabilities = ["MediaControl"];
    device.Attributes = [];
    plugin.Devices[deviceId] = device;
}

I’ve also tried sending with and without a carriage return - socket.send(command + “\r”). Doesn’t change anything.

Am I missing something fundamental? I’m super close! Thanks for the help!

I also tried with a new line feed - socket.send(command + “\n”) and that didn’t work either.

In your onChangeRequest(), try:

    socket.send(command + "\r\n");

That did it! Totally works! Thank you very much for your help!

1 Like