Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC2217 connections; boardname: prefix in paths #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ def process_pattern(fn):

def resolve_path(path):
"""Resolves path and converts it into an absolute path."""
# if path containes ':' it is a remote path, do not resolve
if ':' in path:
return path
if path[0] == '~':
# ~ or ~user
path = os.path.expanduser(path)
Expand Down Expand Up @@ -547,6 +550,19 @@ def get_dev_and_path(filename):
If the file is not associated with the remote device, then the dev
portion of the returned tuple will be None.
"""

# Check if filename can be split by ':' into a device name and a path.
# If so, then we assume that the file is associated with the named device.
# if device name is empty then use the default device.
if ':' in filename:
dev_name, filename = filename.split(':', 1)
if dev_name == '':
return (DEFAULT_DEV, filename)
with DEV_LOCK:
for dev in DEVS:
if dev.name == dev_name:
return (dev, filename)

if DEFAULT_DEV:
if DEFAULT_DEV.is_root_path(filename):
return (DEFAULT_DEV, filename)
Expand Down
89 changes: 60 additions & 29 deletions rshell/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,69 @@ def __init__(self, device, baudrate=115200, user='micro', password='python', wai
if device and device[0].isdigit() and device[-1].isdigit() and device.count('.') == 3:
# device looks like an IP address
self.serial = TelnetToSerial(device, user, password, read_timeout=10)
elif device.startswith('rfc2217://'):
self.openRfc2217Serial(device, baudrate, wait, rts, dtr)
else:
self.openSerial(device, baudrate, wait, rts, dtr)

def openSerial(self, device, baudrate=115200, wait=0, rts='', dtr=''):
import serial
delayed = False
if serial.VERSION == '3.0':
self.serial = serial.Serial(baudrate=baudrate, inter_byte_timeout=1)
else:
self.serial = serial.Serial(baudrate=baudrate, interCharTimeout=1)
if rts != '':
self.serial.rts = parse_bool(rts)
if dtr != '':
self.serial.dtr = parse_bool(dtr)
self.serial.port = device
for attempt in range(wait + 1):
try:
# Assigning the port attribute will attempt to open the port
self.serial.open()
break
except (OSError, IOError): # Py2 and Py3 have different errors
if wait == 0:
continue
if attempt == 0:
sys.stdout.write('Waiting {} seconds for pyboard '.format(wait))
delayed = True
time.sleep(1)
sys.stdout.write('.')
sys.stdout.flush()
else:
if delayed:
print('')
raise PyboardError('failed to access ' + device)
if delayed:
print('')

def openRfc2217Serial(self, device, baudrate=115200, wait=0, rts='', dtr=''):
delayed = False
for attempt in range(wait + 1):
try:
# Try to open rfc2217 serial port
import serial
self.serial = serial.serial_for_url(device, baudrate=baudrate, rtscts=parse_bool(rts), dsrdtr=parse_bool(dtr))
break
except (BrokenPipeError, OSError, IOError): # Py2 and Py3 have different errors
if wait == 0:
continue
if attempt == 0:
sys.stdout.write('Waiting {} seconds for rfc2217 pipe to be open '.format(wait))
delayed = True
time.sleep(1)
sys.stdout.write('.')
sys.stdout.flush()
else:
import serial
delayed = False
if serial.VERSION == '3.0':
self.serial = serial.Serial(baudrate=baudrate, inter_byte_timeout=1)
else:
self.serial = serial.Serial(baudrate=baudrate, interCharTimeout=1)
if rts != '':
self.serial.rts = parse_bool(rts)
if dtr != '':
self.serial.dtr = parse_bool(dtr)
self.serial.port = device
for attempt in range(wait + 1):
try:
# Assigning the port attribute will attempt to open the port
self.serial.open()
break
except (OSError, IOError): # Py2 and Py3 have different errors
if wait == 0:
continue
if attempt == 0:
sys.stdout.write('Waiting {} seconds for pyboard '.format(wait))
delayed = True
time.sleep(1)
sys.stdout.write('.')
sys.stdout.flush()
else:
if delayed:
print('')
raise PyboardError('failed to access ' + device)
if delayed:
print('')
raise PyboardError('failed to access ' + device)
if delayed:
print('')



def close(self):
self.serial.close()
Expand Down