Hi to everyone,
I wrote a software that sends strings to a servo-motor via COMM port while pressing arrow keys.
The movement starts on keydown event and should stop on keyup event.
The problem is that sometimes the software hangs after a keydown string and this prevents from receiving keyup string and going on.
Can anyone find out the bug in this code that causes this problem?
Thanks for your attention.
Code:Private Sub Form_Load()
MSComm2.CommPort = Combo4.ListIndex
' speed 9600, no parity, 8 data bit and 1 stop bit
MSComm2.settings = "9600,N,8,1"
MSComm2.InBufferSize = 1024
' open port
MSComm2.PortOpen = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> KeyCode1 Then
KeyCode1 = KeyCode
Stringa = ""
Select Case KeyCode
Case vbKeyLeft And Shift = 1
Stringa = "#:Me#"
Case vbKeyRight And Shift = 1
Stringa = "#:Mw#"
Case vbKeyUp And Shift = 1
Stringa = "#:Ms#"
Case vbKeyDown And Shift = 1
Stringa = "#:Mn#"
Case Else
End Select
If Stringa <> "" And MSComm2.PortOpen Then
MSComm2.Output = Stringa
TastoPremuto = True
End If
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If TastoPremuto Then
If MSComm2.PortOpen Then
MSComm2.Output = "#:Q#"
End If
KeyCode1 = 0
TastoPremuto = False
End If
End Sub

