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
99f0a67c
Commit
99f0a67c
authored
Jan 11, 2012
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test21 uses a class to access cp210x eeprom.
parent
5baa048f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
54 deletions
+14
-54
test21.py
test/fmcadc100m14b4cha/python/test21.py
+14
-54
No files found.
test/fmcadc100m14b4cha/python/test21.py
View file @
99f0a67c
...
...
@@ -15,67 +15,28 @@ from ctypes import *
from
ptsexcept
import
*
from
cp210x_eeprom
import
usb
,
valuefile
,
cp210x
from
cp210x_eeprom.eeprom
import
EEPROM
import
cp210x_eeprom
"""
test21: Store calibration data to calibraton box CP2103 EEPROM
test21: Store calibration data to CP2103 EEPROM
The calibration box contains a voltage reference that has to
be calibrated for each input voltage range of the FmcAdc.
A multimeter of at least 6 digits has to be used for the
calibration. The result of the calibration is stored in the
cp2103 EEPROM.
"""
# Calibration box vendor and
device
IDs
BOX_USB_V
ID
=
"10C4"
# Cygnal Integrated Products, Inc.
BOX_USB_P
ID
=
"EA60"
# CP210x Composite Device
# Calibration box vendor and
product
IDs
BOX_USB_V
ENDOR_ID
=
0x10c4
# Cygnal Integrated Products, Inc.
BOX_USB_P
RODUCT_ID
=
0xea60
# CP210x Composite Device
CALIBR_RANGES
=
[
'10V'
,
'1V'
,
'100mV'
]
def
find_device
(
vid
,
pid
):
usb_patterns
=
[]
vid
=
int
(
vid
,
16
)
pid
=
int
(
pid
,
16
)
usb_patterns
.
append
(
dict
(
idVendor
=
vid
,
idProduct
=
pid
))
for
dev
in
cp210x
.
Cp210xProgrammer
.
list_devices
(
usb_patterns
):
return
dev
def
get_calibr_data
(
dev
):
dev
.
open
()
try
:
eeprom
=
EEPROM
(
dev
)
finally
:
dev
.
close
()
eeprom_value
=
eeprom
.
get_values
()
product_string
=
eeprom_value
[
'product_string'
]
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.'
)
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.'
)
return
calibr_data
def
set_calibr_data
(
dev
,
data
):
dev
.
open
()
product_string
=
data
[
CALIBR_RANGES
[
0
]]
+
' '
+
data
[
CALIBR_RANGES
[
1
]]
+
' '
+
data
[
CALIBR_RANGES
[
2
]]
print
"New product string value:
\"
%
s
\"
"
%
product_string
try
:
dev
.
set_product_string
(
product_string
)
print
"Calibration data written to cp210x EEPROM."
finally
:
dev
.
close
()
def
input_calibr_data
(
range_str
):
while
(
True
):
calibr_string
=
raw_input
(
"Enter calibration voltage for "
+
range_str
+
" range (in volts, max 10 char): "
)
...
...
@@ -88,8 +49,7 @@ def input_calibr_data(range_str):
def
main
():
usb
.
init
()
dev
=
find_device
(
BOX_USB_VID
,
BOX_USB_PID
)
box_eeprom
=
cp210x_eeprom
.
CCP210x_Eeprom
(
"
%
X"
%
BOX_USB_VENDOR_ID
,
"
%
X"
%
BOX_USB_PRODUCT_ID
)
# Ask user to input calibration data
calibr_data
=
{}
...
...
@@ -97,10 +57,10 @@ def main ():
calibr_data
[
range_str
]
=
input_calibr_data
(
range_str
)
# Write calibration data to cp210x EEPROM
set_calibr_data
(
dev
,
calibr_data
)
box_eeprom
.
set_calibr_data
(
calibr_data
)
print
"Readback calibration data from cp210x EEPROM."
calibr_data
=
get_calibr_data
(
dev
)
calibr_data
=
box_eeprom
.
get_calibr_data
(
)
for
range_str
,
value
in
calibr_data
.
iteritems
():
print
"
%5
s range calibration voltage is:
%
s V"
%
(
range_str
,
value
)
...
...
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