Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
total_control_app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Drechsler
total_control_app
Commits
1e48dd61
Commit
1e48dd61
authored
Oct 25, 2018
by
Martin Drechsler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add props files
parent
54ac5cf2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
241 additions
and
0 deletions
+241
-0
ao.py
props/ao.py
+104
-0
digital.py
props/digital.py
+137
-0
No files found.
props/ao.py
0 → 100644
View file @
1e48dd61
from
__future__
import
absolute_import
,
division
,
print_function
from
builtins
import
*
# @UnusedWildImport
from
mcculw
import
ul
from
mcculw.enums
import
BoardInfo
,
InfoType
,
ULRange
,
ErrorCode
,
ScanOptions
from
mcculw.ul
import
ULError
from
examples.props.propsbase
import
Props
class
AnalogOutputProps
(
Props
):
"""Provides analog output information on the hardware configured at the
board number given.
This class is used to provide hardware information for the library
examples, and may change hardware values. It is recommended that the
values provided by this class be hard-coded in production code.
"""
def
__init__
(
self
,
board_num
):
self
.
_board_num
=
board_num
self
.
resolution
=
self
.
_get_resolution
()
self
.
num_chans
=
self
.
_get_num_chans
()
self
.
available_ranges
=
self
.
_get_available_ranges
()
self
.
supports_v_out
=
self
.
_get_supports_v_out
(
self
.
available_ranges
)
self
.
supported_scan_options
=
self
.
_get_supported_scan_options
()
self
.
supports_scan
=
(
ScanOptions
.
CONTINUOUS
in
self
.
supported_scan_options
)
def
_get_resolution
(
self
):
return
ul
.
get_config
(
InfoType
.
BOARDINFO
,
self
.
_board_num
,
0
,
BoardInfo
.
DACRES
)
def
_get_num_chans
(
self
):
return
ul
.
get_config
(
InfoType
.
BOARDINFO
,
self
.
_board_num
,
0
,
BoardInfo
.
NUMDACHANS
)
def
_get_supported_scan_options
(
self
):
try
:
return
ScanOptions
(
ul
.
get_config
(
InfoType
.
BOARDINFO
,
self
.
_board_num
,
0
,
BoardInfo
.
DACSCANOPTIONS
))
except
ULError
:
return
ScanOptions
(
0
)
def
_get_available_ranges
(
self
):
result
=
[]
# Check if the range is ignored by passing a bogus range in
try
:
ul
.
v_out
(
self
.
_board_num
,
0
,
-
5
,
0
)
range_ignored
=
True
except
ULError
as
e
:
if
(
e
.
errorcode
==
ErrorCode
.
NETDEVINUSE
or
e
.
errorcode
==
ErrorCode
.
NETDEVINUSEBYANOTHERPROC
):
raise
range_ignored
=
False
if
range_ignored
:
# Try and get the range configured in InstaCal
try
:
curr_range
=
ULRange
(
ul
.
get_config
(
InfoType
.
BOARDINFO
,
self
.
_board_num
,
0
,
BoardInfo
.
DACRANGE
))
result
.
append
(
curr_range
)
except
ULError
as
e
:
if
(
e
.
errorcode
==
ErrorCode
.
NETDEVINUSE
or
e
.
errorcode
==
ErrorCode
.
NETDEVINUSEBYANOTHERPROC
):
raise
return
result
for
dac_range
in
ULRange
:
try
:
ul
.
v_out
(
self
.
_board_num
,
0
,
dac_range
,
0
)
result
.
append
(
dac_range
)
print
(
dac_range
)
except
ULError
as
e
:
if
(
e
.
errorcode
==
ErrorCode
.
NETDEVINUSE
or
e
.
errorcode
==
ErrorCode
.
NETDEVINUSEBYANOTHERPROC
):
raise
return
result
def
get_units_string
(
self
,
ao_range
):
if
ao_range
in
[
ULRange
.
MA4TO20
,
ULRange
.
MA2TO10
,
ULRange
.
MA1TO5
,
ULRange
.
MAPT5TO2PT5
]:
return
"mA"
else
:
return
"V"
def
_get_supports_v_out
(
self
,
available_ranges
):
if
len
(
available_ranges
)
==
0
:
return
False
try
:
ul
.
v_out
(
self
.
_board_num
,
0
,
available_ranges
[
0
],
0
)
except
ULError
:
return
False
return
True
props/digital.py
0 → 100644
View file @
1e48dd61
from
__future__
import
absolute_import
,
division
,
print_function
from
builtins
import
*
# @UnusedWildImport
from
mcculw
import
ul
from
mcculw.enums
import
InfoType
,
BoardInfo
,
DigitalInfo
,
DigitalPortType
,
\
DigitalIODirection
,
FunctionType
from
examples.props.propsbase
import
Props
from
mcculw.ul
import
ULError
class
DigitalProps
(
Props
):
"""Provides digital IO information on the hardware configured at the
board number given.
This class is used to provide hardware information for the library
examples, and may change hardware values. It is recommended that the
values provided by this class be hard-coded in production code.
"""
def
__init__
(
self
,
board_num
):
self
.
_board_num
=
board_num
self
.
num_ports
=
self
.
_get_num_digital_chans
()
self
.
port_info
=
[]
for
port_index
in
range
(
self
.
num_ports
):
self
.
port_info
.
append
(
PortInfo
(
board_num
,
port_index
))
def
_get_num_digital_chans
(
self
):
try
:
return
ul
.
get_config
(
InfoType
.
BOARDINFO
,
self
.
_board_num
,
0
,
BoardInfo
.
DINUMDEVS
)
except
ULError
:
return
0
class
PortInfo
(
object
):
def
__init__
(
self
,
board_num
,
port_index
):
self
.
_board_num
=
board_num
self
.
_port_index
=
port_index
self
.
type
=
self
.
_get_digital_dev_type
()
self
.
first_bit
=
self
.
_get_first_bit
(
port_index
,
self
.
type
)
self
.
num_bits
=
self
.
_get_num_bits
()
self
.
in_mask
=
self
.
_get_in_mask
()
self
.
out_mask
=
self
.
_get_out_mask
()
self
.
is_bit_configurable
=
self
.
_get_is_bit_configurable
(
self
.
type
,
self
.
first_bit
,
self
.
in_mask
,
self
.
out_mask
)
self
.
is_port_configurable
=
self
.
_get_is_port_configurable
(
self
.
type
,
self
.
in_mask
,
self
.
out_mask
)
self
.
supports_input
=
self
.
_get_supports_input
(
self
.
in_mask
,
self
.
is_port_configurable
)
self
.
supports_input_scan
=
self
.
_get_supports_input_scan
()
self
.
supports_output
=
self
.
_get_supports_output
(
self
.
out_mask
,
self
.
is_port_configurable
)
self
.
supports_output_scan
=
self
.
_get_supports_output_scan
()
def
_get_num_bits
(
self
):
return
ul
.
get_config
(
InfoType
.
DIGITALINFO
,
self
.
_board_num
,
self
.
_port_index
,
DigitalInfo
.
NUMBITS
)
def
_get_supports_input
(
self
,
in_mask
,
is_port_programmable
):
return
in_mask
>
0
or
is_port_programmable
def
_get_supports_input_scan
(
self
):
try
:
ul
.
get_status
(
self
.
_board_num
,
FunctionType
.
DIFUNCTION
)
except
ULError
:
return
False
return
True
def
_get_supports_output_scan
(
self
):
try
:
ul
.
get_status
(
self
.
_board_num
,
FunctionType
.
DOFUNCTION
)
except
ULError
:
return
False
return
True
def
_get_supports_output
(
self
,
out_mask
,
is_port_programmable
):
return
out_mask
>
0
or
is_port_programmable
def
_get_first_bit
(
self
,
port_index
,
port_type
):
# A few devices (USB-SSR08 for example) start at FIRSTPORTCL and
# number the bits as if FIRSTPORTA and FIRSTPORTB exist for
# compatibility with older digital peripherals
if
port_index
==
0
and
port_type
==
DigitalPortType
.
FIRSTPORTCL
:
return
16
return
0
def
_get_is_bit_configurable
(
self
,
port_type
,
first_bit
,
in_mask
,
out_mask
):
if
in_mask
&
out_mask
>
0
:
return
False
# AUXPORT type ports might be configurable, check if d_config_bit
# completes without error
if
port_type
==
DigitalPortType
.
AUXPORT
:
try
:
ul
.
d_config_bit
(
self
.
_board_num
,
port_type
,
first_bit
,
DigitalIODirection
.
OUT
)
ul
.
d_config_bit
(
self
.
_board_num
,
port_type
,
first_bit
,
DigitalIODirection
.
IN
)
except
ULError
:
return
False
return
True
return
False
def
_get_is_port_configurable
(
self
,
port_type
,
in_mask
,
out_mask
):
if
in_mask
&
out_mask
>
0
:
return
False
# Check if d_config_port completes without error
try
:
ul
.
d_config_port
(
self
.
_board_num
,
port_type
,
DigitalIODirection
.
OUT
)
ul
.
d_config_port
(
self
.
_board_num
,
port_type
,
DigitalIODirection
.
IN
)
except
ULError
:
return
False
return
True
def
_get_digital_dev_type
(
self
):
return
DigitalPortType
(
ul
.
get_config
(
InfoType
.
DIGITALINFO
,
self
.
_board_num
,
self
.
_port_index
,
DigitalInfo
.
DEVTYPE
))
def
_get_in_mask
(
self
):
return
ul
.
get_config
(
InfoType
.
DIGITALINFO
,
self
.
_board_num
,
self
.
_port_index
,
DigitalInfo
.
INMASK
)
def
_get_out_mask
(
self
):
return
ul
.
get_config
(
InfoType
.
DIGITALINFO
,
self
.
_board_num
,
self
.
_port_index
,
DigitalInfo
.
OUTMASK
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment