Hello everyone, recently bought an Arduino Leonardo, however I am not able to receive data on VB.net side, I can send data to Arduino but can´t receive, DataReceived event doesn´t fire on VB.NET, can someone help me, already googled and I can´t see no reason why event DataReceived isn´t working.
Here´s my Vb code :
Public Class Form1
Public WithEvents SerialP As System.IO.Ports.SerialPort
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'GetSerialPortNames()
SerialP = New System.IO.Ports.SerialPort
SerialP.BaudRate = 9600
SerialP.PortName = "COM15"
SerialP.DataBits = 8
SerialP.ReadTimeout = 5000
SerialP.WriteTimeout = 5000
SerialP.Parity = IO.Ports.Parity.None
SerialP.StopBits = IO.Ports.StopBits.One
SerialP.Handshake = IO.Ports.Handshake.None
'SerialP.Encoding = System.Text.Encoding.Default 'very important!
SerialP.Encoding = System.Text.Encoding.UTF8
SerialP.Open()
Catch ex As Exception
SerialP.Close()
End Try
End Sub
Public Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialP.DataReceived
MessageBox.Show("")
End Sub
Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
'cmboComm.Items.Add(sp)
Next
End Sub
Private Sub SendToSerialP()
If SerialP.IsOpen Then
SerialP.Write("H")
Else
'SerialP.Write(txtSend.Text)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendToSerialP()
End Sub
Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
SerialP.Close()
End Sub
End Class
And here is my Sketch :
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
int counter;
void setup() {
// initialize serial communication:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
establishContact();
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
counter = 0;
}
void loop() {
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}