I have a visual studio program to send instruction to Arduino uno. But when I try to compile I see the following error.
"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
"
Can any one please help me to solve this problem?
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
I think the variable name in the below line is conflicting.
Shared _serialPort1 As SerialPort
Try renaming the variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.