H
<p>I have been trying to do following with my embedded board:
Send command, read response (parse string from the response), send another command, read response (parse string from the response)...
<p>Until now I have no success.
<p>I found that the when I parse the string in response to the 1st command issued and then I send another command, the board has already passed the instance where I want to send the command. How do I synchronize this?
<p>Here is the code I am using:
<pre>
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 4
MSComm1.Settings = "115200,N,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 0
MSComm1.DTREnable = True
MSComm1.PortOpen = True
Open "C:\K113.txt" For Append As #1
End Sub
Private Sub MSComm1_OnComm()
Dim strInput As Variant
Dim tmp As String
Dim val As Integer
tmp = ""
Select Case MSComm1.CommEvent
Case comEvReceive
strInput = MSComm1.Input
val = StrComp(tmp, strInput, vbTextCompare)
Do While (val <> 0)
strInput = MSComm1.Input
Print #1, strInput; 'send output to file, semicolon required
strBuf = strBuf & strInput 'append master buffer
If InStrRev(strBuf, "DRAM") Then
'if string found send another command to the board
MSComm1.Output = Chr$(13) + "printenv" + Chr$(13)
ElseIf InStrRev(strBuf, "gatewayip") Then
MSComm1.Output = Chr$(13) + "md 0x100000" + Chr$(13)
End If
Loop
End Select
Close #1
End Sub
Private Sub Reboot_Click()
Dim Reboot As Variant
Reboot = Chr$(13) + "reboot" + Chr$(13)
MSComm1.Output = Reboot
End Sub
</pre>
<p>How do I fix this? Any pointers? Any sample code? Examples?
Send command, read response (parse string from the response), send another command, read response (parse string from the response)...
<p>Until now I have no success.
<p>I found that the when I parse the string in response to the 1st command issued and then I send another command, the board has already passed the instance where I want to send the command. How do I synchronize this?
<p>Here is the code I am using:
<pre>
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 4
MSComm1.Settings = "115200,N,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 0
MSComm1.DTREnable = True
MSComm1.PortOpen = True
Open "C:\K113.txt" For Append As #1
End Sub
Private Sub MSComm1_OnComm()
Dim strInput As Variant
Dim tmp As String
Dim val As Integer
tmp = ""
Select Case MSComm1.CommEvent
Case comEvReceive
strInput = MSComm1.Input
val = StrComp(tmp, strInput, vbTextCompare)
Do While (val <> 0)
strInput = MSComm1.Input
Print #1, strInput; 'send output to file, semicolon required
strBuf = strBuf & strInput 'append master buffer
If InStrRev(strBuf, "DRAM") Then
'if string found send another command to the board
MSComm1.Output = Chr$(13) + "printenv" + Chr$(13)
ElseIf InStrRev(strBuf, "gatewayip") Then
MSComm1.Output = Chr$(13) + "md 0x100000" + Chr$(13)
End If
Loop
End Select
Close #1
End Sub
Private Sub Reboot_Click()
Dim Reboot As Variant
Reboot = Chr$(13) + "reboot" + Chr$(13)
MSComm1.Output = Reboot
End Sub
</pre>
<p>How do I fix this? Any pointers? Any sample code? Examples?