From 683479776fff26480fe6d28928725dfc984aada8 Mon Sep 17 00:00:00 2001 From: Jared Sanson Date: Sun, 11 Aug 2019 20:36:00 -0700 Subject: [PATCH] Merge scan_pjon.py into scan.py --- scan.py | 16 ++++++++++--- scan_pjon.py | 68 ---------------------------------------------------- settings.py | 5 ++-- 3 files changed, 16 insertions(+), 73 deletions(-) delete mode 100644 scan_pjon.py diff --git a/scan.py b/scan.py index 5e5ca05..eb7c92f 100644 --- a/scan.py +++ b/scan.py @@ -4,13 +4,23 @@ # and displays the result. # -from pymate.matenet import MateNET, MateDevice -from settings import SERIAL_PORT +from pymate.matenet import MateNET, MateNETPJON, MateDevice +import settings print("MATE Bus Scan") # Create a MateNET bus connection -bus = MateNET(SERIAL_PORT) + +if settings.SERIAL_PROTO == 'PJON': + port = MateNETPJON(settings.SERIAL_PORT) + bus = MateNET(port) + + # PJON is more reliable, so we don't need to retry packets + bus.RETRY_PACKET = 0 + +else: + bus = MateNET(settings.SERIAL_PORT) + def print_device(d): dtype = d.scan() diff --git a/scan_pjon.py b/scan_pjon.py deleted file mode 100644 index 121bb7e..0000000 --- a/scan_pjon.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python -# -# Scans the Mate bus for any attached devices, -# and displays the result. -# - -from pymate.matenet import MateNET, MateNETPJON, MateDevice -from settings import SERIAL_PORT -import logging - -ch = logging.StreamHandler() - -#log = logging.getLogger('mate.pjon') -#log.setLevel(logging.DEBUG) -#log.addHandler(ch) - -print("MATE Bus Scan") - -# Create a MateNET bus connection, connected via PJON bus -port = MateNETPJON(SERIAL_PORT) -bus = MateNET(port) -bus.RETRY_PACKET = 0 - -def print_device(d): - dtype = d.scan() - - # No response from the scan command. - # there is nothing at this port. - if dtype is None: - print('Port%d: -' % ( - d.port - )) - else: - try: - rev = d.revision - except Exception as e: - rev = str(e) - - if dtype not in MateNET.DEVICE_TYPES: - print("Port%d: Unknown device type: %d" % ( - d.port, - dtype - )) - else: - print("Port%d: %s (Rev: %s)" % ( - d.port, - MateNET.DEVICE_TYPES[dtype], - rev - )) - return dtype - -# The root device -d0 = MateDevice(bus, port=0) -dtype = d0.scan() -if not dtype: - print('No device connected!') - exit() -print_device(d0) - -# Child devices attached to a hub -# (Only valid if the root device is a hub) -if dtype == MateNET.DEVICE_HUB: - for i in range(1,10): - subdev = MateDevice(bus, port=i) - print_device(subdev) - -print -print('Finished!') \ No newline at end of file diff --git a/settings.py b/settings.py index 4bee4d7..e45c24e 100644 --- a/settings.py +++ b/settings.py @@ -1,2 +1,3 @@ -#SERIAL_PORT = '/dev/ttyUSB0' -SERIAL_PORT = 'COM1' +#SERIAL_PORT = '/dev/ttyUSB0' +SERIAL_PORT = 'COM1' +SERIAL_PROTO = 'MATE' # 'PJON' or 'MATE'