The pySerial library is really good. Today I installed it and in half an hour I got acquainted with its class methods, even though I have little knowledge about serial ports and the like.
With some trial and error about the connection parameters, I was even able to solve the problem with non-printable characters, tweaking the bytesize
of the connection.
Briefly, these are the steps I did in the interactive ipython console:
-
>>> import serial >>> ser = serial.Serial('/dev/ttyUSB0', \ baudrate=9600, bytesize=serial.SEVENBITS, timeout=0, \ parity=serial.PARITY_NONE, rtscts=1) >>> ser.open()
- at this point, start the transfer from the device
- check that you have received some data:
>>> ser.inWaiting() 648L
A non-zero result means that you have received something.
- I saved this value to use it with the
read()
method of theSerial
class:>>> n = ser.inWaiting() >>> result = ser.read(n)
- The
result
object is a string, seeing its contents is as simple as:>>> print(result) 0001 OR.COOR 0002 0S X 0.000 Y 0.000 Z 0.000 0003 Om 397.0370 0004 POLAR 0005 INPUT th 1.500 ih 0.000 0006 INPUT th 0.000 ih 0.000 Z 0.000 0007 1 X -0.472 Y 1.576 Z 0.004 END
As you can see, there are no errors after the
END
sentence, because the serial connection is handled gracefully now. The previous attempt withcat /dev/ttyUSB0
was a bit brutal…
For now, that’s all. I go back studying and maybe also writing some Python code for this Total Station. If you have got a total station and want to contribute to this project, let me know by leaving a comment here.
Lascia un commento