视频交换机的以太网/远程控制示例代码

时间:2019-03-27 11:48:24

标签: c++ telnet

我们有一个NTI视频开关(型号SM-nCm-15V-LC Veemux系列),需要通过以太网进行控制。如果我通过telnet会话连接到该服务器,则可以发送命令,并且该开关可以正常工作。我们对一些以太网代码进行了编码,以将相同的命令发送到交换机,但它不起作用。我联系了NTI,后者向我发送了一些通用telnet代码的链接,但是该代码打开了我不想执行的telnet窗口。他们说没有可发送给我的示例代码。

有人在那里做过吗?我已经附上了代码(没有任何特定的telnet代码),所以也许我遗漏了一些东西?我知道端口2005是正确的(根据文档,它可以在腻子telnet窗口中使用)。

非常感谢您的协助!

我尝试将套接字连接类型从0更改为TCP(6),并且没有任何区别,并且尝试在消息中的/ r之后添加/ n,但这也不起作用

char CSMessage[9] = { 'C','S',' ', (char)0x30, (char)0x00,',', (char)0x30, (char)0x00, '\r' };

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;
}

现在,交换机不响应。如果我打开telnet窗口并手动发送有效的命令,则说明代码方面出了问题。

0 个答案:

没有答案