Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: TrashAmbishion en 27 Enero 2013, 23:43 pm



Título: SerialPort y Modem ?
Publicado por: TrashAmbishion en 27 Enero 2013, 23:43 pm
Lo que espero es un Ok del Modem mas recibo un 65 alguna idea, quizas sea por el tipo de lectura que estoy haciendo....Salu2

Disculpen por repetir el Topic si pudieran borrar el otro estaria agradecido...gracias

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