VBNET 2010 x SERIAL PORT
Boa tarde !
Estou testando um código de comunicação pela porta serial onde mando um carácter pro dispositivo e este me devolve uma serie de dados separados por #, gostaria de criar um array e colocar cada dado lido numa posição deste array mas o codigo abaixo retorna com o erro Troubleshooting Exceptions: System.InvalidOperationException .
Ppor favor alguém pode ajudar, estou migrando de vb6 para vbnet 2010 e estou encontrando dificuldades, sou novato.
Obrigado.
O formato do dado recebido em no textbox:
18.18|17.62|17.34|17.27|17.24|17.21|17.17|17.12|17.08|17.03|17.00|16.92|16.93|16.87|16.89|16.84|
Código:
Public Class Form1
Dim WithEvents SerialPort As New IO.Ports.SerialPort
Delegate Sub myMethodDelegate(ByVal [text] As String)
Dim myD1 As New myMethodDelegate(AddressOf myShowStringMethod)
Dim Valor() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort.BaudRate = 115200
SerialPort.PortName = "COM6"
SerialPort.Open()
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
SerialText.Text = ""
SerialPort.Write("1")
End Sub
Sub myShowStringMethod(ByVal myString As String)
'CHEGADA DE DADOS PELA SERIAL
SerialText.AppendText(myString)
Valor(0) = myString <---- Troubleshooting Exceptions: System.InvalidOperationException .
End Sub
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
Dim str As String = SerialPort.ReadExisting()
Invoke(myD1, str)
End Sub
Private Sub Form1_Deactivate(sender As System.Object, e As System.EventArgs) Handles MyBase.Deactivate
SerialPort.Close()
End Sub
End Class
Discussão (1)
Carregando comentários...