Code Monkey home page Code Monkey logo

bosch-glm-rangefinder's Introduction

BOSCH GLM rangefinder

Python3 script to remote control a BOSCH GLM 100C or GLM 50C rangefinder.

This script provides remote control features for the BOSCH GLM 100C/50C measuring device via its Bluetooth serial interface. The device uses the transfer protocol as described in this blog post.

As the protocol seems to be identical for various Bosch measuring devices this script could also work for Bluetooth enabled rangefinders like PLR30C, PLR40C or PLR50C. If so please let me know!

Features

  • measure (returns distance millimeters)
  • turn laser on and off
  • turn display backlight on and off

Dependencies

The script was only tested on Windows. But since the Python module used is multi-platform, it should also support Linux and MacOS. See pybluez for further information.

Install pybluez for the Python3 interpreter via pip:

pip3 install pybluez

Run the script

Use the command line tool

python3 glm100c.py

Instructions on how to use get printed to the command line.

Import into your project

from glm100c import GLM100C

rangefinder = GLM100C()
if not rangefinder.connected: exit(1) 

distance = rangefinder.measure_from_tripod_socket()
if distance is not -1: print(distance, 'mm')

bosch-glm-rangefinder's People

Contributors

loran425 avatar maekos avatar philipptrenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bosch-glm-rangefinder's Issues

GLM 50C connect problem

Hi,
I used the glm50c,py for test, just slightly modified the original
changing from GLM100 to GLM50
and using only GLM50 for search string
adding prints to check

the result is:
/usr/bin/python3.5 /home/zoltan/PycharmProjects/MC50Boschlaser/glm50c.py
Searching for BOSCH GLM50C ...
Found BOSCH GLM50C @ 00:13:43:59:FC:1B
address:
00:13:43:59:FC:1B
Connecting to BOSCH GLM50C failed connect(self)
Could not connect to BOSCH GLM50C

Process finished with exit code 0

the address is the same if I connect manually, as can be seen on the picture.

what can be the solution?
best regards
Zoltan

connected

glm50c.txt

GLM50 Fail to connect

good afternoon,

I'm using MAC OS.

I can find the GLM50C but I cannot connect.
I even tried a fork that you had indicated in an issue that is closed and doesn't work.

can you help?

Searching for BOSCH GLM50C
Found BOSCH GLM50C @ b'00:13:43:85:21:53'
Trying to connect with GLM50C
Can't connect with GLM50C
Could not connect to GLM50C

Unable to measure after connecting to GLM50C

I patched the file that it can also find the GLM50C.

>>> rangefinder = GLM100C()
Searching for BOSCH GLM100C ...
BOSCH GLM50C X9225
Found BOSCH GLM100C @ 00:13:43:71:78:EF

but then a new error appeared on my Raspberry Pi Zero W with raspbian:

>>> rangefinder.measure_from_back()
Traceback (most recent call last):
  File "<string>", line 3, in send
_bluetooth.error: (9, 'Bad file descriptor')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chg/git/BOSCH-GLM-rangefinder/glm100c.py", line 103, in measure_from_back
    m = self.measure()
  File "/home/chg/git/BOSCH-GLM-rangefinder/glm100c.py", line 78, in measure
    self.socket.send(self.cmds['measure'])
  File "<string>", line 5, in send
bluetooth.btcommon.BluetoothError: (9, 'Bad file descriptor')

Running with sudo did not improve the situation so this is not a permission issue ;(
Any Ideas what's wrong?

Command help

Hi there,

I'm wondering what the listen command is supposed to do as I'm currently getting some strange results..
Also if you have any leads on where to find other commands from the protocol it would be of great help!

Thanks :)

help needed pairing Ubuntu and/or Windows with Bosch PLR 30 C

After pressing the Bluetooh key on the Bosch PLR 30 C, the bluetooth item appears in the Bosch PLR 30 C's screen, and Ubuntu does discover the Bosch PLR 30 C. In Ubuntu, when I click on Connect, Ubuntu says:

image

After Confirming that ... still Disconnected.

Tip how to get the Bluetooth connection working?

image

image

GLM50C Connect Problem

I too tried with glm50c. Scripts says could not connect to glm50c but the scripts is able to find the device plz find any solution to it
Best Regards
Pratham Bumb

GLM50C - read angel/inlclination

Hello all,

I managed to read the distance value with your code.
Thank you very much for that.

The GLM 50 C can also measure angle/inclination.
I found the command to start the measuring of the angle, but
unfortunately I didn't find the correct command to read the value from the device.

Finding the command was a little bit tricky,
but I add a function to your code that automatically tries all possible commands.
(Sorry for the bad code, but these are my first tests with python)

It would be tool, if you could check, if there is a command to read the angle.

Thanks in advance

Some of the commands I found:

#[192, 64, 0, 238], #measure length
#[192, 65, 0, 150], #laser on
#[192, 66, 0, 205], #laser off
#[192, 69, 0, 208], #horn on
#[192, 70, 0, 139], #horn off
#[192, 71, 0, 243], #backlight on
#[192, 72, 0, 177], #backlight off
#[192, 84, 0, 22], #level in mainframe off
#[192, 85, 0, ???],#lock angle on device (first time locked, second call releases the measuring)
#[194, 64, 0, ???],#measure length but with longer received data b'\x00\x044<\x96\x08\x00\x00' 
def findCmd2(self):
    
    with open ('cmds' + str(time.time()), 'w') as f:
        f.write('start finding command structure\n\n')
        #list
        addrList = range(192,256) #startbyte: everything greater greater or equal 192 [C0] works
        cmdList = range(0,256) #command
        cmdData = range(0,1)#range(0,2) #data: found no use so far
        #build command
        for g in addrList:
            for i in cmdList:
                for c in cmdData:
                    checkSumArr = [g, i, 0] #create command used for checksum
                    checkSumBytes = bytes(checkSumArr) #convert decimal command
                    k = crc8(checkSumBytes) #calculate checksum
                    cmdArr = [g,i,c,k] #create full command for device
                    cmd = bytes(cmdArr) #convert decimal command
                    
                    #exclude bad commands
                    #command cause strange beahviour or decive reboot
                    if ((cmdArr == [192, 53, 0, 166]) or
                        (cmdArr == [192, 55, 0, 86]) or
                        (cmdArr == [192, 56, 0, 20]) or
                        (cmdArr == [192, 54, 0, 46]) or
                        (cmdArr == [192, 58, 0, 228]) or
                        (cmdArr == [192, 59, 0, 156]) or
                        (cmdArr == [192, 60, 0, 82]) or
                        (cmdArr == [192, 61, 0, 42]) or
                        (cmdArr == [192, 55, 1, 86]) or
                        (cmdArr == [192, 55, 1, 240]) or
                        (cmdArr == [192, 56, 1, 20]) or
                        (cmdArr == [192, 56, 1, 178]) or
                        (cmdArr == [192, 53, 1, 0]) or
                        (cmdArr == [192, 54, 1, 46]) or
                        (cmdArr == [192, 55, 1, 240]) or                            
                        (cmdArr == [192, 54, 1, 136]) or
                        (cmdArr == [192, 58, 1, 228]) or
                        (cmdArr == [192, 59, 1, 156]) or
                        (cmdArr == [192, 60, 1, 82]) or
                        (cmdArr == [192, 61, 1, 42]) or
                        (cmdArr == [192, 57, 1, 108]) or
                        (cmdArr == [192, 57, 1, 202]) or
                        (cmdArr == [192, 58, 1, 66]) or
                        (cmdArr == [192, 59, 1, 58]) or
                        (cmdArr == [192, 60, 1, 244]) or
                        (cmdArr == [192, 61, 1, 140]) or
                        (cmdArr == [192, 62, 0, 162]) or
                        (cmdArr == [192, 62, 1, 4]) or
                        (cmdArr == [192, 63, 0, 218]) or
                        (cmdArr == [193, 54, 0, 102]) or
                        (cmdArr == [192, 57, 0, 108]) or
                        ((i > 50) and (i<60))): 
                        continue
                    
                    print("cmd:\t ", end='')
                    print(cmdArr, end='')
                    f.write("cmd:\t ")
                    f.write(str(cmdArr))
                    
                    self.socket.send(cmd)
                    sleep(0.01) #seems not necessary
                    data = self.socket.recv(1024)
                    sleep(0.5) #seems not necessary
                    if ((self.status[data[0]] is 'ok') or (self.status[data[0]] is 'invalid access level')):
                        #print('')
                        
                        print("\tdata:\t", end='')
                        print(data)
                        f.write("\tdata:\t")
                        f.write(str(data))
                        f.write('\n')
                        #print(data, end='')
                        #print("cmd status: ", end='')
                        #print(self.status[data[0]])
                        continue
                    
                    else:
                        print('')
                        if (self.status[data[0]] != 'communication timeout'):
                            print('--> unknown return:\t', end='')
                            print(data)
                        f.write('\n')
                        
                    if self.status[data[0]] is 'unknown command':
                        print('uC', end='')
                    
                    if self.status[data[0]] is 'unknown return value2':
                        print('uC', end='')
                        
                    if self.status[data[0]] is 'invalid access level':
                        print('--> invalid access level')
                    
                    if self.status[data[0]] is 'hardware error':
                        print('--> hardware error')
                    
                    if self.status[data[0]] is 'device not ready':
                        print('--> device not ready')
                    
                    if self.status[data[0]] is 'communication timeout':
                        print('--> communication timeout')
             
def crc8(data, iv=0xaa, poly=0xa6):
    value = iv
    for b in data:
        for i in range(8):
            x, value = (value >> 7) ^ (b >> (7-i)) & 1, (value << 1) & 0xff
            if x:
                value ^= poly
    return value

Notify current measurement  | Parsing meassure result from hex to decimal

Hi all,

  • is there a way to get always the latest measure data? In the best case I want get the current measurement always when it changed through the notify channel

does someone knows how to parse the measure result from hex to decimal:

e.g. I got following data:
1,816 m => 00041386000036

edit: I found a other thread where it is described:
receive frame: [status][length][...][checksum]

00 status
04 length

0x00008613 little endian result => hex to dec => 34323 *0,05 => 1716 + 100mm device length => 1,816m

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.