summaryrefslogtreecommitdiff
path: root/sbhs_server/scan_machines.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commit4336f5f06f61de30ae3fa54650fce63a9d5ef5be (patch)
tree23b4ee9b8e8f24bf732acf2f7ad22ed50cdd5670 /sbhs_server/scan_machines.py
downloadSBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.gz
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.bz2
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.zip
added all server files
Diffstat (limited to 'sbhs_server/scan_machines.py')
-rw-r--r--sbhs_server/scan_machines.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/sbhs_server/scan_machines.py b/sbhs_server/scan_machines.py
new file mode 100644
index 0000000..2548941
--- /dev/null
+++ b/sbhs_server/scan_machines.py
@@ -0,0 +1,58 @@
+#!/usb/bin/python
+import sbhs
+import os
+import sys
+
+# erase the old map_machine_ids.txt file
+try:
+ file('map_machine_ids.txt', 'w').close()
+except:
+ print 'Failed to create machine map file file'
+ sys.exit(1)
+
+# open the map_machine_ids file for writing
+try:
+ map_machine_file = file('map_machine_ids.txt', 'w')
+except:
+ print 'Failed to create machine map file file'
+ sys.exit(1)
+
+# get list of device file names that start with ttyUSB* in the /dev folder
+#device_files = []
+device_files = [each for each in os.listdir('/dev') if each.startswith('ttyUSB')]
+print device_files
+
+# if no device filename found then exit
+if not device_files:
+ print 'No USB device found in /dev folder'
+ sys.exit(1)
+
+for device in device_files:
+ s = sbhs.Sbhs()
+ # getting the number from the device filename
+ dev_id = device[6:]
+ try:
+ dev_id = int(dev_id)
+ except:
+ print 'Invalid device name /dev/%s' % device
+ continue
+ # connect to device
+ res = s.connect_device(dev_id)
+ if not res:
+ print 'Cannot connect to /dev/%s' % device
+ s.disconnect()
+ continue
+ # get the machine id from the device
+ machine_id = s.getMachineId()
+ if machine_id < 0:
+ print 'Cannot get machine id from /dev/%s' % device
+ s.disconnect()
+ continue
+ print 'Found SBHS device /dev/%s with machine id %d' % (device, machine_id)
+ map_str = "%d=/dev/%s\n" % (machine_id, device)
+ map_machine_file.write(map_str)
+
+print 'Done. Exiting...'
+map_machine_file.close()
+sys.exit(1)
+