I am trying to read lightware rangefinder SF11 through serial but using Raspberry, and I am not familiar with Python, but I tried this:
import time
import serial
print('Code is Running.')
# Make a connection to the com port.
serialPortName = '/dev/ttyUSB0'
serialPortBaudRate = 115200
port = serial.Serial(serialPortName, serialPortBaudRate, timeout=0.1)
port.write('www\r\n')
port.readline() # Read and ignore any unintended responses
port.write('?\r\n') # Get the product information
productInfo = port.readline()
print('Product information: ' + productInfo)
while True:
port.write('LD\r\n') # reading distance (First return, default filtering)
distanceStr = port.readline()
distanceCM = float(distanceStr) * 100 # Convert the distance string into a number
print(distanceCM)
time.sleep(0.05) # Wait for 50ms before the next reading
When I run the code it's turn this:
Traceback (most recent call last):
File "range.py", line 25, in <module>
distanceCM = float(distanceStr) * 100 # Convert the distance string into a number
ValueError: invalid literal for float(): 1.72 m 0.086 V