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 に答える