Go Down

Topic: problem with visualbasic 2010 coding (Read 3 times) previous topic - next topic

arduino_learners

paul...how to intialized the serial port1?

PaulS

Quote
how to intialized the serial port1?

Initialization is the second step. You have not explained the first step - declaration.

tuxduino

Code: [Select]

Private Sub Button1_Click(ByVal sender As Object, ByVal _e As EventArgs) Handles Button1.Click
        If Button1.Text = "Close" Then    ' will fail it button's text is " Close" (notice the extra space)
            SerialPort1.Close()
            Button1.Text = "Open"
        Else
            If Not SerialPort1.IsOpen Then SerialPort1.Open()    ' where is endif ?

            Button1.Text = " Close"    ' one extra space!

        End If
    End Sub


Where do you set the port options (baud rate, etc. ?).

arduino_learners

PaulS, here is the declaration for the serialport1.

Public Class Form1
    Dim voltage As Integer
    Dim WithEvents longitude As SerialPort = New  _
        System.IO.Ports.SerialPort("COM23", 9600, Parity.None, 8, StopBits.One)

however, i still get the same error " system.InvalidOperationException ".

arduino_learners

tuxduino...

actually i got the coding from other pages.

Private Sub Button1_Click(ByVal sender As Object, ByVal _e As EventArgs) Handles Button1.Click
        If Button1.Text = "Close" Then    ' will fail it button's text is " Close" (notice the extra space)
            SerialPort1.Close()
            Button1.Text = "Open"
        Else
            If Not SerialPort1.IsOpen Then SerialPort1.Open()    ' where is endif ?

            Button1.Text = " Close"    ' one extra space!( meaning of the code)?

        End If// here is the end if .
    End Sub

hope u can help me in understanding me the button.text= "close" code..i can get ur comment on that code.

Go Up