2015-05-01 20 views
-1

我想編輯我發現的開源代碼,那裏有一些錯誤,無論如何,我解決了一切,但我仍然有這個: 我把一個組合下拉菜單,下拉菜單在串口之間選擇與arduino進行通信,但是如果我選擇了其他端口,程序選擇COM5似乎總是如此。 這是錯誤我有當我按下啓動按鈕,溝通VB.net選擇串口System.IO.IOException

An unhandled exception of type 'System.IO.IOException' occurred in System.dll 
Additional information: The port 'COM5' does not exist. 

,這是組合下拉菜單代碼

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) 
               Handles ComboBox1.SelectedIndexChanged 
End Sub 

與此代碼爲啓動按鈕

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) 
                   Handles Button7.Click 
     SerialPort1.Open() 
     SerialPort1.Write("~") 
     SerialPort1.Write("LCD is working!") 
     Timer2.Start() 
     SerialPort1.Close() 
End Sub 

回答

0

但似乎總是程序選擇COM5,如果我選擇其他端口或不。這是錯誤我有當我按下開始按鈕進行溝通

此代碼

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged 
End Sub 

旨在讓用戶選擇組合框指標和設定他們選擇哪個串行端口。但是,該處理程序的主體是空的,所以它實際上並沒有做任何事情。

代碼

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click 
     SerialPort1.Open() 

大概是其中異常被拋出。您沒有在您顯示的代碼中的任何地方更改SerialPort1的設置。據推測,您應該添加一些代碼到ComboBox1_SelectedIndexChanged來更新SerialPort1的屬性以反映用戶選擇的COM端口。