C # SerialPort DSR / DTR и подтверждение связи CTS / RTS

Я пытаюсь установить связь с устройством, используя класс SerialPort в C # /. NET.

Документация по взаимодействию с устройством описана здесь.


Документация RS232


Я использую НУЛЕВОЙ модемный кабель, при этом TX / RX и все контакты для квитирования меняются местами (проверено).

Я ожидал, что следующий код C # будет работать, но я не получаю никакого ответа (от низкого к высокому) от камеры, с которой я пытаюсь взаимодействовать. Я уверен, что проблема в коде. Эта камера работает с другими «ПК». Почему я никогда не смогу добиться того, чтобы DsrHolding (нуль-модемный кабель, поэтому DTR от камеры был высоким) стал истинным в моем коде?

static void Main(string[] args)
{
    var serialPort = new SerialPort("COM5");

    // start the DSR/DTR handshake
    // we are using a null modem cable, so DTR/DSR is switched
    serialPort.DtrEnable = true;
    while (!serialPort.DsrHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the DTR line to go high.");
    }


    // start the RTS/CTS handshake
    // we are using a null modem cable, so RTS/CTS is switched
    serialPort.RtsEnable = true;
    while (!serialPort.CtsHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the RTS line to go high.");
    }

    // read/write
    //serialPort.Write("Some command");
    //var response = serialPort.ReadChar();
    //while (response != stopBit)
    //    response = serialPort.ReadChar();

    // close the connection because we have written/read our data

    // start the DSR/DTR handshake
    // we are using a null modem cable, so DTR/DSR is switched
    serialPort.DtrEnable = false;
    while (serialPort.DsrHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the DTR line to go low.");
    }


    // start the RTS/CTS handshake
    // we are using a null modem cable, so RTS/CTS is switched
    serialPort.RtsEnable = false;
    while (serialPort.CtsHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the RTS line to go low.");
    }
}

person Paul Knopf    schedule 26.06.2014    source источник
comment
Почему вы используете нуль-модемный кабель? В документации камеры сказано, что вам следует?   -  person Steve Wellens    schedule 26.06.2014
comment
Так что камера может отправлять данные с помощью TX, а я могу получать их с помощью RX.   -  person Paul Knopf    schedule 26.06.2014
comment
В документации камеры сказано, что вам следует использовать нуль-модемный кабель?   -  person Steve Wellens    schedule 26.06.2014
comment
Не конкретно, нет.   -  person Paul Knopf    schedule 26.06.2014
comment
Вы сказали, что эта камера работает с другими ПК. С кабелем которым пользуетесь?   -  person dbasnett    schedule 26.06.2014


Ответы (2)


Вы пробовали использовать прямой кабель? Камера может уже позаботиться о том, какие контакты нужно скрестить.

person egfconnor    schedule 26.06.2014

В вашем коде отсутствует serialPort.Open();

person Peter    schedule 14.11.2016