Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC ADC 100M 14b 4cha - Testing
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC ADC 100M 14b 4cha - Testing
Commits
588efe04
Commit
588efe04
authored
Jun 01, 2012
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cp210x_eeprom: Add exception class and comments.
parent
c53a3d68
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
cp210x_eeprom.py
test/fmcadc100m14b4cha/python/cp210x_eeprom.py
+20
-3
No files found.
test/fmcadc100m14b4cha/python/cp210x_eeprom.py
View file @
588efe04
...
...
@@ -18,8 +18,24 @@ from ptsexcept import *
from
cp210x
import
usb
,
valuefile
,
cp210x
from
cp210x.eeprom
import
EEPROM
"""
cp210x_eeprom: Access to USB-UART bridge CP2103 EEPROM
Note: The EEPROM is used to store calibration data (reference voltage output for
the three ranges). The data are stores as a string in the "Product String".
Format: "4.09551500 0.40967800 0.04096060"
"""
CALIBR_RANGES
=
[
'10V'
,
'1V'
,
'100mV'
]
class
CP210xEepromOperationError
(
Exception
):
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
def
__str__
(
self
):
return
(
"CP210x EEPROM:
%
s"
%
(
self
.
msg
))
class
CCP210x_Eeprom
:
...
...
@@ -37,6 +53,8 @@ class CCP210x_Eeprom:
self
.
dev
.
open
()
try
:
eeprom
=
EEPROM
(
self
.
dev
)
except
:
raise
CP210xEepromOperationError
(
'Cannot open device.'
)
finally
:
self
.
dev
.
close
()
eeprom_value
=
eeprom
.
get_values
()
...
...
@@ -44,15 +62,14 @@ class CCP210x_Eeprom:
#print "Product string: \"%s\"" % product_string
calibr_string_list
=
product_string
.
split
(
' '
)
if
len
(
calibr_string_list
)
!=
3
:
raise
Exception
(
'Product string has the wrong format.'
)
raise
CP210xEepromOperationError
(
'Product string has the wrong format.'
)
calibr_data
=
{}
for
i
in
range
(
len
(
calibr_string_list
)):
pattern
=
r'\b[0-9]\.[0-9]{8}\b'
if
re
.
search
(
pattern
,
calibr_string_list
[
i
]):
calibr_data
[
CALIBR_RANGES
[
i
]]
=
calibr_string_list
[
i
]
else
:
raise
Exception
(
'Product string has the wrong format.'
)
raise
CP210xEepromOperationError
(
'Product string has the wrong format.'
)
return
calibr_data
...
...
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