Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai All,
I am developing one VB Application in VS 2010. I am using Serialport property for sending Quiries to GSM Modem through Micro USB Cable. While using of this serialport property out of this method, i got run time errors ... any one please tell me how to use this property out of this event in the same class.


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Try
            Dim mySerialPort As New SerialPort(ComboBox1.Text)
            mySerialPort.BaudRate = 19200
            mySerialPort.Parity = Parity.None
            mySerialPort.StopBits = StopBits.One
            mySerialPort.DataBits = 8
            mySerialPort.Handshake = Handshake.None
            AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler
            mySerialPort.Open()
            If mySerialPort.IsOpen = True Then
                'For i As Integer = 1 To 3
                '    mySerialPort.Write("AT+CMGR=" & i & vbCrLf)
                '    MsgBox("AT+CMGR=" & i & vbCrLf)
                'Next
                '    ComboBox1.Enabled = False
                mySerialPort.Write("AT+CMGL=" & Chr(34) & "REC UNREAD" & Chr(34) & vbCrLf)
            End If
            ToolStripStatusLabel1.Text = ToolStripStatusLabel1.Text & "   " & ComboBox1.Text & "," & "19200" & "," & "N" & "," & "1" & "," & "8" & "," & "N"
        Catch Ex As Exception
            MsgBox(Ex.Message)
        End Try
    End Sub
Posted
Comments
Romain TAILLANDIER 16-Dec-11 2:38am
   
You have to start with some MSDN documentation ...
http://msdn.microsoft.com/fr-fr/library/system.io.ports.serialport.aspx

1 solution

You've got a serious design flaw in your app. You should have a seperate class that manages the connection of the serial port. You'd maintain a class-global instance of this class in your form, then just call methods in that class from your handlers that tell it how to manipulate the serial port.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900