11
22"""
3- Basic usage of PPK2 Python API - multiprocessing version
3+ Basic usage of PPK2 Python API - multiprocessing version.
44The basic ampere mode sequence is:
551. read modifiers
662. set ampere mode
773. read stream of data
88"""
99import time
10- from ppk2_api .ppk2_api import PPK2_MP
10+ from ppk2_api .ppk2_api import PPK2_MP as PPK2_API
1111
12- ppk2s_connected = PPK2_MP .list_devices ()
12+ ppk2s_connected = PPK2_API .list_devices ()
1313if (len (ppk2s_connected ) == 1 ):
1414 ppk2_port = ppk2s_connected [0 ]
1515 print (f'Found PPK2 at { ppk2_port } ' )
1616else :
1717 print (f'Too many connected PPK2\' s: { ppk2s_connected } ' )
1818 exit ()
1919
20- ppk2_test = PPK2_MP (ppk2_port )
20+ ppk2_test = PPK2_API (ppk2_port , buffer_max_size_seconds = 1 , buffer_chunk_seconds = 0.01 )
2121ppk2_test .get_modifiers ()
22- ppk2_test .use_ampere_meter () # set ampere meter mode
23- ppk2_test .toggle_DUT_power ("OFF" ) # disable DUT power
22+ ppk2_test .set_source_voltage (3300 )
2423
25- ppk2_test .start_measuring () # start measuring
24+ ppk2_test .use_source_meter () # set source meter mode
25+ ppk2_test .toggle_DUT_power ("ON" ) # enable DUT power
2626
27+ ppk2_test .start_measuring () # start measuring
2728# measurements are a constant stream of bytes
28- # multiprocessing variant starts a process in the background which constantly
29- # polls the device in order to prevent losing samples. It will buffer the
30- # last 10s (by default) of data so get_data() can be called less frequently.
31- for i in range (0 , 10 ):
29+ # the number of measurements in one sampling period depends on the wait between serial reads
30+ # it appears the maximum number of bytes received is 1024
31+ # the sampling rate of the PPK2 is 100 samples per millisecond
32+ for i in range (0 , 1000 ):
3233 read_data = ppk2_test .get_data ()
3334 if read_data != b'' :
3435 samples = ppk2_test .get_samples (read_data )
3536 print (f"Average of { len (samples )} samples is: { sum (samples )/ len (samples )} uA" )
36- time .sleep (0.5 )
37+ time .sleep (0.001 )
3738
38- ppk2_test .toggle_DUT_power ("ON" )
39+ ppk2_test .toggle_DUT_power ("OFF" ) # disable DUT power
40+
41+ ppk2_test .use_ampere_meter () # set ampere meter mode
3942
4043ppk2_test .start_measuring ()
41- for i in range (0 , 10 ):
44+ for i in range (0 , 1000 ):
4245 read_data = ppk2_test .get_data ()
4346 if read_data != b'' :
4447 samples = ppk2_test .get_samples (read_data )
4548 print (f"Average of { len (samples )} samples is: { sum (samples )/ len (samples )} uA" )
46- time .sleep (0.5 ) # lower time between sampling -> less samples read in one sampling period
47-
48- ppk2_test .stop_measuring ()
49+ time .sleep (0.001 ) # lower time between sampling -> less samples read in one sampling period
4950
51+ ppk2_test .stop_measuring ()
0 commit comments