Esempio n. 1
0
def open_ftdi():
	if (ftdi.ftdi_init(ftdic) < 0) :
		print "ftdi_init fehlgeschlagen"
		exit(-1)
	
	else:
		print "ftdi_init geklappt"


	#Öffne FTDI-Chip FT232R - evt. andere Nummern eintragen! 
	#Tut auch mit FT245BL
	ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001)
	if (ret) < 0:
		print "Konnte Gerät nicht öffnen:" + ret + "(" + \
			ftdi.ftdi_get_error_string(ftdic) + ")"
		exit(-1)
	else:
		print "Gerät erfolgreich geöffnet"

	#Bitbag mit DTR, RX und TX beginnen
	#2. Argument macht die Pins D0-D7 ansprechbar


	#ftdi.ftdi_enable_bitbang(ftdic, D[0]|D[1]|D[2]|D[3]|D[4]|D[5]|D[6]|D[7] )
	ftdi.ftdi_enable_bitbang(ftdic,0x1 | 0x2| 0x4| 0x8| 0x10| 0x20| 0x40| 0x80)

	#Am Anfang ausschalten
	ftdi.ftdi_write_data(ftdic, chr(255), 1)
Esempio n. 2
0
def write_ftdi(i):
	if (ftdi.ftdi_write_data(ftdic, chr(255), 1) != 1):
		print "Fehler: ftdi noch nicht geöffnet (open_ftdi())"
	elif not (0 <= int(i) <= 255):
		print "Uebergebene Zahl im falschen Wertebereich"
	else:
		ftdi.ftdi_write_data(ftdic, chr(255-int(i)), 1)
 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)
Esempio n. 4
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)
Esempio n. 5
0
 def flush_output(self):
     if self.hw_error or not len(self.wr_buffer):
         return
     buf = None
     for i in self.wr_buffer:
         if buf is None:
             buf = chr(i)
         else:
             buf += chr(i)
     ret = ftdi.ftdi_write_data(self.ftdic, buf, len(self.wr_buffer))
     if ret < 0:
         self.hw_error = ret
         self.i2c_error = True
     self.wr_buffer = bytearray()
Esempio n. 6
0
 def flush_output(self):
     if self.hw_error or not len(self.wr_buffer):
         return
     buf = None
     for i in self.wr_buffer:
         if buf is None:
             buf = chr(i)
         else:
             buf += chr(i)
     ret = ftdi.ftdi_write_data(self.ftdic, buf, len(self.wr_buffer))
     if ret < 0:
         self.hw_error = ret
         self.i2c_error = True
     self.wr_buffer = bytearray()
Esempio n. 7
0
        with open('status', 'w') as f:             \
               f.write ('closed' if is_closed else 'open')

    LOG.info("Full: %s\t Masked: %s\t Is Closed: %s\t To Write: %s", \
     hex(ord(result)),
     hex(ord(result) & RXT),
     is_closed,
     hex(ord(result) | CTS)
    )

    opening = False
    if toggle_door:
        LOG.info("Opening Door")
        opening = True
        # activating the relay
        ftdi.ftdi_write_data(ftdic, chr(ord(result) | CTS), 1)

    time.sleep(3)

    if toggle_door and opening:
        # trying to work with the existing result variable has strange
        # behavior - rereading the pins
        new_result = " "
        ftdi.ftdi_read_pins(ftdic, new_result)

        LOG.info("... %s vs %s & %s = %s", \
         hex(ord(result)),
         hex(ord(new_result)),
         hex(~CTS),
         hex(ord(new_result) & (~CTS))
        )
Esempio n. 8
0
def jtag_lengthen():
    ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
    ftdi.ftdi_set_bitmode(F, 0x08, ftdi.BITMODE_BITBANG)
    ftdi.ftdi_write_data(F, '\x00', 1)
Esempio n. 9
0
def power_button_assert():
    ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
    ftdi.ftdi_set_bitmode(F, 0x40, ftdi.BITMODE_BITBANG)
    ftdi.ftdi_write_data(F, '\x40', 1)
    time.sleep(4)
    ftdi.ftdi_write_data(F, '\x00', 1)
Esempio n. 10
0
def power_force_off():
    ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
    ftdi.ftdi_set_bitmode(F, 0x30, ftdi.BITMODE_BITBANG)
    ftdi.ftdi_write_data(F, '\x30', 1)
Esempio n. 11
0
def ppc_halt_off():
    ftdi.ftdi_set_interface(F, ftdi.INTERFACE_B)
    ftdi.ftdi_set_bitmode(F, 0x00, ftdi.BITMODE_BITBANG)
    ftdi.ftdi_write_data(F, '\x00', 1)
Esempio n. 12
0
 def write(self, data):
     r = ftdi.ftdi_write_data(self.ft_ctx, data, len(data))
     if r >= 0:
         return r
     else:
         raise RuntimeError("Error writing (%d)" % r)
def power_force_off():
   ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
   ftdi.ftdi_set_bitmode(F, 0x30, ftdi.BITMODE_BITBANG)
   ftdi.ftdi_write_data(F, '\x30', 1)
def power_button_assert():
   ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
   ftdi.ftdi_set_bitmode(F, 0x40, ftdi.BITMODE_BITBANG)
   ftdi.ftdi_write_data(F, '\x40', 1)
   time.sleep(4)
   ftdi.ftdi_write_data(F, '\x00', 1)
def jtag_lengthen():
   ftdi.ftdi_set_interface(F, ftdi.INTERFACE_D)
   ftdi.ftdi_set_bitmode(F, 0x08, ftdi.BITMODE_BITBANG)
   ftdi.ftdi_write_data(F, '\x00', 1)
Esempio n. 16
0
 def write(self, data):
     r = ftdi.ftdi_write_data(self.ft_ctx, data, len(data))
     if r >= 0:
         return r
     else:
         raise RuntimeError("Error writing (%d)" % r)
Esempio n. 17
0
		with open ('status', 'w') as f: \
			f.write ('closed' if is_closed else 'open')

	LOG.info("Full: %s\t Masked: %s\t Is Closed: %s\t To Write: %s", \
		hex(ord(result)),
		hex(ord(result) & RXT),
		is_closed,
		hex(ord(result) | CTS)
	)

	opening=False
	if toggle_door:
		LOG.info("Opening Door")
		opening = True
		# activating the relay
		ftdi.ftdi_write_data(ftdic, chr(ord(result) | CTS), 1)

	time.sleep(3)

	if toggle_door and opening:
		# trying to work with the existing result variable has strange
		# behavior - rereading the pins
		new_result = " "
		ftdi.ftdi_read_pins(ftdic, new_result)

		LOG.info("... %s vs %s & %s = %s", \
			hex(ord(result)),
			hex(ord(new_result)),
			hex(~CTS),
			hex(ord(new_result) & (~CTS))
		)
#!/usr/bin/python
import ftdi
import time

F = ftdi.ftdi_context()

ftdi.ftdi_init(F)

ftdi.ftdi_usb_open(F, 0x0403, 0x6011)

ftdi.ftdi_set_interface(F, ftdi.INTERFACE_B)

ftdi.ftdi_set_bitmode(F, 0x08, ftdi.BITMODE_BITBANG)

ftdi.ftdi_write_data(F, '\x00', 1)

ftdi.ftdi_usb_close(F)
def ppc_halt_off():
   ftdi.ftdi_set_interface(F, ftdi.INTERFACE_B)
   ftdi.ftdi_set_bitmode(F, 0x00, ftdi.BITMODE_BITBANG)
   ftdi.ftdi_write_data(F, '\x00', 1)