Go Down

Topic: Serial communication using C# (Read 1 time) previous topic - next topic


How do I print my voltage readings I'm getting from Arduino to the console window in C#?


Jun 12, 2017, 08:15 pm Last Edit: Jun 13, 2017, 09:59 am by septillion
You're on the wrong forum mate ;) That's a C# question. If you send the values to the PC via Serial you need to open the Serial port in your C# application.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake



Jun 13, 2017, 02:18 am Last Edit: Jun 13, 2017, 02:19 am by ron_sutherland
I guess that is one way to do an Anonymous search.


Also YaCy looks interesting if Google has gotten irritating enough.

my projects: https://github.com/epccs


Jun 13, 2017, 08:55 am Last Edit: Jun 13, 2017, 09:01 am by horace
example of a simple C# terminal using a Form
Code: [Select]
using System;
using System.Windows.Forms;
using System.IO.Ports;

namespace CsharpTerminal
    public partial class Form1 : Form
        // delegate to transfer received data to TextBox
        public delegate void AddDataDelegate(String myString);
        public AddDataDelegate myDelegate;
        public Form1()
            this.myDelegate = new AddDataDelegate(AddDataMethod);

        // key on textbox pressed, read key and transmit down serial line
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        if( serialPort1.IsOpen)
            textBox1.AppendText("No COM port open" + Environment.NewLine);

     // data received from serial port - display on textbox
     private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            //textBox1.AppendText(serialPort1.ReadExisting());  // not thread safe
            string s = serialPort1.ReadExisting();
            textBox1.Invoke(this.myDelegate, new Object[] { s });

     // display seral data on textbox
     public void AddDataMethod(String myString)

     private void Form1_FormClosed(object sender, FormClosedEventArgs e)


it can be made more sophisticated by adding menus to select COM port, Baud rate, etc
Screen dump of Form attached - communicating with an Arduino Nano

Go Up