SerialPort y Modem ?

Iniciado por TrashAmbishion, 27 Enero 2013, 23:43 PM

0 Miembros y 1 Visitante están viendo este tema.

TrashAmbishion

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 (vbnet) [Seleccionar]


Imports System.IO.Ports

Public Class Form1

    Private mySerialPort As New SerialPort
    Private comBuffer As Byte()
    Private Delegate Sub UpdateFormDelegate()
    Private UpdateFormDelegate1 As UpdateFormDelegate

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            AddHandler mySerialPort.DataReceived, AddressOf mySerialPort_DataReceived
            CommPortSetup()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub mySerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
        'Handles serial port data received events
        UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay)
        Dim n As Integer = mySerialPort.BytesToRead 'find number of bytes in buf
        comBuffer = New Byte(n - 1) {} 're dimension storage buffer
        mySerialPort.Read(comBuffer, 0, n) 'read data from the buffer

        Me.Invoke(UpdateFormDelegate1) 'call the delegate
    End Sub

    Private Sub UpdateDisplay()
        Label2.Text = CStr(comBuffer(0))
    End Sub

    Private Sub CommPortSetup()
        With mySerialPort
            .PortName = "COM3"
            .BaudRate = 9600
            .DataBits = 8
            .Parity = Parity.None
            .StopBits = StopBits.One
            .Handshake = Handshake.None
        End With
        Try
            mySerialPort.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mySerialPort.WriteLine("AT+VCID")
    End Sub
End Class