SerialPort Klasa

Definicja

Reprezentuje zasób portu szeregowego.

public ref class SerialPort : System::ComponentModel::Component
public class SerialPort : System.ComponentModel.Component
type SerialPort = class
    inherit Component
Public Class SerialPort
Inherits Component
Dziedziczenie

Przykłady

W poniższym przykładzie kodu pokazano użycie SerialPort klasy , aby umożliwić dwóm użytkownikom czat z dwóch oddzielnych komputerów połączonych za pomocą kabla modemu o wartości null. W tym przykładzie użytkownicy są monitowani, aby ustawić port i nazwę użytkownika przed rozpoczęciem rozmowy. Oba komputery muszą wykonać program w celu osiągnięcia pełnej funkcjonalności tego przykładu.

#using <System.dll>

using namespace System;
using namespace System::IO::Ports;
using namespace System::Threading;

public ref class PortChat
{
private:
    static bool _continue;
    static SerialPort^ _serialPort;

public:
    static void Main()
    {
        String^ name;
        String^ message;
        StringComparer^ stringComparer = StringComparer::OrdinalIgnoreCase;
        Thread^ readThread = gcnew Thread(gcnew ThreadStart(PortChat::Read));

        // Create a new SerialPort object with default settings.
        _serialPort = gcnew SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort->PortName = SetPortName(_serialPort->PortName);
        _serialPort->BaudRate = SetPortBaudRate(_serialPort->BaudRate);
        _serialPort->Parity = SetPortParity(_serialPort->Parity);
        _serialPort->DataBits = SetPortDataBits(_serialPort->DataBits);
        _serialPort->StopBits = SetPortStopBits(_serialPort->StopBits);
        _serialPort->Handshake = SetPortHandshake(_serialPort->Handshake);

        // Set the read/write timeouts
        _serialPort->ReadTimeout = 500;
        _serialPort->WriteTimeout = 500;

        _serialPort->Open();
        _continue = true;
        readThread->Start();

        Console::Write("Name: ");
        name = Console::ReadLine();

        Console::WriteLine("Type QUIT to exit");

        while (_continue)
        {
            message = Console::ReadLine();

            if (stringComparer->Equals("quit", message))
            {
                _continue = false;
            }
            else
            {
                _serialPort->WriteLine(
                    String::Format("<{0}>: {1}", name, message) );
            }
        }

        readThread->Join();
        _serialPort->Close();
    }

    static void Read()
    {
        while (_continue)
        {
            try
            {
                String^ message = _serialPort->ReadLine();
                Console::WriteLine(message);
            }
            catch (TimeoutException ^) { }
        }
    }

    static String^ SetPortName(String^ defaultPortName)
    {
        String^ portName;

        Console::WriteLine("Available Ports:");
        for each (String^ s in SerialPort::GetPortNames())
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Enter COM port value (Default: {0}): ", defaultPortName);
        portName = Console::ReadLine();

        if (portName == "")
        {
            portName = defaultPortName;
        }
        return portName;
    }

    static Int32 SetPortBaudRate(Int32 defaultPortBaudRate)
    {
        String^ baudRate;

        Console::Write("Baud Rate(default:{0}): ", defaultPortBaudRate);
        baudRate = Console::ReadLine();

        if (baudRate == "")
        {
            baudRate = defaultPortBaudRate.ToString();
        }

        return Int32::Parse(baudRate);
    }

    static Parity SetPortParity(Parity defaultPortParity)
    {
        String^ parity;

        Console::WriteLine("Available Parity options:");
        for each (String^ s in Enum::GetNames(Parity::typeid))
        {
            Console::WriteLine("   {0}", s);
        }
        
        Console::Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString());
        parity = Console::ReadLine();

        if (parity == "")
        {
            parity = defaultPortParity.ToString();
        }

        return (Parity)Enum::Parse(Parity::typeid, parity);
    }

    static Int32 SetPortDataBits(Int32 defaultPortDataBits)
    {
        String^ dataBits;

        Console::Write("Enter DataBits value (Default: {0}): ", defaultPortDataBits);
        dataBits = Console::ReadLine();

        if (dataBits == "")
        {
            dataBits = defaultPortDataBits.ToString();
        }

        return Int32::Parse(dataBits);
    }

    static StopBits SetPortStopBits(StopBits defaultPortStopBits)
    {
        String^ stopBits;

        Console::WriteLine("Available Stop Bits options:");
        for each (String^ s in Enum::GetNames(StopBits::typeid))
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Enter StopBits value (None is not supported and \n" +
            "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString());
        stopBits = Console::ReadLine();

        if (stopBits == "")
        {
            stopBits = defaultPortStopBits.ToString();
        }

        return (StopBits)Enum::Parse(StopBits::typeid, stopBits);
    }

    static Handshake SetPortHandshake(Handshake defaultPortHandshake)
    {
        String^ handshake;

        Console::WriteLine("Available Handshake options:");
        for each (String^ s in Enum::GetNames(Handshake::typeid))
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Enter Handshake value (Default: {0}):", defaultPortHandshake.ToString());
        handshake = Console::ReadLine();

        if (handshake == "")
        {
            handshake = defaultPortHandshake.ToString();
        }

        return (Handshake)Enum::Parse(Handshake::typeid, handshake);
    }
};

int main()
{
    PortChat::Main();
}
// Use this code inside a project created with the Visual C# > Windows Desktop > Console Application template.
// Replace the code in Program.cs with this code.

using System;
using System.IO.Ports;
using System.Threading;

public class PortChat
{
    static bool _continue;
    static SerialPort _serialPort;

    public static void Main()
    {
        string name;
        string message;
        StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
        Thread readThread = new Thread(Read);

        // Create a new SerialPort object with default settings.
        _serialPort = new SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort.PortName = SetPortName(_serialPort.PortName);
        _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
        _serialPort.Parity = SetPortParity(_serialPort.Parity);
        _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
        _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
        _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);

        // Set the read/write timeouts
        _serialPort.ReadTimeout = 500;
        _serialPort.WriteTimeout = 500;

        _serialPort.Open();
        _continue = true;
        readThread.Start();

        Console.Write("Name: ");
        name = Console.ReadLine();

        Console.WriteLine("Type QUIT to exit");

        while (_continue)
        {
            message = Console.ReadLine();

            if (stringComparer.Equals("quit", message))
            {
                _continue = false;
            }
            else
            {
                _serialPort.WriteLine(
                    String.Format("<{0}>: {1}", name, message));
            }
        }

        readThread.Join();
        _serialPort.Close();
    }

    public static void Read()
    {
        while (_continue)
        {
            try
            {
                string message = _serialPort.ReadLine();
                Console.WriteLine(message);
            }
            catch (TimeoutException) { }
        }
    }

    // Display Port values and prompt user to enter a port.
    public static string SetPortName(string defaultPortName)
    {
        string portName;

        Console.WriteLine("Available Ports:");
        foreach (string s in SerialPort.GetPortNames())
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Enter COM port value (Default: {0}): ", defaultPortName);
        portName = Console.ReadLine();

        if (portName == "" || !(portName.ToLower()).StartsWith("com"))
        {
            portName = defaultPortName;
        }
        return portName;
    }
    // Display BaudRate values and prompt user to enter a value.
    public static int SetPortBaudRate(int defaultPortBaudRate)
    {
        string baudRate;

        Console.Write("Baud Rate(default:{0}): ", defaultPortBaudRate);
        baudRate = Console.ReadLine();

        if (baudRate == "")
        {
            baudRate = defaultPortBaudRate.ToString();
        }

        return int.Parse(baudRate);
    }

    // Display PortParity values and prompt user to enter a value.
    public static Parity SetPortParity(Parity defaultPortParity)
    {
        string parity;

        Console.WriteLine("Available Parity options:");
        foreach (string s in Enum.GetNames(typeof(Parity)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), true);
        parity = Console.ReadLine();

        if (parity == "")
        {
            parity = defaultPortParity.ToString();
        }

        return (Parity)Enum.Parse(typeof(Parity), parity, true);
    }
    // Display DataBits values and prompt user to enter a value.
    public static int SetPortDataBits(int defaultPortDataBits)
    {
        string dataBits;

        Console.Write("Enter DataBits value (Default: {0}): ", defaultPortDataBits);
        dataBits = Console.ReadLine();

        if (dataBits == "")
        {
            dataBits = defaultPortDataBits.ToString();
        }

        return int.Parse(dataBits.ToUpperInvariant());
    }

    // Display StopBits values and prompt user to enter a value.
    public static StopBits SetPortStopBits(StopBits defaultPortStopBits)
    {
        string stopBits;

        Console.WriteLine("Available StopBits options:");
        foreach (string s in Enum.GetNames(typeof(StopBits)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Enter StopBits value (None is not supported and \n" +
         "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString());
        stopBits = Console.ReadLine();

        if (stopBits == "" )
        {
            stopBits = defaultPortStopBits.ToString();
        }

        return (StopBits)Enum.Parse(typeof(StopBits), stopBits, true);
    }
    public static Handshake SetPortHandshake(Handshake defaultPortHandshake)
    {
        string handshake;

        Console.WriteLine("Available Handshake options:");
        foreach (string s in Enum.GetNames(typeof(Handshake)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Enter Handshake value (Default: {0}):", defaultPortHandshake.ToString());
        handshake = Console.ReadLine();

        if (handshake == "")
        {
            handshake = defaultPortHandshake.ToString();
        }

        return (Handshake)Enum.Parse(typeof(Handshake), handshake, true);
    }
}
' Use this code inside a project created with the Visual Basic > Windows Desktop > Console Application template.
' Replace the default code in Module1.vb with this code. Then right click the project in Solution Explorer,
' select Properties, and set the Startup Object to PortChat.

Imports System.IO.Ports
Imports System.Threading

Public Class PortChat
    Shared _continue As Boolean
    Shared _serialPort As SerialPort

    Public Shared Sub Main()
        Dim name As String
        Dim message As String
        Dim stringComparer__1 As StringComparer = StringComparer.OrdinalIgnoreCase
        Dim readThread As New Thread(AddressOf Read)

        ' Create a new SerialPort object with default settings.
        _serialPort = New SerialPort()

        ' Allow the user to set the appropriate properties.
        _serialPort.PortName = SetPortName(_serialPort.PortName)
        _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate)
        _serialPort.Parity = SetPortParity(_serialPort.Parity)
        _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits)
        _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits)
        _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake)

        ' Set the read/write timeouts
        _serialPort.ReadTimeout = 500
        _serialPort.WriteTimeout = 500

        _serialPort.Open()
        _continue = True
        readThread.Start()

        Console.Write("Name: ")
        name = Console.ReadLine()

        Console.WriteLine("Type QUIT to exit")

        While _continue
            message = Console.ReadLine()

            If stringComparer__1.Equals("quit", message) Then
                _continue = False
            Else
                _serialPort.WriteLine([String].Format("<{0}>: {1}", name, message))
            End If
        End While

        readThread.Join()
        _serialPort.Close()
    End Sub

    Public Shared Sub Read()
        While _continue
            Try
                Dim message As String = _serialPort.ReadLine()
                Console.WriteLine(message)
            Catch generatedExceptionName As TimeoutException
            End Try
        End While
    End Sub

    ' Display Port values and prompt user to enter a port.
    Public Shared Function SetPortName(defaultPortName As String) As String
        Dim portName As String

        Console.WriteLine("Available Ports:")
        For Each s As String In SerialPort.GetPortNames()
            Console.WriteLine("   {0}", s)
        Next

        Console.Write("Enter COM port value (Default: {0}): ", defaultPortName)
        portName = Console.ReadLine()

        If portName = "" OrElse Not (portName.ToLower()).StartsWith("com") Then
            portName = defaultPortName
        End If
        Return portName
    End Function
    ' Display BaudRate values and prompt user to enter a value.
    Public Shared Function SetPortBaudRate(defaultPortBaudRate As Integer) As Integer
        Dim baudRate As String

        Console.Write("Baud Rate(default:{0}): ", defaultPortBaudRate)
        baudRate = Console.ReadLine()

        If baudRate = "" Then
            baudRate = defaultPortBaudRate.ToString()
        End If

        Return Integer.Parse(baudRate)
    End Function

    ' Display PortParity values and prompt user to enter a value.
    Public Shared Function SetPortParity(defaultPortParity As Parity) As Parity
        Dim parity As String

        Console.WriteLine("Available Parity options:")
        For Each s As String In [Enum].GetNames(GetType(Parity))
            Console.WriteLine("   {0}", s)
        Next

        Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), True)
        parity = Console.ReadLine()

        If parity = "" Then
            parity = defaultPortParity.ToString()
        End If

        Return CType([Enum].Parse(GetType(Parity), parity, True), Parity)
    End Function
    ' Display DataBits values and prompt user to enter a value.
    Public Shared Function SetPortDataBits(defaultPortDataBits As Integer) As Integer
        Dim dataBits As String

        Console.Write("Enter DataBits value (Default: {0}): ", defaultPortDataBits)
        dataBits = Console.ReadLine()

        If dataBits = "" Then
            dataBits = defaultPortDataBits.ToString()
        End If

        Return Integer.Parse(dataBits.ToUpperInvariant())
    End Function
    ' Display StopBits values and prompt user to enter a value.

    Public Shared Function SetPortStopBits(defaultPortStopBits As StopBits) As StopBits
        Dim stopBits As String

        Console.WriteLine("Available StopBits options:")
        For Each s As String In [Enum].GetNames(GetType(StopBits))
            Console.WriteLine("   {0}", s)
        Next

        Console.Write("Enter StopBits value (None is not supported and " &
                      vbLf & "raises an ArgumentOutOfRangeException. " &
                      vbLf & " (Default: {0}):", defaultPortStopBits.ToString())
        stopBits = Console.ReadLine()

        If stopBits = "" Then
            stopBits = defaultPortStopBits.ToString()
        End If

        Return CType([Enum].Parse(GetType(StopBits), stopBits, True), StopBits)
    End Function
    Public Shared Function SetPortHandshake(defaultPortHandshake As Handshake) As Handshake
        Dim handshake As String

        Console.WriteLine("Available Handshake options:")
        For Each s As String In [Enum].GetNames(GetType(Handshake))
            Console.WriteLine("   {0}", s)
        Next

        Console.Write("Enter Handshake value (Default: {0}):", defaultPortHandshake.ToString())
        handshake = Console.ReadLine()

        If handshake = "" Then
            handshake = defaultPortHandshake.ToString()
        End If

        Return CType([Enum].Parse(GetType(Handshake), handshake, True), Handshake)
    End Function
End Class

Uwagi

Ta klasa służy do kontrolowania zasobu pliku portu szeregowego. Ta klasa zapewnia synchroniczne i sterowane zdarzeniami operacje we/wy, dostęp do stanów przypinania i przerwania oraz dostęp do właściwości sterownika szeregowego. Ponadto funkcjonalność tej klasy może być opakowana w obiekt wewnętrzny Stream , dostępny za pośrednictwem BaseStream właściwości i przekazana do klas, które opakowywać lub używać strumieni.

Klasa SerialPort obsługuje następujące kodowanie: ASCIIEncoding, , UTF8EncodingUnicodeEncoding, UTF32Encodingi dowolne kodowanie zdefiniowane w mscorlib.dll, gdzie strona kodowa jest mniejsza niż 50000 lub strona kodowa to 54936. Możesz użyć alternatywnych kodowań, ale musisz użyć ReadByte metody lub Write i wykonać kodowanie samodzielnie.

Metoda służy do pobierania GetPortNames prawidłowych portów dla bieżącego komputera.

SerialPort Jeśli obiekt zostanie zablokowany podczas operacji odczytu, nie przerywaj wątku. Zamiast tego należy zamknąć strumień podstawowy lub usunąć SerialPort obiekt.

Konstruktory

SerialPort()

Inicjuje nowe wystąpienie klasy SerialPort.

SerialPort(IContainer)

Inicjuje SerialPort nowe wystąpienie klasy przy użyciu określonego IContainer obiektu.

SerialPort(String)

Inicjuje SerialPort nowe wystąpienie klasy przy użyciu określonej nazwy portu.

SerialPort(String, Int32)

Inicjuje SerialPort nowe wystąpienie klasy przy użyciu określonej nazwy portu i szybkości transmisji.

SerialPort(String, Int32, Parity)

Inicjuje SerialPort nowe wystąpienie klasy przy użyciu określonej nazwy portu, szybkości transmisji i bitu parzystości.

SerialPort(String, Int32, Parity, Int32)

Inicjuje nowe wystąpienie SerialPort klasy przy użyciu określonej nazwy portu, szybkości transmisji, bitów parzystości i bitów danych.

SerialPort(String, Int32, Parity, Int32, StopBits)

Inicjuje SerialPort nowe wystąpienie klasy przy użyciu określonej nazwy portu, szybkości transmisji, bitów parzystości, bitów danych i bitów stop.

Pola

InfiniteTimeout

Wskazuje, że nie powinno wystąpić przekroczenie limitu czasu.

Właściwości

BaseStream

Pobiera obiekt źródłowy Stream dla SerialPort obiektu.

BaudRate

Pobiera lub ustawia częstotliwość transmisji szeregowej.

BreakState

Pobiera lub ustawia stan sygnału przerwania.

BytesToRead

Pobiera liczbę bajtów danych w buforze odbioru.

BytesToWrite

Pobiera liczbę bajtów danych w buforze wysyłania.

CanRaiseEvents

Pobiera wartość wskazującą, czy składnik może zgłosić zdarzenie.

(Odziedziczone po Component)
CDHolding

Pobiera stan linii Wykrywania operatora dla portu.

Container

Pobiera element IContainer zawierający element Component.

(Odziedziczone po Component)
CtsHolding

Pobiera stan wiersza Wyczyść do wysłania.

DataBits

Pobiera lub ustawia standardową długość bitów danych na bajt.

DesignMode

Pobiera wartość wskazującą, czy Component element jest obecnie w trybie projektowania.

(Odziedziczone po Component)
DiscardNull

Pobiera lub ustawia wartość wskazującą, czy bajty null są ignorowane podczas przesyłania między portem a buforem odbioru.

DsrHolding

Pobiera stan sygnału gotowego do zestawu danych (DSR).

DtrEnable

Pobiera lub ustawia wartość, która umożliwia sygnał gotowy do terminalu danych (DTR) podczas komunikacji szeregowej.

Encoding

Pobiera lub ustawia kodowanie bajtów dla konwersji tekstu przed i po transmisji.

Events

Pobiera listę programów obsługi zdarzeń dołączonych do tego Componentelementu .

(Odziedziczone po Component)
Handshake

Pobiera lub ustawia protokół uzgadniania dla transmisji danych przez port szeregowy przy użyciu wartości z Handshake.

IsOpen

Pobiera wartość wskazującą stan SerialPort otwarcia lub zamknięcia obiektu.

NewLine

Pobiera lub ustawia wartość używaną do interpretacji końca wywołania metod ReadLine() i WriteLine(String) .

Parity

Pobiera lub ustawia protokół sprawdzania parzystości.

ParityReplace

Pobiera lub ustawia bajt, który zastępuje nieprawidłowe bajty w strumieniu danych, gdy wystąpi błąd parzystości.

PortName

Pobiera lub ustawia port komunikacji, w tym wszystkie dostępne porty COM, ale nie tylko.

ReadBufferSize

Pobiera lub ustawia rozmiar buforu wejściowego SerialPort .

ReadTimeout

Pobiera lub ustawia liczbę milisekund przed przekroczeniem limitu czasu, gdy operacja odczytu nie zostanie zakończona.

ReceivedBytesThreshold

Pobiera lub ustawia liczbę bajtów w wewnętrznym buforze wejściowym przed wystąpieniem DataReceived zdarzenia.

RtsEnable

Pobiera lub ustawia wartość wskazującą, czy sygnał żądania wysyłania (RTS) jest włączony podczas komunikacji szeregowej.

Site

Pobiera lub ustawia wartość ISite .Component

(Odziedziczone po Component)
StopBits

Pobiera lub ustawia standardową liczbę stopbitów na bajt.

WriteBufferSize

Pobiera lub ustawia rozmiar buforu wyjściowego portu szeregowego.

WriteTimeout

Pobiera lub ustawia liczbę milisekund przed przekroczeniem limitu czasu, gdy operacja zapisu nie zostanie zakończona.

Metody

Close()

Zamyka połączenie portu, ustawia IsOpen właściwość na false, i usuwa obiekt wewnętrzny Stream .

CreateObjRef(Type)

Tworzy obiekt zawierający wszystkie istotne informacje wymagane do wygenerowania serwera proxy używanego do komunikowania się z obiektem zdalnym.

(Odziedziczone po MarshalByRefObject)
DiscardInBuffer()

Odrzuca dane z buforu odbierania sterownika szeregowego.

DiscardOutBuffer()

Odrzuca dane z buforu transmisji sterownika szeregowego.

Dispose()

Zwalnia wszelkie zasoby używane przez element Component.

(Odziedziczone po Component)
Dispose(Boolean)

Zwalnia zasoby niezarządzane używane przez element SerialPort i opcjonalnie zwalnia zasoby zarządzane.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetLifetimeService()
Przestarzałe.

Pobiera bieżący obiekt usługi okresu istnienia, który kontroluje zasady okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
GetPortNames()

Pobiera tablicę nazw portów szeregowych dla bieżącego komputera.

GetService(Type)

Zwraca obiekt, który reprezentuje usługę dostarczaną przez Component obiekt lub przez element Container.

(Odziedziczone po Component)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
InitializeLifetimeService()
Przestarzałe.

Uzyskuje obiekt usługi okresu istnienia w celu kontrolowania zasad okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
MemberwiseClone(Boolean)

Tworzy płytkią kopię bieżącego MarshalByRefObject obiektu.

(Odziedziczone po MarshalByRefObject)
Open()

Otwiera nowe połączenie portu szeregowego.

Read(Byte[], Int32, Int32)

Odczytuje liczbę bajtów z buforu wejściowego SerialPort i zapisuje te bajty w tablicy bajtów z określonym przesunięciem.

Read(Char[], Int32, Int32)

Odczytuje liczbę znaków z buforu wejściowego SerialPort i zapisuje je w tablicy znaków przy danym przesunięciu.

ReadByte()

Synchronicznie odczytuje jeden bajt z buforu wejściowego SerialPort .

ReadChar()

Synchronicznie odczytuje jeden znak z buforu wejściowego SerialPort .

ReadExisting()

Odczytuje wszystkie natychmiast dostępne bajty na podstawie kodowania zarówno w strumieniu, jak i w buforze wejściowym SerialPort obiektu.

ReadLine()

Odczytuje do NewLine wartości w buforze wejściowym.

ReadTo(String)

Odczytuje ciąg do określonego value w buforze wejściowym.

ToString()

Zwraca wartość String zawierającą nazwę Componentobiektu , jeśli istnieje. Ta metoda nie powinna być zastępowana.

(Odziedziczone po Component)
Write(Byte[], Int32, Int32)

Zapisuje określoną liczbę bajtów na porcie szeregowym przy użyciu danych z buforu.

Write(Char[], Int32, Int32)

Zapisuje określoną liczbę znaków do portu szeregowego przy użyciu danych z buforu.

Write(String)

Zapisuje określony ciąg na porcie szeregowym.

WriteLine(String)

Zapisuje określony ciąg i NewLine wartość w buforze wyjściowym.

Zdarzenia

DataReceived

Wskazuje, że dane zostały odebrane za pośrednictwem portu reprezentowanego SerialPort przez obiekt .

Disposed

Występuje, gdy składnik jest usuwany przez wywołanie Dispose() metody .

(Odziedziczone po Component)
ErrorReceived

Wskazuje, że wystąpił błąd z portem reprezentowanym SerialPort przez obiekt.

PinChanged

Wskazuje, że na porcie reprezentowanym przez obiekt wystąpiło zdarzenie sygnału SerialPort niezwiązanego z danymi.

Dotyczy