Skip to content

Commit d820c9b

Browse files
committed
Fix for issue sparkfun#4
1 parent 938359e commit d820c9b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

svl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
import argparse
3737
import serial
3838
import serial.tools.list_ports as list_ports
39+
import termios
3940
import sys
4041
import time
4142
import math
4243
import os.path
4344
from sys import exit
45+
import platform as sys_pf
4446

4547
SCRIPT_VERSION_MAJOR = "1"
4648
SCRIPT_VERSION_MINOR = "7"
@@ -336,9 +338,24 @@ def main():
336338
bl_success = False
337339
entered_bootloader = False
338340

341+
system_type = sys_pf.system().lower()
339342
for _ in range(num_tries):
340343

341344
with serial.Serial(args.port, args.baud, timeout=args.timeout) as ser:
345+
# Set port to known state
346+
if system_type == "linux":
347+
attrs = termios.tcgetattr(ser.fd)
348+
c_iflag = 0
349+
c_oflag = 0
350+
port_speed = attrs[4]
351+
c_cflag = termios.CS8 | termios.CREAD | termios.HUPCL | termios.CLOCAL | port_speed
352+
c_lflag = 0
353+
c_ispeed = port_speed
354+
c_ospeed = port_speed
355+
termios.tcsetattr(ser.fd, termios.TCSANOW,
356+
[c_iflag, c_oflag, c_cflag, c_lflag, c_ispeed, c_ospeed, attrs[6]])
357+
ser.close()
358+
ser.open()
342359

343360
# startup time for Artemis bootloader (experimentally determined - 0.095 sec min delay)
344361
t_su = 0.15

0 commit comments

Comments
 (0)