Cara Mengatasi Masalah Menghubungkan Arduino Leonardo dengan VB.Net


Program VB.Net standar
——————————————————————
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

——————————————————————————————-

Masalahnya yaitu VB.Net tidak mau menampilkan data, padahal di coding Arduino sudah kita sisipkan sintax Serial.print. Fix masalahnya yaitu di pendeklarasian properties Serial Port.
Dalam hal ini saya menamakan Serial portnya “SeriarP”.
Jadi tambahkan properties SerialP.DtrEnable dan SerialP.RtsEnable keduanya harus dalam keadaaan “True”.

dan taraaa Datanya akan tampil di VB. Selamat Mencoba🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s