Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With mscomm control exists the same problem. Work with async events always its harded. </p> <p>First that is my personal way of deal with it probably exist other way better. so it is one option more.</p> <p>I've run into this problem more than one times and it often i forget how deal with that. so that also be my personal reference</p> <p>First the idea</p> <pre><code>create time of expiration when it became to be reached the information should be complete </code></pre> <p>well we need understand how the events happen</p> <p>Graphic view that be the dead time, the dead time just is a time period</p> <p><img src="https://i.stack.imgur.com/hoNoh.png" alt="Dead Time view"></p> <p>Now in vb6 when async events happen also need to happen two actions in different instant but are tested in the same moment</p> <pre><code>Action #1 that action update the current time </code></pre> <p><img src="https://i.stack.imgur.com/Bjjy2.png" alt="Recurrent time"></p> <pre><code>Actions #2 that is limited to update the time current time for async event </code></pre> <p><img src="https://i.stack.imgur.com/ZwxMW.png" alt="update time for async event"></p> <pre><code>Both event are combined on one infinity loop method the purpose is check current time against the current time of async event </code></pre> <p><img src="https://i.stack.imgur.com/WhIM4.png" alt="verification for both counter times"></p> <p>Also we will need some utility for keep track of time i used the win api GetTickCount</p> <p>In mscomm also we will need add flag and string for know if some was received it for not wait so much in call to interface in the port</p> <p>Also that code can throw event it for reuse and isolate</p> <p>now see the skeleton of vb6 class</p> <pre><code>class Module SocketReceptorVb6 Private Declare Function GetTickCount Lib "kernel32" () As Long ' API tick withevents _tcpControll as Winsock private m_currentState As Eventstate 'is a enumerate Waiting, Receiving private m_currentTimeAsynEvent As Long ' current time for async event private m_buffer As String private m_timeOut as Long Public Event StreamReceived(ByVal stream As String) 'Event completed Property TimeOut private sub Class_Initialize() m_currentState = Waiting end sub sub tcpControl_DataArrival(bytesTotal) sub Receiving sub InitFlags End Class </code></pre> <p>well now look at the 3 methods more closely</p> <pre><code>InitFlags Method </code></pre> <p>That clean variables and prepare the ambient, see the content</p> <pre><code>m_currentState = Waiting //state of the process m_buffer = vbNullString //reset the buffer used for the information </code></pre> <p>  </p> <pre><code>tcpControl_DataArrival Method </code></pre> <p>That method have the next responsibilities</p> <pre><code> -update buffer -initialize infinity loop -update m_currentTimeAsynEvent </code></pre> <p>content of the method</p> <pre><code>Dim sBuff As String wskConnect.GetData sBuff, vbString m_buffer = m_buffer &amp; sBuff ' update time for Asyn Event m_currentTimeAsynEvent = GetTickCount() if m_currentState = Waiting then m_currentState = Receiving InfinityLoop() end if </code></pre> <p>  </p> <pre><code>InfinityLoop Method verify that the expiration time has been reached </code></pre> <p> </p> <pre><code>Content method Dim current_time As Long ' the time point o current time Do current_time = GetTickCount() ' timeout reach, exit of loop If current_time &gt; m_currentTimeAsynEvent + m_timeOut Then Exit Do End If DoEvents Loop RaiseEvent StreamReceived(m_buffer) InitFlags 'Reset flags and variables </code></pre> <p>Note: <strong>that code expected lead with a single stream not multiple socket responses</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload