Time Required: 30 Minutes
Prerequisite: Please complete the Simple 2x2 Matrix control tutorial (which can be found here)
By the End of this tutorial you will:
1) Be able to identify functions that are available as part of modules.
2) Be able to execute a Serial command to an external device.
3) Be able to execute an IR command stored on a device.
4) Be able to send TCP and UDP commands to devices.
You Will Need:
Serial Controlled Device with appropriate cabling.
IR Controlled Device, and an IR Bug wired appropriately.
Host PC running Google Chrome.
Terminal Program that can act as a TCP/UDP server. A good free one is Packet Sender
1) Create a New Panel (Full Editor) in Panel Builder.
2) Access the setup script and add an SVSI N_Series Require.
3) Define the IP address of a Decoder, and an Encoder with friendly names.
4) After defining the N_Series device IP's, add another line that reads "myPc = "169.254.10.90"; Change the IP address to that of your Host PC you are working with.
//WHAT IS BEING CONTROLLED
//WHERE IS IT:
display = N_Series("169.254.34.55"); //This is a decoder
mediaPlayer = N_Series("169.254.114.220"); //This is an Encoder
//IP ADDRESS FOR UDP/TCP CLIENT
myPC = "169.254.10.90"; //HOST PC IP ADDRESS
5) Save the script and return to the main Panel Builder screen.
IDENTIFYING AVAILABLE FUNCTIONS:
Sending IR and Serial commands are pre-built functions contained within the module for SVSi devices. In addition to these functions, there are many others (including switching streams, enable/disable DVI ports, etc.) A list of available functions is included as part of the help file for any module, and can be accessed easily for reference. Third party modules (if properly written) should also contain help files for easy reference.
1) Add a button to the Panel, highlight it and access the scripting window.
2) in the bottom left, click HELP > Module Help.
3) this will open a new tab and let you view any of the loaded Modules. Select the SVSi > N_Series Module from the drop down.
4) The top section of the module will contain the help file. In it, you can see the functions, and the required parameters (like the below switch command)
This will tell you the function to use (the part that follows the period in display.<Function>, and any parameters it may require (like Stream Number for a switch command).
5) When done with the help file, close the tab, and return to Panel Builder. You may not close the code window, and delete the button.
SERIAL COMMANDS VIA AN ENCODER/DECODER
1) Add two buttons to the Panel, Position them. Add the text "ON" to one of them and "Off" to the other. In the button editor , assign the buttons to Hard Keys.
2) Click the "ON" button, and access the script editor. In the State 1 script, enter: display.serialHex(asciiToHex("ka 0 01") + " 0d");
WHAT IS THIS CODE DOING?
In the above code sample, two separate FUNCTIONs are in use. The first is the serialHex function that has been written as part of the N_Series require/module. This will pass the value contained between the () to the decoders serial port (to be sent to the display). This function requires the command to be converted into HEX bytes before sending the command.
The second function in the code is the asciiToHex function. This function is converting the ASCII string ("ka 0 01") into hex characters. After the conversion the " 0d" is added, as that byte is already in hex (and is used by the display as the end of line/command delimiter). Combining these two functions allows the string to be sent out in hex and ready for the display to accept. The two methods are interchangeable as shown below:
display.serialHex(asciiToHex("ka 0 01") + " 0d"); // Is the same thing as the below code
display.serialHex("6b 61 20 30 20 30 31 0d"); //Is the same thing as the above code
NOTE: This command is specific to LG Displays, For your panel, substitute the appropriate command string from the manufacturer of the display being controlled.
3) Save the script "On" button script, and repeat the process for the "Off" Button, but change the command to the off command for your device: display.serialHex(asciiToHex("ka 0 00") + " 0d");
4) Save the project, and send to the touch panel (or view it in the browser). if the Serial commands are correct, then your display should turn off and on!.
DEBUGGING USING CONSOLE
One of the benefits of being a browser based control system, is that modern day browser have tools pre-built in to anaylze the code running in the browser. This feature is the console. With Google Chrome and Mozilla Firefox, you can access the console by hitting the F12 key on your keyboard.
To see exactly what is being sent out to the decoder do the following:
1) Preview the panel. Hit F12 while viewing the panel to see the console.
2) Click the On or Off key, and in the console something similar to the below example should appear (you can click the icon in the console to clear the existing message queue before clicking the button - NOTE: This is the Chrome Icon, it may differ based on browser used.
the "send>" line is showing the browser sent the command. The command itself is a tcpclient and consists of tcpclient <ip address> <port> <command>. Serial commands are directed to port 50004 on the SVSi device. You will notice the command is in hex. To convert to ASCII, copy the command, and then in N-Able, open tools > Serial Commands, and paste the code into the Hex line. This will then translate the bytes into ASCII for you to compare with the original command.
One additional thing you can do with Console is to use the console.log() function built into browsers to add messages to the console (useful for debugging). To do this, add the following line to your ON button and then click the button while viewing the console.
console.log("PRESSED THE ON BUTTON!");
NOTE: There is an alternative method of sending Serial commands to the SVSi Encoders/Decoders. Similar to the IR process documented below, you can save serial commands to the unit and execute with serial("COMMANDNAME");
INFRARED (IR) COMMANDS VIA AN ENCODER/DECODER
1) IR Commands are sent by recalling a command stored on an Encoder or Decoder. For instructions on this process, please view this help document.
2) When saving commands on the device, please note that names are cASe sensitive, and space specific. The recommendation is to save the commands in the same format at all times, with no spaces. (IE - play, pause, stop, fastForward) When your relevant commands have been saved, return to Panel Builder.
3) Add two more buttons, and add appropriate text for Two different IR commands (like, Power and Home), style the buttons as needed and assign to hard keys.
4) Add the following to the button state 1 script - mediaPlayer.sendIR("power"); //Change power to the name you saved the command
5) Save the script, and repeat for the other button, but change "power" to "home" or your second command name.
6) Preview the project (or send to the N-Touch) and click one of the buttons.
7) If you have a device attached via IR AND the command is correct, you should see the appropriate action occur (The unit powers off/on or returns to home). If you have an IR bug with a visible LED, you should see it blink.
DEBUGGING USING DEVICE LOGS
IR commands, along with most other commands (like switching streams) are tracked in the SVSI device log contained on each encoder and decoder. This log is useful for troubleshooting (especially for IR commands) as it will keep track of the last 200 commands. One item not traced in the Log - Serial Commands (as they are not processed by the device, simply passed through the port). In this case, if you don' t have an actual IR device, or Bug to test with, you can:
1) load any IR Command into the IR library, then execute the command from the touch panel. After executing the command, log into the SVSi device and view the log. If the device received the command to execute the IR command, it will show here (as shown below):
There are several key pieces of information included in the log, including: The IP Address the command was generated from, The port the command was received on, The method (TCP/UDP) and the command received. By showing here in the log, we can determine that the device did receive the command to execute the IR command. If the source didn't respond to the command, then it can easily be determined that: 1) there may be a problem with the command. SVSi does require the long-form pronto hex code 2) there may be a problem with the wiring or position of the IR bug.
The Following examples use Packet Sender as the TCP and UDP server to receive the network commands. You can use any terminal program that supports this functionality but may need to change the port number to match your software.
1) On Panel Builders main screen, add two more buttons and add the text "TCP" to one, and "UDP" to the other. Assign the buttons to hard keys.
2) Access the script editor on the TCP button, and from the drop down, add a TCP client. This will add the tcp client to your code window:
//sends message/data to a device
tcpclient('192.168.1.12', 50002, asciiToHex('message/data'));
3) Modify the tcpclient. In place of the IP address, change it to myPC (defined in the setup script). Change the port (50002) to port 2101, and in the section for message/data, change the text to 'TCP Command". You code should now read:
//sends message/data to a device
tcpclient(myPC, 2101, asciiToHex('TCP Command'));
4) Save the script, and access the script editor for the "UDP" button.
5) Add a UDP client from the Dropdown, and modify it. In place of the IP address, change it to myPC (defined in the setup script). Change the port (50002) to port 55056, and in the section for message/data, change the text to 'UDP Command". You code should now read:
//sends message/data to a device
udpclient(myPC, 55056, asciiToHex('UDP Command'));
6) Save the script, and the project. Send the project to N-Touch, or view in the browser.
7) Open Packet Sender. In the Settings tab, verify that the "Enable UDP Server" and "Enable TCP Server" are checked, and the port numbers are set to 55056 and 2101.
8) Next, view the traffic log of Packet Sender. From the N-Touch or your browser, click the TCP button, then the UDP button. You should see the packets appear in the traffic log of Packet Sender.