How to do it...

We will create the following missileControl.py script, which will include two classes and a default main() function to test it:

  1. Import the required modules as follows:
#!/usr/bin/python3 
# missileControl.py 
import time 
import usb.core 
  1. Define the SamMissile() class, which provides the specific commands for the USB device, as follows:
class SamMissile(): idVendor=0x1130 idProduct=0x0202 idName="Tenx Technology SAM Missile" # Protocol control bytes bmRequestType=0x21 bmRequest=0x09 wValue=0x02 wIndex=0x01 # Protocol command bytes INITA = [ord('U'), ord('S'), ord('B'), ord('C'), 0, 0, 4, 0] INITB = [ord('U'), ord('S'), ord('B'), ord('C'), 0, 64, 2, 0] CMDFILL = [ 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.