Skip to content

Commit f33efe3

Browse files
committed
Improve readout.py & scan.py
1 parent 1502558 commit f33efe3

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

readout.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from pymate.matenet import MateNET, MateMXDevice
22
from time import sleep
3+
from settings import SERIAL_PORT
34

45
print "MATE emulator (MX)"
56

67

78
# Create a MateNET bus connection
8-
bus = MateNET('/dev/ttyUSB0')
9+
bus = MateNET(SERIAL_PORT)
10+
11+
# Find an MX device on the bus
12+
port = bus.find_device(MateNET.DEVICE_MX)
913

1014
# Create a new MATE emulator attached to the specified port
11-
mate = MateMXDevice(bus)
15+
mate = MateMXDevice(bus, port)
1216

1317
# Check that an MX unit is attached and is responding
1418
mate.scan()

scan.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
from pymate.matenet import MateNET, MateDevice
8-
from srv1.settings import SERIAL_PORT
8+
from settings import SERIAL_PORT
99

1010
print("MATE Bus Scan")
1111

@@ -26,12 +26,18 @@ def print_device(d):
2626
rev = d.revision
2727
except Exception as e:
2828
rev = str(e)
29-
30-
print("Port%d: %s (Rev: %s)" % (
31-
d.port,
32-
MateNET.DEVICE_TYPES[dtype],
33-
rev
34-
))
29+
30+
if dtype not in MateNET.DEVICE_TYPES:
31+
print("Port%d: Unknown device type: %d" % (
32+
d.port,
33+
dtype
34+
))
35+
else:
36+
print("Port%d: %s (Rev: %s)" % (
37+
d.port,
38+
MateNET.DEVICE_TYPES[dtype],
39+
rev
40+
))
3541
return dtype
3642

3743
# The root device

settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#SERIAL_PORT = '/dev/ttyUSB0'
2+
SERIAL_PORT = 'COM9'

0 commit comments

Comments
 (0)