Refactor modbusclient

Hi @arnaudsoullie, 

This pull request tries to fix small bugs in https://github.com/rapid7/metasploit-framework/pull/3309 and refactor code, do you mind to review land it into your repo before going ahead with https://github.com/rapid7/metasploit-framework/pull/3309 ? It shouldn't break nothing, just refactor code and fix small bugs, specially when using the msf tcp mixin and API.

Thanks in advance!