Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 0996701c39695e24fbb4992471ba5298f52a4fe6

adding new example code for using serial device
  
1#Copyright (c) 2010-11, Walter Bender, Tony Forster
2#
3# This Python block writes serial output to a USB port and pushes
4# serial input to the heap.
5#
6# To use this block:
7# (1) import this file into a Python Block;
8# (2) pass text strings as an argument
9# (3) use a Pop Block to retrieve any strings input from serial device.
10
11
12def myblock(tw, x): # x is the string to transmit
13 import serial # you may need to install this library
14
15 # serial device on USB, 9600 baud
16 ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
17
18 ser.write(str(x)) #send string x
19 st = ser.read(1000) #read up to 1000 bytes
20 tw.lc.heap.append(st) #append to heap
21 ser.close()