Page MenuHomec4science

yocto_powerrelay.py
No OneTemporary

File Metadata

Created
Mon, Nov 25, 07:37

yocto_powerrelay.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("yoctoLib.python.26380/Sources"))
from yocto_api import *
from yocto_relay import *
from exceptions import YoctoConnectionError
def connect(device_target):
# Setup the API to use local USB devices
errmsg = YRefParam()
if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS:
sys.exit("init error" + errmsg.value)
if device_target == 'ANY':
# retreive any Relay
relay = YRelay.FirstRelay()
if relay is None:
raise YoctoConnectionError('no device connected')
else:
relay = YRelay.FindRelay(device_target + ".relay1")
if not (relay.isOnline()):
raise YoctoConnectionError('device offline')
off(relay)
return relay
def on(relay):
relay.set_state(YRelay.STATE_A)
def off(relay):
relay.set_state(YRelay.STATE_B)

Event Timeline