File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
3
+ import serial , sys
4
+
5
+ if len (sys .argv ) < 2 :
6
+ print "Usage:" , sys .argv [0 ], "<device> <speed> [word]*"
7
+ exit ()
8
+
9
+ device = sys .argv [1 ]
10
+ speed = 9600
11
+ chatscript = []
12
+ if len (sys .argv ) >= 3 :
13
+ speed = int (sys .argv [2 ])
14
+ if len (sys .argv ) > 3 :
15
+ chatscript = sys .argv [3 :]
16
+ chatscript .append ("" )
17
+
18
+ tty = serial .Serial (device , speed )
19
+ istr = ""
20
+ while (len (chatscript ) > 0 ):
21
+ istr += tty .read ()
22
+ if (len (istr ) >= 2 and istr [len (istr )- 2 :] == ": " ):
23
+ print istr
24
+ ostr = chatscript .pop (0 )
25
+ print ostr
26
+ tty .write (ostr )
27
+ istr = ""
28
+
29
+ try :
30
+ while True :
31
+ istr += tty .read ()
32
+ if ((len (istr ) >= 2 and istr [len (istr )- 2 :] == ": " ) or (istr [len (istr )- 1 ] == "\n " )):
33
+ print istr
34
+ istr = ""
35
+ except KeyboardInterrupt :
36
+ pass
37
+ print istr
38
+
39
+
40
+
41
+
You can’t perform that action at this time.
0 commit comments