def _handle_invalid_read_response(self, res, expected_len):
if not res:<EOL><INDENT>reset(self.stick)<EOL>raise pyhsm.exception.YHSM_Error('<STR_LIT>'% (pyhsm.defines.cmd2str(self.command)) )<EOL><DEDENT>self.stick.write('<STR_LIT>', '<STR_LIT>')<EOL>res2 = self.stick.read(<NUM_LIT:50>) <EOL>lines = res2.split('<STR_LIT:\n>')<EOL>for this in lines:<EOL><INDENT>if re.match('<STR_LIT>', this):<EOL><INDENT>raise pyhsm.exception.YHSM_Error('<STR_LIT>')<EOL><DEDENT><DEDENT>raise pyhsm.exception.YHSM_Error('<STR_LIT>'% (self.stick.device, res.encode('<STR_LIT>')))<EOL>
This function is called when we do not get the expected frame header in
response to a command. Probable reason is that we are not talking to a
YubiHSM in HSM mode (might be a modem, or a YubiHSM in configuration mode).

Throws a hopefully helpful exception.