Exemplo n.º 1
0
 def read(self, n):
     buf = "\x00"*n
     r = ftdi.ftdi_read_data(self.ft_ctx, buf, n)
     if r >= 0:
         return buf[:r]
     else:
         raise RuntimeError("Error reading (%d)" % r)
Exemplo n.º 2
0
 def read(self, n):
     buf = "\x00" * n
     r = ftdi.ftdi_read_data(self.ft_ctx, buf, n)
     if r >= 0:
         return buf[:r]
     else:
         raise RuntimeError("Error reading (%d)" % r)
Exemplo n.º 3
0
    def flush_input(self):
        while len(self.dest) and not self.hw_error:

            data = chr(0)*len(self.dest)
            ret = ftdi.ftdi_read_data(self.ftdic, data, len(self.dest))
            if ret < 0:
                self.hw_error = ret
                self.i2c_error = True
                break

            for b in data[:ret]:
                self.dest.pop(0)(ord(b))
Exemplo n.º 4
0
    def flush_input(self):
        while len(self.dest) and not self.hw_error:

            data = chr(0) * len(self.dest)
            ret = ftdi.ftdi_read_data(self.ftdic, data, len(self.dest))
            if ret < 0:
                self.hw_error = ret
                self.i2c_error = True
                break

            for b in data[:ret]:
                self.dest.pop(0)(ord(b))
Exemplo n.º 5
0
 def readOne(self):
     """ read 1 char from usb
     """
     buf = ' '
     err = ftdi.ftdi_read_data(self.__ftdic, buf, 1)
     if err < 0:
         self._log.error("Can't read data (%d, %s)" % (err, ftdi.ftdi_get_error_string(self.__ftdic)))
         self.shutdown()
         raise FtdiError("Can't read data (%d, %s)" % (err, ftdi.ftdi_get_error_string(self.__ftdic)))
     if err:
         c = unichr(ord(buf) % 0x80)  # Clear bit 7
         return c
     else:
         return None
 def guessResetDirection(self, h):
     if (self.resetValue is None or self.nBootValue is None):
         CBUS_2 = 4
         CBUS_0 = 1
         RESET_LINE = CBUS_2
         GPIO5_LINE = CBUS_0
         resetLow = ((RESET_LINE << 4) | 0)
         resetHigh = ((RESET_LINE << 4) | RESET_LINE)
         GPIO5Low = ((GPIO5_LINE << 4) | 0)
         GPIO5High = ((GPIO5_LINE << 4) | GPIO5_LINE)
         h.usb_write_timeout = 1000
         h.usb_read_timeout = 1000
         ret = ftdi.ftdi_set_baudrate(h, 115200)
         ret = (ret + ftdi.ftdi_setflowctrl(h, ftdi.SIO_DISABLE_FLOW_CTRL))
         ret = (ret + ftdi.ftdi_set_line_property(
             h, ftdi.BITS_8, ftdi.STOP_BIT_1, ftdi.NONE))
         for i in range(2):
             if (i % 2) == 0:
                 resetValue = resetHigh
                 nbootValue = GPIO5High
             else:
                 resetValue = resetLow
                 nbootValue = GPIO5Low
             ftdi.ftdi_set_bitmode(h, resetValue, ftdi.BITMODE_CBUS)
             time.sleep(0.10000000000000001)
             ftdi.ftdi_set_bitmode(h, nbootValue, ftdi.BITMODE_CBUS)
             time.sleep(0.10000000000000001)
             ftdi.ftdi_set_bitmode(h, 0, ftdi.BITMODE_CBUS)
             ftdi.ftdi_usb_purge_rx_buffer(h)
             ftdi.ftdi_usb_purge_tx_buffer(h)
             ftdi.ftdi_write_data(h, struct.pack('B', 127), 1)
             startTime = time.time()
             inbuff = '\x00'
             nbyte_rcvd = 0
             while (nbyte_rcvd == 0 and (time.time() - startTime) < 1):
                 nbyte_rcvd = ftdi.ftdi_read_data(h, inbuff, 1)
                 continue
             if nbyte_rcvd > 0:
                 reply = struct.unpack('B', inbuff)
                 if (reply[0]) == 121:
                     self.resetValue = resetValue
                     self.nBootValue = nbootValue
                     break
                 else:
                     continue
             continue
     return (self.resetValue, self.nBootValue)
Exemplo n.º 7
0
	def guessResetDirection(self, h):
		if (self.resetValue is None or self.nBootValue is None):
			CBUS_2 = 4
			CBUS_0 = 1
			RESET_LINE = CBUS_2
			GPIO5_LINE = CBUS_0
			resetLow = ((RESET_LINE << 4) | 0)
			resetHigh = ((RESET_LINE << 4) | RESET_LINE)
			GPIO5Low = ((GPIO5_LINE << 4) | 0)
			GPIO5High = ((GPIO5_LINE << 4) | GPIO5_LINE)
			h.usb_write_timeout = 1000
			h.usb_read_timeout = 1000
			ret = ftdi.ftdi_set_baudrate(h, 115200)
			ret = (ret + ftdi.ftdi_setflowctrl(h, ftdi.SIO_DISABLE_FLOW_CTRL))
			ret = (ret + ftdi.ftdi_set_line_property(h, ftdi.BITS_8, ftdi.STOP_BIT_1, ftdi.NONE))
			for i in range(2):
				if (i % 2) == 0:
					resetValue = resetHigh
					nbootValue = GPIO5High
				else:
					resetValue = resetLow
					nbootValue = GPIO5Low
				ftdi.ftdi_set_bitmode(h, resetValue, ftdi.BITMODE_CBUS)
				time.sleep(0.10000000000000001)
				ftdi.ftdi_set_bitmode(h, nbootValue, ftdi.BITMODE_CBUS)
				time.sleep(0.10000000000000001)
				ftdi.ftdi_set_bitmode(h, 0, ftdi.BITMODE_CBUS)
				ftdi.ftdi_usb_purge_rx_buffer(h)
				ftdi.ftdi_usb_purge_tx_buffer(h)
				ftdi.ftdi_write_data(h, struct.pack('B', 127), 1)
				startTime = time.time()
				inbuff = '\x00'
				nbyte_rcvd = 0
				while (nbyte_rcvd == 0 and (time.time() - startTime) < 1):
					nbyte_rcvd = ftdi.ftdi_read_data(h, inbuff, 1)
					continue
				if nbyte_rcvd > 0:
					reply = struct.unpack('B', inbuff)
					if (reply[0]) == 121:
						self.resetValue = resetValue
						self.nBootValue = nbootValue
						break
					else:
						continue
				continue
		return (self.resetValue, self.nBootValue)
Exemplo n.º 8
0
def getTrame(ftdiContext):
	# Récupérer une trame
	buf=' '
	startCapture = False
	stopCapture = False
	trame = []
	while not stopCapture:
		f = ftdi.ftdi_read_data(ftdiContext, buf, 0x1)
		if f != 0:
			ordBuf = ord(buf) & 0x07f
			if ordBuf == CAR_STX:
				startCapture = True
			if startCapture and ordBuf == CAR_ETX:
				stopCapture = True
			if startCapture:
				trame.append(ordBuf)
		time.sleep(0.01)
		
	return trame;