|
-
Dec 26th, 2001, 01:08 AM
#1
Thread Starter
Lively Member
rs232 serial
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
Thankyou for any and all help. It is greatly appreciated
-
Dec 26th, 2001, 11:28 AM
#2
Addicted Member
I'm also currently doing some things with rs232, here's parts of my code that should get you started.
Code:
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.
-
Dec 26th, 2001, 03:52 PM
#3
Thread Starter
Lively Member
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.
Thankyou for any and all help. It is greatly appreciated
-
Dec 26th, 2001, 05:00 PM
#4
Addicted Member
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! 
The Online MSDN contains everything that the CD's do.
http://msdn.microsoft.com/default.asp
-
Dec 27th, 2001, 03:12 PM
#5
Lively Member
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
-
Dec 27th, 2001, 03:24 PM
#6
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|