Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 10th, 2011  |  syntax: Python  |  size: 0.46 KB  |  views: 532  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import serial
  2. import time
  3.  
  4. baudrate = raw_input("Please enter the required baud rate:")
  5.  
  6. ## You need to add the locations for your system, i.e. COM* for Windows, /dev/tty* for Nix systems
  7.  
  8. locations=['COM3']
  9. for device in locations:
  10.         try:
  11.                 print "Trying...", device
  12.                 arduino = serial.Serial(device, baudrate)
  13.                 break
  14.         except:
  15.                 print "Failed.."
  16. count = 5
  17. time.sleep(1)
  18. while count < 10:
  19.         try:
  20.                 print arduino.readline()
  21.         except:
  22.                 print "Fail"