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.

 

walterf25

Expert
Licensed User
Longtime User
From what I understand this device has bluetooth connection, have you tried connecting to it via BLE, you should be able to implement the same code from the python script in B4A.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Yes, I have. I use this example program.
As soon as a connection is established, the connection is terminated.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Try the Bluetooth classic library instead, not the BLE.
 
Upvote 0

emexes

Expert
Licensed User
Try the Bluetooth classic library instead, not the BLE.

Or try a serial terminal emulation program, see if you can at least connect to the device without being disconnected.

If that is successful, then use Bluetooth (Classic) rather than Bluetooth (Low Energy) - they are different and not compatible, other than coexisting - and every few seconds alternate beween sending these two four-byte commands:

'backlight_on': b'\xC0\x47\x00\x20',
'backlight_off': b'\xC0\x48\x00\x62'

or in B4Xese:

Dim BacklightOn() As Byte = Array As Byte(0xC0, 0x47, 0x00, 0x20)
Dim BacklightOff() As Byte = Array As Byte(0xC0, 0x48, 0x00, 0x62)
 
Upvote 0

emexes

Expert
Licensed User
The definitive example seems to be this:


but your sending routine would be sending Byte Arrays rather than Strings:

B4X:
'Public Sub SendMessage (msg As String)
'    AStream.Write(msg.GetBytes("utf8"))
'End Sub

Public Sub SendCommand (cmd() As Byte)
    AStream.Write(cmd)
End Sub

Dim BacklightOn()  As Byte = Array As Byte(0xC0, 0x47, 0x00, 0x20)
Dim BacklightOff() As Byte = Array As Byte(0xC0, 0x48, 0x00, 0x62)

Do While True
    SendCommand(BacklightOn)
    Sleep(2000)
    SendCommand(BacklightOff)
    Sleep(2000)
Loop
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Where is this code supposed to go?
The connection is now maintained.

Dim BacklightOn() As Byte = Array As Byte(0xC0, 0x47, 0x00, 0x20)
Dim BacklightOff() As Byte = Array As Byte(0xC0, 0x48, 0x00, 0x62)

Do While True
SendCommand(BacklightOn)
Sleep(2000)
SendCommand(BacklightOff)
Sleep(2000)
Loop
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Do you have a link to it?
Maybe this one?
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Thanks DonManfred, the connection is established.
The only question is, how do I get the measurement data?
Bluetooth is not something I have much experience with.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Yes, but not how to get the measurement data.
That's why I posted a Github script above on how to do it in Python but not with B4A
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but not how to get the measurement data
have you tried to log what you get in the asyncstream newdata event after you started a Distancecalculation?

B4X:
Private Sub AStream_NewData (Buffer() As Byte)
' LOG the Buffer-Data to get inspired
End Sub
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Nothing is displayed

B4X:
Private Sub AStream_NewData (Buffer() As Byte)
    ChatPage1.NewMessage(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
    
    Log("AStream_NewData = "&BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
 
Upvote 0

emexes

Expert
Licensed User
how do I get the measurement data?

Walk before run.

Can you turn backlight off and on?

Sample code can go pretty much anywhere that runs after connection is established.

Or add two buttons to turn backlight on and off, and put the relevant code in the button handlers.
 
Upvote 0

emexes

Expert
Licensed User
how do I get the measurement data?

The clues are in:
Python:
'measure':          b'\xC0\x40\x00\xEE',
Python:
def measure(self):
    self.socket.send(self.cmds['measure'])
    data = self.socket.recv(1024)
    #print('received:', data)

    if self.status[data[0]] is 'ok':
        try:
            # distance to object from top of device
            distance = int(struct.unpack("<L", data[2:6])[0])*0.05
            #print(distance, 'mm')

but you'd be logging the data bytes like:
B4X:
Sub AStreams1_NewData(Buffer() As Byte)
    Dim bc As ByteConverter
    Log(bc.HexFromBytes(Buffer))
End Sub

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…