WaitForEvent method failed Error 87

LeeBaron
2012-02-16
2013-04-30
  • LeeBaron
    LeeBaron
    2012-02-16

    Hi
    I am getting this error

    code:

    ComPort.WriteStr(data);
    WaitForEvent( events, 0 ,1000);     
    // no error here. by the way WaitForEvent( events, nil ,1000) as documented does not work
    ComPort.WriteStr(data);
    WaitForEvent( events, 0 ,1000);      //  WaitForEvent method failed Error 87

    events is     // sqare bracket

    What is error 87, where to look for?

    Lee

     

  • Anonymous
    2012-10-31

    Set events :=  before every call of WaitForEvent.

     
  • yTake
    yTake
    2012-11-29

    I have a question same as WaitForEvent. 

    vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    var
        evts  : TComEvents;
    begin
        ComPort1.ClearBuffer( True, True );
        if ComPort1.Connected = True then
            ComPort1.Close();
        try
            ComPort1.Events :=  ;
            ComPort1.EventChar  :=  LF;
            ComPort1.Open();
            evts  :=  ;
            ComPort1.WriteStr( cmd );
            ComPort1.WaitForEvent( evts, 0, 3000 );
            if  evRxFlag  in  evts  then
            begin
                Memo2.Lines.Add( rev_str );
            end;

        finally

        end;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    This skip "Memo2.Lines.Add( rev_str );" part. 
    Even communication recieve 'LF' (#$A)!

    How do I catch the event receiving 'LF'. 

    I am looking forward to someone answer. 

    Thank you. 

     
  • yTake
    yTake
    2012-11-30

    You mean like this to use BBCode ? 

    I have a question same as WaitForEvent.
    vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    var evts : TComEvents;
    begin
        ComPort1.ClearBuffer( True, True );
        if ComPort1.Connected = True then ComPort1.Close();
        try
            ComPort1.Events := ;
            ComPort1.EventChar := LF;
            ComPort1.Open();
            evts := ;
            ComPort1.WriteStr( cmd );
            ComPort1.WaitForEvent( evts, 0, 3000 );
            if evRxFlag in evts then
            begin
                Memo2.Lines.Add( rev_str );
            end;
        finally

        end;
    end;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    This skip "Memo2.Lines.Add( rev_str );" part.
    Even communication recieve 'LF' (#$A)!
    How do I catch the event receiving 'LF'.
    I am looking forward to someone answer.
    Thank you.

     
  • yTake
    yTake
    2012-11-30

    Sorry I made mistake to post. 

    more information for this situation. 
    I put "OnRxFlag" event rutine.  And it works properly if I do not use "WaitForEvent"
    Also I receive all other characters "OnRxChar" event and copy all characters to Memo field "OnRxFlag",

    But when I use "WaitForEvent", it does not work. 

    Please advise. 

     
  • You misuse the WaitForEvent, it is an Internal call not to be used in this way.
    Review examples included with ComPort.

     
  • yTake
    yTake
    2012-11-30

    Thanks. 

    There are only two sample source code however there is no usage of "WaitForEvent". 
    I have referred to ComPort Lib help file. 
    Yes, of course, there are same method for internal use but there are described clearly not call directry.  But "WaitForEvent" is not mentioned so that "WaitForEvent" can be called directly, am I wrong understanding? 

    Then, I should use "sleep" to wait LF character. 

     
  • Again; You misuse the WaitForEvent, it is an Internal call not to be used in this way.
    Review examples included with ComPort.

    You can NOT send a string and then just wait for a response string.
    Review examples included with ComPort.

     
  • yTake
    yTake
    2012-12-02

    Yes, I had reviewed attached sample however there is no sample code using "WaitForEvent" so that I post here. 
    There are only two sample source code files such as "ComMainForm.pas" and "MTMainForm.pas" for DELPHI. 
    Did you find WaitForEvent example in those files? 

    If not, Is it possible to show sample source code for WaitForEvent here ? 

     
  • It is NOT POSSIBLE to use the WaitForEvent as you wish.

     
  • yTake
    yTake
    2012-12-04

    Thank you very much for your advise. 

    I see.  It is not possible to do

    By the way, what should I do in case of following.

    With communication to the serial device, it is command to send to device and it must reply as string terminated with #$0D, #$0A and it have to be wait before sending next command. 

    I did so with using sleep procedure, not Event .  (This can be OK)

    With using "OnRxChar" and "OnRxFlag" then successfully receiving answer telegram and detecting #$0A but it can not wait sending next command.  May be my source code is bad. 

     
  • Study examples;
    Use ComDataPack;
    Review ComDataPacket component events for ideas on how to implement or Comport OnRxBuf event.
    Avoid using sleep or anything like that.

    Send your string and exit;  otherwise you will be BLOCKING all other user interface events waiting for response.
    wait for the events of the onRxbuf or ComDataPacket to occur before you continue.
    You must become familiar with the event driven nature of Windows.

     
  • yTake
    yTake
    2012-12-06

    Thanks a lot. 

    I try to use ComDataPacket.