Line 6... |
Line 6... |
6 |
import serial |
6 |
import serial |
7 |
import time |
7 |
import time |
8 |
|
8 |
|
9 |
#### Script Arguments ############################################### |
9 |
#### Script Arguments ############################################### |
10 |
|
10 |
|
11 |
if len(sys.argv) != 3 : |
11 |
if len(sys.argv) < 3 : |
12 |
sys.stderr.write("Invalid number of arguments.\n") |
12 |
sys.stderr.write("Invalid number of arguments.\n") |
13 |
sys.stderr.write("Usage: %s device command\n" % (sys.argv[0], )) |
13 |
sys.stderr.write("Usage: %s device command\n" % (sys.argv[0], )) |
14 |
sys.exit(1) |
14 |
sys.exit(1) |
15 |
|
15 |
|
16 |
print("setcol: initiating") |
16 |
print("setcol: initiating") |
17 |
|
17 |
|
18 |
try: |
18 |
try: |
19 |
ser = serial.Serial(sys.argv[1], 9600, timeout=0) |
19 |
ser = serial.Serial(sys.argv[1]) |
20 |
time.sleep(2) |
20 |
time.sleep(2) |
21 |
command = sys.argv[2] |
21 |
command = sys.argv[2] |
22 |
ser.write(command) |
22 |
for c in command: |
- |
|
23 |
ser.write(c) |
- |
|
24 |
print("setcol: sending %s" % c) |
- |
|
25 |
time.sleep(2) |
23 |
ser.close() |
26 |
ser.close() |
24 |
print("setcol: sending") |
- |
|
25 |
time.sleep(len(command)*1.5) |
- |
|
26 |
print("setcol: done") |
27 |
print("setcol: done") |
27 |
sys.exit(0) |
28 |
sys.exit(0) |
28 |
|
29 |
|
29 |
except IOError: |
30 |
except IOError: |
30 |
print("setcol: can not open device.") |
31 |
print("setcol: can not open device.") |