Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
We have an NTI video switch (model SM-nCm-15V-LC Veemux series) that we need to control via ethernet. If I connect to it through a telnet session I can send the commands and the switch works just fine. We coded up some ethernet code to send the same commands to the switch and it doesn't work. I contacted NTI who sent me a link to some generic telnet code but that code opens a telnet window which I do not want to do. They say they don't have any sample code to send me.

Has anyone out there done this before? I have attached the code (without any specific telnet code) so maybe I am missing something? I know the port 2005 is right (according to the documentation plus it works in a putty telnet window).

Any assistance is greatly appreciated!

What I have tried:

void CVideoSwitchControl::Initialize()
{
    vidSwitchPort = 2005;

    //Set up networking
	WSADATA wsaData;
	HRESULT hr;
	hr = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (hr != 0)
	{
		//Something went wrong
		AfxMessageBox("Error with setting up networking...");
		exit(0);
	}

	//Create socket
	vidSwitchSock = socket(AF_INET, SOCK_STREAM, 0);
	if (vidSwitchSock == INVALID_SOCKET)
	{
		//Something went wrong
		AfxMessageBox("Error creating socket.");
		WSACleanup();
		exit(0);
	}

	//Setup connection criteria to switch
	vidSwitchAddr.sin_family = AF_INET;
	hr = inet_pton(AF_INET, "192.168.1.30", &vidSwitchAddr.sin_addr);
	if (hr < 0)
	{
		//Something went wrong...
		AfxMessageBox("Failed to resolve IP of switch.");
		exit(0);
	}
	vidSwitchAddr.sin_port = htons(vidSwitchPort);

	//Attempt to establish connection
	hr = connect(vidSwitchSock, (SOCKADDR *)&vidSwitchAddr, sizeof(vidSwitchAddr));
	if (hr == SOCKET_ERROR)
	{
		//Something went wrong...
		AfxMessageBox("Failed to establish connection to switch.");
		WSACleanup();
		exit(0);
	}

	char buff[10];

	//Any response from the switch after connection?
	bytesRecv = recv(vidSwitchSock, (char*)&buff, sizeof(buff), 0);
	if (bytesRecv == SOCKET_ERROR || bytesRecv== 0)
	{
		//Something went wrong...
		AfxMessageBox("Switch not responding.");
		WSACleanup();
		exit(0);
	}

	//What did we get back?
	

	//if we got response, we're in and the switch in ready for control
	return;
}
void CVideoSwitchControl::SetVideoSwitch(int channel, OutputMonitor monitor)
{
	//did we receive valid channel and monitor values?
	if (channel >= MaxInputs)
	{
		//Invalid input channel
		AfxMessageBox("Invalid input selected for video switch.");
		exit(0);
	}
	if (monitor >= MaxMonitors)
	{
		//Invalid monitor selected for output
		AfxMessageBox("Invalid output monitor selected for video switch.");
		exit(0);
	}

	//Pack up CS message bytes 5 and 8
	CSMessage[4] = (char)inputMap[channel - 1];
	CSMessage[7] = (char)outputMap[monitor - 1];

	//Send CS message to video switch
	bytesSent = send(vidSwitchSock, (char*)&CSMessage, sizeof(CSMessage), 0);
	if (bytesSent == SOCKET_ERROR || bytesSent == 0)
	{
		//Video switch not responding
		AfxMessageBox("Video switch not responding.");
		WSACleanup();
		return;
	}

	//Maybe check for what the switch responds?...
	return;
}
Posted
Comments
[no name] 13-Mar-19 10:31am    
Connecting in the first place is supposed to be the hard part. I think this stuff is easier in C# and .NET from the looks of it.
Rick York 13-Mar-19 10:56am    
My advice is to fire up Wireshark and monitor the traffic on the connection with a telnet window so you can see exactly what packets are transmitted. It has a built-in filter for telnet packets so it should be fairly simple to see what you need to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900