How to use pyftdi - 10 common examples

To help you get started, we’ve selected a few pyftdi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_default_param(self):
        with patch.object(Ftdi, 'find_all', return_value=[(0, 0, 'AD2', 1, 'AD2')]):
            device = USBDevice.find()

            self.assertEqual(device.interface, 'AD2')
github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_all_exception(self):
            with patch.object(Ftdi, 'find_all', side_effect=[USBError('testing'), FtdiError]) as mock:
                with self.assertRaises(CommError):
                    devices = USBDevice.find_all()

                with self.assertRaises(CommError):
                    devices = USBDevice.find_all()
github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_with_param(self):
            with patch.object(Ftdi, 'find_all', return_value=[(0, 0, 'AD2-1', 1, 'AD2'), (0, 0, 'AD2-2', 1, 'AD2')]):
                device = USBDevice.find((0, 0, 'AD2-1', 1, 'AD2'))
                self.assertEquals(device.interface, 'AD2-1')

                device = USBDevice.find((0, 0, 'AD2-2', 1, 'AD2'))
                self.assertEquals(device.interface, 'AD2-2')
github eblot / pyftdi / pyftdi / bits.py View on Github external
def __setitem__(self, index, value):
        if isinstance(value, BitSequence):
            if issubclass(value.__class__, self.__class__) and \
               value.__class__ != self.__class__:
                raise BitSequenceError("Cannot set item with instance of a "
                                       "subclass")
        if isinstance(index, slice):
            value = self.__class__(value, length=len(self._seq[index]))
            self._seq[index] = value.sequence()
        else:
            if not isinstance(value, BitSequence):
                value = self.__class__(value)
            val = value.tobit()
            if index > len(self._seq):
                raise BitSequenceError("Cannot change the sequence size")
            self._seq[index] = val
github OpenAgricultureFoundation / openag-device-software / scripts / i2c / usb-cable-leds.py View on Github external
if os.getenv("VIRTUAL_ENV") == None:
    print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance with the USB-I2C cable
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")

# Get our I2C bus multiplexer (MUX).  
# It's really a DAC that lets us have 8 different I2C busses.
mux_address = int(os.getenv("DEFAULT_MUX_ADDRESS"), 16)
i2c = i2c_controller.get_port(mux_address)

# Set MUX channel byte to 3, for the PFC_EDU board and 6 color LED DAC.
channel = int(3)
channel_byte = 0x01 << channel

# Write to the MUX, to set the channel number
i2c.write([channel_byte])

# Set up to talk to the LED DAC at I2C address 0x47
led_dac = i2c_controller.get_port(0x47)
github OpenAgricultureFoundation / openag-device-software / device / peripherals / common / dac5578 / scripts / usb-cable-set-one-port.py View on Github external
print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance
print("I2C cable init...")
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")
address = int(sys.argv[1], 16)
print("I2C address 0x{:2X}".format(address))
i2c = i2c_controller.get_port(address)

# Get the port from the command line
port = int(sys.argv[2])
byte = 0x30 + port

# Get the value in hex from the command line
value = int(sys.argv[3], 16)

# Set the port high
print("Port={} value={}/0x{:2X}".format(port, value, value))
i2c.write([byte, value, 0x00])
github OpenAgricultureFoundation / openag-device-software / device / peripherals / common / dac5578 / scripts / ft232_all_ports_low.py View on Github external
if os.getenv("VIRTUAL_ENV") == None:
    print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")
i2c = i2c_controller.get_port(0x47)

# Set all channels low
for i in range(8):
    byte = 0x30 + i
    i2c.write([byte, 0x00, 0x00])
github OpenAgricultureFoundation / openag-device-software / device / peripherals / common / dac5578 / scripts / usb-cable-toggle-relay.py View on Github external
print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance
print("I2C cable init...")
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")
address = int(sys.argv[1], 16)
print("I2C address 0x{:2X}".format(address))
i2c = i2c_controller.get_port(address)

# Get the port from the command line
port = int(sys.argv[2])
byte = 0x30 + port

# Toggle the port high, wait a sec, then low.
print("Port {} high...".format(port))
i2c.write([byte, 0xFF, 0x00])  # to high
time.sleep(2)
print("Port {} low...".format(port))
i2c.write([byte, 0x00, 0x00])  # to low
github OpenAgricultureFoundation / openag-device-software / device / peripherals / modules / t6713 / scripts / read_co2.py View on Github external
if os.getenv("VIRTUAL_ENV") == None:
    print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")
i2c = i2c_controller.get_port(0x15)

# Get co2 data bytes
i2c.write([0x04, 0x13, 0x8A, 0x00, 0x01])  # status
bytes_ = i2c.read(4)

# Parse co2 data bytes
_, _, msb, lsb = bytes_
co2 = float(msb * 256 + lsb)
co2 = round(co2, 0)
print("CO2: {} ppm".format(co2))
github OpenAgricultureFoundation / openag-device-software / device / peripherals / modules / t6713 / scripts / read_status.py View on Github external
if os.getenv("VIRTUAL_ENV") == None:
    print("Please activate your virtual environment then re-run script")
    exit(0)

# Ensure platform info is sourced
if os.getenv("PLATFORM") == None:
    print("Please source your platform info then re-run script")
    exit(0)

# Ensure platform is usb-to-i2c enabled
if os.getenv("IS_USB_I2C_ENABLED") != "true":
    print("Platform is not usb-to-i2c enabled")
    exit(0)

# Initialize i2c instance
i2c_controller = I2cController()
i2c_controller.configure("ftdi://ftdi:232h/1")
i2c = i2c_controller.get_port(0x15)

# Read data bytes
i2c.write([0x04, 0x13, 0x8B, 0x00, 0x01])
bytes_ = i2c.read(4)

# Parse data bytes
_, _, status_msb, status_lsb = bytes_
error_condition = (bool(bitwise.get_bit_from_byte(0, status_lsb)),)
flash_error = (bool(bitwise.get_bit_from_byte(1, status_lsb)),)
calibration_error = (bool(bitwise.get_bit_from_byte(2, status_lsb)),)
rs232 = (bool(bitwise.get_bit_from_byte(0, status_msb)),)
rs485 = (bool(bitwise.get_bit_from_byte(1, status_msb)),)
i2c_ = (bool(bitwise.get_bit_from_byte(2, status_msb)),)
warm_up_mode = (bool(bitwise.get_bit_from_byte(3, status_msb)),)