binary serial input problem

lucifer1

Member
Solved: binary serial input problem

:sign0085:

I have a problem with evaluating the serial incomming stream.

I am trying to tune my GPS mouse

I can:
- open the serial port
- send binary commands to the mouse

now the problem:
The mouse is sending permanently the NMEA string to the com port.
When I send a binary command to the mouse it returns the binary string as confirmation. This binary string is just somewhere in the middle of the NMEA string.

I am not interrested in the NMEA string evaluation, I just want to find the binary data.

I am successfull sending the array "Dim command(56) as byte" to the mouse.

Why is the code below not working??

Thanks for your help
Christoph

B4X:
Sub serial1_OnCom
   if serial1.inbuffercount > 10 then
      buffer() = serial1.InputArray   'take the serial data into buffer
      
      ' search the array for the code sequence 
      ' stored in the array command() 
      
      for i = 0 to (ArrayLen (buffer())-7)
      ' only check the first 6 bytes
         for j = 0 to 5
            last.text= buffer(i+j)
            if buffer(i+j) <> command(j) then exit
         next j
         if j = 5 then
            select buffer(i+6)
            case 2
            last.text= "command OK"
            mode.text= "Pedestrian"
            case 3
            last.text= "command OK"            
            mode.text= "Automotive"
            case 6
            last.text= "command OK"
            mode.text= "Airborne <2g"            
            case else
            last.text= "FAILED"                     
            mode.text= ""   
            end select
            exit 
         end if
      next
   end if
End Sub
 
Last edited:

lucifer1

Member
Thanks for the Hint Erel,

Command is in total 56 Byte long

the first are:
181
98
6
26
40
0
2 This is the byte I need to check (Value 2, 3 or 6)
0
0
0
3
3
 

lucifer1

Member
I finally solved the problem.

For whatever reason the call

Sub serial1_OnCom

did occur only once or twice and the stopped. Therefore I never got the necessary data.

now I use a timer.
B4X:
Sub timer1_tick
   'textbox1.Text = serial1.InputString
   if serial1.inbuffercount > 90 then
      Timer1.Enabled = false
      Timer2.Enabled = true
      buffer() = serial1.InputArray   'take the serial data into buffer
      
      ' search the array for the code sequence 
      ' stored in the array pede() 
      
      for i = 0 to (ArrayLen (buffer())-7)
      ' only check the first 4 bytes
         for j = 0 to 3
            if buffer(i+j) <> pede(j) then exit
         next j
         if j = 4 then
            select buffer(i+6)
            case 2
            mode.text= "Pedestrian"
            case 3
            mode.text= "Automotive"
            case 6
            mode.text= "Airborne <2g"            
            end select
            if command > 0 then
               if    buffer(i+6) = command then
                  last.text= "Command OK"   
               else
               end if
            else 
               last.text= ""   
            end if
            exit 
         else if j = 2
            if buffer (i + 2) = 5 and buffer (i + 3) = 1 then last.text= "Config saved OK"   
         end if
      next
      if last.Text = "wait reply..." then last.Text = "FAILED" 
   end if
End Sub
Here is the full application: Set_WBT201
 
Last edited:
Top