title: How to use c# methods with serial port in asp .net core?
body: <p>I have a task to create web app with ASP .NET core 2.0 where you can communicate with modem and send SMS using AT command. I have a piece of code which can send messages using Serial Port but ASP doesn't have this library so how can I use this code in ASP .NET? <br>
  Method:
  <br></p>
  
  <pre><code>private SerialPort _serialPort;
  
      public void SendSms()
      {
          Console.WriteLine("Write phone number");
          string phoneNr = Console.ReadLine();
          Console.WriteLine("Write message");
          string message = Console.ReadLine();
  
          _serialPort = new SerialPort("COM2", 9600);
  
          Thread.Sleep(1000);
  
          _serialPort.Open();
  
          Thread.Sleep(1000);
  
          _serialPort.Write("AT+CMGF=1\r");
  
          Thread.Sleep(1000);
  
          _serialPort.Write("AT+CMGS=\"" + phoneNr + "\"\r\n");
  
          Thread.Sleep(1000);
  
          _serialPort.Write(message + "\x1A");
  
          Thread.Sleep(1000);
  
          _serialPort.Close();
      }
  </code></pre>
  
  <p><br>
  Also in my app I have chat window so I want to use input box and button to write and send SMS. </p>
  
  <pre><code> &lt;form method="post"&gt;
              &lt;input asp-for="MessageBody" id="textInput" type="text" placeholder="Enter message..." class="form-control " /&gt;
              &lt;button asp-action="SendMessage" id="sendButton" class="btn btn-primary btn-block" type="submit"&gt;Send&lt;/button&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p><br></p>
  
  <p>For now <strong>SendMessage</strong> only saves message into database.
  <br>
  Sorry if my question is formulated not in the best way, writing here for the first time.</p>