Pour éditer le wiki, il faut demander un compte à un Lapin !

Difference between revisions of "ArduinoSerialRead"

From Le L∞p's Wiki
Jump to: navigation, search
m (Text replace - "</tt>" to "</code>")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
* arduino_read.py
+
<code>arduino_read.py</code> par [[User:Guyzmo|Guyzmo]]
<pre>
+
<syntaxhighlight lang="python">
 
#!/usr/bin/env python
 
#!/usr/bin/env python
 
# Simple CLI arduino serial debug read/write
 
# Simple CLI arduino serial debug read/write
Line 19: Line 19:
 
c = None
 
c = None
 
while True:
 
while True:
     c = sys.stdout.write(ser.read(1))
+
     sys.stdout.write(ser.read(1))
 
     sys.stdout.flush()
 
     sys.stdout.flush()
 
     try:  
 
     try:  
        sys.stdin.read(1)
+
      c = sys.stdin.read(1)
 
         ser.write(c)
 
         ser.write(c)
 
         ser.flush()
 
         ser.flush()
Line 28: Line 28:
 
     except:  
 
     except:  
 
         continue
 
         continue
</pre>
+
</syntaxhighlight>
 +
 
 +
[[Category:Arduino]]

Latest revision as of 22:31, 12 April 2013

arduino_read.py par Guyzmo

#!/usr/bin/env python
# Simple CLI arduino serial debug read/write
# (c)2010, Guyzmo <guyzmo{at}hackable-devices.org>

import sys, serial, fcntl, os

fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

try:
    ser = serial.Serial(sys.argv[1], baudrate = 9600)
except:
    print "Please use a tty port available. Like /dev/tty.USB0"
    exit(1)

c = None
while True:
    sys.stdout.write(ser.read(1))
    sys.stdout.flush()
    try: 
       c = sys.stdin.read(1)
        ser.write(c)
        ser.flush()
        c=None
    except: 
        continue