Hello,
I am using sleeping delay between in my application - send the first serial packet and then delay a few seconds and then send the 2nd packet. The data to be sent is stored in SequenceBuffer(n1,num). The first string is teh first packet to be sent. The second string is delay value and the 3rd string is the 2nd packet to be sent. So in my code when n1 is 1 (the 2nd string), I delay a few seconds based on the string value in SequenceBuffer(1,num)

I expect after the 1st packet is sent, there is a delay. But the delay occurred before the 1st packet sent and then sent both packets. TO make it simple, I changed to delay 10seconds. Any idea?

Private Sub SendSequenceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendSequenceButton.Click
Dim n1, n2 As Byte
Dim DelaySecond As String = ""
If SequenceBuffer(0, 0) = 0 Then 'if theere is at least one sequence active, SequenceBuffer(0, 0) is not 0
MsgBox("No Active Sequence! Please Open Esisting One or Create a New One")
Exit Sub
End If

'send all packets in sequence
For n1 = 0 To 100
If SequenceBuffer(n1, 0) = 0 Then
Exit For
Else 'if valid packet
If n1 = 1 Then
Threading.Thread.Sleep(10000)
Else
SendBuffer(0) = SequenceBuffer(n1, 0) 'format
BytesSent = (SendBuffer(0) >> 4) + 1
For n2 = 3 To BytesSent - 2
SendBuffer(n2) = SequenceBuffer(n1, n2)
Next
SendBuffer(BytesSent - 1) = CalCheckSum(SendBuffer, BytesSent - 2) 'checksum

SendPacket(BytesSent)
End If

End If
Next
End Sub