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;
WSADATA wsaData;
HRESULT hr;
hr = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (hr != 0)
{
AfxMessageBox("Error with setting up networking...");
exit(0);
}
vidSwitchSock = socket(AF_INET, SOCK_STREAM, 0);
if (vidSwitchSock == INVALID_SOCKET)
{
AfxMessageBox("Error creating socket.");
WSACleanup();
exit(0);
}
vidSwitchAddr.sin_family = AF_INET;
hr = inet_pton(AF_INET, "192.168.1.30", &vidSwitchAddr.sin_addr);
if (hr < 0)
{
AfxMessageBox("Failed to resolve IP of switch.");
exit(0);
}
vidSwitchAddr.sin_port = htons(vidSwitchPort);
hr = connect(vidSwitchSock, (SOCKADDR *)&vidSwitchAddr, sizeof(vidSwitchAddr));
if (hr == SOCKET_ERROR)
{
AfxMessageBox("Failed to establish connection to switch.");
WSACleanup();
exit(0);
}
char buff[10];
bytesRecv = recv(vidSwitchSock, (char*)&buff, sizeof(buff), 0);
if (bytesRecv == SOCKET_ERROR || bytesRecv== 0)
{
AfxMessageBox("Switch not responding.");
WSACleanup();
exit(0);
}
return;
}
void CVideoSwitchControl::SetVideoSwitch(int channel, OutputMonitor monitor)
{
if (channel >= MaxInputs)
{
AfxMessageBox("Invalid input selected for video switch.");
exit(0);
}
if (monitor >= MaxMonitors)
{
AfxMessageBox("Invalid output monitor selected for video switch.");
exit(0);
}
CSMessage[4] = (char)inputMap[channel - 1];
CSMessage[7] = (char)outputMap[monitor - 1];
bytesSent = send(vidSwitchSock, (char*)&CSMessage, sizeof(CSMessage), 0);
if (bytesSent == SOCKET_ERROR || bytesSent == 0)
{
AfxMessageBox("Video switch not responding.");
WSACleanup();
return;
}
return;
}