i cannot paste the print screen of the error..
after compiling the coding...another window appeared stated that " an invalid operation excerption was unhandled"
The error is: Failed to initialize because CategoryName is missing
tq.
i cannot paste the print screen of the error..
after compiling the coding...another window appeared stated that " an invalid operation excerption was unhandled"
The error is: Failed to initialize because CategoryName is missing
tq.
Where is SerialPort1 defined/initialized? How is it defined and initialized?
should it be initialized?how? because previously i have complied the code, but no error happens. how ever , the error appeared as i put the timer function to the code.
paul...how to intialized the serial port1?
how to intialized the serial port1?
Initialization is the second step. You have not explained the first step - declaration.
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. ?).
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 ".
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.
(Please use code tags (# button in the editor toolbar above) when posting code.)
Please have a look at this (corrected) version of the code:
Private Sub Button1_Click(ByVal sender As Object, ByVal _e As EventArgs) Handles Button1.Click
If Button1.Text = "Close" Then
SerialPort1.Close()
Button1.Text = "Open"
Else
If Not SerialPort1.IsOpen Then
SerialPort1.Open()
Button1.Text = " Close"
End If
End if
End Sub
Let's try to explain it in pseudocode:
if button1 label is "Close" then (A)
close the serial port
change button1 label to "Open"
else
if serial port is not already open
open it
change button1 label to "Close" (B)
endif
endif
(B) If the string assigned here is not exactly equal to that tested in (A) the code won't work.
In the code fragment posted earlier, in (B) you have " Close", with an extra space before the first letter. That's not going to be equal to "Close" in (A), so the IF will always fail.
I hope it's clearer now.
tuxdino,i have try compile will your code.however..the compiling error still exist.the error stated that "A first chance exception of type 'System.InvalidOperationException' occurred in System.dll"
My advice was about the errors in the piece of code you posted. Presumably that exception comes from another part of the code. Without seeing the full code, it's hard to tell.
Also, does it happen just by clicking that Button1 or when some serial data comes in ?
tuxdino..PaulS..here is the full code
Imports System.Text
Imports System.IO.Ports
Imports System.Threading
Imports System.TimeZone
Imports System.Math
Public Class Form1
Dim voltage As Integer
Dim WithEvents longitude As SerialPort = New _
System.IO.Ports.SerialPort("COM23", 9600, Parity.None, 8, StopBits.One)
Delegate Sub ProcessDataDelegate(ByVal Longitude As String, ByVal Latitude As String)
Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Try
Dim Longitude As Integer = SerialPort1.ReadLine()
Dim Latitude As Integer = SerialPort1.ReadLine()
Me.Invoke(New ProcessDataDelegate(AddressOf ProcessData), Longitude, Latitude)
Catch ex As Exception
MessageBox.Show(ex.ToString, " Unable to get the location")
SerialPort1.Close()
End Try
End Sub
Sub ProcessData(ByVal Longitude As String, ByVal Latitude As String)
TextBox1.Text = Longitude
TextBox2.Text = Latitude
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal _e As EventArgs) Handles Button1.Click
If Button1.Text = "Close" Then
SerialPort1.Close()
Button1.Text = "Open"
Else
If Not SerialPort1.IsOpen Then
SerialPort1.Open()
Button1.Text = " Close"
End If
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal _e As FormClosingEventArgs
) Handles Me.FormClosing
SerialPort1.Close()
End Sub
Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
WebBrowser2.Navigate("maps.google.com/maps?q=")
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (voltage <= 0.5) Then
MsgBox("Checked")
Else
MsgBox("Unchecked")
End If
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
If CheckedListBox1.GetItemCheckState(voltage <= 0.5) Then
CheckedListBox1.Text = True
CheckedListBox1.CheckOnClick = True
Else
If Not CheckedListBox1.CheckOnClick Then
CheckedListBox1.Text = False
End If
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If (voltage <= 0.5) Then
CheckedListBox1.Text = True
MsgBox(" safe")
TextBox3.Show()
End If
If (voltage >= 0.5 And voltage <= 0.6) Then
CheckedListBox2.Text = True
MsgBox(" WARNING")
TextBox3.Show()
End If
If (voltage <= 0.6 And voltage <= 0.7) Then
CheckedListBox3.Text = True
MsgBox("DANGER")
TextBox3.Show()
End If
End Sub
Private Sub SplitContainer2_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer2.Panel2.Paint
End Sub
Private Sub SplitContainer1_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel1.Paint
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub CheckedListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox2.SelectedIndexChanged
If CheckedListBox2.GetItemCheckState(voltage >= 0.5 And voltage <= 0.6) Then
CheckedListBox2.Text = True
CheckedListBox2.CheckOnClick = True
Else
If Not CheckedListBox2.CheckOnClick Then
CheckedListBox1.Text = False
End If
End If
End Sub
Private Sub CheckedListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox3.SelectedIndexChanged
If CheckedListBox3.GetItemCheckState(voltage >= 0.6 And voltage <= 0.7) Then
CheckedListBox2.Text = True
CheckedListBox2.CheckOnClick = True
Else
If Not CheckedListBox2.CheckOnClick Then
CheckedListBox1.Text = False
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1
End Sub
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.GetContainerControl()
If (voltage = 0.5) Then
End If
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.TextChanged
Label6.Text = DateString
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.TextChanged
Label7.Text = TimeOfDay
End Sub
End Class
Does that "Unable to get the location" error message box show up ?
System.IO.Ports.SerialPort("COM23", 9600, Parity.None, 8, StopBits.One)
On some versions of Windows, in some software, using "COMnn" as the port name does not work. "COMn" does (a single digit). Why are there so many COM ports on your system? Mine has never used a number higher than 8.
Search the forum (the old one, especially) for "COM port above 9" to see how to use port names with numbers greater than 9. It involves some ridiculous combination of periods and slashes. See if that helps.
no.because of the error..i cannot compile the code.it gets hang eventhough there are no syntax error stated.maybe it wont works because im receiving the lat and long by a serial comm from the receiver.
no.because of the error..i cannot compile the code.
Until now, you've at least implied that the problem was happening when you ran the code.
You'll need to zip up your whole project and attach it as a zip file if you want us to help you debug this.
ok.Pauls.how to attach the zip file here.thanks..
"Additional options..."
i will send the code for u to help me debug it.tq.
" sorry for asking a lot of question above as im new in arduino and visual basic"