By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Receiving Data From Serial Port & Starting a Timer - Visual Basic Express

P: 1
Alright. So I'm building a small timing system as a "beta" for a local racetrack. I know that the VB Timer is inaccurate .. But that's why it's a beta. I'm using Visual Basic Express 2010

I'm taking an infrared sensor, and connecting it to a microcontroller. The microcontroller will read the input of the sensor (whether it's broke or not) and then decide what it needs to do.

Here's how it's SUPPOSED to work together:

You choose how many laps of qualifying you would want to do on the VB program. 1 lap or 2 laps. The VB program will then send a string to the microcontroller saying whether it's 1 or 2 laps. Next, the microcontroller checks to make sure the infrared is not broke, and it's reflecting off of the reflector. If it is reflecting, the program will wait until the infrared beam is broke. Now it will send a string to the VB program. The VB program will decide what that string is supposed to mean. (Start or Stop the timer). The problem I'm having is getting the VB program to receive the data being sent, and doing something with it. Here is the code i'm using to send data to the microcontroller:
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents serialPort As New IO.Ports.SerialPort
  5. serialPort.Write("1") ' ThPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. If serialPort.IsOpen Then
  7. serialPort.Close()
  8. End If
  9. Try
  10. With serialPort
  11. .PortName = "COM5"
  12. .BaudRate = 9600
  13. .Parity = IO.Ports.Parity.None
  14. .DataBits = 8
  15. .StopBits = IO.Ports.StopBits.One
  16. .Handshake = IO.Ports.Handshake.None
  17. End With
  18. serialPort.Open()
  19. Catch ex As Exception
  20. MsgBox(ex.ToString)
  21. End Try
  23. End Sub
  25. Private Sub OneLap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OneLap.Click
  27. 'When you click OneLap it will show a bunch of labels, and other buttons.
  29. PictureBox2.Visible = True
  30. Label1.Visible = False
  31. Button1.Visible = False
  32. Button2.Visible = False
  33. Button3.Visible = True
  34. OneThousandths.Visible = True
  35. OneHundredths.Visible = True
  36. OneTenths.Visible = True
  37. OneDP.Visible = True
  38. OneSeconds.Visible = True
  39. Button4.Visible = True
  40. Button6.Visible = True
  41. Label2.Visible = True
  42. Label15.Visible = True
  43. Label16.Visible = True
  44. CheckBox1.Visible = Truee microcontroller reads "1" as 1 Lap Qualifying
  46. End Sub
This code above only shows what would happens when you click a button for 1 Lap Qualifying.

Here's what I need the VB Program to do:

When the Microcontroller sends a string of "1" it needs to start the timer. When it receives the string of "2" it needs to stop the timer.

(if it's two laps)

When the Microcontroller sends a string of "3" it needs to start the Lap One timer. When it Receives the string of "4" it needs to stop the Lap One timer and Start the Lap Two timer. When it receives the string "5" it needs to stop the Lap Two timer.

I am fairly new to this, so how would I do it??

Any help is appreciated!!

May 25 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.