Prezados, sou novato no assunto e me interessei bastante com as possibilidades do Arduino. Começei a fazer alguns testes usando a IDE do próprio Arduino. Como sou programador, resolvi tentar comunicar o arduino com o Vb.Net e consegui enviar dado!!! :-).
Porém não consegui ler do arduino. Só consigo enviar. Receber não.
A minha aplicação dá erro (Error: Serial Port read timed out.) ao tentar ler a porta serial. Segue abaixo trechos do código.
Alguém pode dar uma solução, se possível em vb.net????
Abs
======================================
VB.net
======================================
Sub SendSerialData(ByVal data As String)
- ' Send strings to a serial port.*
- Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM4")*
- If com1.IsOpen Then*
- com1.BaudRate = "9600"*
- com1.DataBits = 8*
- com1.Parity = 0*
- com1.StopBits = 1*
- com1.WriteLine(data)*
- Else*
- MsgBox("A porta está fechada.")*
- End If*
- com1.Close()*
- End Using*
End sub
Private Sub ReceiveSerialData() - ' Receive strings from a serial port.*
- Dim returnStr As String = ""*
- Dim Incoming As String*
- Dim com1 As IO.Ports.SerialPort = Nothing*
- Try*
- com1 = My.Computer.Ports.OpenSerialPort("COM4")*
- com1.BaudRate = "9600"*
- com1.DataBits = 8*
- com1.Parity = 0*
- com1.StopBits = 1*
- com1.ReadTimeout = 1000 '1seg*
- Do*
- Incoming = com1.ReadLine()*
- If Incoming Is Nothing Then*
- Exit Do*
- Else*
- returnStr &= Incoming & vbCrLf*
- End If*
- Loop*
- Catch ex As TimeoutException*
- returnStr = "Error: Serial Port read timed out."*
- Finally*
- If com1 IsNot Nothing Then com1.Close()*
- End Try*
- MsgBox(returnStr)*
- End Sub*