viva... a minha experiencia em VB é pouca, na verdade ainda só criei uma aplicação a comunicar com um picaxe. Fica aqui o código do modulo responsável pela parte da comunicação, na esperança de que possa ser util.
Imports System.IO.Ports
Imports System.Text
Module Module1
Dim WithEvents portacom As New SerialPort("com4", 9600, Parity.None, 8, StopBits.One)
Sub main()
TestWorker = New System.ComponentModel.BackgroundWorker
TestWorker.WorkerReportsProgress = True
TestWorker.WorkerSupportsCancellation = True
TestWorker.RunWorkerAsync()
End Sub
'------------------------------
Public WithEvents TestWorker As System.ComponentModel.BackgroundWorker
Private Sub TestWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles TestWorker.DoWork
'portacom.ReadTimeout = 200
' portacom.WriteTimeout = 500
Dim buffer As New StringBuilder()
Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort(com, 9600, Parity.None, 8, StopBits.One)
Do
Threading.Thread.Sleep(250)
Dim pacoteinicial As String = comPort.ReadLine()
If pacoteinicial Is Nothing Then
Exit Do
Else
buffer.AppendLine(pacoteinicial)
pacoterecebido = pacoteinicial
End If
Threading.Thread.Sleep(250)
If pagina1 = True Then identificador = 5
If janela_ferramenta_aberta = True Then identificador = 7
enviar = (identificador & ferramenta & pacote_envio)
comPort.Write(enviar)
Loop
End Using
End Sub
End Module