Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pysamples/serial.py
blob: 153bf90b9f91e7bae34aaf2999d657653871ed6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Copyright (c) 2010-11, Walter Bender, Tony Forster
#
# This Python block writes serial output to a USB port and pushes
# serial input to the heap.
#
# To use this block:
#    (1) import this file into a Python Block;
#    (2) pass text strings as an argument
#    (3) use a Pop Block to retrieve any strings input from serial device.


def myblock(tw, x):  # x is the string to transmit    
   import serial   # you may need to install this library

   # serial device on USB, 9600 baud
   ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)

   ser.write(str(x))  #send string x
   st = ser.read(1000)  #read up to 1000 bytes
   tw.lc.heap.append(st)  #append to heap
   ser.close()