title: I can't send data through serial port using Visual Studio 2017 (C#)
body: <p>I try to make a windows application and I have a problem with C# serial communication. I've read a lot of articles about it and watched a lot of youtube tutorials, but the communication still doesn't work. I'm using Visual Studio 2017(community) on Windows 8.1 system. The problem is, that my code can open the serial port and it can close it but when I try to send data between them, nothing happens. For testing I used TeraTerm and sent out some bytes with it to my microcontroller and the micorC could receive that. But with my code, as I said, nothing happens. My code is:</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using System.IO.Ports;
  
   namespace Cucc
  {
      public partial class Form1 : Form
      {
          byte[] d = new byte[1] { 0x0d };
          byte[] a = new byte[1] { 0x0a };
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              serialPort1 = new SerialPort();
              serialPort1.PortName = "COM4"; 
              serialPort1.BaudRate = 9600;
              serialPort1.DataBits = 8;
              serialPort1.StopBits = StopBits.One;
              serialPort1.Parity = Parity.None;
              serialPort1.Open();
  
  
          } 
  
          private void button2_Click(object sender, EventArgs e)
          {
              // Try to send some stuff here
              serialPort1.WriteLine("1");
              serialPort1.Write(a, 0, 1);
              serialPort1.Write(d, 0, 1);
          }
  
          private void button3_Click(object sender, EventArgs e)
          {
               serialPort1.Close();
          }
      }
   }
  </code></pre>
  
  <p>My microcontroller always connects to the COM4 port (everytime I connect it, I check the port). Does anyone have any idea, why can't I send data out? I tried with Microsoft Visual C# 2008 Express Edition too, but the code didn't work.</p>
  
  <p>Thanks in advance!</p>