CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    41

    dealing with Serialport calls from other forms

    Hi
    I'm using VB.NET 2005 trying to create a options form that lets you select the serial port to use I'm using:
    HTML Code:
    Sub GetSerialPortNames()
            ' Show all available COM ports.
            For Each sp As String In My.Computer.Ports.SerialPortNames
                Serial_list.Items.Add(sp)
            Next
        End Sub
    to create a list of ports this works then using
    Code:
      Private Sub btnConnect_Click( _
             ByVal sender As System.Object, _
             ByVal e As System.EventArgs) _
             Handles btnConnect.Click
    
            If SerialPort1.IsOpen Then
                SerialPort1.Close()
            End If
    
            Try
                With SerialPort1
                    .PortName = Serial_list.Text
                    .BaudRate = 9600
                    .Parity = IO.Ports.Parity.None
                    .DataBits = 8
                    .StopBits = IO.Ports.StopBits.One
                End With
                SerialPort1.Open()
                btnConnect.Enabled = False
                btnDisconnect.Enabled = True
    to open the port this also works. The problem being that when i try accessing serialport1 from the main form i get and error being Handles clause requires a WithEvents variable defined in the containing type or one of its base types
    The error is occuring at this line:
    Code:
     Private Sub port_dataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles optionspage.SerialPort1.DataReceived
    Thanks guys look forward to hearing from someone that knows more than me - michael

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: dealing with Serialport calls from other forms

    Did you define it using the with events option?

    Since you did not post the definition I can not tell but from the error message my guess would be that you did not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured