Download latest PyUSB from :
http://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-beta-2/pyusb-1.0.0b2.tar.gz/download
Place file “pyusb-1.0.0b2.tar.gz” on your desktop
gunzip <pyusb-1.0.0b2.tar.gz |tar xvfp -
cd pyusb-1.0.0b2
sudo ./setup.py install
Make a new python script with the following code — don’t forget your #! line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<span class="kwd">import</span><span class="pln"> usb busses </span><span class="pun">=</span><span class="pln"> usb</span><span class="pun">.</span><span class="pln">busses</span><span class="pun">()</span> <span class="kwd">for</span><span class="pln"> bus </span><span class="kwd">in</span><span class="pln"> busses</span><span class="pun">:</span><span class="pln"> devices </span><span class="pun">=</span><span class="pln"> bus</span><span class="pun">.</span><span class="pln">devices </span><span class="kwd">for</span><span class="pln"> devi </span><span class="kwd">in</span><span class="pln"> devices</span><span class="pun">:</span> <span class="kwd">print</span> <span class="str">"Device:"</span><span class="pun">,</span><span class="pln"> devi</span><span class="pun">.</span><span class="pln">filename </span><span class="kwd">print_internals(devi)</span><span class="pun"> def</span><span class="pln"> print_internals</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">):</span> <span class="kwd">for</span><span class="pln"> attrib </span><span class="kwd">in</span><span class="pln"> dir</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">):</span> <span class="kwd">if</span> <span class="kwd">not</span><span class="pln"> attrib</span><span class="pun">.</span><span class="pln">startswith</span><span class="pun">(</span><span class="str">'_'</span><span class="pun">)</span> <span class="kwd">and</span> <span class="kwd">not</span><span class="pln"> attrib </span><span class="pun">==</span> <span class="str">'configurations'</span><span class="pun">:</span><span class="pln"> x</span><span class="pun">=</span><span class="pln">getattr</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">,</span><span class="pln"> attrib</span><span class="pun">)</span> <span class="kwd">print</span> <span class="str">" "</span><span class="pun">,</span><span class="pln"> attrib</span><span class="pun">,</span><span class="pln"> x </span><span class="kwd">for</span><span class="pln"> config </span><span class="kwd">in</span><span class="pln"> dev</span><span class="pun">.</span><span class="pln">configurations</span><span class="pun">:</span> <span class="kwd">for</span><span class="pln"> attrib </span><span class="kwd">in</span><span class="pln"> dir</span><span class="pun">(</span><span class="pln">config</span><span class="pun">):</span> <span class="kwd">if</span> <span class="kwd">not</span><span class="pln"> attrib</span><span class="pun">.</span><span class="pln">startswith</span><span class="pun">(</span><span class="str">'_'</span><span class="pun">):</span><span class="pln"> x</span><span class="pun">=</span><span class="pln">getattr</span><span class="pun">(</span><span class="pln">config</span><span class="pun">,</span><span class="pln"> attrib</span><span class="pun">)</span> </code><code><span class="pun"> </span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<span class="kwd">import</span><span class="pln"> usb</span><span class="pln"> busses </span><span class="pun">=</span><span class="pln"> usb</span><span class="pun">.</span><span class="pln">busses</span><span class="pun">()</span> <span class="kwd">for</span><span class="pln"> bus </span><span class="kwd">in</span><span class="pln"> busses</span><span class="pun">:</span><span class="pln"> devices </span><span class="pun">=</span><span class="pln"> bus</span><span class="pun">.</span><span class="pln">devices </span><span class="kwd">for</span><span class="pln"> dev </span><span class="kwd">in</span><span class="pln"> devices</span><span class="pun">:</span><span class="pln"> _name </span><span class="pun">=</span><span class="pln"> usb</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="pln">get_string</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">dev</span><span class="pun">,</span><span class="lit">256</span><span class="pun">,2</span><span class="pun">)</span> <span class="kwd">print</span> <span class="str">"device name="</span><span class="pun">,</span><span class="pln">_name </span><span class="kwd">print</span> <span class="str">"Device:"</span><span class="pun">,</span><span class="pln"> dev</span><span class="pun">.</span><span class="pln">filename </span><span class="kwd">print</span> <span class="str">" Device class:"</span><span class="pun">,</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">deviceClass </span><span class="kwd">print</span> <span class="str">" Device sub class:"</span><span class="pun">,</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">deviceSubClass </span><span class="kwd">print</span> <span class="str">" Device protocol:"</span><span class="pun">,</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">deviceProtocol </span><span class="kwd">print</span> <span class="str">" Max packet size:"</span><span class="pun">,</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">maxPacketSize </span><span class="kwd">print</span> <span class="str">" idVendor:"</span><span class="pun">,</span><span class="pln">hex</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">idVendor</span><span class="pun">)</span> <span class="kwd">print</span> <span class="str">" idProduct:"</span><span class="pun">,</span><span class="pln">hex</span><span class="pun">(</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">idProduct</span><span class="pun">)</span> <span class="kwd">print</span> <span class="str">" Device Version:"</span><span class="pun">,</span><span class="pln">dev</span><span class="pun">.</span><span class="pln">deviceVersion </span><span class="kwd">for</span><span class="pln"> config </span><span class="kwd">in</span><span class="pln"> dev</span><span class="pun">.</span><span class="pln">configurations</span><span class="pun">:</span> <span class="kwd">print</span> <span class="str">" Configuration:"</span><span class="pun">,</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">value </span><span class="kwd">print</span> <span class="str">" Total length:"</span><span class="pun">,</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">totalLength </span><span class="kwd">print</span> <span class="str">" selfPowered:"</span><span class="pun">,</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">selfPowered </span><span class="kwd">print</span> <span class="str">" remoteWakeup:"</span><span class="pun">,</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">remoteWakeup </span><span class="kwd">print</span> <span class="str">" maxPower:"</span><span class="pun">,</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">maxPower </span><span class="kwd">for</span><span class="pln"> intf </span><span class="kwd">in</span><span class="pln"> config</span><span class="pun">.</span><span class="pln">interfaces</span><span class="pun">:</span> <span class="kwd">print</span> <span class="str">" Interface:"</span><span class="pun">,</span><span class="pln">intf</span><span class="pun">[</span><span class="lit">0</span><span class="pun">].</span><span class="pln">interfaceNumber </span><span class="kwd">for</span><span class="pln"> alt </span><span class="kwd">in</span><span class="pln"> intf</span><span class="pun">:</span> <span class="kwd">print</span> <span class="str">" Alternate Setting:"</span><span class="pun">,</span><span class="pln">alt</span><span class="pun">.</span><span class="pln">alternateSetting </span><span class="kwd">print</span> <span class="str">" Interface class:"</span><span class="pun">,</span><span class="pln">alt</span><span class="pun">.</span><span class="pln">interfaceClass </span><span class="kwd">print</span> <span class="str">" Interface sub class:"</span><span class="pun">,</span><span class="pln">alt</span><span class="pun">.</span><span class="pln">interfaceSubClass </span><span class="kwd">print</span> <span class="str">" Interface protocol:"</span><span class="pun">,</span><span class="pln">alt</span><span class="pun">.</span><span class="pln">interfaceProtocol </span><span class="kwd">for</span><span class="pln"> ep </span><span class="kwd">in</span><span class="pln"> alt</span><span class="pun">.</span><span class="pln">endpoints</span><span class="pun">:</span> <span class="kwd">print</span> <span class="str">" Endpoint:"</span><span class="pun">,</span><span class="pln">hex</span><span class="pun">(</span><span class="pln">ep</span><span class="pun">.</span><span class="pln">address</span><span class="pun">)</span> <span class="kwd">print</span> <span class="str">" Type:"</span><span class="pun">,</span><span class="pln">ep</span><span class="pun">.</span><span class="pln">type </span><span class="kwd">print</span> <span class="str">" Max packet size:"</span><span class="pun">,</span><span class="pln">ep</span><span class="pun">.</span><span class="pln">maxPacketSize </span><span class="kwd">print</span> <span class="str">" Interval:"</span><span class="pun">,</span><span class="pln">ep</span><span class="pun">.</span><span class="pln">interval</span> |
Save the file, change permissions and run.
We now know the name of our USB device and we can write an if/then line in our script to give the usb port location (filename) to our Hex/Serial code in order to speak with our Satellite USB device.