elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Trabajando con Puerto COM - SerialPort !! Dudita !
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Trabajando con Puerto COM - SerialPort !! Dudita !  (Leído 2,417 veces)
TrashAmbishion


Desconectado Desconectado

Mensajes: 756


Ver Perfil
Trabajando con Puerto COM - SerialPort !! Dudita !
« en: 24 Enero 2013, 01:18 am »

holas estoy tratando de leer la respuesta del Modem al comando que le paso y me devuelve un numero, no entiendo porque quizas sea en el tipo de lectura que se hace que es con un buffer....

Alguna idea...Lo que espero es un OK

Código
  1. Imports System.IO.Ports
  2.  
  3. Public Class Form1
  4.  
  5.    Private mySerialPort As New SerialPort
  6.    Private comBuffer As Byte()
  7.    Private Delegate Sub UpdateFormDelegate()
  8.    Private UpdateFormDelegate1 As UpdateFormDelegate
  9.  
  10.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11.        Try
  12.            AddHandler mySerialPort.DataReceived, AddressOf mySerialPort_DataReceived
  13.            CommPortSetup()
  14.        Catch ex As Exception
  15.            MessageBox.Show(ex.Message)
  16.        End Try
  17.    End Sub
  18.  
  19.    Private Sub mySerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
  20.        'Handles serial port data received events
  21.        UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay)
  22.        Dim n As Integer = mySerialPort.BytesToRead 'find number of bytes in buf
  23.        comBuffer = New Byte(n - 1) {} 're dimension storage buffer
  24.        mySerialPort.Read(comBuffer, 0, n) 'read data from the buffer
  25.  
  26.        Me.Invoke(UpdateFormDelegate1) 'call the delegate
  27.    End Sub
  28.  
  29.    Private Sub UpdateDisplay()
  30.        Label2.Text = CStr(comBuffer(0))
  31.    End Sub
  32.  
  33.    Private Sub CommPortSetup()
  34.        With mySerialPort
  35.            .PortName = "COM3"
  36.            .BaudRate = 9600
  37.            .DataBits = 8
  38.            .Parity = Parity.None
  39.            .StopBits = StopBits.One
  40.            .Handshake = Handshake.None
  41.        End With
  42.        Try
  43.            mySerialPort.Open()
  44.        Catch ex As Exception
  45.            MessageBox.Show(ex.Message)
  46.        End Try
  47.    End Sub
  48.  
  49.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  50.        mySerialPort.WriteLine("AT+VCID")
  51.    End Sub
  52. End Class
  53.  


« Última modificación: 27 Enero 2013, 23:41 pm por TrashAmbishion » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
C# System.IO.Port SerialPort
Hacking Mobile
hoofmen 8 23,060 Último mensaje 31 Mayo 2009, 10:33 am
por Jubjub
Configuración serialPort en C#
.NET (C#, VB.NET, ASP)
Meta 0 2,311 Último mensaje 7 Diciembre 2008, 05:32 am
por Meta
SerialPort para Sockets en Visual Basic .NET?
.NET (C#, VB.NET, ASP)
*Ghost* 1 5,722 Último mensaje 16 Febrero 2010, 21:23 pm
por Jackerst
SerialPort y Modem ?
.NET (C#, VB.NET, ASP)
TrashAmbishion 0 2,029 Último mensaje 27 Enero 2013, 23:43 pm
por TrashAmbishion
Problemita usando el SerialPort ?
.NET (C#, VB.NET, ASP)
TrashAmbishion 0 1,600 Último mensaje 5 Junio 2013, 00:26 am
por TrashAmbishion
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines