System.IO.Ports.SerialPort.Write C# (CSharp) Méthode

Write() public méthode

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
Résultat void
		public void Write (byte [] buffer, int offset, int count)
		{
			CheckOpen ();
			if (buffer == null)
				throw new ArgumentNullException ("buffer");

			if (offset < 0 || count < 0)
				throw new ArgumentOutOfRangeException ();

			if (buffer.Length - offset < count)
				throw new ArgumentException ("offset+count",
							     "The size of the buffer is less than offset + count.");

			stream.Write (buffer, offset, count);
		}

Same methods

SerialPort::Write ( char buffer, int offset, int count ) : void
SerialPort::Write ( string str ) : void

Usage Example

Exemple #1
44
 public static void Main()
 {
     SerialPort serialPort = new SerialPort("COM1", 115200, Parity.None);
     serialPort.ReadTimeout = 5000; // milliseconds
     serialPort.Open();
     byte[] outBuffer = Encoding.UTF8.GetBytes("All right?\r\n");
     byte[] inBuffer = new byte[2];
     while (true)
     {
         Debug.Print("Request data");
         serialPort.Write(outBuffer, 0, outBuffer.Length);
         int count = serialPort.Read(inBuffer, 0, 2);
         if (count == 2)
         {
             Debug.Print("Received expected two bytes!");
         }
         else
         {
             if (count == 0)
                 Debug.Print("No response!");
             if (count == 1)
                 Debug.Print("Not enough bytes received!");
         }
         Debug.Print(string.Empty);
     }
 }
All Usage Examples Of System.IO.Ports.SerialPort::Write