#!/usr/bin/python # main.py # This file is part of Android ATMega8u2 Serial # # Copyright (C) 2011 - Manuel Di Cerbo, Nexus-Computing GmbH # # Android ATMega8u2 Serial is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Android ATMega8u2 Serial is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Android ATMega8u2 Serial; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA # # # Thanks to the LUFA-lib project: # http://code.google.com/p/lufa-lib/ # Thanks to the Arduino firmware project: # https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares # import usb import thread def setup(): busses = usb.busses() handle = 0 print "setting up" for bus in busses: devices = bus.devices for dev in devices: if dev.idVendor == 0x2341: handle = dev.open() handle.setConfiguration(dev.configurations[0]) handle.claimInterface(dev.configurations[0].interfaces[1][0]) handle.controlMsg(requestType = 0x21, request = 34, value = 0, index = 0, buffer = 0, timeout = 0) # SetControlLineState handle.controlMsg(requestType = 0x21, request = 32, value = 0, index = 0, buffer = [0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08], timeout = 0) # SetLineEncoding: 8N1, 9600 baud print "done" return handle def sendCommand(handle): while True: msg = raw_input("enter command in hex (0xA4): ") try: num = int(msg, 16) print "sending "+hex(num) handle.bulkWrite(0x04, [num,],0) except Exception as inst: print inst print "cannot parse number" if __name__=='__main__': handle = setup() sendCommand(handle)