Beispiel #1
0
class USBSock(object):
    'Object for USB connection to NXT'

    type = 'usb'

    def __init__(self, device):
        self.device = device
        self.debug = False

    def __str__(self):
        return 'USB (%s)' % (self.device.filename)

    def _debug(self, message, err=''):
        if self.debug:
            print message, err

    def connect(self):
        'Use to connect to NXT.'
        self._debug('Connecting via USB...')
        try:
            if os.name != 'nt' and self.device.is_kernel_driver_active(
                    NXT_INTERFACE):
                self.device.detach_kernel_driver(NXT_INTERFACE)
            self.device.set_configuration(NXT_CONFIGURATION)
        except Exception, err:
            self._debug('ERROR:usbsock:connect', err)
            raise
        self._debug('Connected.')
        return Brick(self)
Beispiel #2
0
class USBSock(object):
    'Object for USB connection to NXT'

    bsize = 60	# USB socket block size

    type = 'usb'

    def __init__(self, device):
        self.device = device
        self.debug = False

    def __str__(self):
        return 'USB (%s)' % (self.device.filename)

    def connect(self):
        'Use to connect to NXT.'
        if self.debug:
            print 'Connecting via USB...'
        try:
            if self.device.is_kernel_driver_active(NXT_INTERFACE):
                self.device.detach_kernel_driver(NXT_INTERFACE)
            self.device.set_configuration(NXT_CONFIGURATION)
        except Exception, err:
            if self.debug:
                print 'ERROR:usbsock:connect', err
            raise
        if self.debug:
            print 'Connected.'
        return Brick(self)
 def connect(self):
     if self.debug:
         print('Connecting via Bluetooth...')
     sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
     sock.connect((self.host, BlueSock.PORT))
     self.sock = sock
     if self.debug:
         print('Connected.')
     return Brick(self)
Beispiel #4
0
 def connect(self):
     config = self.device.configurations[0]
     iface = config.interfaces[0][0]
     self.blk_out, self.blk_in = iface.endpoints
     self.handle = self.device.open()
     self.handle.setConfiguration(1)
     self.handle.claimInterface(0)
     self.handle.reset()
     return Brick(self)
 def connect(self):
     if self.debug:
         print('Connecting via Server...')
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.connect((self.host, self.port))
     #TODO: sasl authentication here?
     self.sock = sock
     if self.debug:
         print('Connected.')
     self.send('\x98')
     self.type = 'ip' + self.recv()
     return Brick(self)
Beispiel #6
0
 def connect(self, addrport=None):
     if self._sock is None:
         if self.debug:
             print("No NXT object assigned")
         assert addrport is not None
         # Port is ignored
         addr, port = addrport
         self._sock = pyfantom.NXT(addr)
     else:
         if self.debug:
             print("Using existing NXT object")
     return Brick(self)
Beispiel #7
0
 def connect(self):
     'Use to connect to NXT.'
     self._debug('Connecting via USB...')
     try:
         if os.name != 'nt' and self.device.is_kernel_driver_active(
                 NXT_INTERFACE):
             self.device.detach_kernel_driver(NXT_INTERFACE)
         self.device.set_configuration(NXT_CONFIGURATION)
     except Exception as err:
         self._debug('ERROR:usbsock:connect', err)
         raise
     self._debug('Connected.')
     return Brick(self)
Beispiel #8
0
 def connect(self):
     'Use to connect to NXT.'
     if self.debug:
         print 'Connecting via USB...'
     config = self.device.configurations[0]
     iface = config.interfaces[0][0]
     self.blk_out, self.blk_in = iface.endpoints
     self.handle = self.device.open()
     self.handle.setConfiguration(1)
     self.handle.claimInterface(0)
     self.handle.reset()
     if self.debug:
         print 'Connected.'
     return Brick(self)
Beispiel #9
0
 def connect(self):
     'Use to connect to NXT.'
     if self.debug:
         print('Connecting via USB...')
     config = self.device.configurations[0]
     iface = config.interfaces[0][0]
     self.blk_out, self.blk_in = iface.endpoints
     self.handle = self.device.open()
     self.handle.setConfiguration(1)
     self.handle.claimInterface(0)
     if os.name != 'nt': # http://code.google.com/p/nxt-python/issues/detail?id=33
         self.handle.reset()
     if self.debug:
         print('Connected.')
     return Brick(self)
Beispiel #10
0
 def connect(self, addrport=None):
     if self._sock is None:
         if self.debug:
             print("No NXT object assigned")
         assert addrport is not None
         # Port is ignored
         addr, port = addrport
         paired_addr = pyfantom.pair_bluetooth(addr)
         if self.debug:
             print(("BT Paired Addr: ", paired_addr))
         self._sock = pyfantom.NXT(paired_addr)
     else:
         if self.debug:
             print("Using existing NXT object")
     return Brick(self)
Beispiel #11
0
 def connect(self):
     sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
     sock.connect((self.host, BlueSock.PORT))
     self.sock = sock
     return Brick(self)
Beispiel #12
0
 def connect(self):
     self._device = open(self._filename, 'r+b', buffering=0)
     return Brick(self)