0

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

"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
4

1 回答 1

1

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

Shared _serialPort1 As SerialPort

尝试重命名变量。

于 2012-11-20T09:56:04.017 回答