I want to write a small software that sends data to the Arduino and receives data. At the moment, there are two buttons that send either a 1 or a 2, and the Arduino responses with the same number to check.
Sending the data to the Arduino is no problem at all. But receiving is. Unfortunately, I'm not sure if it's a problem with receiving data, or just with handling the data (something with threading). I hope someone could help me. I swear, I googled for hours, and found lots of solutions, but most of them caused various problems for the compiler or didn't work.
I'm sure the Arduino code is correct (the TX LED flashes when the data is sent), so here's the Visual Studio part:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "com11"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim message As Integer
message = SerialPort1.ReadLine()
Label1.Text = message