Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92977356
yocto_powerrelay.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 07:37
Size
941 B
Mime Type
text/x-python
Expires
Wed, Nov 27, 07:37 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22534634
Attached To
rSERVICENOWCHATALERT servicenow-chat-alert
yocto_powerrelay.py
View Options
#!/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
Log In to Comment