File: test-serial-read.py

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (25 lines) | stat: -rw-r--r-- 426 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python

# This test has to run on a Raspberry Pi connected throw a USB
# to serial adapter to a laptop.

from __future__ import print_function

import time
import serial

ser = serial.Serial(
  port='/dev/ttyUSB0',
  baudrate = 9600,
  timeout=0
)
          
while True:
  data = ser.read(9)
  if len(data) > 0:
    print('Got:', len(data), 'data:', data)

  time.sleep(0.5)
  print('not blocked')

ser.close()