No announcement yet.

Multi-Thread question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Wyman A Belts
    Guest replied
    Hi Scott,
    I think you posted something about this before, and I've done
    some research since then. I've been successfully using a
    variation of the following code for awhile now and it works fine.
    Tom Hanlin said something about Ring detection being inconsistent,
    but it's worked fine for me on a lowball Win LT modem on Win2000
    and Windows Millenium. Anyway, here goes:

    #Compile Exe "C:\RINGTEST.EXE"
    #Include ""
    Function CommWait(ByVal PortHandle As Long) As Long
      Dim EventMaskIn As Long             'Bit Map Of Event that occured
    'Tell Win32 What To Wait For:
      Call SetCommMask(PortHandle, %EV_RING)
    'Now Wait:
      Call WaitCommEvent(PortHandle, EventMaskIn, ByVal 0&)
      Print "Ring Detected"
    End Function
    Function WinMain(ByVal hCurInstance   As Long, _
                     ByVal hPrevInstance  As Long, _
                     lpszCmdLine          As Asciiz Ptr, _
                     ByVal nCmdShow       As Long) Export As Long
      Dim hComm                           As Long
      Dim hCommPB                         As Long
      Dim hThread                         As Long
      Dim RingDetected                    As Long
    'Open a PB Comm Port:
      Comm Open "COM3" As #hCommPB
    'Get The Win32 Handle:
      hComm                               = FileAttr(hCommPB, 2)
    'Set The Comm Port Params:
      Comm Set #hCommPB, Baud             = 57600
      Comm Set #hCommPB, Byte             = 8
      Comm Set #hCommPB, Parity           = %False
      Comm Set #hCommPB, Stop             = 0
      Comm Set #hCommPB, TxBuffer         = 2048
      Comm Set #hCommPB, RxBuffer         = 4096
      Thread Create CommWait(hComm) To hThread
        Sleep 500
        Thread Status hThread To RingDetected
      Loop Until RingDetected = 0           'Thread's Dead
      Print "Press Any Key To End"
      Comm Close #hCommPB
    End Function
    Good Luck!!!!

    [email protected]

    [This message has been edited by Wyman A Belts (edited July 05, 2000).]

    Leave a comment:

  • Guest
    Guest replied
    Check out the COMMTIMEOUTS and ReadFile APIs. ReadFile and CTO
    can do your "sleeps" while waiting for a specified number of
    characters to be received. If you are writing for NT you can use
    the SetCommMask and WaitCommEvent APIs to wait for a ring.


    Leave a comment:

  • Lance Edmonds
    The thread would just have to loop around until COMM(#hComm, RXQUE) was non-zero. Because this thread would not contain any GUI related code, DIALOG DOEVENTS would not be necessary unless another thread was causing starvation of the monitoring thread. Therefore, the thread would use no GDI resources and with the appropriate SLEEP time-slice releasing, would use a very low level of CPU time.

    One note: DIALOG DOEVENTS is a PB/DLL statement, so you need to write your own message loop for PB/CC, but one important fact is that that a PB/CC app should never do this unless it really does create a GUI window (which is allowed to be hidden). Without a GUI window, you will run into GPF problems on some versions of Windows.

    Since you are a registered PB/DLL 6.0 customer Scott, check out the COMM.BAS example in the SAMPLES folder - the COMM 'Receive' thread should be easily modified to poll for receive buffer activity, which can them be examined for the "RING" + CHR$(13,10) stream. I'm not at my DEV PC to check, but I seem to remember using a thread in the PB/CC example too.

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Scott Turchin
    started a topic Multi-Thread question

    Multi-Thread question

    If I want to build a ring detector for COMM work, and I want to spawn a simple thread that just sits there and listens for a RING, how would I do a Dialog Doevents so the thread didn't use any resources if nothing was happening on the line.


    mailto:[email protected][email protected]</A>
    MCSE, MCP+Internet