2012-11-16 167 views
0

我有一个视觉工作室程序发送指令到Arduino uno。但是当我尝试编译时,我看到以下错误。Arduino uno与Visual Studio 2008

"WithEvents variable 'SerialPort1' implicitly defines >'_SerialPort1', which conflicts with a member of the same name in class 'Form1'. C:\Users\*****\Desktop\WindowsApplication1\WindowsApplication1\Form1.Designer.vb 77 
" 

任何人都可以帮我解决这个问题吗?

Imports System.IO 
Imports System.IO.Ports 
Imports System.Threading 

Public Class Form1 
    Shared _continue As Boolean 
    Shared _serialPort1 As SerialPort 


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     SerialPort1.Close() 
     SerialPort1.PortName = "com31" 'change com port to match your Arduino port 
     SerialPort1.BaudRate = 9600 
     SerialPort1.DataBits = 8 
     SerialPort1.Parity = Parity.None 
     SerialPort1.StopBits = StopBits.One 
     SerialPort1.Handshake = Handshake.None 
     SerialPort1.Encoding = System.Text.Encoding.Default 'very important! 
    End Sub 



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     SerialPort1.Open() 
     SerialPort1.Write("1") 
     SerialPort1.Close() 
    End Sub 


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
     SerialPort1.Open() 
     SerialPort1.Write("0") 
     SerialPort1.Close() 
    End Sub 
End Class 

回答

1

我认为下面一行中的变量名是冲突的。

Shared _serialPort1 As SerialPort 

尝试重命名该变量。