Pages: [1]   Go Down
Author Topic: Vb.Net DataReceived event doesn´t fire up on leonardo  (Read 2655 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :

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 :

Code:
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);
  }
}

* Arduino.rar (52.8 KB - downloaded 15 times.)
« Last Edit: September 27, 2012, 07:31:14 pm by ntiagobr » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem solved  smiley-cool, after some digging, i figured out the issue, properties SerialP.DtrEnable and SerialP.RtsEnable must both be set to True.

Thank you all anyway.

I will leave the this post, who knows, it can be useful to someone else.
Logged

Cambridge,UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
If at first you don't succeed; call it version 1.0
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

Just wanted to say thanks for posting up the solution you found, I'd been trying everything I could think of to trick the Leonardo into thinking that the connection was active, but had completely overlooked the handshaking!  smiley-red

Works a treat, thanks again!

Tom
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-grin Great! smiley-wink

I'm glad it helped, I regret there is so little help about this issue.
Logged

Pages: [1]   Go Up
Jump to: