#Testing Thread connections
connected = True
startM = time.time()
count = 0
run = True


#while run == True:
for x in range(0,1):
    count = count + 1
    start = time.time()                     ################################
    here = deviceList
    while here != None:
        try:
            print "Connecting to " + here.getObjectName()
            started = doStart(here)
            if started == True:
                start1 = time.time()            ################################
                numberOfConnectedPorts = len(here.getPort())+1
                readDic = {}
                manipulatedDic = {}
                
                # Reading all ports on device
                for item in range(1,numberOfConnectedPorts):
                    portObj = here.getPortItem(item)
                    readDic[int(portObj.getPortNum())] = read(here, portObj)
                end1 = time.time()              ################################
                print "After Reading all ports: " + str(readDic)                 
                #commit it to the database
                array = ['tempOA','tempRA','tempMA','tempPA','tempSA','humidityOA']
                valDic = {}
from cplReadWrite import read, write, doStop, doStart
import time


obj_type = 'analogInput'
obj_inst = int(2)
prop_id = 'presentValue'
ini_name = 'BACpypes'

doStart(ini_name)

confirmationValue = read(obj_type, obj_inst, prop_id)
print "Current Temperature: " + str(confirmationValue) + "\n"


obj_type = 'analogOutput'
obj_inst = int(3)
value = float(2)
index = int(0)
priority = int(1)

time.sleep(1)

confirmationValue = write(obj_type, obj_inst, prop_id, value, index, priority)
print "Write: " + str(confirmationValue)

value = float(0)

print "Lighting LED for 10 seconds\n"
time.sleep(10)
confirmationValue = write(obj_type, obj_inst, prop_id, value, index, priority)
from cplReadWrite import read, write, doStop, doStart
import time

obj_type = 'analogInput'
obj_inst = int(2)
prop_id = 'presentValue'
ini_name = 'BACpypes'

doStart(ini_name)

confirmationValue = read(obj_type, obj_inst, prop_id)
print "Current Temperature: " + str(confirmationValue) + "\n"

obj_type = 'analogOutput'
obj_inst = int(3)
value = float(2)
index = int(0)
priority = int(1)

time.sleep(1)

confirmationValue = write(obj_type, obj_inst, prop_id, value, index, priority)
print "Write: " + str(confirmationValue)

value = float(0)

print "Lighting LED for 10 seconds\n"
time.sleep(10)
confirmationValue = write(obj_type, obj_inst, prop_id, value, index, priority)
print "Write: " + str(confirmationValue)