-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to turn on/off power and rss-422
- Loading branch information
1 parent
4a7d69b
commit 7886d2a
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import serial | ||
import os | ||
import json | ||
import ow | ||
import argparse | ||
|
||
if __name__ == '__main__': | ||
# args | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--turn-on', dest='powered', action='store_true') | ||
parser.add_argument('--turn-off', dest='powered', action='store_false') | ||
parser.set_defaults(powered=False) | ||
|
||
try: | ||
args = parser.parse_args() | ||
except: | ||
print('args provided are wrong') | ||
exit() | ||
|
||
if args.powered: | ||
print('turning all nodes on, communication off') | ||
else: | ||
print('turning all node off') | ||
|
||
# get the wire1 lib setup to talk the devices | ||
(ow.init('localhost:4304')) | ||
node_list = ow.Sensor('/').sensorList() | ||
|
||
# turn on and put them in a not communicating mode | ||
for sensor in node_list: | ||
if sensor.type == "DS2408": | ||
if args.powered: | ||
sensor.PIO_BYTE = "64" # turn off | ||
sensor.PIO_BYTE = "147" # turn on with comms | ||
sensor.PIO_7 = "0" # turn off RX & TX | ||
sensor.PIO_6 = "1" | ||
else: | ||
sensor.PIO_BYTE = "64" # turn off | ||
sensor.PIO_7 = "0" # turn off RX & TX | ||
sensor.PIO_6 = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import serial | ||
import os | ||
import json | ||
import ow | ||
import argparse | ||
|
||
if __name__ == '__main__': | ||
# args | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--node-id', type=int, default='') | ||
parser.add_argument('--rss-on', dest='rss_state', action='store_true') | ||
parser.add_argument('--rss-off', dest='rss_state', action='store_false') | ||
parser.set_defaults(rss_state=False) | ||
|
||
try: | ||
args = parser.parse_args() | ||
except: | ||
print('args provided are wrong') | ||
exit() | ||
|
||
# get the wire1 lib setup to talk the devices | ||
(ow.init('localhost:4304')) | ||
node_list = ow.Sensor('/').sensorList() | ||
|
||
# serial port to talk through rs422 | ||
ser = serial.Serial('/dev/ttyUSB0', baudrate=115200, timeout=1) | ||
ser.reset_input_buffer() | ||
|
||
with open(os.path.dirname(os.path.realpath(__file__)) + '/../addr_finder/node_order.json') as json_file: | ||
strip_path_inorder = json.load(json_file) | ||
json_file.close() | ||
strip_path_inorder = [node_name['wire1'] for node_name in strip_path_inorder] | ||
|
||
# turn on and put them in a not communicating mode | ||
for sensor in node_list: | ||
if sensor.type == "DS2408": | ||
sensor.PIO_7 = "0" # turn off RX & TX | ||
sensor.PIO_6 = "1" | ||
|
||
# turn on RSS 422 for desired node | ||
sensor = strip_path_inorder[args.node_id-1] | ||
sensor = ow.Sensor(str(sensor)) | ||
if sensor.type == "DS2408": | ||
if args.rss_state == True: | ||
# turn on RS422 | ||
print('Turn on rss for sensor ID:' + str(args.node_id) + ' 1-wire: '+ str(sensor._path)) | ||
sensor.PIO_7 = "1" | ||
sensor.PIO_6 = "0" | ||
else: | ||
# turn off RS422 | ||
print('Turn off rss for sensor ID:' + str(args.node_id) + ' 1-wire: '+ str(sensor._path)) | ||
sensor.PIO_7 = "0" | ||
sensor.PIO_6 = "1" |