Trabajando con Puerto COM - SerialPort !! Dudita !

(1/1)

TrashAmbishion:
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
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
 

Navegación

[0] Índice de Mensajes