Announcement

Collapse
No announcement yet.

Seriele Komunikation

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Seriele Komunikation

    Hallo,

    kann mir jemand erklären, wie ich die serielle Komunikation bewerksteligen sol? Das Problem: Von einer MAschine bekome ich über Statuswerte über die Leitung RX mit der Leitung TX stele ich die Maschine ein. Ich schafe es einfach nicht, es in C# zu realisieren. Wie gesagt, ich brauche nur die Leitung RX, TX und GND.

    Danke für eure Hilfe
    Ronny

  • #2
    Hallo,

    im .NET Framework gibt es keine Unterstützung für die "veralteten" COM-/LPT-Ports. Somit muss man in C# auf Alternativen wie P/Invoke ausweichen. Microsoft hat dazu im <i>MSDN Magazine</i> ein Artikel veröffentlicht: <i>http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/</i>

    Wem das zu umständlich ist, kann entsprechende Klassen nachkaufen: <i>http://www.sax.net/dotnet/communications/</i&gt

    Comment


    • #3
      Hallo,

      ich schlage mich immer noch mit der seriellen Kommunikation herum. Ich habe
      mir die Klasse CommBase von MSDN heruntergeladen und schaffe es immer noch
      nicht mit der Maschine Kontakt aufzunehmen. Über das Windows Terminal
      (2000er Version) funktioniert das ganze.

      Ich brauche wie gesagt, eine simple TX, RX (alle anderen PINS sind nicht
      belegt) Kommunikation. Muß ich eventuell in den Variablen etwas ändern?

      //Port Name (default: "COM1:")

      public string port = "COM2:";

      // Baud Rate (default: 2400) unsupported rates will throw "Bad settings"

      public int baudRate = 4800;

      // The parity checking scheme (default: none)

      public Parity parity = Parity.none;

      // Number of databits 1..8 (default: 8) unsupported values will throw "Bad
      settings"

      public int dataBits = 8;

      // Number of stop bits (default: one)

      public StopBits stopBits = StopBits.one;

      // If true, transmission is halted unless CTS is asserted by the remote
      station (default: false)

      public bool txFlowCTS = false;

      // If true, transmission is halted unless DSR is asserted by the remote
      station (default: false)

      public bool txFlowDSR = false;

      // If true, transmission is halted when Xoff is received and restarted when
      Xon is received (default: false)

      public bool txFlowX = false;

      // If false, transmission is suspended when this station has sent Xoff to
      the remote station (default: true)
      // Set false if the remote station treats any character as an Xon.

      public bool txWhenRxXoff = true;

      // If true, received characters are ignored unless DSR is asserted by the
      remote station (default: false)

      public bool rxGateDSR = false;

      // If true, Xon and Xoff characters are sent to control the data flow from
      the remote station (default: false)

      public bool rxFlowX = false;

      // Specifies the use to which the RTS output is put (default: none)

      public HSOutput useRTS = HSOutput.none;

      // Specidies the use to which the DTR output is put (default: none)

      public HSOutput useDTR = HSOutput.none;

      // The character used to signal Xon for X flow control (default: DC1)

      public ASCII XonChar = ASCII.DC1;

      // The character used to signal Xoff for X flow control (default: DC3)

      public ASCII XoffChar = ASCII.DC3;

      // The number of free bytes in the reception queue at which flow is disabled
      (Default: 0 = Set to 1/10th of actual rxQueue size)

      public int rxHighWater = 0;

      // The number of bytes in the reception queue at which flow is re-enabled
      (Default: 0 = Set to 1/10th of actual rxQueue size)

      public int rxLowWater = 0;

      // Multiplier. Max time for Send in ms = (Multiplier * Characters) +
      Constant
      (default: 0 = No timeout)

      public uint sendTimeoutMultiplier = 0;

      // Constant. Max time for Send in ms = (Multiplier * Characters) + Constant
      (default: 0)

      public uint sendTimeoutConstant = 5000;

      /// Requested size for receive queue (default: 0 = use operating system
      default)

      public int rxQueue = 0;

      /// Requested size for transmit queue (default: 0 = use operating system
      default)

      public int txQueue = 0;

      /// If true, the port will automatically re-open on next send if it was
      previously closed due
      // to an error (default: false)

      public bool autoReopen = true;

      // If true, subsequent Send commands wait for completion of earlier ones
      enabling the results
      // to be checked. If false, errors, including timeouts, may not be detected,
      but performance
      // may be better.

      public bool checkAllSends = true;

      Wenn Ihr mir helfen könntet wäre ich euch sehr verbunden.

      Danke Ronn

      Comment


      • #4
        Hallo Ronny

        Ich schlage mich im Moment ebenfalls mit den Seriellen-Schnittstellen für .Net mit C# herum. Es ist doch jedesmal das gleiche Theater, wenn man eine neue Entwicklungsumgebung einsetzt. Schnittstellen werden immer als Stiefkind behandelt. Wir entwickeln vorwiegen techn. Software. Aufgrund dieser Tatsache möchte ich interessenshalber ebenfalls als Vorabstudie mit den RS-232 Schnittstellen beschäftigen.

        Meine Frage lautet:
        Konntest Du Dein Problem lösen? Wenn ja, dürfte ich nähere Anhaben hierzu erhalten?

        Mit freundlichen Grüssen
        R. Ramuz, Schwei

        Comment


        • #5
          Hallo!
          Wird das ActiveX-Steuerelement MSCOMM32.OCX eigentlich noch mit Windows mitgeliefert ?
          War bei Windows 98 unter \Windows\System zu finden.

          Damit ließ sich immer recht einfach auf die serielle Schnittstelle zugreifen.

          Ka

          Comment


          • #6
            Hallo,
            also von dem MSCOMM32.OCX kann ich unter C# nur abraten, es ist einfach zu unkompliziert und unflexibel. Einfacher geht es mit dem NetSerialComm von Microsoft.

            Beispiel:
            <PRE>
            public class Uart:CommBase
            {
            private CommBaseSettings Settings;
            protected override CommBaseSettings CommSettings()
            {
            // nur RX und TX
            Settings.SetStandard("COM1:", 38400, Handshake.none);
            return Settings;
            }

            protected override bool AfterOpen()
            {
            // hier irgendwelche ersten Kommandos, Break,...
            return true;
            }
            }
            </PRE>

            Noch die entsprechenden virtuellen Funktionen für Byte empfangen ueberschreiben und fertig. Mit Uart.Send() einfach was senden und im ueberschriebenen OnRxChar() die Daten entgegennehmen. Ach ja, die Referenz auf die Commbase.dll nicht vergessen.

            Gruss
            Fran

            Comment

            Working...
            X