Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

GLM50C - read angel/inlclination #10

Closed
Houns opened this issue May 25, 2020 · 2 comments
Closed

GLM50C - read angel/inlclination #10

Houns opened this issue May 25, 2020 · 2 comments

Comments

@Houns
Copy link

Houns commented May 25, 2020

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
@philipptrenz
Copy link
Owner

Hey @Houns,

thanks for your work! Unfortunately I don't own a GLM50C nor do I have access to one, so I cannot test your findings. If you have any progress here, keep me informed ;)

Greetings

@lion1109
Copy link

lion1109 commented Aug 25, 2021

horn_on and horn_off works for me with a GLM50C :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants