M
M
marking7332015-01-16 20:52:00
Arduino
marking733, 2015-01-16 20:52:00

Transferring data from Arduino Uno to C#. How to implement?

Suppose you have an Arduino Uno already programmed. It is necessary to implement in the C # program the transfer of data to the Arduino and vice versa. In the standard Arduino IDE (already with the working arduino) this is done by the port monitor:
bf02ade29aeb46f294d61da8516a1873.PNG
Please show a good example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
papkinv, 2015-01-17
@marking733

communication with arduino goes through the COM port. You need to dig in the direction of the SerialPort class. Something like this

using System;
using System.IO;
using System.IO.Ports;
using System.Text;

namespace MyProgram
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Opening serial port");
            SerialPort sp = new SerialPort("COM3", 115200); //порт и скорость обмена
            sp.Open();
            WriteLine("Hello!");
      while (sp.BytesToRead() <= 0)
      {
        System.Threading.Thread.Sleep(1000);
      }
      Console.WriteLine(sp.ReadLine());
            sp.Close();
        }        
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question