Android Question Bosch Distance Laser GLM Serie

Wolli013

Well-Known Member
Licensed User
Longtime User
Does anyone here use the Bosch GLM50C or similar?
I would like to make a small app where only the measurement data is transmitted and displayed via BLE.
Does anyone have something like this running?
I have only found the Python code so far.

 

Wolli013

Well-Known Member
Licensed User
Longtime User
Many thanks to everyone!
I've now got it working so far.
I now have to refine everything further.
Here is the readout code.
B4X:
Private Sub AStream_NewData (Buffer() As Byte)

    Dim RawInt As Int = Bit.ShiftLeft(Bit.And(Buffer(5), 0xFF), 24) + _
                        Bit.ShiftLeft(Bit.And(Buffer(4), 0xFF), 16) + _
                        Bit.ShiftLeft(Bit.And(Buffer(3), 0xFF),  8) + _
                        Bit.ShiftLeft(Bit.And(Buffer(2), 0xFF),  0)
                        
    Dim distance As Float = RawInt * 0.05/1000 'Direkt vom Laseranfang wird gemessen   
    Log("Distance: " & distance)

    distance = distance + 0.105    'Es wird vom Gerätende gemessen
    Log(NumberFormat(distance, 0, 3))

End Sub
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Maybe you can help me again.
The laser measurement works very well.
But it should also be possible to read the values directly from the device when measuring. now I always have to start the laser in the app. Here is some information that I found.
B4X:
Sub info
    
'Bosch GLM 50/100c Bluetooth PC-serial Measurement Log
'
'The following will put the laser into a mode where each measurement taken will be transmitted over bluetooth serial port profile.
'
'The device(s) send Min, Max, And current values immediately upon completing a measurement.
'To connect To your device, open the virtual COM port associated with your bluetooth driver (usually COM6). Your serial terminal must support HEX data, And allow To turn off CR/LF on transmit.
'
'Enable Logging:
'C0 55 02 01 00 1A
'
'Device responses will look like:
'
'[ Header         ][ #    ][ Err    ][ Curr        ][ Min        ][ Max        ][ Checksum ]
'
'Examples:
'C0 55 10 0A 08      6A     00     DC D7 C1 3F     4E D1 C1 3F     C6 DC C1 3F     3C  //1.514, 1.515, 1.515, 90 deg, back laser
'C0 55 10 0A 08      6B     00     A0 F8 BD 3F     F7 E4 BD 3F     C6 DC C1 3F     8A  //1.484, 1.515, 1.484, 90 deg, back laser
'C0 55 10 0A 08      6C     00     13 F2 BD 3F     F7 E4 BD 3F     C6 DC C1 3F     84  //1.484, 1.515, 1.484, 90 deg, back laser

'This is the measurement data that is received

End Sub
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
I've been trying to figure it out all day.
No idea if it works at all.
I have copied the value I get when I measure directly with the laser. The value is exactly 1.825 meters.
Maybe that will help.
If you are annoyed by me, I can completely understand that.
I am glad that you have already helped me so far that it works at all.

Buffer = C0551006080208E09CE93F000000000000000006
= 1.825 Meter
 
Upvote 0

emexes

Expert
Licensed User
I've been trying to figure it out all day.
Trying to figure *what* out?

Is the problem that this received buffer:

Buffer = C0551006080208E09CE93F000000000000000006

does not match the 1.825 metres that is shown on the display?

Let me work that out by hand (because I don't have B4J etc on my laptop here).

32-bit hex value is bytes 2 to 5, with byte at array index 2 being the "little end".

So is 0x02080610 = 34080272 decimal

scale by 0.05 / 1000 (or divide by 20000) to get 1704.013 mm

This is in the ballpark of your 1825 mm, but I agree it is not exacly 1825 mm.

Can you give us some more buffer examples, say for display readings 500 mm, 1000 mm, 1500 mm and 2000 mm?

As in give us the display readings (might not be exactly xx00 mm) and the corresponding buffer hex strings.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
'SendCommand-Buffer = C05510060834081B0D003F0000000000000000F6 = 50cm
'SendCommand-Buffer = C0551006083A089DEF7F3F0000000000000000EA = 100cm
'SendCommand-Buffer = C0551006083C0815FBBF3F0000000000000000A0 = 150cm
'SendCommand-Buffer = C055100608420831080040000000000000000068 = 200cm

when I read out the laser via my app, I still have to add distance = distance + 0.105 because the laser only measures from the front end and not from the end of the device.
Perhaps this difference is present in the specified dimensions.

the normal measurement via the app works wonderfully, the only thing missing is that I can start and end the measurement on the device and it is then transferred to the app.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
when I read out the laser via my app, I still have to add distance = distance + 0.105 because the laser only measures from the front end and not from the end of the device.
sounds like you need to set the measure-starting.-point in the device-settings.
There is a setting for TOP, BASE and middle of the device i guess.
Check the documentation.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
sounds like you need to set the measure-starting.-point in the device-settings.
There is a setting for TOP, BASE and middle of the device i guess.
Check the documentation.
Yes, I did, so that it starts to measure at the end because you usually hold the device on the floor or on the wall, but the transmission via Bluetooth always only gives the value from the front of the device where the laser is located.
 
Upvote 0

emexes

Expert
Licensed User
Even before checking the latest sample data,
just going off the 1704.013 mm vs expected 1.825 m from post #44,
I'm going to predict that you've found the missing offset:
I still have to add distance = distance + 0.105 because the laser only measures from the front end and not from the end of the device.
?
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
I'll try to explain it again.
There are 2 ways to measure with the laser.
Option 1
From the app, the laser is started and measurement results are received. This works wonderfully. Only 0.105 m needs to be added.
The measurement is started with :
Dim Measure() As Byte = Array As Byte(0xC0, 0x40, 0x00, 0xEE)'measure
B4XPages.MainPage.SendCommand(Measure)

I then get the following values:
SendCommand-Buffer = 00044A86000016 --> at exactly 1.824m

Option 2
The measuring device is used to start the measurement data by pressing a button, which is otherwise also standard. However, I would like to receive the data via Bluetooth even if I press the button on the measuring device.
The logging is started with :
Dim Logging() As Byte = Array As Byte(0xC0, 0x55, 0x02, 0x01, 0x00, 0x1A)'logging
B4XPages.MainPage.SendCommand(Logging)

I then get the following values:
SendCommand-Buffer = C0551006080208E09CE93F000000000000000006--> at exactly 1.825m

How do I get the data from this result as in option 1?
 
Upvote 0

emexes

Expert
Licensed User
Option 1
SendCommand-Buffer = 00044A86000016 --> at exactly 1.824m

Option 2
SendCommand-Buffer = C0551006080208E09CE93F000000000000000006--> at exactly 1.825m

Any chance of getting readings for Option 1 and Option 2 at the same exact distance?

I am starting to wonder if in Option 1 the value is encoded as integer, and in Option 2 the value is encoded as floating point:

HTML:
'SendCommand-Buffer = C0551006083C0815FBBF3F0000000000000000A0 = 150cm   1500 mm
             Buffer = C0551006080208E09CE93F000000000000000006 =         1825 mm
'SendCommand-Buffer = C055100608420831080040000000000000000068 = 200cm   2000 mm


'SendCommand-Buffer = C055100608 3C0815FBBF3F 0000000000000000A0 = 150cm   1500 mm
             Buffer = C055100608 0208E09CE93F 000000000000000006 =         1825 mm
'SendCommand-Buffer = C055100608 420831080040 000000000000000068 = 200cm   2000 mm
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
'SendCommand-Buffer = 00045B86000096 = Distance: 1.720 Einstellung Laser vorne
'SendCommand-Buffer = C0551004086F08DA1BDC3F0000000000000000CC = Distance: 1.720 Einstellung Laser vorne
'SendCommand-Buffer = C0551006087408B5A6E93F0000000000000000E4 = Distance: 1.825 Einstellung Laser hinten
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
some code in B4J

This function:
B4X:
Sub ExtractDistanceOption2(Buffer() As Byte) As Float
    
    Dim FourBytes() As Byte = Array As Byte(Buffer(10), Buffer(9), Buffer(8), Buffer(7))
    
    Dim bc As ByteConverter
    Dim OneFloat() As Float = bc.FloatsFromBytes(FourBytes)
    
    Return OneFloat(0)
    
End Sub

tested with this:
B4X:
Dim SamplePackets(4) = Array As String(         _
    "C0551006083C0815FBBF3F0000000000000000A0", _
    "C0551004086F08DA1BDC3F0000000000000000CC", _
    "C0551006080208E09CE93F000000000000000006", _
    "C055100608420831080040000000000000000068"  _
)

For I = 0 To SamplePackets.Length - 1
    Dim bc As ByteConverter
    Dim Buffer() As Byte = bc.HexToBytes(SamplePackets(I))

    Dim Distance As Float = ExtractDistanceOption2(Buffer)
    
    Log(NumberFormat2(Distance, 1, 3, 3, False) & TAB & bc.HexFromBytes(Buffer))
Next

produces this:
Log output:
Waiting for debugger to connect...
Program started.
1.500    C0551006083C0815FBBF3F0000000000000000A0
1.720    C0551004086F08DA1BDC3F0000000000000000CC
1.825    C0551006080208E09CE93F000000000000000006
2.000    C055100608420831080040000000000000000068

<JOKE>
My invoice is in the mail. ?
</JOKE>
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Yes, it works wonderfully!
You are a good person.
1000 times thank you for helping me.
If we ever meet, I'll buy you a drink!
 
Upvote 0

emexes

Expert
Licensed User
in Option 1 the value is encoded as integer, and in Option 2 the value is encoded as floating point

These functions:
B4X:
Sub ExtractDistanceOption1(Buffer() As Byte) As Float
  
    Dim FourBytes() As Byte = Array As Byte(Buffer(5), Buffer(4), Buffer(3), Buffer(2))
  
    Dim bc As ByteConverter
    Dim OneInt() As Int = bc.IntsFromBytes(FourBytes)
  
    Return OneInt(0) * 0.00005 + 0.105
  
End Sub

Sub ExtractDistanceOption2(Buffer() As Byte) As Float
  
    Dim FourBytes() As Byte = Array As Byte(Buffer(10), Buffer(9), Buffer(8), Buffer(7))
  
    Dim bc As ByteConverter
    Dim OneFloat() As Float = bc.FloatsFromBytes(FourBytes)
  
    Return OneFloat(0)
  
End Sub

tested with this:
B4X:
Dim SamplePackets(4) = Array As String(         _
    "C0551006083C0815FBBF3F0000000000000000A0", _
    "C0551004086F08DA1BDC3F0000000000000000CC", _
    "C0551006080208E09CE93F000000000000000006", _
    "C055100608420831080040000000000000000068", _
    "00044A86000016"                            _
)

For I = 0 To SamplePackets.Length - 1
    Dim bc As ByteConverter
    Dim Buffer() As Byte = bc.HexToBytes(SamplePackets(I))
  
    If Buffer.Length > 10 Then    'distance at bytes 7 to 10
        Dim Distance As Float = ExtractDistanceOption2(Buffer)
    Else if Buffer.Length > 5 Then    'distance at bytes 2 to 5
        Dim Distance As Float = ExtractDistanceOption1(Buffer)
    Else
        Dim Distance As Float = -1
    End If
      
    Log(NumberFormat2(Distance, 1, 3, 3, False) & TAB & bc.HexFromBytes(Buffer))
Next

produce this:
B4X:
Waiting for debugger to connect...
Program started.
1.500    C0551006083C0815FBBF3F0000000000000000A0
1.720    C0551004086F08DA1BDC3F0000000000000000CC
1.825    C0551006080208E09CE93F000000000000000006
2.000    C055100608420831080040000000000000000068
1.824    00044A86000016

<JOKE>
Invoice adjusted proportionately. ??
</JOKE>
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Hello friends, I now have a new laser measuring device from Bosch, the GLM 50-27 C.
This device no longer transmits an advertising stream and must first be connected via the Bosch UUID.
My question is, can I use the same connection code or does it have to run via BLE?
 
Upvote 0

Sickculture

New Member
Hi, I´m reading all your codes and its hard to understand this as non scripter, but I read rangefinder and Bosch. I´ve got a GLM-120C (and a Mileseey D9pro). Both with bluetooth. I´m working on field with a geo app called QGIS and QField. It would be great, to read out the distance, vertical pitch (degree) and perhaps in indirect triangulation measure the linear distance, the pitch and the result of height and length to the upper diagonal point. And all in text csv file for import in QGIS/Qfield. How to get these values in a "simple" workflow?
 
Upvote 0
Top