MATLAB Control of CW Lite


#1

Hello,

I went through all the python/CW and the Matlab setups. The waveforms are visible in the capture GUI.
Also, the MATLAB has a valid Python environment. My working directory is also the location of the .m script files. However, cwconnect() throws some error:

cw = cwconnect()
Python Error: Invalid value
‘ChipWhisperer/OpenADC’ for parameter
‘[‘Generic Settings’, ‘Scope Module’,
‘ChipWhisperer/OpenADC’]’.
Valid values: [‘None’]

Please help in this regard.
Thanks,
Debayan


#2

Hi debayan,
I am taking a look into it now. There is a good chance that the updating of this documentation was overlooked during the transition to cw 4.0. If that is the case I will test working steps and update the wiki documentation.
Cheers,
Franz


#3

Hi Franz,

Thanks for your response.
Running ‘pip install chipwhisperer’ from the WinPython Command Prompt installed the v3.5 CW capture.
So, it is the CW v3.5 running with Python 2.7.10.3.
Please let me know what I should do to resolve the issue.

Thanks,
Debayan


#4

Hi debayan,

Since the documentation was outdated, I rewrote the tutorial and the MATLAB api for cw4.0 and updated the page. I will look into the cw3.5 issue tomorrow, then let you know when I fix it.

If you do not want to wait, you can install cw4.0 from github, there are tutorials on the wiki and the MATLAB api with 4.0 does work.

Cheers,
Franz


#5

Hi Franz,
Thanks a lot for your response.
I tried CW v4.0, but even after following all the steps, MATLAB throws an error on running cwconnect().

pyversion
version: ‘2.7’
executable: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python.exe’
library: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python27.dll’
home: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64’
isloaded: 1

[cw, scope, target] = cwconnect()
Python Error: ‘module’ object has no attribute ‘capture’

[cw, scope, target] = cwconnect(int64(1250), int64(3000))
Python Error: ‘module’ object has no attribute ‘capture’

Please let me know how to resolve this in v4.0.

Thanks,
Debayan


#6

Hi debayan,

I tried to replicate your problem with cw 3.5.0 and could not, I did find a unrelated bug in measure_AES.m and fixed it.
Let me know if the cw 4.0 version of the MATLAB API fixes the issue for you.

Cheers,
Franz


#7

Thanks a lot for your response, Franz.
However, I could not still make it work for v4.0. I am using Windows and downloaded the matlab api codes from github.com/newaetech/cw-apiexam … ter/matlab.
I downloaded the v4.0 from github.com/newaetech/chipwhisperer/releases/.

Please let me know if I am making any mistake.
Thanks,
Debayan


#8

Hi debayan,

Does running the chipwhisperer from the command line work for after you downloaded cw 4.0.? Also which version of windows are you running?
If you run this in your python console

  >> import chipwhisperer as cw 
  >> cw.capture_gui() 

What version of the capture GUI shows up (should be in the top left corner of the GUI)?
Cheers,
Franz


#9

Hi Franz,
Thanks for your response. I am still not able to connect the CWLite with MATLAB.
I am using Windows 10 and Capture v4.0.0. The traces are also getting captured properly!

This is what shows up in MATLAB:

pyversion

version: ‘2.7’
executable: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python.exe’
library: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python27.dll’
home: ‘E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64’
isloaded: 0

[cw, scope, target] = cwconnect()
Python Error: DLL load failed: The specified procedure could not be found.

[cw, scope, target] = cwconnect()
Python Error: ‘module’ object has no attribute ‘capture’

MATLAB first gives the DLL missing error and then continuously gives the 2nd error!!!

Please help me fix the issue!
Thanks,
Debayan


#10

Hi debayan,

To give me a better idea where the problem is could you run these commands in MATLAB and reply with the outputs:

  1. version
  2. py.importlib.import_module('time')
  3. py.importlib.import_module('chipwhisperer')
    Could you give the full output as text for each please.

Cheers,
Franz


#11

Hi Franz,

Thanks a lot for your response.
This is what I see in the Matlab command window.

pyversion

   version: '2.7'
executable: 'E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python.exe'
   library: 'E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64\python27.dll'
      home: 'E:\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.7.13.amd64'
  isloaded: 0

version
ans =
8.5.0.197613 (R2015a)

py.importlib.import_module(‘time’)
ans =
Python module with properties:
ctime: [1x1 py.builtin_function_or_method]
localtime: [1x1 py.builtin_function_or_method]
gmtime: [1x1 py.builtin_function_or_method]
clock: [1x1 py.builtin_function_or_method]
mktime: [1x1 py.builtin_function_or_method]
asctime: [1x1 py.builtin_function_or_method]
strptime: [1x1 py.builtin_function_or_method]
struct_time: [1x1 py.type]
timezone: 18000
altzone: 14400
strftime: [1x1 py.builtin_function_or_method]
time: [1x1 py.builtin_function_or_method]
tzname: [1x2 py.tuple]
accept2dyear: 1
daylight: 1
sleep: [1x1 py.builtin_function_or_method]
<module ‘time’ (built-in)>

py.importlib.import_module(‘chipwhisperer’)
Python Error: DLL load failed: The specified procedure could not be found.

py.importlib.import_module(‘chipwhisperer’)
Python Error: ‘module’ object has no attribute ‘capture’

py.importlib.import_module(‘chipwhisperer’)
Python Error: ‘module’ object has no attribute ‘capture’

Please suggest how to resolve the issue.

Thanks,
Debayan


#12

Hello Franz,

I am not able to solve the problem.
Can you please tell me the versions of the Python and CW that worked for Windows 7/10 with Matlab R2015?
Both Win 7/10 gives the same error in Matlab (as in the last reply).
Am I missing anything?

Thanks,
Debayan


#13

Hi debayan,

Could you open you console and run the python interpreter without the absolute path

 python 

In this python interpreter session can you run the following

>> import sys 
>> sys.executable

Can you send me the output please.

Cheers,
Franz


#14

Hi Franz,

This is what I get.

C:\Program Files (x86)\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\scripts>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import sys
sys.executable
‘C:\Program Files (x86)\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.
7.13.amd64\python.exe’

Thanks,
Debayan


#15

Hi debayan,

Could you run the same thing but not from the working directory of your chipwhisperer install.

 cd C:\ && python 

then run the same commands again inside python

 >> import sys 
 >> sys.executable 

Cheers,
Franz


#16

Hi Franz,

This is what it shows:
C:>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import sys
sys.executable
‘C:\Program Files (x86)\ChipWhisperer\WinPython-64bit-2.7.13.1Zero\python-2.
7.13.amd64\python.exe’

All these looks fine. But still there are errors connecting the Matlab with the CW lite (as mentioned before).
Kindly help me fix the issue!

Thanks,
Debayan


#17

Hi debayan,

I cannot replicate this error on my system, I have been trying numerous possibilities. Chipwhisperer works with the python interpreter without matlab, and “py.importlib.import_module(‘chipwhisperer’)” does not work which bypasses the MATLAB api and manually imports chipwhisperer, which means it is most likely a different problem.

The place I have seen the "Python Error: DLL load failed: The specified procedure could not be found. " is when there is 64-bit version vs. 32-bit version problems. You could try uninstalling chipwhisperer and MATLAB and the cw example api and then reinstall everything but keep it as isolated as possible, so do not add the python included in your installation to the system path and check if your system wide python is not interfering with MATLAB paths (if you have a different python installation installed)

Also make sure everything you have installed is 64 bit, because the DLL exception usually arises when there is problem related to this. It could also be a problem with MATLAB’s api to python, I experienced a few issues with how MATLAB caches calls to the python functions (restarting MATLAB after deleting the *.pyc files usually fixed this).

It could also have to do with and issue with 2015b version that was fixed in later versions (as I am testing with 2017b). If you can it might be good to upgrade your MATLAB installation to the latest one.

Other than that I am not sure what the issue could be. I hope one of these suggestions helps you find a way to fix the problem, or at least give you a starting point on what to look for.

Kind Regards,
Franz


#18

Hello Franz,

Thanks a lot for the response.
For capture v4.0 (with python 64bit-2.7.13.1Zero), missing DLL shows up when I run py.importlib.import_module(‘chipwhisperer’).

py.importlib.import_module(‘chipwhisperer’)
Python Error: DLL load failed: The specified procedure could not be found.

cw = cwconnect()
Python Error: ‘module’ object has no attribute ‘capture’

But, for capture v3.5 (with python 64bit-2.7.10.3), py.importlib.import_module(‘chipwhisperer’) works but cwconnect() gives an error.

py.importlib.import_module(‘chipwhisperer’)
ans =
Python module with properties:
analyzer: [1x1 py.module]
capture: [1x1 py.module]
capture_gui: [1x1 py.function]
analyzer_gui: [1x1 py.function]
hardware: [1x1 py.module]
common: [1x1 py.module]
<module ‘chipwhisperer’ from ‘E:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\chipwhisperer_init_.pyc’>

cw = cwconnect()
Python Error: Invalid value ‘ChipWhisperer/OpenADC’ for parameter ‘[‘Generic Settings’, ‘Scope
Module’, ‘ChipWhisperer/OpenADC’]’.
Valid values: [‘None’]

In both cases, I am using Matlab R2015a in Windows 10 (64 bit).

Thanks,
Debayan


#19

Hi Franz,

I upgraded the Matlab to R2017 and now py.importlib.import_module(‘chipwhisperer’) works properly without any error.
However, as soon as I run cwconnect(), Matlab throws a bunch of USB errors:

py.importlib.import_module(‘chipwhisperer’)
ans =
Python module with properties:
captureN: [1×1 py.function]
getLastExpected: [1×1 py.function]
auxList: [1×1 py.function]
openProject: [1×1 py.function]
os: [1×1 py.module]
createProject: [1×1 py.function]
target: [1×1 py.function]
trace_container_native: [1×1 py.module]
BasicKtp: [1×1 py.type]
hardware: [1×1 py.module]
TargetTemplate: [1×1 py.type]
getLastTextin: [1×1 py.function]
capture: [1×1 py.module]
project: [1×1 py.module]
getLastKey: [1×1 py.function]
cwc: [1×1 py.module]
getLastTextout: [1×1 py.function]
analyzer_gui: [1×1 py.function]
capture_gui: [1×1 py.function]
CWCoreAPI: [1×1 py.type]
cwtarget: [1×1 py.type]
scope: [1×1 py.function]
common: [1×1 py.module]
cwhardware: [1×1 py.type]
gui: [1×1 py.type]
Parameter: [1×1 py.type]
ScopeTemplate: [1×1 py.type]
<module ‘chipwhisperer’ from ‘c:\program files (x86)\chipwhisperer\chipwhisperer\software\chipwhisperer_init_.pyc’>

cw = cwconnect()
[‘ChipWhisperer/OpenADC’, ‘NewAE USB (CWLite/CW1200)’, ‘Serial Number’, ‘Auto’],
[‘OpenADC’, ‘Clock Setup’, ‘CLKGEN Settings’, ‘Multiply’, 2],
[‘OpenADC’, ‘Clock Setup’, ‘CLKGEN Settings’, ‘Divide’, 1],
Error using libusb0>_check (line 431)
Python Error: USBError: [Errno None] libusb0-dll:err [control_msg] sending control message failed, win error: The semaphore timeout period has expired.
Error in libusb0>ctrl_transfer (line 593) timeout
Error in core>ctrl_transfer (line 1043) self.__get_timeout(timeout))
Error in naeusb>readCtrl (line 214) return self.usbdev().ctrl_transfer(0xC1, cmd, value, 0, dlen, timeout=self._timeout)
Error in naeusb>cmdReadMem (line 236) data = self.readCtrl(cmd, dlen=dlen)
Error in _OpenADCInterface>sendMessage (line 1678) check = bytearray(self.serial.cmdReadMem(address, len(pba)))
Error in ChipWhispererExtra>_setTargetIOMode (line 1024) self.oa.sendMessage(CODE_WRITE, ADDR_IOROUTE, data)
Error in ChipWhispererExtra>setTargetIOMode3 (line 1014) self._setTargetIOMode(setting, 2)
Error in parameter>func_wrapper (line 753) func(*args, **kargs)
Error in util>emit (line 233) method(targetObj, *args, **kwargs)
Error in parameter>setValue (line 357) self.sigValueChanged.emit(value, blockSignal=self.setValue)
Error in parameter>init (line 221) self.setValue(self.opts[“default”], init=True)
Error in parameter>addChildren (line 283) addedChildren.append(Parameter(self, ignoreChildren=True, **child))
Error in parameter>addChildren (line 286) child.addChildren(child.ignoredChildren)
Error in parameter>init (line 232) self.addChildren(self.ignoredChildren)
Error in ChipWhispererExtra>init (line 884) self.params = Parameter(name=self.getName(), type=‘group’ , children=ret).register()
Error in ChipWhispererExtra>init (line 679) self.cwEXTRA = CWExtraSettings(oa, cwtype)
Error in OpenADC>_con (line 159) self.advancedSettings = ChipWhispererExtra.ChipWhispererExtra(cwtype, self.scopetype, self.qtadc.sc)
Error in base>con (line 60) if self._con():
Error in init>scope (line 59) scope.con()
Error in cwapi>cwconnect (line 6) scope = cw.scope()

Sometimes I get other kind of error like:

cw = cwconnect()
[‘ChipWhisperer/OpenADC’, ‘NewAE USB (CWLite/CW1200)’, ‘Serial Number’, ‘Auto’],
Error using naeusbchip>con (line 120)
Python Error: IOError: OpenADC: <class ‘usb.core.USBError’>[Errno None] libusb0-dll:err [control_msg] sending control message
failed, win error: The semaphore timeout period has expired.

Can you please help resolve this issue?

Thanks,
Debayan


#20

Hi debayan,

Try restarting MATLAB and running just
METHOD 1

 >> cw, scope, target = cwconnect() 
 >> [textout, trace] = measure_AES(scope, target, [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15],[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15])

OR METHOD 2

 >> cw = py.importlib.import_module('chipwhisperer')
 >> scope = cw.scope() 
 >> target = cw.target(scope) 

If you choose the second method you have bypassed the api and need to use the chipwhisper package manually as you would a python package.

I just want to make sure it is not related to you not disconnecting from the scope. Easiest way to disconnect between uses is to unplug the chipwhisperer and plug it back into the computer. Normally you would run

 scope.dis()
 target.dis()

When running commands you just have to be careful not to try to connect to the scope when it is already in use. More information can be found on the wiki page MATLAB 4.0 api usage

Hope this helps. If you get another error just post that. Another quick question: you are still using cw 4.0?
Cheers,
Franz