interfacing multiview 16 with c#

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Ali123

  • Posts: 2
  • Joined: Mon Oct 14, 2019 9:30 am
  • Real Name: Shehryar Ali

interfacing multiview 16 with c#

PostMon Oct 14, 2019 9:45 am

Hello, how do I change the channels using c# and what commands options are available, please provide the code if possible
Offline

Ian Morrish

  • Posts: 390
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: interfacing multiview 16 with c#

PostMon Oct 14, 2019 11:14 pm

It uses the same api as the VideoHub.
Easier to just use the Videohub tcp text based protocol to set labels and map inputs to window position.

Sent from my SM-G960F using Tapatalk
Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

Ali123

  • Posts: 2
  • Joined: Mon Oct 14, 2019 9:30 am
  • Real Name: Shehryar Ali

Re: interfacing multiview 16 with c#

PostSat Oct 19, 2019 4:43 pm

This is what I am using, it sends the preamble(Version) but I am unable to send any commands, it does not respond:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;


namespace Client01
{
class Program
{
static void Main(string[] args)
{

int port = 9990;
string IpAddress = "192.168.50.150";
Socket ClientSocket= new Socket(AddressFamily
.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ep= new IPEndPoint(IPAddress.Parse(IpAddress), port);
ClientSocket.Connect(ep);
Console.WriteLine("connected!");
while(true)
{

string messageFromClient= null;
Console.WriteLine("Enter the message");
messageFromClient= Console.ReadLine();
ClientSocket.Send(System.Text.Encoding.ASCII.GetBytes(messageFromClient),0,messageFromClient.Length,SocketFlags.None);

byte[] MsgFromServer= new byte[1024];
int size=ClientSocket.Receive(MsgFromServer);
Console.WriteLine("Server "+System.Text.Encoding.ASCII.GetString(MsgFromServer,0,size));
}
}
}
}
Offline

Brendan Dower

Blackmagic Design

  • Posts: 11
  • Joined: Thu Oct 10, 2019 5:56 am
  • Real Name: Brendan Dower

Re: interfacing multiview 16 with c#

PostTue Oct 22, 2019 11:18 pm

Shehryar Ali,

Thanks for providing your code. It's necessary to consume the preamble before you start sending commands to the device. I have re-written your code for you so that it consumes this preamble.

Also, it's highly recommended to use the "try", "catch" blocks when working with sockets to ensure that Exceptions are handled correctly. I have separated the program into 2 classes, a 'TCPConnection' class to handle the telnet connection and the Program class.

I have included the code below. It is commented throughout for your convenience.
It has been tested with the Smart Videohub 12G using Visual Studio Code.

All the best,

Brendan
Blackmagic Design Developer Support

Code: Select all
using System;
using System.Text;
using System.Net.Sockets;
using System.Net;


namespace Client01
{

    //Separates the Socket functions into class/object
    class TCPConnection
    {

        //Connect the Socket to use TCP/IP commands - returns the true or false
        public bool Connect(string IpAddress, int port)
        {
            ClientSocket.ReceiveTimeout = 5000;

            try
            {
                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(IpAddress), port);
                ClientSocket.Connect(ep);
                Console.WriteLine("connected!");
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Connecting to Socket: " + e);
                return false;
            }
        }

        //Send any Command to the Device. Returns true or false
        public bool send(string messageFromClient)
        {
            try
            {
                ClientSocket.Send(Encoding.ASCII.GetBytes(messageFromClient),
                            0, messageFromClient.Length, SocketFlags.None);
                ClientSocket.Send(Encoding.ASCII.GetBytes("\n\n"));
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error sending command on Socket:\n" + e);
                return false;
            }
        }

        //Receive bytes until a terminating string (such as "\n\n").
        //Returns the string or "ERROR"
        public string receiveUntil(string terminator)
        {
            string response = null;
            Byte[] buffer = new byte[terminator.Length - 1];

            while (true)
            {
                Array.Clear(buffer, 0, buffer.Length);
                try
                {
                    ClientSocket.Receive(buffer);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error receiving data from socket:\n" + e);
                    response = "ERROR";
                    break;
                }
                response += Encoding.ASCII.GetString(buffer);
                if (response.Contains(terminator))
                    break;
            }

            return response.TrimEnd('\n','\0');
        }

        //New socket Object
        public Socket ClientSocket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);

    }

    class Program
    {

        //Get the Preamble from the Device - Returns the preamble or "ERROR"
        static string getPreamble(TCPConnection telnet)
        {
            string preamble = telnet.receiveUntil("END PRELUDE:\n\n");
            return preamble;
        }

        //Get the response from your command - Returns the response or "ERROR"
        static string getResponse(TCPConnection telnet)
        {
            string response = telnet.receiveUntil("\n\n");
            return response;
        }

        //Main function - Entry Point to program
        static void Main(string[] args)
        {
            //Create a new Telnet Object
            var telnet = new TCPConnection();

            if (telnet.Connect("192.168.23.125", 9990))
            {
                //Get and print the preamble which is sent on successful connection
                string preamble = getPreamble(telnet);
                Console.WriteLine(preamble + '\n');

                while (true)
                {
                    //User input to send to the device
                    Console.WriteLine("Enter the command");
                    telnet.send(Console.ReadLine());           

                    //Get the ACK or NAK response
                    string ack = getResponse(telnet);
                    Console.WriteLine("Server " + ack + '\n');

                    //If ACK then get the Response from the command
                    if (ack.Contains("ACK"))
                    {
                        string response = getResponse(telnet);
                        Console.WriteLine(response + '\n');
                    }
                }
            }
        }
    }
}
Brendan Dower
Blackmagic Design Developer Support

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests