Exemplo n.º 1
0
 def open(self, usb_reset=True):
     self._debug(3, "MPSSE: Open")
     ftdi.usb_open(self._ctx, FT232H_VID, FT232H_PID)
     if usb_reset:
         ftdi.usb_reset(self._ctx)
     ftdi.read_data_set_chunksize(self._ctx, 65535)
     ftdi.write_data_set_chunksize(self._ctx, 65535)
     # RESET MPSSE
     ftdi.set_bitmode(self._ctx, 0, 0)
     # Enable MPSSE
     ftdi.set_bitmode(self._ctx, 0, 2)
     # Set Latency timer to 16ms
     ftdi.set_latency_timer(self._ctx, 16)
Exemplo n.º 2
0
	def __init__(self):
		self.ftdic = ftdi1.new()
		print "usb_open ret = ", ftdi1.usb_open(self.ftdic, 0x0403, 0x8c81)
		print "set_bitmode ret = ", ftdi1.set_bitmode(self.ftdic, 0x00, ftdi1.BITMODE_RESET)		# Reset port to normal operation
		print "set_baudrate ret = ", ftdi1.set_baudrate(self.ftdic, 115200)		# 115200 baud
		print "setflowctrl ret = ", ftdi1.setflowctrl(self.ftdic, ftdi1.SIO_DISABLE_FLOW_CTRL)
		print "setdtr ret = ", ftdi1.setdtr(self.ftdic, 1)
		print "setrts ret = ", ftdi1.setrts(self.ftdic, 1)
 def open_comms(self):
     self.ftdic = ftdi.new()
     ret = ftdi.usb_open(self.ftdic, self.idVendor, self.idProduct)
     print ret
     ret = ftdi.usb_purge_buffers(self.ftdic)
     print ret
     ret = ftdi.set_bitmode(self.ftdic, 0xFF, ftdi.BITMODE_BITBANG)
     print ret
Exemplo n.º 4
0
def main():
    """Main program"""
    context = ftdi.new()

    version_info = ftdi.get_library_version()
    print("[FTDI version] major: %d, minor: %d, micro: %d" \
               ", version_str: %s, snapshot_str: %s" %
               (version_info.major, version_info.minor, version_info.micro,
               version_info.version_str, version_info.snapshot_str))

    # try to open an ftdi 0x6010 or 0x6001
    ret = ftdi.usb_open(context, 0x0403, 0x6010)
    if ret < 0:
        ret = ftdi.usb_open(context, 0x0403, 0x6001)

    print("ftdi.usb_open(): %d" % ret)
    print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600))

    ftdi.free(context)
Exemplo n.º 5
0
def main():
    """Main program"""
    context = ftdi.new()

    version_info = ftdi.get_library_version()
    print("[FTDI version] major: %d, minor: %d, micro: %d" \
               ", version_str: %s, snapshot_str: %s" %
               (version_info.major, version_info.minor, version_info.micro,
               version_info.version_str, version_info.snapshot_str))

    # try to open an ftdi 0x6010 or 0x6001
    ret = ftdi.usb_open(context, UM232H_B_VID, UM232H_B_PID)
    if ret < 0:
        ret = ftdi.usb_open(context, UM232H_B_VID, UM232H_B_PID)
        
    print("ftdi.usb_open(): %d" % ret)
    print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600))

    ftdi.free(context)
Exemplo n.º 6
0
 def __init__(self, VID=0x0403, PID=0x6010, _debug_out=None):
     """Open USB connection and initialize FTDI context."""
     context = ftdi.new()
     if not (ftdi.usb_open(context, VID, PID) == 0):
         ftdi.free(context)
         self.ftdic = None
         raise IOError('could not open USB connection!')
     ftdi.set_bitmode(context, 0, ftdi.BITMODE_SYNCFF)
     self.ftdic = context
     self._debug_ftdi = False
     self._debug_out = _debug_out
     self._debug_lock = threading.Lock()
Exemplo n.º 7
0
def bruteforce_connection_props():
    for bits in [ftdi.BITS_8]:  #[ftdi.BITS_7, ftdi.BITS_8]:
        for sbit in [ftdi.STOP_BIT_1, ftdi.STOP_BIT_15, ftdi.STOP_BIT_2]:
            for parity in [
                    ftdi.NONE, ftdi.ODD, ftdi.EVEN, ftdi.MARK, ftdi.SPACE
            ]:
                for break_ in [ftdi.BREAK_ON]:  #, ftdi.BREAK_OFF]:
                    print(bits, sbit, parity, break_)
                    ctx = ftdi.new()
                    ret = ftdi.usb_open(ctx, 0x0760, 0x0002)
                    assert ret == 0
                    ret = ftdi.set_baudrate(ctx, 38400)
                    assert ret == 0, 'baudrate error'

                    ftdi.set_line_property2(ctx, bits, sbit, parity, break_)

                    send_msg_led(ctx, 2, 0x49, True)

                    input('waiting')

                    ftdi.free(ctx)
Exemplo n.º 8
0
def main():
    ctx = ftdi.new()

    ret = ftdi.usb_open(ctx, 0x0760, 0x0002)
    assert ret == 0, 'ftdi.usb_open error: {}'.format(ret)

    ret = ftdi.set_baudrate(ctx, 38400)
    assert ret == 0, 'baudrate error'

    try:
        code.interact(local={
            'ctx': ctx,
            'ftdi': ftdi,
            'read_continuously': read_continuously,
            'parse_continuously': parse_continuously,
            'send_msg_slider': send_msg_slider,
            'send_msg_led': send_msg_led,
            'bruteforce_properties': bruteforce_properties,
        },
                      banner='ftdi & ctx imported',
                      exitmsg='cleaning up!')
    finally:
        ftdi.free(ctx)
        print('done')
Exemplo n.º 9
0
print( 'Number of FTDI devices found: %d\n' % ret )
curnode = devlist
#i = 0
#while( curnode != None ):
#    ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdictx, curnode.dev )
#    if ret < 0:
#        print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) )
#        os._exit( 1 )
#    print( 'Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i, manufacturer, description, serial ) )
#    curnode = curnode.next
#    i += 1

# Open USB to the first FT232H							 
# TODO: Way to select which FT232H if multiple found, using usb_open_dev() with the device instance from devlist[]
ret = ftdi.usb_open( ftdictx, FT232H_VID, FT232H_PID )
if ret < 0:
    print( 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) )
    os._exit( 1 )

# Reset MPSSE by sending mask = 0x00 and mode = BITMODE_RESET
ret = ftdi.set_bitmode(ftdictx, 0x00, ftdi.BITMODE_RESET)
if ret < 0:
    print( 'unable to reset bitmode: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) )
    os._exit( 1 )

# Configure the mode (see http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232H.pdf, section 4
#  http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf,
#  and http://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8h.html#a2250f7812c87a96ada7fd4f19b82f666)
ret = ftdi.set_bitmode( ftdictx, 0x00, ftdi.BITMODE_SYNCBB )		# Synchronous BitBang, D0-D7 input
if ret < 0:
Exemplo n.º 10
0
curnode = devlist
i = 0
while (curnode != None):
    ret, manufacturer, description, serial = ftdi.usb_get_strings(
        ftdic, curnode.dev)
    if ret < 0:
        print('ftdi_usb_get_strings failed: %d (%s)' %
              (ret, ftdi.get_error_string(ftdic)))
        os._exit(1)
    print('Device #%d: manufacturer="%s" description="%s" serial="%s"\n' %
          (i, manufacturer, description, serial))
    curnode = curnode.next
    i += 1

# open usb
ret = ftdi.usb_open(ftdic, UM232H_B_VID, UM232H_B_PID)
if ret < 0:
    print('unable to open ftdi device: %d (%s)' %
          (ret, ftdi.get_error_string(ftdic)))
    os._exit(1)

## bitbang
#ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
#if ret < 0:
#print( 'Cannot enable bitbang' )
#os._exit( 1 )
#print( 'turning everything on' )
#ftdi.write_data( ftdic, chr(0xff), 1 )
#time.sleep( 1 )
#print( 'turning everything off\n' )
#ftdi.write_data( ftdic, chr(0x00), 1 )
Exemplo n.º 11
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
Tinkering that I did on Fedora 23 using this library:

http://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.2.tar.bz2
'''

import sys
import time
import ftdi1 as ftdi

# My DS_UM232H:
usb_vendor = 0x0403
usb_model = 0x6014

context = ftdi.new()

dev = ftdi.usb_open(context, usb_vendor, usb_model)

if dev < 0:
    print 'Failed to open.  :-('

while True:
    aa, bb = ftdi.read_data(context, 1000)
    if aa != 0:
        # print bb[:aa],
        sys.stdout.write(bb[:aa])
    else:
        time.sleep(0.01)
Exemplo n.º 12
0
def red(context):
    actuate(context, RED_ON)
    actuate(context, GREEN_OFF)


def green(context):
    # turn on Green light
    actuate(context, GREEN_ON)
    actuate(context, RED_OFF)


def off(context):
    actuate(context, RED_OFF)
    actuate(context, GREEN_OFF)


context = ftd.new()
ftd.usb_open(context, 0x0403, 0x6001)
ftd.set_bitmode(context, 0xff, ftd.BITMODE_BITBANG)
# Everything off --- shouldn't be necessary.
ftd.write_data(context, bytes([0x00]))

if len(sys.argv) == 1:
    off(context)
elif sys.argv[1] == 'red':
    red(context)
elif sys.argv[1] == 'green':
    green(context)
else:
    print("Usage: lavalamps [red|green]")
Exemplo n.º 13
0
    print( 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
    os._exit( 1 )
print( 'Number of FTDI devices found: %d\n' % ret )
curnode = devlist
i = 0
while( curnode != None ):
    ret, manufacturer, description, serial = ftdi.usb_get_strings( ftdic, curnode.dev )
    if ret < 0:
        print( 'ftdi_usb_get_strings failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
        os._exit( 1 )
    print( 'Device #%d: manufacturer="%s" description="%s" serial="%s"\n' % ( i, manufacturer, description, serial ) )
    curnode = curnode.next
    i += 1

# open usb
ret = ftdi.usb_open( ftdic, UM232H_B_VID, UM232H_B_PID  )
if ret < 0:
    print( 'unable to open ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) ) )
    os._exit( 1 )


## bitbang
#ret = ftdi.set_bitmode( ftdic, 0xff, ftdi.BITMODE_BITBANG )
#if ret < 0:
    #print( 'Cannot enable bitbang' )
    #os._exit( 1 )
#print( 'turning everything on' )
#ftdi.write_data( ftdic, chr(0xff), 1 )
#time.sleep( 1 )
#print( 'turning everything off\n' )
#ftdi.write_data( ftdic, chr(0x00), 1 )
Exemplo n.º 14
0
curnode = devlist
i = 0
while (curnode != None):
    ret, manufacturer, description, serial = ftdi.usb_get_strings(
        ftdic, curnode.dev)
    if ret < 0:
        print('ftdi_usb_get_strings failed: %d (%s)' %
              (ret, ftdi.get_error_string(ftdic)))
        os._exit(1)
    print('Device #%d: manufacturer="%s" description="%s" serial="%s"\n' %
          (i, manufacturer, description, serial))
    curnode = curnode.next
    i += 1

# open usb
ret = ftdi.usb_open(ftdic, 0x0403, 0x6001)
if ret < 0:
    print('unable to open ftdi device: %d (%s)' %
          (ret, ftdi.get_error_string(ftdic)))
    os._exit(1)

# bitbang
ret = ftdi.set_bitmode(ftdic, 0xff, ftdi.BITMODE_BITBANG)
if ret < 0:
    print('Cannot enable bitbang')
    os._exit(1)

#for i in range( 8 ):
val = 0x0
print('enabling bit #%d (0x%02x)' % (i, val))
ftdi.write_data(ftdic, chr(val))
Exemplo n.º 15
0
BG_BLUE = ANSI('\033[0;44m')
MAGENTA = ANSI('\033[0;35m')
MAGENTA2 = ANSI('\033[1;35m')
CYAN = ANSI('\033[0;36m')
CYAN2 = ANSI('\033[1;36m')
WHITE = ANSI('\033[0;37m')
WHITE2 = ANSI('\033[1;37m')


def BIT(x):
    return 1 << x


# Initialize FTDI device connection.
ctx = ftdi.new()
ftdi.usb_open(ctx, 0x263d, 0x4001)
ftdi.usb_reset(ctx)

# Disable flow control. Commented out because it is unclear if this is necessary.
#self._check(ftdi.setflowctrl, ftdi.SIO_DISABLE_FLOW_CTRL)

# Change read & write buffers to maximum size, 65535 bytes.
ftdi.read_data_set_chunksize(ctx, 65535)
ftdi.write_data_set_chunksize(ctx, 65535)

# Clear pending read data & write buffers.
ftdi.usb_purge_buffers(ctx)
# Reset MPSSE
ftdi.set_bitmode(ctx, 0, 0)
# Enable MPSSE
ftdi.set_bitmode(ctx, 0, 2)
Exemplo n.º 16
0
#!/usr/bin/python3

import ftdi1
f = ftdi1.new()
ftdi1.usb_open(f, 0x0403, 0x6001)
ftdi1.set_bitmode(f, 1, 0)
ftdi1.write_data(f, bytes([0]))
ftdi1.write_data(f, bytes([1]))
ftdi1.usb_close(f)
Exemplo n.º 17
0
curnode = devlist
i = 0
while(curnode != None):
    ret, manufacturer, description, serial = ftdi.usb_get_strings(
        ftdic, curnode.dev)
    if ret < 0:
        print('ftdi_usb_get_strings failed: %d (%s)' %
              (ret, ftdi.get_error_string(ftdic)))
        os._exit(1)
    print('#%d: manufacturer="%s" description="%s" serial="%s"\n' %
          (i, manufacturer, description, serial))
    curnode = curnode.next
    i += 1

# open usb
ret = ftdi.usb_open(ftdic, 0x0403, 0x6001)
if ret < 0:
    print('unable to open ftdi device: %d (%s)' %
          (ret, ftdi.get_error_string(ftdic)))
    os._exit(1)


# bitbang
ret = ftdi.set_bitmode(ftdic, 0xff, ftdi.BITMODE_BITBANG)
if ret < 0:
    print('Cannot enable bitbang')
    os._exit(1)
print('turning everything on')
ftdi.write_data(ftdic, chr(0xff), 1)
time.sleep(1)
print('turning everything off\n')