-
Notifications
You must be signed in to change notification settings - Fork 10
/
serial_example_series_1.py
66 lines (49 loc) · 1.46 KB
/
serial_example_series_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/python
from xbee import XBee
import serial
"""
serial_example.py
By Paul Malmsten, 2010
Demonstrates reading the low-order address bits from an XBee Series 1
device over a serial port (USB) in API-mode.
"""
def main():
"""
Sends an API AT command to read the lower-order address bits from
an XBee Series 1 and looks for a response
"""
try:
# Open serial port
ser = serial.Serial('/dev/tts/0', 9600)
# Create XBee Series 1 object
xbee = XBee(ser)
# Send AT packet
x = xbee.send('at', frame_id='A', command='DH')
print x
# Wait for response
response = xbee.wait_read_frame()
print response
# Send AT packet
x = xbee.send('at', frame_id='B', command='DL')
print x
# Wait for response
response = xbee.wait_read_frame()
print response
# Send AT packet
x = xbee.send('at', frame_id='C', command='MY')
print x
# Wait for response
response = xbee.wait_read_frame()
print response
# Send AT packet
x = xbee.send('at', frame_id='D', command='CE')
print x
# Wait for response
response = xbee.wait_read_frame()
print response
except KeyboardInterrupt:
pass
finally:
ser.close()
if __name__ == '__main__':
main()