Beispiel #1
0
def testBoard(boardType, numRelays, devID=None):
    dr = dae_RelayBoard.DAE_RelayBoard(boardType)
    testException(dr.setAllStatesOn)
    if devID is not None:
        dr.initialise(devID)
    else:
        dr.initialise()
    testException(dr.setState, numRelays+1, True)
    testException(dr.getState, numRelays+1)
    testException(dr.setState, 0, True)
    testException(dr.getState, 0)
    dr.disconnect()
Beispiel #2
0
 def __init__(self, boardType, *args):
     
     dr = dae_RelayBoard.DAE_RelayBoard(boardType)
     dr.initialise(*args)
     
     dr.setAllStatesOff()
     
     print "Turn on one-by-one"
     for relay in range(1,dr.getNumRelays()+1):
         testStateFunctions(dr, relay, True)
     
     print "\n\nTurn off one-by-one"
     for relay in range(1,dr.getNumRelays()+1):
         testStateFunctions(dr, relay, False)
     
     print "\n\nTurn all on"
     dr.setAllStatesOn()
     testGetFunctions(dr)
     time.sleep(0.5)
     
     print "\n\nTurn all off"
     dr.setAllStatesOff()
     time.sleep(0.5)
     testGetFunctions(dr)
     
     print "\n\nTurn even on"
     evenStates = {}
     for relay in range(1,dr.getNumRelays()+1): 
         evenStates[relay] = relay%2==0
     dr.setStates(evenStates) 
     time.sleep(0.5)   
     testGetFunctions(dr)
     
     print "\n\nTurn first on"
     dr.setState(1,True)  
     time.sleep(0.5)  
     testGetFunctions(dr)
     
     print "\n\nTurn first off"
     dr.setState(1,False) 
     time.sleep(0.5)   
     testGetFunctions(dr)
     
     dr.disconnect()
         
         
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#-----------------------------------------------------------------------------

#Example Code

import time
import dae_RelayBoard

dr = dae_RelayBoard.DAE_RelayBoard(dae_RelayBoard.DAE_RELAYBOARD_TYPE_8)

dr.initialise()

dr.setAllStatesOff()

#Turn on one-by-one
for r in range(1, dr.getNumRelays() + 1):
    dr.setState(r, True)
    time.sleep(0.5)
    print(dr.getStates())

#Turn off one-by-one
for r in range(1, dr.getNumRelays() + 1):
    dr.setState(r, False)
    time.sleep(0.5)
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#-----------------------------------------------------------------------------

#Tests for the interval timings. Change below to test for different times:
INTERVAL = 0.050
#Set Com port below:
COMPORT = "COM8"

import time
import testCommon
import dae_RelayBoard

dr = dae_RelayBoard.DAE_RelayBoard(dae_RelayBoard.DAE_RELAYBOARD_TYPE_16,
                                   INTERVAL)
dr.initialise(COMPORT)

dr.setAllStatesOff()
testCommon.testGetFunctions(dr, False)

for relay in range(1, dr.getNumRelays() + 1):
    dr.setState(relay, True)
    testCommon.testGetFunctions(dr, False)

dr.disconnect()