Expression expected VB.net

The error is expression expected on line 12
  Private Shared Sub InitializeComPort(port As String, baud As Integer)
            ComPort = New SerialPort(port, baud)
            ComPort.PortName = port
            ComPort.BaudRate = baud
            ComPort.Parity = Parity.None
            ComPort.StopBits = StopBits.One
            ComPort.DataBits = 8
            ComPort.ReceivedBytesThreshold = 9
            ComPort.RtsEnable = True
            ComPort.DtrEnable = True
            ComPort.Handshake = System.IO.Ports.Handshake.XOnXOff
            AddHandler ComPort.DataReceived, += New SerialDataReceivedEventHandler(OnSerialDataReceived)<-------------HERE is error
            OpenPort(ComPort)
        End Sub

Open in new window

LVL 6
r3nderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
The format of the AddHandler statement is different from your line of code:
https://msdn.microsoft.com/en-us/library/7taxzxka.aspx

eg.  AddHandler Obj.Ev_Event, AddressOf EventHandler


You should have something like the following
AddHandler ComPort.DataReceived, += AddressOf OnSerialDataReceived
0
Éric MoreauSenior .Net ConsultantCommented:
have a look at this other question. It is handling the events: http://www.experts-exchange.com/Programming/Languages/.NET/Q_27929112.html
0
AndyAinscowFreelance programmer / ConsultantCommented:
oops, didn't delete enough after copying your line of code:
AddHandler ComPort.DataReceived,  AddressOf OnSerialDataReceived
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Fernando SotoRetiredCommented:
Hi  r3nder;

Replace your line 12 with the following line
AddHandler ComPort.DataReceived, AddressOf ComPort_DataReceived

Open in new window

Then you need to create a event handler with the following signature.
 
Private Sub ComPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) 

    ‘’ Here you place your code to handle the received data

End Sub

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3nderAuthor Commented:
Thank you Mr Soto
0
Fernando SotoRetiredCommented:
Not a problem r3nder, glad to help.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Any reason you didn't want to split between the other experts who pointed out exactly the same but rather earlier?
0
r3nderAuthor Commented:
No not really - got a notification checked the answer and awarded points accordingly
0
AndyAinscowFreelance programmer / ConsultantCommented:
OK.  I'll try to remember you award to the last person how posts not the first with the correct answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.