SerialPort 클래스

정의

직렬 포트 리소스를 나타냅니다.

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

예제

다음 코드 예제에서는 클래스를 SerialPort 사용하여 두 사용자가 null 모뎀 케이블로 연결된 두 대의 별도 컴퓨터에서 채팅할 수 있도록 하는 방법을 보여 줍니다. 이 예제에서는 채팅하기 전에 사용자에게 포트 설정 및 사용자 이름을 묻는 메시지가 표시됩니다. 이 예제의 모든 기능을 구현하려면 두 컴퓨터가 모두 프로그램을 실행해야 합니다.

#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

설명

이 클래스를 사용하여 직렬 포트 파일 리소스를 제어합니다. 이 클래스는 동기 및 이벤트 기반 I/O, 고정 및 중단 상태에 대한 액세스, 직렬 드라이버 속성에 대한 액세스를 제공합니다. 또한 이 클래스의 기능은 내부 Stream 개체에 래핑되고, 속성을 통해 BaseStream 액세스할 수 있으며, 스트림을 래핑하거나 사용하는 클래스에 전달될 수 있습니다.

클래스는 SerialPort , ASCIIEncoding, UTF8Encoding, UnicodeEncodingUTF32Encoding및 코드 페이지가 50000 미만이거나 코드 페이지가 54936인 mscorlib.dll 정의된 인코딩을 지원합니다. 대체 인코딩을 사용할 수 있지만 또는 Write 메서드를 ReadByte 사용하고 직접 인코딩을 수행해야 합니다.

메서드를 GetPortNames 사용하여 현재 컴퓨터의 유효한 포트를 검색합니다.

SerialPort 읽기 작업 중에 개체가 차단되면 스레드를 중단하지 마세요. 대신 기본 스트림을 닫거나 개체를 삭제합니다 SerialPort .

생성자

SerialPort()

SerialPort 클래스의 새 인스턴스를 초기화합니다.

SerialPort(IContainer)

지정된 IContainer 개체를 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

SerialPort(String)

지정된 포트 이름을 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

SerialPort(String, Int32)

지정된 포트 이름 및 전송 속도를 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

SerialPort(String, Int32, Parity)

지정된 포트 이름, 전송 속도 및 패리티 비트를 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

SerialPort(String, Int32, Parity, Int32)

지정된 포트 이름, 전송 속도, 패리티 비트 및 데이터 비트를 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

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

지정된 포트 이름, 전송 속도, 패리티 비트, 데이터 비트 및 정지 비트를 사용하여 SerialPort 클래스의 새 인스턴스를 초기화합니다.

필드

InfiniteTimeout

시간 초과가 발생하지 않아야 함을 나타냅니다.

속성

BaseStream

SerialPort 개체의 내부 Stream 개체를 가져옵니다.

BaudRate

직렬 전송 속도를 가져오거나 설정합니다.

BreakState

중단 신호 상태를 가져오거나 설정합니다.

BytesToRead

수신 버퍼에 있는 데이터의 바이트 수를 가져옵니다.

BytesToWrite

송신 버퍼에 있는 데이터의 바이트 수를 가져옵니다.

CanRaiseEvents

구성 요소가 이벤트를 발생시킬 수 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
CDHolding

포트의 CD(Carrier Detect) 선 상태를 가져옵니다.

Container

IContainer을 포함하는 Component를 가져옵니다.

(다음에서 상속됨 Component)
CtsHolding

CTS(Clear to Send) 선의 상태를 가져옵니다.

DataBits

바이트 당 데이터 비트의 표준 길이를 가져오거나 설정합니다.

DesignMode

Component가 현재 디자인 모드인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
DiscardNull

포트와 수신 버퍼 간의 전송 시 null 바이트를 무시할지를 나타내는 값을 가져오거나 설정합니다.

DsrHolding

DSR(Data Set Ready) 신호의 상태를 가져옵니다.

DtrEnable

직렬 통신 동안 DTR(Data Terminal Ready) 신호를 사용할 수 있는지를 나타내는 값을 가져오거나 설정합니다.

Encoding

텍스트의 전송 전 및 전송 후 변환을 위한 바이트 인코딩을 가져오거나 설정합니다.

Events

Component에 연결된 이벤트 처리기의 목록을 가져옵니다.

(다음에서 상속됨 Component)
Handshake

Handshake의 값을 사용하여 데이터의 직렬 포트 전송을 위한 핸드셰이킹 프로토콜을 가져오거나 설정합니다.

IsOpen

SerialPort 개체의 열림 또는 닫힘 상태를 나타내는 값을 가져옵니다.

NewLine

ReadLine()WriteLine(String) 메서드의 호출 끝을 해석하는 데 사용되는 값을 가져오거나 설정합니다.

Parity

패리티 검사 프로토콜을 가져오거나 설정합니다.

ParityReplace

패리티 오류가 발생할 때 데이터 스트림의 잘못된 바이트를 바꾸는 바이트를 가져오거나 설정합니다.

PortName

사용할 수 있는 모든 COM 포트를 비롯한 통신 포트를 가져오거나 설정합니다.

ReadBufferSize

SerialPort 입력 버퍼의 크기를 가져오거나 설정합니다.

ReadTimeout

읽기 작업을 마쳐야 하는 제한 시간(밀리초)을 가져오거나 설정합니다.

ReceivedBytesThreshold

DataReceived 이벤트가 발생하기 전 내부 입력 버퍼의 바이트 수를 가져오거나 설정합니다.

RtsEnable

직렬 통신에 RTS(Request to Send) 신호를 사용할 수 있는지를 나타내는 값을 가져오거나 설정합니다.

Site

ComponentISite를 가져오거나 설정합니다.

(다음에서 상속됨 Component)
StopBits

바이트 당 정지 비트의 표준 개수를 가져오거나 설정합니다.

WriteBufferSize

직렬 포트 출력 버퍼의 크기를 가져오거나 설정합니다.

WriteTimeout

쓰기 작업을 마쳐야 하는 제한 시간(밀리초)을 가져오거나 설정합니다.

메서드

Close()

포트 연결을 닫고, IsOpen 속성을 false로 설정하고, 내부 Stream 개체를 삭제합니다.

CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
DiscardInBuffer()

직렬 드라이버의 수신 버퍼에서 데이터를 삭제합니다.

DiscardOutBuffer()

직렬 드라이버의 전송 버퍼에서 데이터를 삭제합니다.

Dispose()

Component에서 사용하는 모든 리소스를 해제합니다.

(다음에서 상속됨 Component)
Dispose(Boolean)

SerialPort에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetPortNames()

현재 컴퓨터의 직렬 포트 이름이 포함된 배열을 가져옵니다.

GetService(Type)

Component 또는 해당 Container에서 제공하는 서비스를 나타내는 개체를 반환합니다.

(다음에서 상속됨 Component)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Open()

새 직렬 포트 연결을 엽니다.

Read(Byte[], Int32, Int32)

SerialPort 입력 버퍼에서 여러 바이트를 읽고 해당 바이트를 바이트 배열의 지정된 오프셋에 씁니다.

Read(Char[], Int32, Int32)

SerialPort 입력 버퍼에서 여러 문자를 읽고 해당 문자를 문자 배열의 지정된 오프셋에 씁니다.

ReadByte()

SerialPort 입력 버퍼에서 1바이트를 동기적으로 읽습니다.

ReadChar()

SerialPort 입력 버퍼에서 하나의 문자를 동기적으로 읽습니다.

ReadExisting()

인코딩을 기준으로 SerialPort 개체의 스트림 및 입력 버퍼 모두에서 즉시 사용할 수 있는 모든 바이트를 읽습니다.

ReadLine()

입력 버퍼에서 NewLine 값까지 읽습니다.

ReadTo(String)

입력 버퍼에서 지정된 value까지의 문자열을 읽습니다.

ToString()

Component의 이름이 포함된 String을 반환합니다(있는 경우). 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 Component)
Write(Byte[], Int32, Int32)

버퍼의 데이터를 사용하여 지정된 수의 바이트를 직렬 포트에 씁니다.

Write(Char[], Int32, Int32)

버퍼의 데이터를 사용하여 지정된 수의 문자를 직렬 포트에 씁니다.

Write(String)

직렬 포트에 지정된 문자열을 씁니다.

WriteLine(String)

지정한 문자열 및 NewLine 값을 출력 버퍼에 씁니다.

이벤트

DataReceived

SerialPort 개체가 나타내는 포트를 통해 데이터를 수신했음을 나타냅니다.

Disposed

Dispose() 메서드를 호출하여 구성 요소를 삭제할 때 발생합니다.

(다음에서 상속됨 Component)
ErrorReceived

SerialPort 개체가 나타내는 포트에서 오류가 발생했음을 나타냅니다.

PinChanged

SerialPort 개체가 나타내는 포트에서 데이터가 아닌 신호 이벤트가 발생했음을 나타냅니다.

적용 대상