background preloader

Python serial

Facebook Twitter

Sniffing RS232 traffic with python « Things and thoughts. Today, I had to check that traffic between an embedded java application (in an eWON 4101) and a Coronis WavePort modem was following a given rule (less than 10 milliseconds between the bytes).

Sniffing RS232 traffic with python « Things and thoughts

I have used a great thing : the SpyCable. It allowed me to monitor either the send traffic or the received one using two serial ports. I’ve then written a small python script to monitor the bytes entering the port, printing Coronis frames with time information if some bytes were written with more than 10 milliseconds interval. One of the very important thing to check before doing some serial sniffing is the influence of the FIFO buffer in the UART chip. To make things work “real-time”, set the following parameter on your serial port : did@ddp:~$ setserial /dev/ttyS0 uart 8250 low_latency Here is the script used (depends on pyserial) (does anyone know how to paste python code keeping identation in wordpress ?)

#! Conclusion was that some of the bytes where a bit slow … Like this: Like Loading... PySerial module.

Acessing /dev/tty, pty, virtual terminal

Short introduction — pySerial v2.6 documentation. Opening serial ports Open port 0 at “9600,8,N,1”, no timeout: >>> import serial>>> ser = serial.Serial(0) # open first serial port>>> print ser.name # check which port was really used>>> ser.write("hello") # write a string>>> ser.close() # close port Open named port at “19200,8,N,1”, 1s timeout: >>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1)>>> x = ser.read() # read one byte>>> s = ser.read(10) # read up to ten bytes (timeout)>>> line = ser.readline() # read a '\n' terminated line>>> ser.close() Open second port at “38400,8,E,1”, non blocking HW handshaking: >>> ser = serial.Serial(1, 38400, timeout=0,... parity=serial.PARITY_EVEN, rtscts=1)>>> s = ser.read(100) # read up to one hundred bytes... # or as much is in the buffer Readline Be carefully when using readline().

Short introduction — pySerial v2.6 documentation

Do also have a look at the example files in the examples directory in the source distribution or online. Note. Welcome to pySerial’s documentation — pySerial v2.6 documentation. Python » Dr. Rainer Hessmer. A lot has happened since my last blog.

Python » Dr. Rainer Hessmer

The big news is that basic balancing is working now. Let’s start with the now almost obligatory photo of the current robot state: For better weight distribution the batteries, motor controller and the Arduino Mega board have been rearranged. The gray box between the wheels underneath the robot platform houses the 3-axis accelerometer ADX330 and the dual axis gyroscope IDG300. I used the same components as in my Lego prototype (for details see Building a Self-Balancing Robot – The Prototype). Enough about the hardware. Let’s start with … The Arduino Program The main program is BalancingRobot.pde. ADXL300: Access to the ADXL330 accelerometer and associated angle calculationsIDG300: Access to and calibration of the IDG300 gyroscopeQuadratureEncoder: Handling of the quadrature encoder signals Others deserve a little bit of explanation.

Communicating with the Sabertooth Motor Driver The Sabertooth class is used from within the Arduino program like so: