C# SerialPort-DSR/DTR und CTS/RTS-handshaking

Ich versuche zu kommunizieren mit einem Gerät mit C#/.NET SerialPort Klasse.

In der Dokumentation für die Interaktion mit dem Gerät ist hier beschrieben.


C# SerialPort-DSR/DTR und CTS/RTS-handshaking


Bin ich mit einem NULL-modem-Kabel mit dem TX/RX-und alle die handshake-pins vertauscht (verifiziert).

Ich würde erwarten, dass die folgenden C# - code zu arbeiten, aber ich bekomme keine Antwort zurück (niedrig bis hoch) aus der Kamera, ich bin versucht zu interagieren. Ich bin sicher, dass das problem mit der code aber. Diese Kamera arbeitet mit anderen "PCs". Warum würde ich nie DsrHolding (null-modem-Kabel, also DTR high von der Kamera) zu wahren in meinen code?

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.");
    }
}
Warum verwenden Sie ein null-modem-Kabel? Macht in der Dokumentation zur Kamera sagen Sie soll?
So kann man die Kamera senden von Daten über TX und erhalte ich kann es mit dem RX.
Macht in der Dokumentation zur Kamera sagen, Sie sollten verwenden Sie ein null-modem-Kabel?
Nicht speziell, Nein.
Sie sagte, "Diese Kamera arbeitet mit anderen "PCs". Mit dem Kabel verwendest du?

InformationsquelleAutor Paul Knopf | 2014-06-26

Schreibe einen Kommentar