System.IO.Ports.SerialPortBase.Read C# (CSharp) Méthode

Read() public méthode

Reads data from a serial port.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The output buffer that stores the data read from the serial port.
offset int The offset value that indicates where writing to the output buffer from the serial port is to begin.
count int The number of bytes of data to be read.
Résultat int
        public virtual int Read(byte[] buffer, int offset, int count)
        {
            if (IsReading)                                                      // If DataReceived event is being requested,
                lock (_bufferSync)                                              // we have to use our reading buffer:
                {
                    int usedLength = GetBufferedData(buffer, offset, count);    // read data from it
                    AdvancePosition(usedLength);                                // and remove them.
                    return usedLength;                                          // TODO: Implement read timeout.
                }
            else
                return ReadDirect(buffer, offset, count);          // Otherwise, we can directly read the serial port data.
        }