Hola, vengo a buscar ayuda para mi proyecto escolar. Este es mi primer programa y se trataba de un nivel de agua usando arduino y un sensor ultrasonico. Estos componentes se controlarian a travez de un programa que diseñe en visual basic, pero al darle click en conectar (el boton abre el puerto serial para leer los datos del arduino) este simplemete me dice que el com3 no esta disponible. Pido ayuda de la manera mas atenta ya que este proyecto lo debo entregar el lunes y es lo unico que me falta. De antemano gracias por su atencion.<
Imports System
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Screen1
Dim C_AREA As Double
Dim C_ALTO As Double
Dim C_VOLUMEN As Double
Dim Dato As String
Dim Distancia As Double
Dim Altura_Arduino As Double
Dim Cerrar As Double
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
buscarpuerto()
SerialPort1.PortName = CPUERTO.Text
End Sub
Private Sub buscarpuerto()
Try
CPUERTO.Items.Clear()
For Each puerto As String In My.Computer.Ports.SerialPortNames
CPUERTO.Items.Add(puerto)
Next
If CPUERTO.Items.Count > 0 Then
CPUERTO.SelectedIndex = 0
Else
MsgBox("No hay ningún puerto disponible.")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
If SerialPort1.IsOpen() Then
Dato = SerialPort1.ReadLine()
Distancia = CDbl(Val(Dato))
CheckForIllegalCrossThreadCalls = False
If Distancia > 0 Then
Text_Distancia.Text = Distancia.ToString()
If Cerrar = 3 Then
SerialPort1.Close()
End If
End If
End If
End Sub
'pantallas'
Private Sub PB2_Click(sender As Object, e As EventArgs) Handles PB2.Click
Me.Show()
End Sub
Private Sub PB3_Click(sender As Object, e As EventArgs) Handles PB3.Click
Screen2.Show()
End Sub
'boton conectar
Private Sub Button_CONECTAR_Click(sender As Object, e As EventArgs) Handles Button_CONECTAR.Click
Cerrar = 0
Try
With SerialPort1
.BaudRate = 9600
.DataBits = 8
.Parity = IO.Ports.Parity.None
.StopBits = 1
.PortName = CPUERTO.Text
.Open()
If .IsOpen Then
ESTADO.Text = "Conectado"
Else
MsgBox("Conexion fallida", MsgBoxStyle.Critical)
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
'Boton cerrar
Private Sub Button_DESCONECTAR_Click(sender As Object, e As EventArgs) Handles Button_DESCONECTAR.Click
Cerrar = 3
CPUERTO.Items.Clear()
ESTADO.Text = "Desconectado"
End Sub
'boton buscar puerto
Private Sub Button_PUERTO_Click(sender As Object, e As EventArgs) Handles Button_PUERTO.Click
buscarpuerto()
End Sub
Private Sub Text_Ancho1_TextChanged(sender As Object, e As EventArgs) Handles Text_Ancho1.TextChanged
C_ALTO = Double.Parse(Text_Ancho1.Text, Globalization.NumberStyles.Currency)
End Sub
Private Sub Text_Altura1_TextChanged(sender As Object, e As EventArgs) Handles Text_Altura1.TextChanged
C_AREA = Double.Parse(Text_Altura1.Text, Globalization.NumberStyles.Currency)
End Sub
Private Sub TextALT_ARD_TextChanged(sender As Object, e As EventArgs) Handles TextALT_ARD.TextChanged
Altura_Arduino = Double.Parse(TextALT_ARD.Text, Globalization.NumberStyles.Currency)
End Sub
Private Sub Button_Enviar_Click(sender As Object, e As EventArgs) Handles Button_Enviar.Click
If C_AREA > 0 And C_ALTO > 0 Then
Dim Despreciable As Double = Distancia - Altura_Arduino
C_VOLUMEN = (C_AREA * C_ALTO) - Despreciable
Label_VAGUA.Text = C_VOLUMEN.ToString()
End If
End Sub