PDA

Click to See Complete Forum and Search --> : rs232 serial


rattack
Dec 26th, 2001, 12:08 AM
I have a phototransistor attached to my serial port which turns on and of and sends pulses to the port.What i need to do is time how long between between pulses and display in text box.
I am assuming mscomm is the best way to do this..as well as a timer of some description.
Is this correct if so can someone point me to a good tutorial where I can learn how to do this.

Thankyou:cool: :cool:

Kraig K
Dec 26th, 2001, 10:28 AM
I'm also currently doing some things with rs232, here's parts of my code that should get you started.


Public Sub Form_Load()
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm() 'COM1
Dim InBuffer As String
Select Case MSComm1.CommEvent

'Events
Case comEvReceive
'start timer here
End Select
End Sub


The above code will open the comm port and trigger the CommEvent whenever something comes in the port. So just start the timer where I've noted then stop it when the next pulse comes in, need an IF statement. I'm not sure how to figure out how much time has elapsed but I'm thinking the MSComm control was giving you the most problems. Don't forget to set your port settings and close the port in Form_Unload. The port settings may give you a little trouble, but you should be able to get it. I learned how to use MSComm through the help system.

rattack
Dec 26th, 2001, 02:52 PM
Thanks Kraigk,

That has got me going.Maybe you can answer another question.
As I metioned I want to count time between pulses.If I start timer at first pulse and stop it at second,can I also restart the timer at the second pulse to time from second to third???I do not want to miss any pulses or have gaps in timing.This is very important to my project.I will also need to time down to milliseconds to be accurate.:D :D :D

Kraig K
Dec 26th, 2001, 04:00 PM
I think every time you enable a timer, it starts back at zero. I haven't used them that much so maybe there is an option, look thru the online MSDN. If I think of something I'll post back, time to go home! :D

The Online MSDN contains everything that the CD's do.

http://msdn.microsoft.com/default.asp

dbarr
Dec 27th, 2001, 02:12 PM
Instead of a time rtry using the API. Declare the follwing in a module:

Public Declare Function GetTickCount Lib "kernel32" () As Long

Then you can use a sub like this:

Public Sub WaitFor(mSeconds As Long)
Dim prevTime As Long
prevTime = GetTickCount
Do Until GetTickCount >= prevTime + mSeconds
DoEvents
Loop
End Sub

dbarr
Dec 27th, 2001, 02:24 PM
Sorry that was a Delay routine I use...

But the GetTickCount can be used to give you the number of milliseconds since you started Windows.