Commit 99f0a67c authored by Matthieu Cattin's avatar Matthieu Cattin

test21 uses a class to access cp210x eeprom.

parent 5baa048f
......@@ -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_VID = "10C4" # Cygnal Integrated Products, Inc.
BOX_USB_PID = "EA60" # CP210x Composite Device
# Calibration box vendor and product IDs
BOX_USB_VENDOR_ID = 0x10c4 # Cygnal Integrated Products, Inc.
BOX_USB_PRODUCT_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 "%5s range calibration voltage is: %s V" % (range_str, value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment