Private Sub MSComm1_OnComm() If (MSComm1.InBufferCount >= 97) Then ' enough for a DEBUG packet? bs1Buffer = bs1Buffer & MSComm1.Input ' yes, transfer to work buffer End If End Sub Private Sub Parse_Debug_Packet() Dim syncStr As String Dim foundSync As Long Dim checkLen As Long Dim idx As Byte syncStr = String$(17, &HF0) & String(1, &H5A) ' create sync string foundSync = InStr(1, bs1Buffer, syncStr, vbTextCompare) ' is it in the packet? If (foundSync > 0) Then ' if > 0, yes checkLen = Len(bs1Buffer) - (foundSync + 18) ' do we have the whole packet? If (checkLen >= 32) Then bs1Buffer = Mid$(bs1Buffer, (foundSync + 18)) ' remove sync header bs1IORegs(0) = Asc(Mid$(bs1Buffer, 18, 1)) ' DIRS bs1IORegs(1) = Asc(Mid$(bs1Buffer, 17, 1)) ' PINS (out) bs1IORegs(2) = Asc(Mid$(bs1Buffer, 7, 1)) ' PINS (in) For idx = 0 To 13 bs1ByteRegs(idx) = Asc(Mid$(bs1Buffer, (19 + idx), 1)) Next For idx = 0 To 6 bs1WordRegs(idx) = (CLng(bs1ByteRegs(idx * 2 + 1)) * 256) _ + bs1ByteRegs(idx * 2) Next bs1Buffer = Mid$(bs1Buffer, 32) ' clear current debug values End If End If End Sub