Results 1 to 6 of 6

Thread: rs232 serial

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Sunny Queensland
    Posts
    91

    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

  2. #2
    Addicted Member
    Join Date
    Aug 2001
    Location
    Minneapolis, MN
    Posts
    189
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Sunny Queensland
    Posts
    91
    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

  4. #4
    Addicted Member
    Join Date
    Aug 2001
    Location
    Minneapolis, MN
    Posts
    189
    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

  5. #5
    Lively Member dbarr's Avatar
    Join Date
    Oct 2001
    Location
    Syracuse, NY
    Posts
    86
    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

  6. #6
    Lively Member dbarr's Avatar
    Join Date
    Oct 2001
    Location
    Syracuse, NY
    Posts
    86
    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
  •  



Click Here to Expand Forum to Full Width